Search in sources :

Example 6 with RetryableHazelcastException

use of com.hazelcast.spi.exception.RetryableHazelcastException in project hazelcast by hazelcast.

the class PromotionCommitOperation method beforePromotion.

/**
 * Sends {@link BeforePromotionOperation}s for all promotions and register a callback on each operation to track when
 * operations are finished.
 */
private CallStatus beforePromotion() {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    InternalPartitionServiceImpl partitionService = getService();
    if (!partitionService.getMigrationManager().acquirePromotionPermit()) {
        throw new RetryableHazelcastException("Another promotion is being run currently. " + "This is only expected when promotion is retried to an unresponsive destination.");
    }
    long partitionStateStamp;
    partitionStateStamp = partitionService.getPartitionStateStamp();
    if (partitionState.getStamp() == partitionStateStamp) {
        return alreadyAppliedAllPromotions();
    }
    filterAlreadyAppliedPromotions();
    if (promotions.isEmpty()) {
        return alreadyAppliedAllPromotions();
    }
    ILogger logger = getLogger();
    migrationState = new MigrationStateImpl(Clock.currentTimeMillis(), promotions.size(), 0, 0L);
    partitionService.getMigrationInterceptor().onPromotionStart(MigrationParticipant.DESTINATION, promotions);
    partitionService.getPartitionEventManager().sendMigrationProcessStartedEvent(migrationState);
    if (logger.isFineEnabled()) {
        logger.fine("Submitting BeforePromotionOperations for " + promotions.size() + " promotions. " + "Promotion partition state stamp: " + partitionState.getStamp() + ", current partition state stamp: " + partitionStateStamp);
    }
    PromotionOperationCallback beforePromotionsCallback = new BeforePromotionOperationCallback(this, promotions.size());
    for (MigrationInfo promotion : promotions) {
        if (logger.isFinestEnabled()) {
            logger.finest("Submitting BeforePromotionOperation for promotion: " + promotion);
        }
        Operation op = new BeforePromotionOperation(promotion, beforePromotionsCallback);
        op.setPartitionId(promotion.getPartitionId()).setNodeEngine(nodeEngine).setService(partitionService);
        operationService.execute(op);
    }
    return CallStatus.VOID;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ILogger(com.hazelcast.logging.ILogger) MigrationStateImpl(com.hazelcast.internal.partition.MigrationStateImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationCycleOperation(com.hazelcast.internal.partition.MigrationCycleOperation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 7 with RetryableHazelcastException

use of com.hazelcast.spi.exception.RetryableHazelcastException 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 8 with RetryableHazelcastException

use of com.hazelcast.spi.exception.RetryableHazelcastException in project hazelcast by hazelcast.

the class Invocation_RetryTest method testNoStuckInvocationsWhenRetriedMultipleTimes.

@Test
public void testNoStuckInvocationsWhenRetriedMultipleTimes() throws Exception {
    Config config = new Config();
    config.setProperty(ClusterProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    NodeEngineImpl localNodeEngine = getNodeEngineImpl(local);
    NodeEngineImpl remoteNodeEngine = getNodeEngineImpl(remote);
    final OperationServiceImpl operationService = (OperationServiceImpl) localNodeEngine.getOperationService();
    NonResponsiveOperation op = new NonResponsiveOperation();
    op.setValidateTarget(false);
    op.setPartitionId(1);
    InvocationFuture future = (InvocationFuture) operationService.invokeOnTarget(null, op, remoteNodeEngine.getThisAddress());
    Field invocationField = InvocationFuture.class.getDeclaredField("invocation");
    invocationField.setAccessible(true);
    Invocation invocation = (Invocation) invocationField.get(future);
    invocation.notifyError(new RetryableHazelcastException());
    invocation.notifyError(new RetryableHazelcastException());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Iterator<Invocation> invocations = operationService.invocationRegistry.iterator();
            assertFalse(invocations.hasNext());
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) Config(com.hazelcast.config.Config) TimeoutException(java.util.concurrent.TimeoutException) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) Iterator(java.util.Iterator) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with RetryableHazelcastException

use of com.hazelcast.spi.exception.RetryableHazelcastException in project hazelcast by hazelcast.

the class CallerRunsPartitionScanExecutor method execute.

@Override
public Collection<QueryableEntry> execute(String mapName, Predicate predicate, Collection<Integer> partitions) {
    RetryableHazelcastException storedException = null;
    Collection<QueryableEntry> result = new ArrayList<QueryableEntry>();
    for (Integer partitionId : partitions) {
        try {
            result.addAll(partitionScanRunner.run(mapName, predicate, partitionId));
        } catch (RetryableHazelcastException e) {
            // see discussion at https://github.com/hazelcast/hazelcast/pull/5049#discussion_r28773099 for details.
            if (storedException == null) {
                storedException = e;
            }
        }
    }
    if (storedException != null) {
        throw storedException;
    }
    return result;
}
Also used : RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) ArrayList(java.util.ArrayList) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 10 with RetryableHazelcastException

use of com.hazelcast.spi.exception.RetryableHazelcastException in project hazelcast by hazelcast.

the class FetchPartitionStateOperation method run.

@Override
public void run() {
    final Address caller = getCallerAddress();
    final Address master = getNodeEngine().getMasterAddress();
    if (!caller.equals(master)) {
        final String msg = caller + " requested our partition table but it's not our known master. " + "Master: " + master;
        getLogger().warning(msg);
        throw new RetryableHazelcastException(msg);
    }
    InternalPartitionServiceImpl service = getService();
    partitionState = service.createPartitionStateInternal();
}
Also used : Address(com.hazelcast.nio.Address) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)

Aggregations

RetryableHazelcastException (com.hazelcast.spi.exception.RetryableHazelcastException)22 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)6 Address (com.hazelcast.cluster.Address)5 TopologyChangedException (com.hazelcast.jet.core.TopologyChangedException)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)3 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)3 MembershipManager (com.hazelcast.internal.cluster.impl.MembershipManager)3 TriggerMemberListPublishOp (com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp)3 ILogger (com.hazelcast.logging.ILogger)3 Address (com.hazelcast.nio.Address)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2 MemberLeftException (com.hazelcast.core.MemberLeftException)2 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)2 Predicate (com.hazelcast.query.Predicate)2 NodeEngine (com.hazelcast.spi.impl.NodeEngine)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2