Search in sources :

Example 96 with Member

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;
}
Also used : RaftNodeStatus(com.hazelcast.cp.internal.raft.impl.RaftNodeStatus) AppendSuccessResponse(com.hazelcast.cp.internal.raft.impl.dto.AppendSuccessResponse) Clock(com.hazelcast.internal.util.Clock) CP_METRIC_RAFT_SERVICE_TERMINATED_RAFT_NODE_GROUP_IDS(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_TERMINATED_RAFT_NODE_GROUP_IDS) InstallSnapshot(com.hazelcast.cp.internal.raft.impl.dto.InstallSnapshot) RaftIntegration(com.hazelcast.cp.internal.raft.impl.RaftIntegration) ManagedService(com.hazelcast.internal.services.ManagedService) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) VoteResponse(com.hazelcast.cp.internal.raft.impl.dto.VoteResponse) ClusterService(com.hazelcast.internal.cluster.ClusterService) Future(java.util.concurrent.Future) CPGroup(com.hazelcast.cp.CPGroup) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) Map(java.util.Map) CPSubsystemConfig(com.hazelcast.config.cp.CPSubsystemConfig) RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) StringUtil.equalsIgnoreCase(com.hazelcast.internal.util.StringUtil.equalsIgnoreCase) CP_PREFIX_RAFT_METADATA(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_PREFIX_RAFT_METADATA) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) RaftRemoteService(com.hazelcast.cp.internal.datastructures.spi.RaftRemoteService) CPPersistenceService(com.hazelcast.cp.internal.persistence.CPPersistenceService) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) CP_PREFIX_RAFT_GROUP(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_PREFIX_RAFT_GROUP) EventListener(java.util.EventListener) PartitionReplicationEvent(com.hazelcast.internal.partition.PartitionReplicationEvent) CPMember(com.hazelcast.cp.CPMember) CP_DISCRIMINATOR_GROUPID(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_DISCRIMINATOR_GROUPID) GetActiveRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveRaftGroupIdsOp) CPGroupAvailabilityEventImpl(com.hazelcast.cp.event.impl.CPGroupAvailabilityEventImpl) Versions(com.hazelcast.internal.cluster.Versions) GetInitialRaftGroupMembersIfCurrentGroupMemberOp(com.hazelcast.cp.internal.raftop.GetInitialRaftGroupMembersIfCurrentGroupMemberOp) CP_METRIC_RAFT_SERVICE_NODES(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_NODES) RaftManagedService(com.hazelcast.cp.internal.datastructures.spi.RaftManagedService) VoteRequest(com.hazelcast.cp.internal.raft.impl.dto.VoteRequest) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) CP_PREFIX_RAFT(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_PREFIX_RAFT) SYSTEM_EXECUTOR(com.hazelcast.spi.impl.executionservice.ExecutionService.SYSTEM_EXECUTOR) RestoredRaftState(com.hazelcast.cp.internal.raft.impl.persistence.RestoredRaftState) LINEARIZABLE(com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE) BiConsumer(java.util.function.BiConsumer) CPMembershipListener(com.hazelcast.cp.event.CPMembershipListener) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) MembershipServiceEvent(com.hazelcast.internal.services.MembershipServiceEvent) DEFAULT_GROUP_NAME(com.hazelcast.cp.CPGroup.DEFAULT_GROUP_NAME) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RaftState(com.hazelcast.cp.internal.raft.impl.state.RaftState) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) Properties(java.util.Properties) RaftLog(com.hazelcast.cp.internal.raft.impl.log.RaftLog) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MembershipAwareService(com.hazelcast.internal.services.MembershipAwareService) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) ExecutionException(java.util.concurrent.ExecutionException) AddCPMemberOp(com.hazelcast.cp.internal.raftop.metadata.AddCPMemberOp) CPGroupAvailabilityEvent(com.hazelcast.cp.event.CPGroupAvailabilityEvent) ManagedExecutorService(com.hazelcast.internal.util.executor.ManagedExecutorService) RaftStateStore(com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore) Member(com.hazelcast.cluster.Member) ResetCPMemberOp(com.hazelcast.cp.internal.operation.ResetCPMemberOp) PreVoteRequest(com.hazelcast.cp.internal.raft.impl.dto.PreVoteRequest) ForceDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.ForceDestroyRaftGroupOp) SnapshotAwareService(com.hazelcast.cp.internal.raft.SnapshotAwareService) RaftServicePreJoinOp(com.hazelcast.cp.internal.raftop.metadata.RaftServicePreJoinOp) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) AppendFailureResponse(com.hazelcast.cp.internal.raft.impl.dto.AppendFailureResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CPGroupAvailabilityListener(com.hazelcast.cp.event.CPGroupAvailabilityListener) CannotRemoveCPMemberException(com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) ProbeLevel(com.hazelcast.internal.metrics.ProbeLevel) CP_METRIC_RAFT_SERVICE_DESTROYED_GROUP_IDS(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_DESTROYED_GROUP_IDS) Preconditions.checkTrue(com.hazelcast.internal.util.Preconditions.checkTrue) ResponseAlreadySentException(com.hazelcast.spi.exception.ResponseAlreadySentException) UnsafeStateReplicationOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeStateReplicationOp) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) LogFileStructure(com.hazelcast.cp.internal.raft.impl.persistence.LogFileStructure) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) METADATA_CP_GROUP_NAME(com.hazelcast.cp.CPGroup.METADATA_CP_GROUP_NAME) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TriggerLeaderElection(com.hazelcast.cp.internal.raft.impl.dto.TriggerLeaderElection) RaftRole(com.hazelcast.cp.internal.raft.impl.RaftRole) MetricsPlugin(com.hazelcast.internal.diagnostics.MetricsPlugin) UUID(java.util.UUID) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode) List(java.util.List) LEADER_LOCAL(com.hazelcast.cp.internal.raft.QueryPolicy.LEADER_LOCAL) Entry(java.util.Map.Entry) Preconditions.checkFalse(com.hazelcast.internal.util.Preconditions.checkFalse) CP_METRIC_RAFT_SERVICE_MISSING_MEMBERS(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_METRIC_RAFT_SERVICE_MISSING_MEMBERS) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) ConcurrentMap(java.util.concurrent.ConcurrentMap) AppendRequest(com.hazelcast.cp.internal.raft.impl.dto.AppendRequest) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Collections.newSetFromMap(java.util.Collections.newSetFromMap) CPMembershipEvent(com.hazelcast.cp.event.CPMembershipEvent) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) EventPublishingService(com.hazelcast.spi.impl.eventservice.EventPublishingService) CPGroupId(com.hazelcast.cp.CPGroupId) Timer(com.hazelcast.internal.util.Timer) NodeEngine(com.hazelcast.spi.impl.NodeEngine) GetActiveRaftGroupByNameOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveRaftGroupByNameOp) Data(com.hazelcast.internal.serialization.Data) NON_LOCAL_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.NON_LOCAL_MEMBER_SELECTOR) RemoveCPMemberOp(com.hazelcast.cp.internal.raftop.metadata.RemoveCPMemberOp) Preconditions.checkState(com.hazelcast.internal.util.Preconditions.checkState) ConfigValidator.checkCPSubsystemConfig(com.hazelcast.internal.config.ConfigValidator.checkCPSubsystemConfig) CP_TAG_NAME(com.hazelcast.internal.metrics.MetricDescriptorConstants.CP_TAG_NAME) TimeUnit(java.util.concurrent.TimeUnit) PreVoteResponse(com.hazelcast.cp.internal.raft.impl.dto.PreVoteResponse) GracefulShutdownAwareService(com.hazelcast.internal.services.GracefulShutdownAwareService) PreJoinAwareService(com.hazelcast.internal.services.PreJoinAwareService) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) MANAGEMENT_TASK_PERIOD_IN_MILLIS(com.hazelcast.cp.internal.RaftGroupMembershipManager.MANAGEMENT_TASK_PERIOD_IN_MILLIS) CannotRemoveCPMemberException(com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) ClusterService(com.hazelcast.internal.cluster.ClusterService) CPMember(com.hazelcast.cp.CPMember) Member(com.hazelcast.cluster.Member)

