Search in sources :

Example 16 with StoreId

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

the class ReadReplicaStartupProcess method syncStoreWithUpstream.

private void syncStoreWithUpstream(MemberId source) throws IOException, StoreIdDownloadFailedException, StoreCopyFailedException, StreamingTransactionsFailedException {
    if (localDatabase.isEmpty()) {
        debugLog.info("Local database is empty, attempting to replace with copy from upstream server %s", source);
        debugLog.info("Finding store id of upstream server %s", source);
        StoreId storeId = remoteStore.getStoreId(source);
        debugLog.info("Copying store from upstream server %s", source);
        localDatabase.delete();
        storeCopyProcess.replaceWithStoreFrom(source, storeId);
        debugLog.info("Restarting local database after copy.", source);
    } else {
        ensureSameStoreIdAs(source);
    }
}
Also used : StoreId(org.neo4j.causalclustering.identity.StoreId)

Example 17 with StoreId

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

the class ReadReplicaStartupProcess method ensureSameStoreIdAs.

private void ensureSameStoreIdAs(MemberId upstream) throws StoreIdDownloadFailedException {
    StoreId localStoreId = localDatabase.storeId();
    StoreId remoteStoreId = remoteStore.getStoreId(upstream);
    if (!localStoreId.equals(remoteStoreId)) {
        throw new IllegalStateException(format("This read replica cannot join the cluster. " + "The local database is not empty and has a mismatching storeId: expected %s actual %s.", remoteStoreId, localStoreId));
    }
}
Also used : StoreId(org.neo4j.causalclustering.identity.StoreId)

Example 18 with StoreId

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

the class TxPullRequestEncodeDecodeTest method shouldEncodeAndDecodePullRequestMessage.

@Test
public void shouldEncodeAndDecodePullRequestMessage() {
    // given
    EmbeddedChannel channel = new EmbeddedChannel(new TxPullRequestEncoder(), new TxPullRequestDecoder());
    final long arbitraryId = 23;
    TxPullRequest sent = new TxPullRequest(arbitraryId, new StoreId(1, 2, 3, 4));
    // when
    channel.writeOutbound(sent);
    channel.writeInbound(new Object[] { channel.readOutbound() });
    // then
    TxPullRequest received = (TxPullRequest) channel.readInbound();
    assertNotSame(sent, received);
    assertEquals(sent, received);
}
Also used : StoreId(org.neo4j.causalclustering.identity.StoreId) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 19 with StoreId

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

the class TxPullRequestHandlerTest method shouldNotStreamTxsAndReportErrorIfTheLocalDatabaseIsNotAvailable.

@Test
public void shouldNotStreamTxsAndReportErrorIfTheLocalDatabaseIsNotAvailable() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> false, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(1, storeId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_STORE_UNAVAILABLE, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the local database is unavailable.", 2L));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 20 with StoreId

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

the class TxPullRequestHandlerTest method shouldRespondWithBatchOfTransactions.

@Test
public void shouldRespondWithBatchOfTransactions() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    when(logicalTransactionStore.getTransactions(14L)).thenReturn(txCursor(cursor(tx(14), tx(15), tx(16), tx(17))));
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
    // then
    verify(context, times(3)).write(ResponseMessageType.TX);
    verify(context).write(new TxPullResponse(storeId, tx(14)));
    verify(context).write(new TxPullResponse(storeId, tx(15)));
    verify(context).write(new TxPullResponse(storeId, tx(16)));
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_BATCH, 15L));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Aggregations

StoreId (org.neo4j.causalclustering.identity.StoreId)28 Test (org.junit.Test)14 Monitors (org.neo4j.kernel.monitoring.Monitors)9 File (java.io.File)6 CatchupServerProtocol (org.neo4j.causalclustering.catchup.CatchupServerProtocol)6 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)6 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)6 MemberId (org.neo4j.causalclustering.identity.MemberId)5 NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)4 TransactionLogCatchUpWriter (org.neo4j.causalclustering.catchup.tx.TransactionLogCatchUpWriter)3 TxPullClient (org.neo4j.causalclustering.catchup.tx.TxPullClient)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 CatchupResult (org.neo4j.causalclustering.catchup.CatchupResult)2 TxPullRequestResult (org.neo4j.causalclustering.catchup.TxPullRequestResult)2 StoreCopyFailedException (org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException)2 TxPullResponseListener (org.neo4j.causalclustering.catchup.tx.TxPullResponseListener)2 UpstreamDatabaseSelectionException (org.neo4j.causalclustering.readreplica.UpstreamDatabaseSelectionException)2 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)2 NoSuchTransactionException (org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException)2