Search in sources :

Example 11 with StoreId

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

the class TxPullRequestHandlerTest method shouldNotStreamTxEntriesIfStoreIdMismatches.

@Test
public void shouldNotStreamTxEntriesIfStoreIdMismatches() throws Exception {
    // given
    StoreId serverStoreId = new StoreId(1, 2, 3, 4);
    StoreId clientStoreId = new StoreId(5, 6, 7, 8);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> serverStoreId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(1, clientStoreId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_STORE_ID_MISMATCH, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", 2L, clientStoreId, serverStoreId));
}
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 12 with StoreId

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

the class TxPullRequestHandlerTest method shouldRespondWithoutTransactionsIfTheyDoNotExist.

@Test
public void shouldRespondWithoutTransactionsIfTheyDoNotExist() 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)).thenThrow(new NoSuchTransactionException(14));
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_TRANSACTION_PRUNED, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", 14L));
}
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) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 13 with StoreId

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

the class RemoteStoreTest method shouldCopyStoreFilesAndPullTransactions.

@Test
public void shouldCopyStoreFilesAndPullTransactions() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
    TxPullClient txPullClient = mock(TxPullClient.class);
    when(txPullClient.pullTransactions(any(), any(), anyLong(), any())).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
    MemberId localhost = new MemberId(UUID.randomUUID());
    remoteStore.copy(localhost, storeId, new File("destination"));
    // then
    verify(storeCopyClient).copyStoreFiles(eq(localhost), eq(storeId), any(StoreFileStreams.class));
    verify(txPullClient).pullTransactions(eq(localhost), eq(storeId), anyLong(), any(TxPullResponseListener.class));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) TransactionLogCatchUpWriter(org.neo4j.causalclustering.catchup.tx.TransactionLogCatchUpWriter) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreId(org.neo4j.causalclustering.identity.StoreId) TxPullResponseListener(org.neo4j.causalclustering.catchup.tx.TxPullResponseListener) Monitors(org.neo4j.kernel.monitoring.Monitors) TxPullRequestResult(org.neo4j.causalclustering.catchup.TxPullRequestResult) TxPullClient(org.neo4j.causalclustering.catchup.tx.TxPullClient) File(java.io.File) Test(org.junit.Test)

Example 14 with StoreId

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

the class TestStoreId method assertAllStoresHaveTheSameStoreId.

public static void assertAllStoresHaveTheSameStoreId(List<File> coreStoreDirs, FileSystemAbstraction fs) throws IOException {
    Set<StoreId> storeIds = new HashSet<>();
    try (PageCache pageCache = StandalonePageCacheFactory.createPageCache(fs)) {
        for (File coreStoreDir : coreStoreDirs) {
            storeIds.add(doReadStoreId(coreStoreDir, pageCache));
        }
    }
    assertEquals("Store Ids " + storeIds, 1, storeIds.size());
}
Also used : StoreId(org.neo4j.causalclustering.identity.StoreId) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) HashSet(java.util.HashSet)

Example 15 with StoreId

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

the class StoreIdMarshal method unmarshal0.

protected StoreId unmarshal0(ReadableChannel channel) throws IOException {
    byte exists = channel.get();
    if (exists == 0) {
        return null;
    } else if (exists != 1) {
        throw new DecoderException("Unexpected value: " + exists);
    }
    long creationTime = channel.getLong();
    long randomId = channel.getLong();
    long upgradeTime = channel.getLong();
    long upgradeId = channel.getLong();
    return new StoreId(creationTime, randomId, upgradeTime, upgradeId);
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) StoreId(org.neo4j.causalclustering.identity.StoreId)

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