use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class AbstractPartitionOperation method createFragmentReplicationOperations.
final Collection<Operation> createFragmentReplicationOperations(PartitionReplicationEvent event, ServiceNamespace ns) {
assert !(ns instanceof NonFragmentedServiceNamespace) : ns + " should be used only for fragmented services!";
assertRunningOnPartitionThread();
Collection<Operation> operations = emptySet();
NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
Collection<ServiceInfo> services = nodeEngine.getServiceInfos(FragmentedMigrationAwareService.class);
for (ServiceInfo serviceInfo : services) {
FragmentedMigrationAwareService service = serviceInfo.getService();
if (!service.isKnownServiceNamespace(ns)) {
continue;
}
operations = prepareAndAppendReplicationOperation(event, ns, service, serviceInfo.getName(), operations);
}
return operations;
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class AbstractPartitionOperation method prepareAndAppendReplicationOperation.
private Collection<Operation> prepareAndAppendReplicationOperation(PartitionReplicationEvent event, ServiceNamespace ns, FragmentedMigrationAwareService service, String serviceName, Collection<Operation> operations) {
Operation op = service.prepareReplicationOperation(event, singleton(ns));
if (op == null) {
return operations;
}
op.setServiceName(serviceName);
if (isEmpty(operations)) {
operations = newSetOf(operations);
}
operations.add(op);
return operations;
}
use of com.hazelcast.spi.impl.operationservice.Operation 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;
}
use of com.hazelcast.spi.impl.operationservice.Operation 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.Operation in project hazelcast by hazelcast.
the class MasterJobContext method tryStartJob.
/**
* Starts the execution of the job if it is not already completed,
* cancelled or failed.
* <p>
* If the job is already cancelled, triggers the job completion procedure.
* <p>
* If the job quorum is not satisfied, reschedules the job restart.
* <p>
* If there was a membership change and the partition table is not completely
* fixed yet, reschedules the job restart.
*/
void tryStartJob(Supplier<Long> executionIdSupplier) {
mc.coordinationService().submitToCoordinatorThread(() -> {
executionStartTime = System.currentTimeMillis();
try {
JobExecutionRecord jobExecRec = mc.jobExecutionRecord();
jobExecRec.markExecuted();
Tuple2<DAG, ClassLoader> dagAndClassloader = resolveDagAndCL(executionIdSupplier);
if (dagAndClassloader == null) {
return;
}
DAG dag = dagAndClassloader.f0();
assert dag != null;
ClassLoader classLoader = dagAndClassloader.f1();
// must call this before rewriteDagWithSnapshotRestore()
String dotRepresentation = dag.toDotString(defaultParallelism, defaultQueueSize);
long snapshotId = jobExecRec.snapshotId();
String snapshotName = mc.jobConfig().getInitialSnapshotName();
String mapName = snapshotId >= 0 ? jobExecRec.successfulSnapshotDataMapName(mc.jobId()) : snapshotName != null ? EXPORTED_SNAPSHOTS_PREFIX + snapshotName : null;
if (mapName != null) {
rewriteDagWithSnapshotRestore(dag, snapshotId, mapName, snapshotName);
} else {
logger.info("Didn't find any snapshot to restore for " + mc.jobIdString());
}
MembersView membersView = Util.getMembersView(mc.nodeEngine());
logger.info("Start executing " + mc.jobIdString() + ", execution graph in DOT format:\n" + dotRepresentation + "\nHINT: You can use graphviz or http://viz-js.com to visualize the printed graph.");
logger.fine("Building execution plan for " + mc.jobIdString());
Util.doWithClassLoader(classLoader, () -> mc.setExecutionPlanMap(createExecutionPlans(mc.nodeEngine(), membersView.getMembers(), dag, mc.jobId(), mc.executionId(), mc.jobConfig(), jobExecRec.ongoingSnapshotId(), false, mc.jobRecord().getSubject())));
logger.fine("Built execution plans for " + mc.jobIdString());
Set<MemberInfo> participants = mc.executionPlanMap().keySet();
Version coordinatorVersion = mc.nodeEngine().getLocalMember().getVersion().asVersion();
Function<ExecutionPlan, Operation> operationCtor = plan -> new InitExecutionOperation(mc.jobId(), mc.executionId(), membersView.getVersion(), coordinatorVersion, participants, mc.nodeEngine().getSerializationService().toData(plan), false);
mc.invokeOnParticipants(operationCtor, this::onInitStepCompleted, null, false);
} catch (Throwable e) {
finalizeJob(e);
}
});
}
Aggregations