Search in sources :

Example 1 with TxPullRequestResult

use of org.neo4j.causalclustering.catchup.TxPullRequestResult 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 2 with TxPullRequestResult

use of org.neo4j.causalclustering.catchup.TxPullRequestResult 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)

Example 3 with TxPullRequestResult

use of org.neo4j.causalclustering.catchup.TxPullRequestResult in project neo4j by neo4j.

the class RemoteStore method pullTransactions.

private CatchupResult pullTransactions(MemberId from, StoreId expectedStoreId, File storeDir, long fromTxId, boolean asPartOfStoreCopy) throws IOException, StoreCopyFailedException {
    try (TransactionLogCatchUpWriter writer = transactionLogFactory.create(storeDir, fs, pageCache, logProvider, fromTxId, asPartOfStoreCopy)) {
        log.info("Pulling transactions from: %d", fromTxId);
        long previousTxId = fromTxId - 1;
        CatchupResult lastStatus;
        do {
            TxPullRequestResult result = txPullClient.pullTransactions(from, expectedStoreId, previousTxId, writer);
            lastStatus = result.catchupResult();
            previousTxId = result.lastTxId();
        } while (lastStatus == SUCCESS_END_OF_BATCH);
        return lastStatus;
    } catch (CatchUpClientException e) {
        throw new StoreCopyFailedException(e);
    }
}
Also used : TransactionLogCatchUpWriter(org.neo4j.causalclustering.catchup.tx.TransactionLogCatchUpWriter) CatchupResult(org.neo4j.causalclustering.catchup.CatchupResult) CatchUpClientException(org.neo4j.causalclustering.catchup.CatchUpClientException) TxPullRequestResult(org.neo4j.causalclustering.catchup.TxPullRequestResult)

Aggregations

TxPullRequestResult (org.neo4j.causalclustering.catchup.TxPullRequestResult)3 TransactionLogCatchUpWriter (org.neo4j.causalclustering.catchup.tx.TransactionLogCatchUpWriter)3 File (java.io.File)2 Test (org.junit.Test)2 TxPullClient (org.neo4j.causalclustering.catchup.tx.TxPullClient)2 TxPullResponseListener (org.neo4j.causalclustering.catchup.tx.TxPullResponseListener)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 StoreId (org.neo4j.causalclustering.identity.StoreId)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 Monitors (org.neo4j.kernel.monitoring.Monitors)2 CatchUpClientException (org.neo4j.causalclustering.catchup.CatchUpClientException)1 CatchupResult (org.neo4j.causalclustering.catchup.CatchupResult)1