use of com.hazelcast.spi.exception.TargetNotMemberException 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.spi.exception.TargetNotMemberException 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.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.
the class TopologyChangeTest method when_coordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends.
private void when_coordinatorLeaves_AutoScalingOff_then_jobFailsOrSuspends(boolean snapshotted) throws Throwable {
// Given
HazelcastInstance client = createHazelcastClient();
DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, nodeCount)));
JobConfig config = new JobConfig();
config.setAutoScaling(false);
config.setProcessingGuarantee(snapshotted ? EXACTLY_ONCE : NONE);
// When
Job job = client.getJet().newJob(dag, config);
NoOutputSourceP.executionStarted.await();
instances[0].getLifecycleService().terminate();
NoOutputSourceP.proceedLatch.countDown();
assertTrueEventually(() -> {
JobStatus status = null;
while (status == null) {
try {
status = job.getStatus();
} catch (TargetNotMemberException ignored) {
}
}
assertEquals(snapshotted ? SUSPENDED : FAILED, status);
}, 10);
}
use of com.hazelcast.spi.exception.TargetNotMemberException in project hazelcast by hazelcast.
the class OperationServiceImpl_invokeOnTargetTest method whenNonExistingTarget.
@Test
public void whenNonExistingTarget() {
Address remoteAddress = getAddress(remote);
remote.shutdown();
// ensure local instance observes remote shutdown
assertClusterSizeEventually(1, local);
String expected = "foobar";
DummyOperation operation = new DummyOperation(expected) {
@Override
public ExceptionAction onInvocationException(Throwable throwable) {
// when TargetNotMemberException is get, invocation may fail with MemberLeftException too.
if (throwable instanceof TargetNotMemberException) {
return ExceptionAction.THROW_EXCEPTION;
}
return super.onInvocationException(throwable);
}
};
InternalCompletableFuture<String> invocation = operationService.invokeOnTarget(null, operation, remoteAddress);
try {
invocation.joinInternal();
fail();
} catch (TargetNotMemberException e) {
}
}
Aggregations