Search in sources :

Example 1 with PartitionStamp

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");
    }
}
Also used : InternalIndex(com.hazelcast.query.impl.InternalIndex) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) PartitionStamp(com.hazelcast.query.impl.GlobalIndexPartitionTracker.PartitionStamp) Indexes(com.hazelcast.query.impl.Indexes)

Example 2 with PartitionStamp

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));
}
Also used : PartitionStamp(com.hazelcast.query.impl.GlobalIndexPartitionTracker.PartitionStamp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PartitionStamp (com.hazelcast.query.impl.GlobalIndexPartitionTracker.PartitionStamp)2 Indexes (com.hazelcast.query.impl.Indexes)1 InternalIndex (com.hazelcast.query.impl.InternalIndex)1 RetryableHazelcastException (com.hazelcast.spi.exception.RetryableHazelcastException)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1