Search in sources :

Example 6 with RaftNodeImpl

use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.

the class SemaphoreAdvancedTest method testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot.

@Test
public void testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot() throws ExecutionException, InterruptedException {
    semaphore.init(1);
    spawn(() -> {
        try {
            semaphore.tryAcquire(2, 10, MINUTES);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    CPGroupId groupId = getGroupId();
    assertTrueEventually(() -> {
        HazelcastInstance leader = leaderInstanceOf(groupId);
        SemaphoreService service = getNodeEngineImpl(leader).getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertFalse(registry.getWaitTimeouts().isEmpty());
    });
    for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
        semaphore.acquire();
        semaphore.release();
    }
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftNodeImpl raftNode = getRaftNode(instance, groupId);
            assertNotNull(raftNode);
            LogEntry snapshotEntry = getSnapshotEntry(raftNode);
            assertTrue(snapshotEntry.index() > 0);
            List<RestoreSnapshotOp> ops = (List<RestoreSnapshotOp>) snapshotEntry.operation();
            for (RestoreSnapshotOp op : ops) {
                if (op.getServiceName().equals(SemaphoreService.SERVICE_NAME)) {
                    ResourceRegistry registry = (ResourceRegistry) op.getSnapshot();
                    assertFalse(registry.getWaitTimeouts().isEmpty());
                    return;
                }
            }
            fail();
        }
    });
    instances[1].shutdown();
    HazelcastInstance newInstance = factory.newHazelcastInstance(createConfig(groupSize, groupSize));
    newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    assertTrueEventually(() -> {
        SemaphoreService service = getNodeEngineImpl(newInstance).getService(SemaphoreService.SERVICE_NAME);
        SemaphoreRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertFalse(registry.getWaitTimeouts().isEmpty());
        assertEquals(1, registry.availablePermits(objectName));
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RestoreSnapshotOp(com.hazelcast.cp.internal.raftop.snapshot.RestoreSnapshotOp) List(java.util.List) ResourceRegistry(com.hazelcast.cp.internal.datastructures.spi.blocking.ResourceRegistry) LogEntry(com.hazelcast.cp.internal.raft.impl.log.LogEntry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with RaftNodeImpl

use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.

the class HazelcastRaftTestSupport method getLeaderInstance.

protected static HazelcastInstance getLeaderInstance(HazelcastInstance[] instances, CPGroupId groupId) {
    RaftNodeImpl[] raftNodeRef = new RaftNodeImpl[1];
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftNodeImpl raftNode = getRaftNode(instance, groupId);
            if (raftNode != null) {
                raftNodeRef[0] = raftNode;
                return;
            }
        }
        fail();
    });
    RaftNodeImpl raftNode = raftNodeRef[0];
    waitUntilLeaderElected(raftNode);
    RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
    assertNotNull(leaderEndpoint);
    for (HazelcastInstance instance : instances) {
        CPMember cpMember = instance.getCPSubsystem().getLocalCPMember();
        if (cpMember != null && leaderEndpoint.getUuid().equals(cpMember.getUuid())) {
            return instance;
        }
    }
    throw new AssertionError();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) CPMember(com.hazelcast.cp.CPMember)

Example 8 with RaftNodeImpl

use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.

the class HazelcastRaftTestSupport method waitAllForLeaderElection.

protected static RaftNodeImpl waitAllForLeaderElection(HazelcastInstance[] instances, CPGroupId groupId) {
    assertTrueEventually(() -> {
        RaftNodeImpl leaderNode = getLeaderNode(instances, groupId);
        int leaderTerm = getTerm(leaderNode);
        for (HazelcastInstance instance : instances) {
            RaftNodeImpl raftNode = getRaftNode(instance, groupId);
            assertNotNull(raftNode);
            assertEquals(leaderNode.getLocalMember(), getLeaderMember(raftNode));
            assertEquals(leaderTerm, getTerm(raftNode));
        }
    });
    return getLeaderNode(instances, groupId);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 9 with RaftNodeImpl

use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.

the class LocalRaftGroup method getNodesExcept.

public RaftNodeImpl[] getNodesExcept(RaftEndpoint endpoint) {
    RaftNodeImpl[] n = new RaftNodeImpl[nodes.length - 1];
    int i = 0;
    for (RaftNodeImpl node : nodes) {
        if (!node.getLocalMember().equals(endpoint)) {
            n[i++] = node;
        }
    }
    if (i != n.length) {
        throw new IllegalArgumentException();
    }
    return n;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 10 with RaftNodeImpl

use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl in project hazelcast by hazelcast.

the class LocalRaftGroup method createNewRaftNode.

public RaftNodeImpl createNewRaftNode(RestoredRaftState restoredRaftState, RaftStateStore stateStore) {
    checkNotNull(restoredRaftState);
    int oldSize = this.integrations.length;
    int newSize = oldSize + 1;
    RaftEndpoint[] endpoints = new RaftEndpoint[newSize];
    LocalRaftIntegration[] integrations = new LocalRaftIntegration[newSize];
    RaftNodeImpl[] nodes = new RaftNodeImpl[newSize];
    System.arraycopy(this.members, 0, endpoints, 0, oldSize);
    System.arraycopy(this.integrations, 0, integrations, 0, oldSize);
    System.arraycopy(this.nodes, 0, nodes, 0, oldSize);
    LocalRaftIntegration integration = createNewLocalRaftIntegration((TestRaftEndpoint) restoredRaftState.localEndpoint());
    createdNodeCount++;
    integrations[oldSize] = integration;
    RaftEndpoint endpoint = integration.getLocalEndpoint();
    endpoints[oldSize] = endpoint;
    RaftNodeImpl node = restoreRaftNode(groupId, restoredRaftState, raftAlgorithmConfig, integration, stateStore);
    nodes[oldSize] = node;
    this.members = endpoints;
    this.integrations = integrations;
    this.nodes = nodes;
    node.start();
    initDiscovery();
    return node;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Aggregations

RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)38 HazelcastInstance (com.hazelcast.core.HazelcastInstance)18 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 Test (org.junit.Test)14 CPGroupId (com.hazelcast.cp.CPGroupId)9 CPMember (com.hazelcast.cp.CPMember)9 CPGroup (com.hazelcast.cp.CPGroup)8 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 ArrayList (java.util.ArrayList)5 Config (com.hazelcast.config.Config)4 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)4 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)4 ResourceRegistry (com.hazelcast.cp.internal.datastructures.spi.blocking.ResourceRegistry)3 LogEntry (com.hazelcast.cp.internal.raft.impl.log.LogEntry)3 RaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore)3 RestoreSnapshotOp (com.hazelcast.cp.internal.raftop.snapshot.RestoreSnapshotOp)3 List (java.util.List)3