Search in sources :

Example 11 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class UpstreamDatabaseStrategySelectorTest method shouldUseSpecifiedStrategyInPreferenceToDefault.

@Test
public void shouldUseSpecifiedStrategyInPreferenceToDefault() throws Exception {
    // given
    TopologyService topologyService = mock(TopologyService.class);
    MemberId memberId = new MemberId(UUID.randomUUID());
    when(topologyService.coreServers()).thenReturn(new CoreTopology(new ClusterId(UUID.randomUUID()), false, mapOf(memberId, mock(CoreServerInfo.class))));
    ConnectToRandomCoreServerStrategy shouldNotUse = new ConnectToRandomCoreServerStrategy();
    UpstreamDatabaseSelectionStrategy mockStrategy = mock(UpstreamDatabaseSelectionStrategy.class);
    when(mockStrategy.upstreamDatabase()).thenReturn(Optional.of(new MemberId(UUID.randomUUID())));
    UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(shouldNotUse, iterable(mockStrategy), null, NullLogProvider.getInstance());
    // when
    selector.bestUpstreamDatabase();
    // then
    verify(mockStrategy, times(2)).upstreamDatabase();
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Test(org.junit.Test)

Example 12 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class BatchingMessageHandler method collateAndHandleBatch.

private void collateAndHandleBatch(List<RaftMessages.ClusterIdAwareMessage> batch) {
    RaftMessages.NewEntry.BatchRequest batchRequest = null;
    ClusterId clusterId = batch.get(0).clusterId();
    for (RaftMessages.ClusterIdAwareMessage clusterIdAwareMessage : batch) {
        if (batchRequest != null && !clusterIdAwareMessage.clusterId().equals(clusterId)) {
            handler.handle(new RaftMessages.ClusterIdAwareMessage(clusterId, batchRequest));
            batchRequest = null;
        }
        clusterId = clusterIdAwareMessage.clusterId();
        RaftMessage message = clusterIdAwareMessage.message();
        if (message instanceof RaftMessages.NewEntry.Request) {
            RaftMessages.NewEntry.Request newEntryRequest = (RaftMessages.NewEntry.Request) message;
            if (batchRequest == null) {
                batchRequest = new RaftMessages.NewEntry.BatchRequest(batch.size());
            }
            batchRequest.add(newEntryRequest.content());
        } else {
            handler.handle(clusterIdAwareMessage);
        }
    }
    if (batchRequest != null) {
        handler.handle(new RaftMessages.ClusterIdAwareMessage(clusterId, batchRequest));
    }
}
Also used : ClusterId(org.neo4j.causalclustering.identity.ClusterId) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) RaftMessage(org.neo4j.causalclustering.core.consensus.RaftMessages.RaftMessage)

Example 13 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class CoreState method handle.

public synchronized void handle(RaftMessages.ClusterIdAwareMessage clusterIdAwareMessage) {
    Optional<ClusterId> optionalClusterId = clusterBinder.get();
    if (!allowMessageHandling || !optionalClusterId.isPresent()) {
        return;
    }
    ClusterId boundClusterId = optionalClusterId.get();
    ClusterId msgClusterId = clusterIdAwareMessage.clusterId();
    if (msgClusterId.equals(boundClusterId)) {
        try {
            ConsensusOutcome outcome = raftMachine.handle(clusterIdAwareMessage.message());
            if (outcome.needsFreshSnapshot()) {
                downloadSnapshot(clusterIdAwareMessage.message().from());
            } else {
                notifyCommitted(outcome.getCommitIndex());
            }
        } catch (Throwable e) {
            log.error("Error handling message", e);
            raftMachine.panic();
            localDatabase.panic(e);
        }
    } else {
        log.info("Discarding message[%s] owing to mismatched clusterId. Expected: %s, Encountered: %s", clusterIdAwareMessage.message(), boundClusterId, msgClusterId);
    }
}
Also used : ClusterId(org.neo4j.causalclustering.identity.ClusterId) ConsensusOutcome(org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome)

Example 14 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class CoreTopologyTest method shouldDetectRemovedMembers.

@Test
public void shouldDetectRemovedMembers() throws Exception {
    // given
    UUID one = UUID.randomUUID();
    UUID two = UUID.randomUUID();
    Map<MemberId, CoreServerInfo> initialMembers = new HashMap<>();
    initialMembers.put(new MemberId(one), mock(CoreServerInfo.class));
    initialMembers.put(new MemberId(two), mock(CoreServerInfo.class));
    Map<MemberId, CoreServerInfo> newMembers = new HashMap<>();
    newMembers.put(new MemberId(two), mock(CoreServerInfo.class));
    CoreTopology topology = new CoreTopology(new ClusterId(UUID.randomUUID()), true, initialMembers);
    // when
    TopologyDifference diff = topology.difference(new CoreTopology(new ClusterId(UUID.randomUUID()), true, newMembers));
    // then
    assertThat(diff.added().size(), Matchers.equalTo(0));
    assertThat(diff.removed().size(), Matchers.equalTo(1));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) ClusterId(org.neo4j.causalclustering.identity.ClusterId) UUID(java.util.UUID) Test(org.junit.Test)

Example 15 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class CoreTopologyTest method shouldDetectAddedMembers.

@Test
public void shouldDetectAddedMembers() throws Exception {
    // given
    UUID one = UUID.randomUUID();
    UUID two = UUID.randomUUID();
    Map<MemberId, CoreServerInfo> initialMembers = new HashMap<>();
    initialMembers.put(new MemberId(one), mock(CoreServerInfo.class));
    initialMembers.put(new MemberId(two), mock(CoreServerInfo.class));
    Map<MemberId, CoreServerInfo> newMembers = new HashMap<>();
    newMembers.put(new MemberId(one), mock(CoreServerInfo.class));
    newMembers.put(new MemberId(two), mock(CoreServerInfo.class));
    newMembers.put(new MemberId(UUID.randomUUID()), mock(CoreServerInfo.class));
    CoreTopology topology = new CoreTopology(new ClusterId(UUID.randomUUID()), true, initialMembers);
    // when
    TopologyDifference diff = topology.difference(new CoreTopology(new ClusterId(UUID.randomUUID()), true, newMembers));
    // then
    assertThat(diff.added().size(), Matchers.equalTo(1));
    assertThat(diff.removed().size(), Matchers.equalTo(0));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) ClusterId(org.neo4j.causalclustering.identity.ClusterId) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ClusterId (org.neo4j.causalclustering.identity.ClusterId)15 MemberId (org.neo4j.causalclustering.identity.MemberId)10 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 UUID (java.util.UUID)4 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)4 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)3 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)3 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)2 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)2 Member (com.hazelcast.core.Member)1 ClusterIdAwareMessage (org.neo4j.causalclustering.core.consensus.RaftMessages.ClusterIdAwareMessage)1 RaftMessage (org.neo4j.causalclustering.core.consensus.RaftMessages.RaftMessage)1 ConsensusOutcome (org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome)1 ReplicatedContent (org.neo4j.causalclustering.core.replication.ReplicatedContent)1 SimpleFileStorage (org.neo4j.causalclustering.core.state.storage.SimpleFileStorage)1 ClientConnectorAddresses (org.neo4j.causalclustering.discovery.ClientConnectorAddresses)1 NetworkFlushableByteBuf (org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf)1 NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)1 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)1