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();
}
}
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.");
}
}
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());
}
}
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);
}
}
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();
}
}
Aggregations