use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.
the class ClusterStateManager method changeClusterState.
void changeClusterState(ClusterStateChange newState, Collection<Member> members, TransactionOptions options, int partitionStateVersion, boolean isTransient) {
checkParameters(newState, options);
if (isCurrentStateEqualToRequestedOne(newState)) {
return;
}
NodeEngineImpl nodeEngine = node.getNodeEngine();
TransactionManagerServiceImpl txManagerService = (TransactionManagerServiceImpl) nodeEngine.getTransactionManagerService();
Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options);
tx.begin();
try {
String txnId = tx.getTxnId();
addTransactionRecords(newState, tx, members, partitionStateVersion, isTransient);
lockClusterStateOnAllMembers(newState, nodeEngine, options.getTimeoutMillis(), txnId, members, partitionStateVersion);
checkMemberListChange(members);
tx.prepare();
} catch (Throwable e) {
tx.rollback();
throw ExceptionUtil.rethrow(e);
}
try {
tx.commit();
} catch (Throwable e) {
if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
// if new state is passive or frozen. They will be able to rejoin later.
return;
}
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.
the class ClusterStateManager method changeClusterState.
void changeClusterState(@Nonnull ClusterStateChange stateChange, @Nonnull MemberMap memberMap, @Nonnull TransactionOptions options, long partitionStateStamp, boolean isTransient) {
checkParameters(stateChange, options);
if (isCurrentStateEqualToRequestedOne(stateChange)) {
return;
}
ClusterState oldState = getState();
ClusterState requestedState = stateChange.getClusterStateOrNull();
NodeEngineImpl nodeEngine = node.getNodeEngine();
TransactionManagerServiceImpl txManagerService = (TransactionManagerServiceImpl) nodeEngine.getTransactionManagerService();
Transaction tx = txManagerService.newAllowedDuringPassiveStateTransaction(options);
notifyBeforeStateChange(oldState, requestedState, isTransient);
tx.begin();
try {
UUID txnId = tx.getTxnId();
Collection<MemberImpl> members = memberMap.getMembers();
int memberListVersion = memberMap.getVersion();
addTransactionRecords(stateChange, tx, members, memberListVersion, partitionStateStamp, isTransient);
lockClusterStateOnAllMembers(stateChange, nodeEngine, options.getTimeoutMillis(), txnId, members, memberListVersion, partitionStateStamp);
checkMemberListChange(memberListVersion);
tx.prepare();
} catch (Throwable e) {
tx.rollback();
notifyAfterStateChange(oldState, requestedState, isTransient);
if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
throw new IllegalStateException("Cluster members changed during state change!", e);
}
throw ExceptionUtil.rethrow(e);
}
try {
tx.commit();
} catch (Throwable e) {
if (e instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException) {
// if new state is passive or frozen. They will be able to rejoin later.
return;
}
throw ExceptionUtil.rethrow(e);
} finally {
notifyAfterStateChange(oldState, requestedState, isTransient);
}
}
use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.
the class BaseMigrationOperation method verifyExistingDestination.
/**
* Verifies that the destination is a cluster member.
*/
final void verifyExistingDestination() {
PartitionReplica destination = migrationInfo.getDestination();
Member target = getNodeEngine().getClusterService().getMember(destination.address(), destination.uuid());
if (target == null) {
throw new TargetNotMemberException("Destination of migration could not be found! => " + toString());
}
}
use of com.hazelcast.spi.exception.TargetNotMemberException 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.exception.TargetNotMemberException in project hazelcast by hazelcast.
the class JetInstanceImpl method getJobsInt.
@Override
public Map<Address, GetJobIdsResult> getJobsInt(String onlyName, Long onlyJobId) {
Map<Address, CompletableFuture<GetJobIdsResult>> futures = new HashMap<>();
Address masterAddress = null;
// if onlyName != null, only send the operation to master. Light jobs cannot have a name
Collection<Member> targetMembers = onlyName == null ? nodeEngine.getClusterService().getMembers(DATA_MEMBER_SELECTOR) : singleton(nodeEngine.getClusterService().getMembers().iterator().next());
for (Member member : targetMembers) {
if (masterAddress == null) {
masterAddress = member.getAddress();
}
GetJobIdsOperation operation = new GetJobIdsOperation(onlyName, onlyJobId);
InvocationFuture<GetJobIdsResult> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, operation, member.getAddress()).invoke();
futures.put(member.getAddress(), future);
}
Map<Address, GetJobIdsResult> res = new HashMap<>(futures.size());
for (Entry<Address, CompletableFuture<GetJobIdsResult>> en : futures.entrySet()) {
GetJobIdsResult result;
try {
result = en.getValue().get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
result = GetJobIdsResult.EMPTY;
} catch (ExecutionException e) {
// important. If we don't get response from the master, we report it to the user.
if (!en.getKey().equals(masterAddress) && (e.getCause() instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException)) {
result = GetJobIdsResult.EMPTY;
} else {
throw new RuntimeException("Error when getting job IDs: " + e, e);
}
}
res.put(en.getKey(), result);
}
return res;
}
Aggregations