Example 97 with Member

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;
}
Also used : Operation(com.hazelcast.spi.impl.operationservice.Operation) ResetCPMemberOp(com.hazelcast.cp.internal.operation.ResetCPMemberOp) ClusterService(com.hazelcast.internal.cluster.ClusterService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CPMember(com.hazelcast.cp.CPMember) Member(com.hazelcast.cluster.Member) BiConsumer(java.util.function.BiConsumer) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 98 with Member

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));
}
Also used : IExecutorService(com.hazelcast.core.IExecutorService) LinkedList(java.util.LinkedList) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.cluster.Member)

Example 99 with Member

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) Cluster(com.hazelcast.cluster.Cluster) Member(com.hazelcast.cluster.Member) Test(org.junit.Test)

Example 100 with Member

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;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.cluster.Cluster) Member(com.hazelcast.cluster.Member)

Aggregations

Member (com.hazelcast.cluster.Member)429 Test (org.junit.Test)210 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)164 HazelcastInstance (com.hazelcast.core.HazelcastInstance)116 IExecutorService (com.hazelcast.core.IExecutorService)73 Address (com.hazelcast.cluster.Address)62 ArrayList (java.util.ArrayList)55 Future (java.util.concurrent.Future)53 UUID (java.util.UUID)43 Config (com.hazelcast.config.Config)42 CountDownLatch (java.util.concurrent.CountDownLatch)38 Map (java.util.Map)33 HashMap (java.util.HashMap)31 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)28 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)25 List (java.util.List)25 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)24 Operation (com.hazelcast.spi.impl.operationservice.Operation)24 IMap (com.hazelcast.map.IMap)23