use of com.hazelcast.spi.impl.operationservice.impl.InvocationFuture in project hazelcast by hazelcast.
the class JobExecutionService method checkExecutions.
/**
* See also javadoc at {@link CheckLightJobsOperation}.
*/
private void checkExecutions() {
try {
long now = System.nanoTime();
long uninitializedContextThreshold = now - UNINITIALIZED_CONTEXT_MAX_AGE_NS;
Map<Address, List<Long>> executionsPerMember = new HashMap<>();
for (ExecutionContext ctx : executionContexts.values()) {
if (!ctx.isLightJob()) {
continue;
}
Address coordinator = ctx.coordinator();
if (coordinator != null) {
// if coordinator is known, add execution to the list to check
executionsPerMember.computeIfAbsent(coordinator, k -> new ArrayList<>()).add(ctx.executionId());
} else {
// if coordinator is not known, remove execution if it's not known for too long
if (ctx.getCreatedOn() <= uninitializedContextThreshold) {
LoggingUtil.logFine(logger, "Terminating light job %s because it wasn't initialized during %d seconds", idToString(ctx.executionId()), NANOSECONDS.toSeconds(UNINITIALIZED_CONTEXT_MAX_AGE_NS));
terminateExecution0(ctx, TerminationMode.CANCEL_FORCEFUL, new CancellationException());
}
}
}
// submit the query to the coordinator
for (Entry<Address, List<Long>> en : executionsPerMember.entrySet()) {
long[] executionIds = en.getValue().stream().mapToLong(Long::longValue).toArray();
Operation op = new CheckLightJobsOperation(executionIds);
InvocationFuture<long[]> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, op, en.getKey()).invoke();
future.whenComplete((r, t) -> {
if (t instanceof TargetNotMemberException) {
// if the target isn't a member, then all executions are unknown
r = executionIds;
} else if (t != null) {
logger.warning("Failed to check light job state with coordinator " + en.getKey() + ": " + t, t);
return;
}
assert r != null;
for (long executionId : r) {
ExecutionContext execCtx = executionContexts.get(executionId);
if (execCtx != null) {
logger.fine("Terminating light job " + idToString(executionId) + " because the coordinator doesn't know it");
terminateExecution0(execCtx, TerminationMode.CANCEL_FORCEFUL, new CancellationException());
}
}
});
}
// clean up failedJobs
failedJobs.values().removeIf(expiryTime -> expiryTime < now);
} catch (Throwable e) {
logger.severe("Failed to query live light executions: " + e, e);
}
}
use of com.hazelcast.spi.impl.operationservice.impl.InvocationFuture in project hazelcast by hazelcast.
the class ScheduledFutureProxy method dispose.
@Override
public void dispose() {
checkAccessibleHandler();
checkAccessibleOwner();
Operation op = new DisposeTaskOperation(handler);
InvocationFuture future = invoke(op);
handler = null;
future.joinInternal();
}
use of com.hazelcast.spi.impl.operationservice.impl.InvocationFuture in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submit.
@Nonnull
@Override
public <T> Future<T> submit(@Nonnull Runnable task, T result) {
checkNotNull(task, "task must not be null");
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Callable<T> callable = createRunnableAdapter(task);
Data callableData = nodeEngine.toData(callable);
UUID uuid = newUnsecureUUID();
int partitionId = getTaskPartitionId(callable);
Operation op = new CallableTaskOperation(name, uuid, callableData).setPartitionId(partitionId);
InvocationFuture future = invokeOnPartition(op);
return new CancellableDelegatingFuture<>(future, result, nodeEngine, uuid, partitionId);
}
use of com.hazelcast.spi.impl.operationservice.impl.InvocationFuture 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);
}
}
use of com.hazelcast.spi.impl.operationservice.impl.InvocationFuture in project hazelcast by hazelcast.
the class PartitionServiceProxy method isMemberSafe.
@Override
public boolean isMemberSafe(Member member) {
if (member == null) {
throw new NullPointerException("Parameter member must not be null");
}
final Member localMember = nodeEngine.getLocalMember();
if (localMember.equals(member)) {
return isLocalMemberSafe();
}
final Address target = member.getAddress();
final Operation operation = new SafeStateCheckOperation();
final InvocationFuture future = nodeEngine.getOperationService().invokeOnTarget(InternalPartitionService.SERVICE_NAME, operation, target);
boolean safe;
try {
final Object result = future.get(10, TimeUnit.SECONDS);
safe = (Boolean) result;
} catch (Throwable t) {
safe = false;
logger.warning("Error while querying member's safe state [" + member + "]", t);
}
return safe;
}
Aggregations