use of com.hazelcast.query.impl.GlobalIndexPartitionTracker.PartitionStamp in project hazelcast by hazelcast.
the class MapFetchIndexOperation method runInternal.
@Override
protected void runInternal() {
Indexes indexes = mapContainer.getIndexes();
if (indexes == null) {
throw QueryException.error(SqlErrorCode.INDEX_INVALID, "Cannot use the index \"" + indexName + "\" of the IMap \"" + name + "\" because it is not global " + "(make sure the property \"" + ClusterProperty.GLOBAL_HD_INDEX_ENABLED + "\" is set to \"true\")");
}
InternalIndex index = indexes.getIndex(indexName);
if (index == null) {
throw QueryException.error(SqlErrorCode.INDEX_INVALID, "Index \"" + indexName + "\" does not exist");
}
PartitionStamp indexStamp = index.getPartitionStamp();
if (indexStamp == null) {
throw new RetryableHazelcastException("Index is being rebuilt");
}
if (indexStamp.partitions.equals(partitionIdSet)) {
// We clear the requested partitionIdSet, which means that we won't filter out any partitions.
// This is an optimization for the case when there was no concurrent migration.
partitionIdSet = null;
} else {
if (!indexStamp.partitions.containsAll(partitionIdSet)) {
throw new MissingPartitionException("some requested partitions are not indexed");
}
}
switch(index.getConfig().getType()) {
case HASH:
response = runInternalHash(index);
break;
case SORTED:
response = runInternalSorted(index);
break;
case BITMAP:
throw new UnsupportedOperationException("BITMAP index scan is not implemented");
default:
throw new UnsupportedOperationException("Unknown index type: \"" + index.getConfig().getType().name() + "\"");
}
if (!index.validatePartitionStamp(indexStamp.stamp)) {
throw new MissingPartitionException("partition timestamp has changed");
}
}
use of com.hazelcast.query.impl.GlobalIndexPartitionTracker.PartitionStamp in project hazelcast by hazelcast.
the class GlobalIndexPartitionTrackerTest method test_stamp.
@Test
public void test_stamp() {
int count = 100;
GlobalIndexPartitionTracker tracker = new GlobalIndexPartitionTracker(count);
PartitionStamp stamp1 = tracker.getPartitionStamp();
assertEquals(new PartitionStamp(0, partitions(count)), stamp1);
assertTrue(tracker.validatePartitionStamp(stamp1.stamp));
tracker.beginPartitionUpdate();
assertNull(tracker.getPartitionStamp());
tracker.partitionIndexed(1);
PartitionStamp stamp2 = tracker.getPartitionStamp();
assertNotNull(stamp2);
assertEquals(stamp2.partitions, partitions(count, 1));
assertTrue(stamp2.stamp > stamp1.stamp);
assertFalse(tracker.validatePartitionStamp(stamp1.stamp));
assertTrue(tracker.validatePartitionStamp(stamp2.stamp));
tracker.clear();
PartitionStamp stamp3 = tracker.getPartitionStamp();
assertNotNull(stamp3);
assertEquals(stamp3.partitions, partitions(count));
assertTrue(stamp3.stamp > stamp2.stamp);
assertFalse(tracker.validatePartitionStamp(stamp1.stamp));
assertFalse(tracker.validatePartitionStamp(stamp2.stamp));
assertTrue(tracker.validatePartitionStamp(stamp3.stamp));
}
Aggregations