use of org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata in project neo4j by neo4j.
the class PhysicalLogicalTransactionStore method getTransactions.
@Override
public TransactionCursor getTransactions(final long transactionIdToStartFrom) throws IOException {
// look up in position cache
try {
TransactionMetadataCache.TransactionMetadata transactionMetadata = transactionMetadataCache.getTransactionMetadata(transactionIdToStartFrom);
if (transactionMetadata != null) {
// we're good
ReadableLogChannel channel = logFile.getReader(transactionMetadata.getStartPosition());
return new PhysicalTransactionCursor<>(channel, logEntryReader);
}
// ask LogFile about the version it may be in
LogVersionLocator headerVisitor = new LogVersionLocator(transactionIdToStartFrom);
logFile.accept(headerVisitor);
// ask LogFile
TransactionPositionLocator transactionPositionLocator = new TransactionPositionLocator(transactionIdToStartFrom, logEntryReader);
logFile.accept(transactionPositionLocator, headerVisitor.getLogPosition());
LogPosition position = transactionPositionLocator.getAndCacheFoundLogPosition(transactionMetadataCache);
return new PhysicalTransactionCursor<>(logFile.getReader(position), logEntryReader);
} catch (FileNotFoundException e) {
throw new NoSuchTransactionException(transactionIdToStartFrom, "Log position acquired, but couldn't find the log file itself. Perhaps it just recently was deleted? [" + e.getMessage() + "]");
}
}
use of org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata in project neo4j by neo4j.
the class PhysicalLogicalTransactionStore method getMetadataFor.
@Override
public TransactionMetadata getMetadataFor(long transactionId) throws IOException {
if (transactionId <= BASE_TX_ID) {
return METADATA_FOR_EMPTY_STORE;
}
TransactionMetadata transactionMetadata = transactionMetadataCache.getTransactionMetadata(transactionId);
if (transactionMetadata == null) {
try (IOCursor<CommittedTransactionRepresentation> cursor = getTransactions(transactionId)) {
while (cursor.next()) {
CommittedTransactionRepresentation tx = cursor.get();
LogEntryCommit commitEntry = tx.getCommitEntry();
long committedTxId = commitEntry.getTxId();
long timeWritten = commitEntry.getTimeWritten();
TransactionMetadata metadata = transactionMetadataCache.cacheTransactionMetadata(committedTxId, tx.getStartEntry().getStartPosition(), tx.getStartEntry().getMasterId(), tx.getStartEntry().getLocalId(), LogEntryStart.checksum(tx.getStartEntry()), timeWritten);
if (committedTxId == transactionId) {
transactionMetadata = metadata;
}
}
}
if (transactionMetadata == null) {
throw new NoSuchTransactionException(transactionId);
}
}
return transactionMetadata;
}
use of org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata 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.TransactionMetadataCache.TransactionMetadata in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method verifyTransaction.
private void verifyTransaction(TransactionIdStore transactionIdStore, TransactionMetadataCache positionCache, byte[] additionalHeader, int masterId, int authorId, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store) throws IOException {
TransactionMetadata expectedMetadata;
try (TransactionCursor cursor = store.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
boolean hasNext = cursor.next();
assertTrue(hasNext);
CommittedTransactionRepresentation tx = cursor.get();
TransactionRepresentation transaction = tx.getTransactionRepresentation();
assertArrayEquals(additionalHeader, transaction.additionalHeader());
assertEquals(masterId, transaction.getMasterId());
assertEquals(authorId, transaction.getAuthorId());
assertEquals(timeStarted, transaction.getTimeStarted());
assertEquals(timeCommitted, transaction.getTimeCommitted());
assertEquals(latestCommittedTxWhenStarted, transaction.getLatestCommittedTxWhenStarted());
expectedMetadata = new TransactionMetadata(masterId, authorId, tx.getStartEntry().getStartPosition(), tx.getStartEntry().checksum(), timeCommitted);
}
positionCache.clear();
TransactionMetadata actualMetadata = store.getMetadataFor(transactionIdStore.getLastCommittedTransactionId());
assertEquals(expectedMetadata, actualMetadata);
}
Aggregations