use of com.hazelcast.internal.metrics.ProbeUnit.BOOLEAN in project hazelcast by hazelcast.
the class MigrationManager method commitMigrationToDestinationAsync.
/**
* Sends a {@link MigrationCommitOperation} to the destination and returns {@code true} if the new partition state
* was applied on the destination.
*/
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:methodlength" })
private CompletionStage<Boolean> commitMigrationToDestinationAsync(final MigrationInfo migration) {
PartitionReplica destination = migration.getDestination();
if (destination.isIdentical(node.getLocalMember())) {
if (logger.isFinestEnabled()) {
logger.finest("Shortcutting migration commit, since destination is master. -> " + migration);
}
return CompletableFuture.completedFuture(Boolean.TRUE);
}
Member member = node.getClusterService().getMember(destination.address(), destination.uuid());
if (member == null) {
logger.warning("Cannot commit " + migration + ". Destination " + destination + " is not a member anymore");
return CompletableFuture.completedFuture(Boolean.FALSE);
}
try {
if (logger.isFinestEnabled()) {
logger.finest("Sending migration commit operation to " + destination + " for " + migration);
}
migration.setStatus(MigrationStatus.SUCCESS);
UUID destinationUuid = member.getUuid();
MigrationCommitOperation operation = new MigrationCommitOperation(migration, destinationUuid);
InvocationFuture<Boolean> future = nodeEngine.getOperationService().createInvocationBuilder(SERVICE_NAME, operation, destination.address()).setTryCount(Integer.MAX_VALUE).setCallTimeout(memberHeartbeatTimeoutMillis).invoke();
return future.handleAsync((done, t) -> {
// Inspect commit result;
// - if there's an exception, either retry or fail
// - if result is true then success, otherwise failure
logger.fine("Migration commit response received -> " + migration + ", success: " + done + ", failure: " + t);
if (t != null) {
logMigrationCommitFailure(migration, t);
if (t instanceof OperationTimeoutException || t.getCause() instanceof OperationTimeoutException) {
return COMMIT_RETRY;
}
return COMMIT_FAILURE;
}
return done ? COMMIT_SUCCESS : COMMIT_FAILURE;
}, asyncExecutor).thenComposeAsync(result -> {
switch(result) {
case COMMIT_SUCCESS:
return CompletableFuture.completedFuture(true);
case COMMIT_FAILURE:
return CompletableFuture.completedFuture(false);
case COMMIT_RETRY:
logger.fine("Retrying migration commit for -> " + migration);
return commitMigrationToDestinationAsync(migration);
default:
throw new IllegalArgumentException("Unknown migration commit result: " + result);
}
}, asyncExecutor).handleAsync((result, t) -> {
if (t != null) {
logMigrationCommitFailure(migration, t);
return false;
}
if (logger.isFineEnabled()) {
logger.fine("Migration commit result " + result + " from " + destination + " for " + migration);
}
return result;
}, asyncExecutor);
} catch (Throwable t) {
logMigrationCommitFailure(migration, t);
return CompletableFuture.completedFuture(Boolean.FALSE);
}
}
Aggregations