Search in sources :

Example 1 with ReadReplicaInfo

use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.

the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.

private ReadReplicaTopology fakeReadReplicaTopology(MemberId[] readReplicaIds, NoEastGroupGenerator groupGenerator) {
    assert readReplicaIds.length > 0;
    Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
    int offset = 0;
    for (MemberId memberId : readReplicaIds) {
        readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset), groupGenerator.get(memberId)));
        offset++;
    }
    return new ReadReplicaTopology(readReplicas);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology)

Example 2 with ReadReplicaInfo

use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.

the class ClusterOverviewProcedure method apply.

@Override
public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
    List<ReadWriteEndPoint> endpoints = new ArrayList<>();
    CoreTopology coreTopology = topologyService.coreServers();
    Set<MemberId> coreMembers = coreTopology.members().keySet();
    MemberId leader = null;
    try {
        leader = leaderLocator.getLeader();
    } catch (NoLeaderFoundException e) {
        log.debug("No write server found. This can happen during a leader switch.");
    }
    for (MemberId memberId : coreMembers) {
        Optional<CoreServerInfo> coreServerInfo = coreTopology.find(memberId);
        if (coreServerInfo.isPresent()) {
            Role role = memberId.equals(leader) ? Role.LEADER : Role.FOLLOWER;
            endpoints.add(new ReadWriteEndPoint(coreServerInfo.get().connectors(), role, memberId.getUuid(), asList(coreServerInfo.get().groups())));
        } else {
            log.debug("No Address found for " + memberId);
        }
    }
    for (Map.Entry<MemberId, ReadReplicaInfo> readReplica : topologyService.readReplicas().members().entrySet()) {
        ReadReplicaInfo readReplicaInfo = readReplica.getValue();
        endpoints.add(new ReadWriteEndPoint(readReplicaInfo.connectors(), Role.READ_REPLICA, readReplica.getKey().getUuid(), asList(readReplicaInfo.groups())));
    }
    endpoints.sort(comparing(o -> o.addresses().toString()));
    return map((endpoint) -> new Object[] { endpoint.memberId().toString(), endpoint.addresses().uriList().stream().map(URI::toString).toArray(), endpoint.role().name(), endpoint.groups() }, asRawIterator(endpoints.iterator()));
}
Also used : ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Neo4jTypes(org.neo4j.kernel.api.proc.Neo4jTypes) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) LogProvider(org.neo4j.logging.LogProvider) ArrayList(java.util.ArrayList) Iterators.asRawIterator(org.neo4j.helpers.collection.Iterators.asRawIterator) Map(java.util.Map) MemberId(org.neo4j.causalclustering.identity.MemberId) URI(java.net.URI) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) Comparator.comparing(java.util.Comparator.comparing) ProcedureSignature.procedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) Iterators.map(org.neo4j.helpers.collection.Iterators.map) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Set(java.util.Set) UUID(java.util.UUID) Iterables.asList(org.neo4j.helpers.collection.Iterables.asList) List(java.util.List) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Optional(java.util.Optional) Context(org.neo4j.kernel.api.proc.Context) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) ArrayList(java.util.ArrayList) URI(java.net.URI) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) Map(java.util.Map)

Example 3 with ReadReplicaInfo

use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.

the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.

static ReadReplicaTopology fakeReadReplicaTopology(MemberId... readReplicaIds) {
    assert readReplicaIds.length > 0;
    Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
    int offset = 0;
    for (MemberId memberId : readReplicaIds) {
        readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset)));
        offset++;
    }
    return new ReadReplicaTopology(readReplicas);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology)

Example 4 with ReadReplicaInfo

use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.

the class ClusterOverviewProcedureTest method shouldProvideOverviewOfCoreServersAndReadReplicas.

@Test
public void shouldProvideOverviewOfCoreServersAndReadReplicas() throws Exception {
    // given
    final CoreTopologyService topologyService = mock(CoreTopologyService.class);
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    MemberId theLeader = new MemberId(UUID.randomUUID());
    MemberId follower1 = new MemberId(UUID.randomUUID());
    MemberId follower2 = new MemberId(UUID.randomUUID());
    coreMembers.put(theLeader, adressesForCore(0));
    coreMembers.put(follower1, adressesForCore(1));
    coreMembers.put(follower2, adressesForCore(2));
    Map<MemberId, ReadReplicaInfo> replicaMembers = new HashMap<>();
    MemberId replica4 = new MemberId(UUID.randomUUID());
    MemberId replica5 = new MemberId(UUID.randomUUID());
    replicaMembers.put(replica4, addressesForReadReplica(4));
    replicaMembers.put(replica5, addressesForReadReplica(5));
    when(topologyService.coreServers()).thenReturn(new CoreTopology(null, false, coreMembers));
    when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(replicaMembers));
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(theLeader);
    ClusterOverviewProcedure procedure = new ClusterOverviewProcedure(topologyService, leaderLocator, NullLogProvider.getInstance());
    // when
    final RawIterator<Object[], ProcedureException> members = procedure.apply(null, new Object[0]);
    assertThat(members.next(), new IsRecord(theLeader.getUuid(), 5000, Role.LEADER, asSet("core", "core0")));
    assertThat(members.next(), new IsRecord(follower1.getUuid(), 5001, Role.FOLLOWER, asSet("core", "core1")));
    assertThat(members.next(), new IsRecord(follower2.getUuid(), 5002, Role.FOLLOWER, asSet("core", "core2")));
    assertThat(members.next(), new IsRecord(replica4.getUuid(), 6004, Role.READ_REPLICA, asSet("replica", "replica4")));
    assertThat(members.next(), new IsRecord(replica5.getUuid(), 6005, Role.READ_REPLICA, asSet("replica", "replica5")));
    assertFalse(members.hasNext());
}
Also used : ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) MemberId(org.neo4j.causalclustering.identity.MemberId) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) Test(org.junit.Test)

Aggregations

ReadReplicaInfo (org.neo4j.causalclustering.discovery.ReadReplicaInfo)4 MemberId (org.neo4j.causalclustering.identity.MemberId)4 HashMap (java.util.HashMap)3 ClientConnectorAddresses (org.neo4j.causalclustering.discovery.ClientConnectorAddresses)3 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)3 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)2 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)2 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)2 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)2 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Comparator.comparing (java.util.Comparator.comparing)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)1