Search in sources :

Example 26 with StoreId

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

the class StoreFiles method readStoreId.

public StoreId readStoreId(File storeDir) throws IOException {
    File neoStoreFile = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    org.neo4j.kernel.impl.store.StoreId kernelStoreId = MetaDataStore.getStoreId(pageCache, neoStoreFile);
    return new StoreId(kernelStoreId.getCreationTime(), kernelStoreId.getRandomId(), kernelStoreId.getUpgradeTime(), kernelStoreId.getUpgradeId());
}
Also used : StoreId(org.neo4j.causalclustering.identity.StoreId) File(java.io.File)

Example 27 with StoreId

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

the class TxPullRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, final TxPullRequest msg) throws Exception {
    long firstTxId = Math.max(msg.previousTxId(), BASE_TX_ID) + 1;
    long lastTxId = firstTxId;
    CatchupResult status = SUCCESS_END_OF_STREAM;
    StoreId localStoreId = storeIdSupplier.get();
    long lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
    if (localStoreId == null || !localStoreId.equals(msg.expectedStoreId())) {
        status = E_STORE_ID_MISMATCH;
        log.info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", lastTxId, msg.expectedStoreId(), localStoreId);
    } else if (!databaseAvailable.getAsBoolean()) {
        // database is not available for pulling transactions...
        status = E_STORE_UNAVAILABLE;
        log.info("Failed to serve TxPullRequest for tx %d because the local database is unavailable.", lastTxId);
    } else if (lastCommittedTransactionId >= firstTxId) {
        try (IOCursor<CommittedTransactionRepresentation> cursor = logicalTransactionStore.getTransactions(firstTxId)) {
            status = SUCCESS_END_OF_BATCH;
            for (int i = 0; i < batchSize; i++) {
                if (cursor.next()) {
                    ctx.write(ResponseMessageType.TX);
                    CommittedTransactionRepresentation tx = cursor.get();
                    lastTxId = tx.getCommitEntry().getTxId();
                    ctx.write(new TxPullResponse(localStoreId, tx));
                } else {
                    status = SUCCESS_END_OF_STREAM;
                    break;
                }
            }
            ctx.flush();
        } catch (NoSuchTransactionException e) {
            status = E_TRANSACTION_PRUNED;
            log.info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", lastTxId);
        }
    }
    ctx.write(ResponseMessageType.TX_STREAM_FINISHED);
    TxStreamFinishedResponse response = new TxStreamFinishedResponse(status, lastCommittedTransactionId);
    ctx.write(response);
    ctx.flush();
    monitor.increment();
    protocol.expect(State.MESSAGE_TYPE);
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) StoreId(org.neo4j.causalclustering.identity.StoreId) CatchupResult(org.neo4j.causalclustering.catchup.CatchupResult) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException)

Example 28 with StoreId

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

the class CoreStateDownloaderTest method shouldDownloadCompleteStoreWhenEmpty.

@Test
public void shouldDownloadCompleteStoreWhenEmpty() throws Throwable {
    // given
    StoreId remoteStoreId = new StoreId(5, 6, 7, 8);
    when(remoteStore.getStoreId(remoteMember)).thenReturn(remoteStoreId);
    when(localDatabase.isEmpty()).thenReturn(true);
    // when
    downloader.downloadSnapshot(remoteMember, coreState);
    // then
    verify(remoteStore, never()).tryCatchingUp(any(), any(), any());
    verify(storeCopyProcess).replaceWithStoreFrom(remoteMember, remoteStoreId);
}
Also used : StoreId(org.neo4j.causalclustering.identity.StoreId) 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