use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class RaftService method removeCPMember.
public InternalCompletableFuture<Void> removeCPMember(UUID cpMemberUuid) {
ClusterService clusterService = nodeEngine.getClusterService();
InternalCompletableFuture<Void> future = newCompletableFuture();
BiConsumer<Void, Throwable> removeMemberCallback = (response, t) -> {
if (t == null) {
future.complete(null);
} else {
if (t instanceof CannotRemoveCPMemberException) {
t = new IllegalStateException(t.getMessage());
}
complete(future, t);
}
};
invocationManager.<Collection<CPMember>>invoke(getMetadataGroupId(), new GetActiveCPMembersOp()).whenCompleteAsync((cpMembers, t) -> {
if (t == null) {
CPMemberInfo cpMemberToRemove = null;
for (CPMember cpMember : cpMembers) {
if (cpMember.getUuid().equals(cpMemberUuid)) {
cpMemberToRemove = (CPMemberInfo) cpMember;
break;
}
}
if (cpMemberToRemove == null) {
complete(future, new IllegalArgumentException("No CPMember found with uuid: " + cpMemberUuid));
return;
} else {
Member member = clusterService.getMember(cpMemberToRemove.getAddress());
if (member != null) {
logger.warning("Only unreachable/crashed CP members should be removed. " + member + " is alive but " + cpMemberToRemove + " with the same address is being removed.");
}
}
invokeTriggerRemoveMember(cpMemberToRemove).whenCompleteAsync(removeMemberCallback);
} else {
complete(future, t);
}
});
return future;
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class RaftService method resetCPSubsystem.
InternalCompletableFuture<Void> resetCPSubsystem() {
checkState(cpSubsystemEnabled, "CP Subsystem is not enabled!");
InternalCompletableFuture<Void> future = newCompletableFuture();
ClusterService clusterService = nodeEngine.getClusterService();
Collection<Member> members = clusterService.getMembers(NON_LOCAL_MEMBER_SELECTOR);
if (!clusterService.isMaster()) {
return complete(future, new IllegalStateException("Only master can reset CP Subsystem!"));
}
if (config.getCPMemberCount() > members.size() + 1) {
return complete(future, new IllegalStateException("Not enough cluster members to reset CP Subsystem! " + "Required: " + config.getCPMemberCount() + ", available: " + (members.size() + 1)));
}
BiConsumer<Void, Throwable> callback = new BiConsumer<Void, Throwable>() {
final AtomicInteger latch = new AtomicInteger(members.size());
volatile Throwable failure;
@Override
public void accept(Void aVoid, Throwable throwable) {
if (throwable == null) {
if (latch.decrementAndGet() == 0) {
if (failure == null) {
future.complete(null);
} else {
complete(future, failure);
}
}
} else {
failure = throwable;
if (latch.decrementAndGet() == 0) {
complete(future, throwable);
}
}
}
};
long seed = newSeed();
logger.warning("Resetting CP Subsystem with groupId seed: " + seed);
resetLocal(seed);
OperationServiceImpl operationService = nodeEngine.getOperationService();
for (Member member : members) {
Operation op = new ResetCPMemberOp(seed);
operationService.<Void>invokeOnTarget(SERVICE_NAME, op, member.getAddress()).whenCompleteAsync(callback);
}
return future;
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class ConsoleApp method handleExecutorSimulate.
private void handleExecutorSimulate(String[] args) {
String first = args[0];
int threadCount = Integer.parseInt(first.substring(1, first.indexOf(".")));
if (threadCount < 1 || threadCount > 16) {
throw new RuntimeException("threadCount can't be smaller than 1 or larger than 16");
}
int taskCount = Integer.parseInt(args[1]);
int durationSec = Integer.parseInt(args[2]);
long startMs = System.currentTimeMillis();
IExecutorService executor = hazelcast.getExecutorService(EXECUTOR_NAMESPACE + " " + threadCount);
List<Future> futures = new LinkedList<>();
List<Member> members = new LinkedList<>(hazelcast.getCluster().getMembers());
int totalThreadCount = hazelcast.getCluster().getMembers().size() * threadCount;
int latchId = 0;
for (int i = 0; i < taskCount; i++) {
Member member = members.get(i % members.size());
if (taskCount % totalThreadCount == 0) {
latchId = taskCount / totalThreadCount;
hazelcast.getCPSubsystem().getCountDownLatch("latch" + latchId).trySetCount(totalThreadCount);
}
Future f = executor.submitToMember(new SimulateLoadTask(durationSec, i + 1, "latch" + latchId), member);
futures.add(f);
}
for (Future f : futures) {
try {
f.get();
} catch (InterruptedException e) {
currentThread().interrupt();
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
long durationMs = System.currentTimeMillis() - startMs;
println(format("Executed %s tasks in %s ms", taskCount, durationMs));
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class TestProcessorContextTest method test.
@Test
public void test() throws Exception {
Address a0 = new Address("1.2.3.4", 0);
TestProcessorContext c = new TestProcessorContext().setPartitionAssignment(ImmutableMap.of(a0, new int[] { 0, 3, 6 }));
HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
Cluster mockCluster = mock(Cluster.class);
when(mockHazelcastInstance.getCluster()).thenReturn(mockCluster);
Member mockMember = mock(Member.class);
when(mockCluster.getLocalMember()).thenReturn(mockMember);
when(mockMember.getAddress()).thenReturn(a0);
c.setHazelcastInstance(mockHazelcastInstance);
assertArrayEquals(new int[] { 0, 3, 6 }, c.memberPartitions());
c.setLocalParallelism(2);
c.setLocalProcessorIndex(0);
assertArrayEquals(new int[] { 0, 6 }, c.processorPartitions());
c.setLocalProcessorIndex(1);
assertArrayEquals(new int[] { 3 }, c.processorPartitions());
c.setLocalParallelism(3);
c.setLocalProcessorIndex(2);
assertArrayEquals(new int[] { 6 }, c.processorPartitions());
c.setLocalParallelism(4);
c.setLocalProcessorIndex(3);
assertArrayEquals(new int[] {}, c.processorPartitions());
}
use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.
the class TestSupportTest method mockHazelcastInstance.
private HazelcastInstance mockHazelcastInstance() {
HazelcastInstance hzInstance = mock(HazelcastInstance.class);
Cluster cluster = mock(Cluster.class);
Member localMember = mock(Member.class);
when(hzInstance.getCluster()).thenReturn(cluster);
when(cluster.getLocalMember()).thenReturn(localMember);
return hzInstance;
}
Aggregations