Search in sources :

Example 16 with RetryableHazelcastException

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

the class ClusterServiceImpl method handleMastershipClaim.

public MembersView handleMastershipClaim(@Nonnull Address candidateAddress, @Nonnull UUID candidateUuid) {
    checkNotNull(candidateAddress);
    checkNotNull(candidateUuid);
    checkFalse(getThisAddress().equals(candidateAddress), "cannot accept my own mastership claim!");
    lock.lock();
    try {
        checkTrue(isJoined(), candidateAddress + " claims mastership but this node is not joined!");
        checkFalse(isMaster(), candidateAddress + " claims mastership but this node is master!");
        MemberImpl masterCandidate = membershipManager.getMember(candidateAddress, candidateUuid);
        checkTrue(masterCandidate != null, candidateAddress + " claims mastership but it is not a member!");
        MemberMap memberMap = membershipManager.getMemberMap();
        if (!shouldAcceptMastership(memberMap, masterCandidate)) {
            String message = "Cannot accept mastership claim of " + candidateAddress + " at the moment. There are more suitable master candidates in the member list.";
            logger.fine(message);
            throw new RetryableHazelcastException(message);
        }
        if (!membershipManager.clearMemberSuspicion(masterCandidate, "Mastership claim")) {
            throw new IllegalStateException("Cannot accept mastership claim of " + candidateAddress + ". " + getMasterAddress() + " is already master.");
        }
        setMasterAddress(masterCandidate.getAddress());
        MembersView response = memberMap.toTailMembersView(masterCandidate, true);
        logger.warning("Mastership of " + candidateAddress + " is accepted. Response: " + response);
        return response;
    } finally {
        lock.unlock();
    }
}
Also used : RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) MemberImpl(com.hazelcast.cluster.impl.MemberImpl)

Example 17 with RetryableHazelcastException

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

the class BaseMigrationOperation method setActiveMigration.

/**
 * Sets the active migration and the partition migration flag.
 */
void setActiveMigration() {
    InternalPartitionServiceImpl partitionService = getService();
    MigrationManager migrationManager = partitionService.getMigrationManager();
    MigrationInfo currentActiveMigration = migrationManager.addActiveMigration(migrationInfo);
    if (currentActiveMigration != null) {
        if (migrationInfo.equals(currentActiveMigration)) {
            migrationInfo = currentActiveMigration;
            return;
        }
        throw new RetryableHazelcastException("Cannot set active migration to " + migrationInfo + ". Current active migration is " + currentActiveMigration);
    }
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    if (!partitionStateManager.trySetMigratingFlag(migrationInfo.getPartitionId())) {
        throw new RetryableHazelcastException("Cannot set migrating flag, " + "probably previous migration's finalization is not completed yet.");
    }
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) MigrationManager(com.hazelcast.internal.partition.impl.MigrationManager) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 18 with RetryableHazelcastException

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

the class BaseMigrationOperation method verifyMaster.

/**
 * Verifies that the local master is equal to the migration master.
 */
final void verifyMaster() {
    NodeEngine nodeEngine = getNodeEngine();
    InternalPartitionServiceImpl service = getService();
    Address masterAddress = nodeEngine.getMasterAddress();
    if (!migrationInfo.getMaster().equals(masterAddress)) {
        if (!nodeEngine.isRunning()) {
            throw new HazelcastInstanceNotActiveException();
        }
        throw new IllegalStateException("Migration initiator is not master node! => " + toString());
    }
    if (!service.isMemberMaster(migrationInfo.getMaster())) {
        throw new RetryableHazelcastException("Migration initiator is not the master node known by migration system!");
    }
    if (getMigrationParticipantType() == MigrationParticipant.SOURCE && !service.isMemberMaster(getCallerAddress())) {
        throw new IllegalStateException("Caller is not master node! => " + toString());
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) Address(com.hazelcast.cluster.Address) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)

Example 19 with RetryableHazelcastException

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

the class PromotionCommitOperation method beforeRun.

@Override
public void beforeRun() throws Exception {
    if (runStage != RunStage.BEFORE_PROMOTION) {
        return;
    }
    NodeEngine nodeEngine = getNodeEngine();
    final Member localMember = nodeEngine.getLocalMember();
    if (!localMember.getUuid().equals(expectedMemberUuid)) {
        throw new IllegalStateException("This " + localMember + " is promotion commit destination but most probably it's restarted " + "and not the expected target.");
    }
    Address masterAddress = nodeEngine.getMasterAddress();
    Address caller = getCallerAddress();
    if (!caller.equals(masterAddress)) {
        throw new IllegalStateException("Caller is not master node! Caller: " + caller + ", Master: " + masterAddress);
    }
    InternalPartitionServiceImpl partitionService = getService();
    if (!partitionService.isMemberMaster(caller)) {
        throw new RetryableHazelcastException("Caller is not master node known by migration system! Caller: " + caller);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) Member(com.hazelcast.cluster.Member)

Example 20 with RetryableHazelcastException

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

the class LocalRetryableExecution method sendResponse.

@Override
public void sendResponse(Operation op, Object response) {
    tryCount++;
    if (response instanceof RetryableHazelcastException && tryCount < invocationMaxRetryCount) {
        Level level = tryCount > LOG_MAX_INVOCATION_COUNT ? WARNING : FINEST;
        if (logger.isLoggable(level)) {
            logger.log(level, "Retrying local execution: " + toString() + ", Reason: " + response);
        }
        nodeEngine.getExecutionService().schedule(this, invocationRetryPauseMillis, TimeUnit.MILLISECONDS);
    } else {
        this.response = response;
        done.countDown();
    }
}
Also used : RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) Level(java.util.logging.Level)

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