use of org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException 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));
}
use of org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException in project neo4j by neo4j.
the class RemoteStore method getPullIndex.
/**
* Later stages of the startup process require at least one transaction to
* figure out the mapping between the transaction log and the consensus log.
*
* If there are no transaction logs then we can pull from and including
* the index which the metadata store points to. This would be the case
* for example with a backup taken during an idle period of the system.
*
* However, if there are transaction logs then we want to find out where
* they end and pull from there, excluding the last one so that we do not
* get duplicate entries.
*/
private long getPullIndex(File storeDir) throws IOException {
/* this is the metadata store */
ReadOnlyTransactionIdStore txIdStore = new ReadOnlyTransactionIdStore(pageCache, storeDir);
/* Clean as in clean shutdown. Without transaction logs this should be the truth,
* but otherwise it can be used as a starting point for scanning the logs. */
long lastCleanTxId = txIdStore.getLastCommittedTransactionId();
/* these are the transaction logs */
ReadOnlyTransactionStore txStore = new ReadOnlyTransactionStore(pageCache, fs, storeDir, new Monitors());
long lastTxId = BASE_TX_ID;
try (Lifespan ignored = new Lifespan(txStore)) {
TransactionCursor cursor;
try {
cursor = txStore.getTransactions(lastCleanTxId);
} catch (NoSuchTransactionException e) {
log.info("No transaction logs found. Will use metadata store as base for pull request.");
return lastCleanTxId;
}
while (cursor.next()) {
CommittedTransactionRepresentation tx = cursor.get();
lastTxId = tx.getCommitEntry().getTxId();
}
if (lastTxId < lastCleanTxId) {
throw new IllegalStateException("Metadata index was higher than transaction log index.");
}
// we don't want to pull a transaction we already have in the log, hence +1
return lastTxId + 1;
}
}
use of org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException 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);
}
use of org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException in project neo4j by neo4j.
the class HighlyAvailableEditionModule method assureLastCommitTimestampInitialized.
private static void assureLastCommitTimestampInitialized(DependencyResolver resolver) {
MetaDataStore metaDataStore = resolver.resolveDependency(MetaDataStore.class);
LogicalTransactionStore txStore = resolver.resolveDependency(LogicalTransactionStore.class);
TransactionId txInfo = metaDataStore.getLastCommittedTransaction();
long lastCommitTimestampFromStore = txInfo.commitTimestamp();
if (txInfo.transactionId() == TransactionIdStore.BASE_TX_ID) {
metaDataStore.setLastTransactionCommitTimestamp(TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP);
return;
}
if (lastCommitTimestampFromStore == TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP || lastCommitTimestampFromStore == TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP) {
long lastCommitTimestampFromLogs;
try {
TransactionMetadata metadata = txStore.getMetadataFor(txInfo.transactionId());
lastCommitTimestampFromLogs = metadata.getTimeWritten();
} catch (NoSuchTransactionException e) {
lastCommitTimestampFromLogs = TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP;
} catch (IOException e) {
throw new IllegalStateException("Unable to read transaction logs", e);
}
metaDataStore.setLastTransactionCommitTimestamp(lastCommitTimestampFromLogs);
}
}
use of org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException in project neo4j by neo4j.
the class LogVersionLocatorTest method shouldNotFindLogPosition.
@Test
public void shouldNotFindLogPosition() throws NoSuchTransactionException {
// given
final long txId = 1L;
final PhysicalLogicalTransactionStore.LogVersionLocator locator = new PhysicalLogicalTransactionStore.LogVersionLocator(txId);
final LogPosition position = new LogPosition(1, 128);
// when
final boolean result = locator.visit(position, firstTxIdInLog, lastTxIdInLog);
// then
assertTrue(result);
try {
locator.getLogPosition();
fail("should have thrown");
} catch (NoSuchTransactionException e) {
assertEquals("Unable to find transaction " + txId + " in any of my logical logs: " + "Couldn't find any log containing " + txId, e.getMessage());
}
}
Aggregations