use of com.hazelcast.core.MemberLeftException 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.core.MemberLeftException in project hazelcast by hazelcast.
the class MemberListTest method testOutOfSyncMemberList.
/*
* Sets up a situation where node3 removes the master and sets node2 as the
* master but none of the other nodes do. This means that node3 thinks node2
* is master but node2 thinks node1 is master.
*/
@Test
public void testOutOfSyncMemberList() throws Exception {
List<HazelcastInstance> instanceList = buildInstances(3, 25701);
final HazelcastInstance h1 = instanceList.get(0);
final HazelcastInstance h2 = instanceList.get(1);
final HazelcastInstance h3 = instanceList.get(2);
// All three nodes join into one cluster
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
// This simulates each node reading from the other nodes in the list at regular intervals
// This prevents the heart beat code from timing out
final HazelcastInstance[] instances = new HazelcastInstance[] { h1, h2, h3 };
final AtomicBoolean doingWork = new AtomicBoolean(true);
Thread[] workThreads = new Thread[instances.length];
for (int i = 0; i < instances.length; i++) {
final int threadNum = i;
workThreads[threadNum] = new Thread(new Runnable() {
public void run() {
while (doingWork.get()) {
final HazelcastInstance hz = instances[threadNum];
Set<Member> members = new HashSet<Member>(hz.getCluster().getMembers());
members.remove(hz.getCluster().getLocalMember());
final Map<Member, Future<String>> futures = hz.getExecutorService("test").submitToMembers(new PingCallable(), members);
for (Future<String> f : futures.values()) {
try {
f.get();
} catch (MemberLeftException ignored) {
} catch (Exception e) {
e.printStackTrace();
}
}
sleepSeconds(2);
}
}
});
workThreads[threadNum].start();
}
final Node n3 = TestUtil.getNode(h3);
n3.clusterService.removeAddress(h1.getCluster().getLocalMember().getAddress(), null);
// Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
sleepSeconds(30);
doingWork.set(false);
for (Thread t : workThreads) {
t.join();
}
assertClusterSize(3, h1);
assertClusterSize(3, h2);
assertClusterSize(3, h3);
}
use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.
the class AuthenticationBaseMessageTask method reduce.
@Override
protected Object reduce(Map<Member, Object> map) throws Throwable {
for (Map.Entry<Member, Object> entry : map.entrySet()) {
Member member = entry.getKey();
Object response = entry.getValue();
if (response instanceof Throwable) {
if (response instanceof MemberLeftException) {
cleanedUpMembers.add(member);
continue;
}
throw (Throwable) response;
}
boolean isClientDisconnectOperationRun = (Boolean) response;
if (isClientDisconnectOperationRun) {
cleanedUpMembers.add(member);
}
}
return prepareAuthenticatedClientMessage();
}
use of com.hazelcast.core.MemberLeftException in project hazelcast by hazelcast.
the class SerializationTest method testMemberLeftException.
private void testMemberLeftException(String uuid, String host, int port, Member member) throws Exception {
MemberLeftException exception = new MemberLeftException(member);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(exception);
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
ObjectInputStream in = new ObjectInputStream(bin);
MemberLeftException exception2 = (MemberLeftException) in.readObject();
MemberImpl member2 = (MemberImpl) exception2.getMember();
assertEquals(uuid, member2.getUuid());
assertEquals(host, member2.getAddress().getHost());
assertEquals(port, member2.getAddress().getPort());
assertEquals(member.isLiteMember(), member2.isLiteMember());
assertEquals(member.getVersion(), member2.getVersion());
}
use of com.hazelcast.core.MemberLeftException 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);
}
}
Aggregations