Search in sources :

Example 61 with MemberId

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

the class UserDefinedConfigurationStrategy method upstreamDatabase.

@Override
public Optional<MemberId> upstreamDatabase() throws UpstreamDatabaseSelectionException {
    try {
        Filter<ServerInfo> filters = FilterConfigParser.parse(config.get(CausalClusteringSettings.user_defined_upstream_selection_strategy));
        Set<ServerInfo> possibleReaders = topologyService.readReplicas().members().entrySet().stream().map(entry -> new ServerInfo(entry.getValue().connectors().boltAddress(), entry.getKey(), entry.getValue().groups())).collect(Collectors.toSet());
        CoreTopology coreTopology = topologyService.coreServers();
        for (MemberId validCore : coreTopology.members().keySet()) {
            Optional<CoreServerInfo> coreServerInfo = coreTopology.find(validCore);
            if (coreServerInfo.isPresent()) {
                CoreServerInfo serverInfo = coreServerInfo.get();
                possibleReaders.add(new ServerInfo(serverInfo.connectors().boltAddress(), validCore, serverInfo.groups()));
            }
        }
        return filters.apply(possibleReaders).stream().map(ServerInfo::memberId).findAny();
    } catch (InvalidFilterSpecification invalidFilterSpecification) {
        return Optional.empty();
    }
}
Also used : Service(org.neo4j.helpers.Service) InvalidFilterSpecification(org.neo4j.causalclustering.load_balancing.plugins.server_policies.InvalidFilterSpecification) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) Optional(java.util.Optional) Set(java.util.Set) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) Filter(org.neo4j.causalclustering.load_balancing.filters.Filter) ServerInfo(org.neo4j.causalclustering.load_balancing.plugins.server_policies.ServerInfo) Collectors(java.util.stream.Collectors) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) FilterConfigParser(org.neo4j.causalclustering.load_balancing.plugins.server_policies.FilterConfigParser) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ServerInfo(org.neo4j.causalclustering.load_balancing.plugins.server_policies.ServerInfo) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) InvalidFilterSpecification(org.neo4j.causalclustering.load_balancing.plugins.server_policies.InvalidFilterSpecification) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology)

Example 62 with MemberId

use of org.neo4j.causalclustering.identity.MemberId 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 63 with MemberId

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

the class CatchUpTest method happyClusterPropagatesUpdates.

@Test
public void happyClusterPropagatesUpdates() throws Throwable {
    DirectNetworking net = new DirectNetworking();
    // given
    final MemberId leader = member(0);
    final MemberId[] allMembers = { leader, member(1), member(2) };
    final RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
    fixture.bootstrap(allMembers);
    final MemberId leaderMember = fixture.members().withId(leader).member();
    // when
    fixture.members().withId(leader).timeoutService().invokeTimeout(RaftMachine.Timeouts.ELECTION);
    net.processMessages();
    fixture.members().withId(leader).raftInstance().handle(new Request(leaderMember, valueOf(42)));
    net.processMessages();
    // then
    for (MemberId aMember : allMembers) {
        assertThat(integerValues(fixture.members().withId(aMember).raftLog()), hasItems(42));
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Request(org.neo4j.causalclustering.core.consensus.RaftMessages.NewEntry.Request) Test(org.junit.Test)

Example 64 with MemberId

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

the class DirectNetworking method processMessages.

public void processMessages() {
    while (messagesToBeProcessed()) {
        for (Map.Entry<MemberId, Queue<Message>> entry : messageQueues.entrySet()) {
            MemberId id = entry.getKey();
            Queue<Message> queue = entry.getValue();
            if (!queue.isEmpty()) {
                Message message = queue.remove();
                handlers.get(id).handle(message);
            }
        }
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Message(org.neo4j.causalclustering.messaging.Message) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Queue(java.util.Queue)

Example 65 with MemberId

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

the class RemoteStoreTest method shouldSetLastPulledTransactionId.

@Test
public void shouldSetLastPulledTransactionId() throws Exception {
    // given
    long lastFlushedTxId = 12;
    StoreId wantedStoreId = new StoreId(1, 2, 3, 4);
    MemberId localhost = new MemberId(UUID.randomUUID());
    StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
    when(storeCopyClient.copyStoreFiles(eq(localhost), eq(wantedStoreId), any(StoreFileStreams.class))).thenReturn(lastFlushedTxId);
    TxPullClient txPullClient = mock(TxPullClient.class);
    when(txPullClient.pullTransactions(eq(localhost), eq(wantedStoreId), anyLong(), any(TxPullResponseListener.class))).thenReturn(new TxPullRequestResult(SUCCESS_END_OF_STREAM, 13));
    TransactionLogCatchUpWriter writer = mock(TransactionLogCatchUpWriter.class);
    RemoteStore remoteStore = new RemoteStore(NullLogProvider.getInstance(), mock(FileSystemAbstraction.class), null, storeCopyClient, txPullClient, factory(writer), new Monitors());
    // when
    remoteStore.copy(localhost, wantedStoreId, new File("destination"));
    // then
    // the interface is defined as asking for the one preceding
    long previousTxId = lastFlushedTxId - 1;
    verify(txPullClient).pullTransactions(eq(localhost), eq(wantedStoreId), eq(previousTxId), any(TxPullResponseListener.class));
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) TxPullResponseListener(org.neo4j.causalclustering.catchup.tx.TxPullResponseListener) TxPullRequestResult(org.neo4j.causalclustering.catchup.TxPullRequestResult) MemberId(org.neo4j.causalclustering.identity.MemberId) TransactionLogCatchUpWriter(org.neo4j.causalclustering.catchup.tx.TransactionLogCatchUpWriter) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) TxPullClient(org.neo4j.causalclustering.catchup.tx.TxPullClient) File(java.io.File) Test(org.junit.Test)

Aggregations

MemberId (org.neo4j.causalclustering.identity.MemberId)114 Test (org.junit.Test)83 HashMap (java.util.HashMap)26 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)16 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)13 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 DirectNetworking (org.neo4j.causalclustering.core.consensus.DirectNetworking)10 RaftTestFixture (org.neo4j.causalclustering.core.consensus.RaftTestFixture)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 Log (org.neo4j.logging.Log)10 ClusterId (org.neo4j.causalclustering.identity.ClusterId)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)8 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)7 ByteBuf (io.netty.buffer.ByteBuf)6 File (java.io.File)6 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 HashSet (java.util.HashSet)5