Search in sources :

Example 6 with GetActiveCPMembersOp

use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp 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 7 with GetActiveCPMembersOp

use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.

the class RaftInvocationManager method invokeGetMembersToCreateRaftGroup.

private void invokeGetMembersToCreateRaftGroup(String groupName, int groupSize, InternalCompletableFuture<RaftGroupId> resultFuture) {
    RaftGroupId metadataGroupId = raftService.getMetadataGroupId();
    InternalCompletableFuture<List<CPMemberInfo>> f1 = query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
    InternalCompletableFuture<Collection<RaftGroupId>> f2 = query(metadataGroupId, new GetRaftGroupIdsOp(), LINEARIZABLE);
    f1.thenCombineAsync(f2, (cpMembers, groupIds) -> {
        if (cpMembers.size() < groupSize) {
            Exception e = new IllegalArgumentException("There are not enough active CP members to create CP group " + groupName + ". Active CP members: " + cpMembers.size() + ", Requested CP group size: " + groupSize);
            resultFuture.completeExceptionally(e);
            return null;
        }
        long groupIndex = generateRandomGroupIndex(groupIds);
        List<RaftEndpoint> groupEndpoints = generateRandomGroupMembers(cpMembers, groupSize);
        invokeCreateRaftGroup(groupName, groupSize, groupIndex, groupEndpoints, resultFuture);
        return null;
    }).exceptionally(t -> {
        resultFuture.completeExceptionally(t);
        return null;
    });
}
Also used : Collections.shuffle(java.util.Collections.shuffle) ChangeRaftGroupMembershipOp(com.hazelcast.cp.internal.operation.ChangeRaftGroupMembershipOp) AbstractUnsafeRaftOp(com.hazelcast.cp.internal.operation.unsafe.AbstractUnsafeRaftOp) MembershipChangeMode(com.hazelcast.cp.internal.raft.MembershipChangeMode) DEFAULT_DESERIALIZE_RESULT(com.hazelcast.spi.impl.operationservice.InvocationBuilder.DEFAULT_DESERIALIZE_RESULT) RaftInvocationContext(com.hazelcast.spi.impl.operationservice.impl.RaftInvocationContext) CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ArrayList(java.util.ArrayList) CreateRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClusterService(com.hazelcast.internal.cluster.ClusterService) LINEARIZABLE(com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) Invocation(com.hazelcast.spi.impl.operationservice.impl.Invocation) CreateRaftNodeOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftNodeOp) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) CPGroupId(com.hazelcast.cp.CPGroupId) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastException(com.hazelcast.core.HazelcastException) NodeEngine(com.hazelcast.spi.impl.NodeEngine) DefaultRaftReplicateOp(com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp) UnsafeRaftReplicateOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftReplicateOp) Collection(java.util.Collection) RandomPicker(com.hazelcast.internal.util.RandomPicker) QueryPolicy(com.hazelcast.cp.internal.raft.QueryPolicy) Collectors(java.util.stream.Collectors) DestroyRaftGroupOp(com.hazelcast.cp.internal.operation.DestroyRaftGroupOp) RaftQueryOp(com.hazelcast.cp.internal.operation.RaftQueryOp) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CP_SUBSYSTEM_EXECUTOR(com.hazelcast.cp.internal.RaftService.CP_SUBSYSTEM_EXECUTOR) List(java.util.List) CPMember(com.hazelcast.cp.CPMember) RaftInvocation(com.hazelcast.spi.impl.operationservice.impl.RaftInvocation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Comparator(java.util.Comparator) UnsafeRaftQueryOp(com.hazelcast.cp.internal.operation.unsafe.UnsafeRaftQueryOp) Collection(java.util.Collection) GetRaftGroupIdsOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupIdsOp) ArrayList(java.util.ArrayList) List(java.util.List) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) HazelcastException(com.hazelcast.core.HazelcastException)

Example 8 with GetActiveCPMembersOp

use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method when_newCPMemberIsAddedToTheMetadataGroupAfterRestartAndSnapshot_newMemberInstallsSnapshot.

