use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.
the class JobExecutionService method onMemberRemoved.
/**
* Cancels executions that contain the leaving address as the coordinator or a
* job participant
*/
void onMemberRemoved(Member member) {
Address address = member.getAddress();
executionContexts.values().stream().filter(exeCtx -> exeCtx.coordinator() != null && (exeCtx.coordinator().equals(address) || exeCtx.hasParticipant(address))).forEach(exeCtx -> {
LoggingUtil.logFine(logger, "Completing %s locally. Reason: Member %s left the cluster", exeCtx.jobNameAndExecutionId(), address);
terminateExecution0(exeCtx, null, new MemberLeftException(member));
});
}
use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.
the class Invocation method initInvocationTarget.
/**
* Initializes the invocation target.
*
* @throws Exception if the initialization was a failure
*/
final void initInvocationTarget() throws Exception {
Member previousTargetMember = targetMember;
T target = getInvocationTarget();
if (target == null) {
throw newTargetNullException();
}
targetMember = toTargetMember(target);
if (targetMember != null) {
targetAddress = targetMember.getAddress();
} else {
targetAddress = toTargetAddress(target);
}
memberListVersion = context.clusterService.getMemberListVersion();
if (targetMember == null) {
if (previousTargetMember != null) {
// then it means a member left.
throw new MemberLeftException(previousTargetMember);
}
if (!(isJoinOperation(op) || isWanReplicationOperation(op))) {
throw new TargetNotMemberException(target, op.getPartitionId(), op.getClass().getName(), op.getServiceName());
}
}
if (op instanceof TargetAware) {
((TargetAware) op).setTarget(targetAddress);
}
}
use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.
the class XAResourceImpl method recover.
@Override
public Xid[] recover(int flag) throws XAException {
NodeEngine nodeEngine = getNodeEngine();
XAService xaService = getService();
OperationService operationService = nodeEngine.getOperationService();
ClusterService clusterService = nodeEngine.getClusterService();
Collection<Member> memberList = clusterService.getMembers();
List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
for (Member member : memberList) {
if (member.localMember()) {
continue;
}
CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
Address address = member.getAddress();
InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
futureList.add(future);
}
Set<SerializableXID> xids = new HashSet<SerializableXID>(xaService.getPreparedXids());
for (Future<SerializableList> future : futureList) {
try {
SerializableList xidSet = future.get();
for (Data xidData : xidSet) {
SerializableXID xid = nodeEngine.toObject(xidData);
xids.add(xid);
}
} catch (InterruptedException e) {
currentThread().interrupt();
throw new XAException(XAException.XAER_RMERR);
} catch (MemberLeftException e) {
logger.warning("Member left while recovering", e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
logger.warning("Member left while recovering", e);
} else {
throw new XAException(XAException.XAER_RMERR);
}
}
}
return xids.toArray(new SerializableXID[0]);
}
use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.
the class XACollectTransactionsMessageTask method reduce.
@Override
protected Object reduce(Map<Member, Object> map) throws Throwable {
List<Data> list = new ArrayList<>();
for (Object o : map.values()) {
if (o instanceof Throwable) {
if (o instanceof MemberLeftException) {
continue;
}
throw (Throwable) o;
}
SerializableList xidSet = (SerializableList) o;
list.addAll(xidSet.getCollection());
}
List<Xid> xidList = new ArrayList<>(list.size());
list.forEach(xidData -> xidList.add(serializationService.toObject(xidData)));
return xidList;
}
use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.
the class PromoteLiteMemberTest method promotion_shouldFail_whenMasterLeaves_duringPromotion.
@Test
public void promotion_shouldFail_whenMasterLeaves_duringPromotion() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance hz1 = factory.newHazelcastInstance(new Config());
HazelcastInstance hz2 = factory.newHazelcastInstance(new Config());
HazelcastInstance hz3 = factory.newHazelcastInstance(new Config().setLiteMember(true));
assertClusterSizeEventually(3, hz2);
dropOperationsBetween(hz3, hz1, F_ID, singletonList(PROMOTE_LITE_MEMBER));
Cluster cluster = hz3.getCluster();
Future<Exception> future = spawn(() -> {
try {
cluster.promoteLocalLiteMember();
} catch (Exception e) {
return e;
}
return null;
});
assertPromotionInvocationStarted(hz3);
hz1.getLifecycleService().terminate();
assertClusterSizeEventually(2, hz2, hz3);
Exception exception = future.get();
// MemberLeftException is wrapped by HazelcastException
assertInstanceOf(MemberLeftException.class, exception.getCause());
}
Aggregations