use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class StoreMigrator method updateOrAddNeoStoreFieldsAsPartOfMigration.
private void updateOrAddNeoStoreFieldsAsPartOfMigration(File migrationDir, File storeDir, String versionToMigrateTo) throws IOException {
final File storeDirNeoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_ID, MetaDataStore.getRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_ID));
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TIME, System.currentTimeMillis());
// Store the checksum of the transaction id the upgrade is at right now. Store it both as
// LAST_TRANSACTION_CHECKSUM and UPGRADE_TRANSACTION_CHECKSUM. Initially the last transaction and the
// upgrade transaction will be the same, but imagine this scenario:
// - legacy store is migrated on instance A at transaction T
// - upgraded store is copied, via backup or HA or whatever to instance B
// - instance A performs a transaction
// - instance B would like to communicate with A where B's last transaction checksum
// is verified on A. A, at this point not having logs from pre-migration era, will need to
// know the checksum of transaction T to accommodate for this request from B. A will be able
// to look up checksums for transactions succeeding T by looking at its transaction logs,
// but T needs to be stored in neostore to be accessible. Obvioously this scenario is only
// problematic as long as we don't migrate and translate old logs.
TransactionId lastTxInfo = readLastTxInformation(migrationDir);
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_CHECKSUM, lastTxInfo.checksum());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_CHECKSUM, lastTxInfo.checksum());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp());
// add LAST_CLOSED_TRANSACTION_LOG_VERSION and LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET to the migrated
// NeoStore
LogPosition logPosition = readLastTxLogPosition(migrationDir);
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, logPosition.getLogVersion());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, logPosition.getByteOffset());
// Upgrade version in NeoStore
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.STORE_VERSION, MetaDataStore.versionStringToLong(versionToMigrateTo));
}
use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class LegacyLogs method getTransactionInformation.
public Optional<TransactionId> getTransactionInformation(File storeDir, long transactionId) throws IOException {
List<File> logFiles = Arrays.asList(fs.listFiles(storeDir, versionedLegacyLogFilesFilter));
logFiles.sort(NEWEST_FIRST);
for (File file : logFiles) {
Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(file);
boolean hadAnyTransactions = false;
try (IOCursor<LogEntry> cursor = pair.other()) {
// The log entries will come sorted from this cursor, so no need to keep track of identifiers and such.
LogEntryStart startEntry = null;
while (cursor.next()) {
LogEntry logEntry = cursor.get();
if (logEntry instanceof LogEntryStart) {
startEntry = (LogEntryStart) logEntry;
} else if (logEntry instanceof LogEntryCommit) {
hadAnyTransactions = true;
LogEntryCommit commitEntry = logEntry.as();
if (commitEntry.getTxId() == transactionId) {
return Optional.of(new TransactionId(transactionId, startEntry.checksum(), commitEntry.getTimeWritten()));
}
}
}
}
if (hadAnyTransactions) {
// No need to go further back than this. We're looking for the last transaction
break;
}
}
return Optional.empty();
}
use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class ClusterTest method lastCommittedTxTimestamp.
private static long lastCommittedTxTimestamp(HighlyAvailableGraphDatabase db) {
DependencyResolver resolver = db.getDependencyResolver();
MetaDataStore metaDataStore = resolver.resolveDependency(MetaDataStore.class);
TransactionId txInfo = metaDataStore.getLastCommittedTransaction();
return txInfo.commitTimestamp();
}
use of org.neo4j.kernel.impl.store.TransactionId 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.store.TransactionId in project neo4j by neo4j.
the class KernelTransactionsTest method newKernelTransactions.
private static KernelTransactions newKernelTransactions(Locks locks, StorageEngine storageEngine, TransactionCommitProcess commitProcess, boolean testKernelTransactions) throws Throwable {
LifeSupport life = new LifeSupport();
life.start();
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(0, 0, 0));
Tracers tracers = new Tracers("null", NullLog.getInstance(), new Monitors(), mock(JobScheduler.class));
StatementLocksFactory statementLocksFactory = new SimpleStatementLocksFactory(locks);
StatementOperationContainer statementOperationsContianer = new StatementOperationContainer(null, null);
KernelTransactions transactions;
if (testKernelTransactions) {
transactions = createTestTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
} else {
transactions = createTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
}
transactions.start();
return transactions;
}
Aggregations