@Test
public void when_newCPMemberIsAddedToTheMetadataGroupAfterRestartAndSnapshot_newMemberInstallsSnapshot() throws ExecutionException, InterruptedException {
    int nodeCount = 3;
    int commitIndexAdvanceCountToSnapshot = 50;
    Config config = createConfig(nodeCount, nodeCount);
    config.getCPSubsystemConfig().getRaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(commitIndexAdvanceCountToSnapshot);
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        instances[i] = factory.newHazelcastInstance(config);
    }
    assertClusterSizeEventually(nodeCount, instances);
    waitUntilCPDiscoveryCompleted(instances);
    RaftGroupId initialMetadataGroupId = getMetadataGroupId(instances[0]);
    instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    instances[1].getLifecycleService().terminate();
    instances[2].getLifecycleService().terminate();
    HazelcastInstance newInstance1 = factory.newHazelcastInstance(config);
    HazelcastInstance newInstance2 = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, instances[0], newInstance1, newInstance2);
    instances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    RaftGroupId newMetadataGroupId = getRaftService(instances[0]).getMetadataGroupId();
    assertTrue(newMetadataGroupId.getSeed() > initialMetadataGroupId.getSeed());
    assertEquals(newMetadataGroupId.getSeed(), getRaftService(newInstance1).getMetadataGroupId().getSeed());
    assertEquals(newMetadataGroupId.getSeed(), getRaftService(newInstance2).getMetadataGroupId().getSeed());
    for (int i = 0; i < commitIndexAdvanceCountToSnapshot; i++) {
        getRaftInvocationManager(instances[0]).invoke(getMetadataGroupId(instances[0]), new GetActiveCPMembersOp()).get();
    }
    assertTrueEventually(() -> {
        assertTrue(getSnapshotEntry(getRaftNode(instances[0], newMetadataGroupId)).index() >= commitIndexAdvanceCountToSnapshot);
        assertTrue(getSnapshotEntry(getRaftNode(newInstance1, newMetadataGroupId)).index() >= commitIndexAdvanceCountToSnapshot);
        assertTrue(getSnapshotEntry(getRaftNode(newInstance2, newMetadataGroupId)).index() >= commitIndexAdvanceCountToSnapshot);
    });
    instances[0].getCPSubsystem().getAtomicLong("long@group1").set(1);
    instances[0].getCPSubsystem().getAtomicLong("long@group2").set(2);
    instances[0].shutdown();
    HazelcastInstance newInstance3 = factory.newHazelcastInstance(config);
    newInstance3.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    CPGroup metadataGroup = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    CPGroup group1 = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group1").toCompletableFuture().get();
    CPGroup group2 = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group2").toCompletableFuture().get();
    List<CPMember> cpMembers = new ArrayList<>(newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get());
    HazelcastInstance[] newInstances = new HazelcastInstance[] { newInstance1, newInstance2, newInstance3 };
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(newInstances, newMetadataGroupId));
        for (HazelcastInstance instance : Arrays.asList(newInstance1, newInstance2, newInstance3)) {
            assertEquals(newMetadataGroupId.getSeed(), getMetadataGroupId(instance).getSeed());
            RaftNodeImpl raftNode = getRaftNode(instance, newMetadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup m = queryRaftGroupLocally(instance, metadataGroup.id());
            CPGroup g1 = queryRaftGroupLocally(instance, group1.id());
            CPGroup g2 = queryRaftGroupLocally(instance, group2.id());
            assertNotNull(m);
            assertNotNull(g1);
            assertNotNull(g2);
            assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), m.members().toArray(new CPMember[0]));
            assertArrayEquals(group1.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
            assertArrayEquals(group2.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
            List<CPMemberInfo> activeMembers = new ArrayList<>(getRaftService(instance).getMetadataGroupManager().getActiveMembers());
            assertEquals(cpMembers, activeMembers);
        }
    });
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 9 with GetActiveCPMembersOp

use of com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method when_snapshotIsTakenWhileRemovingCPLeader_newMemberInstallsSnapshot.

@Test
public void when_snapshotIsTakenWhileRemovingCPLeader_newMemberInstallsSnapshot() throws Exception {
    int nodeCount = 3;
    int commitIndexAdvanceCountToSnapshot = 50;
    Config config = createConfig(nodeCount, nodeCount);
    config.getCPSubsystemConfig().getRaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(commitIndexAdvanceCountToSnapshot);
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        instances[i] = factory.newHazelcastInstance(config);
    }
    assertClusterSizeEventually(nodeCount, instances);
    waitUntilCPDiscoveryCompleted(instances);
    HazelcastInstance leaderInstance = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
    // Specifically, RemoveCPMemberOp will be in snapshot but CompleteRaftGroupMembershipChangesOp will not.
    for (int i = 0; i < commitIndexAdvanceCountToSnapshot - 5; i++) {
        getRaftInvocationManager(leaderInstance).invoke(getMetadataGroupId(instances[0]), new GetActiveCPMembersOp()).get();
    }
    // This will add 3 entries, RemoveCPMemberOp, ChangeRaftGroupMembersCmd and CompleteRaftGroupMembershipChangesOp.
    // RemoveCPMemberOp will be in snapshot but CompleteRaftGroupMembershipChangesOp will not be included.
    leaderInstance.shutdown();
    HazelcastInstance newInstance = factory.newHazelcastInstance(config);
    newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().join();
    List<CPMember> cpMembers = new ArrayList<>(newInstance.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().join());
    assertTrueEventually(() -> {
        RaftService service = getRaftService(newInstance);
        List<CPMemberInfo> activeMembers = new ArrayList<>(service.getMetadataGroupManager().getActiveMembers());
        assertEquals(cpMembers, activeMembers);
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 CPMember (com.hazelcast.cp.CPMember)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Config (com.hazelcast.config.Config)6 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 CPGroup (com.hazelcast.cp.CPGroup)4 CPGroupId (com.hazelcast.cp.CPGroupId)3 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)3 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)3 LINEARIZABLE (com.hazelcast.cp.internal.raft.QueryPolicy.LINEARIZABLE)2 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)2 List (java.util.List)2 Member (com.hazelcast.cluster.Member)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 NON_LOCAL_MEMBER_SELECTOR (com.hazelcast.cluster.memberselector.MemberSelectors.NON_LOCAL_MEMBER_SELECTOR)1