use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class StoreMigratorTest method shouldExtractTransactionInformationFromMetaDataStore.
@Test
void shouldExtractTransactionInformationFromMetaDataStore() throws Exception {
// given
// ... variables
long txId = 42;
int checksum = 123456789;
long timestamp = 919191919191919191L;
TransactionId expected = new TransactionId(txId, checksum, timestamp);
// ... and files
Path neoStore = databaseLayout.metadataStore();
Files.createFile(neoStore);
// ... and mocks
Config config = mock(Config.class);
LogService logService = mock(LogService.class);
// when
// ... data in record
setRecord(pageCache, neoStore, LAST_TRANSACTION_ID, txId, databaseLayout.getDatabaseName(), NULL);
setRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM, checksum, databaseLayout.getDatabaseName(), NULL);
setRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, timestamp, databaseLayout.getDatabaseName(), NULL);
// ... and with migrator
RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
TransactionId actual = migrator.extractTransactionIdInformation(neoStore, txId, databaseLayout, NULL);
// then
assertEquals(expected, actual);
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class StoreMigratorTest method shouldGenerateTransactionInformationWhenLogsNotPresent.
@Test
void shouldGenerateTransactionInformationWhenLogsNotPresent() throws Exception {
// given
long txId = 42;
Path neoStore = databaseLayout.metadataStore();
Files.createFile(neoStore);
Config config = mock(Config.class);
LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
// when
// ... transaction info not in neo store
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_ID, databaseLayout.getDatabaseName(), NULL));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM, databaseLayout.getDatabaseName(), NULL));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, databaseLayout.getDatabaseName(), NULL));
// ... and with migrator
RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
TransactionId actual = migrator.extractTransactionIdInformation(neoStore, txId, databaseLayout, NULL);
// then
assertEquals(txId, actual.transactionId());
assertEquals(TransactionIdStore.UNKNOWN_TX_CHECKSUM, actual.checksum());
assertEquals(TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP, actual.commitTimestamp());
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class KernelTransactionsTest method newKernelTransactions.
private KernelTransactions newKernelTransactions(Locks locks, StorageEngine storageEngine, TransactionCommitProcess commitProcess, boolean testKernelTransactions, Config config) {
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), clock, config);
final DatabaseTracers databaseTracers = new DatabaseTracers(tracers);
KernelTransactions transactions;
if (testKernelTransactions) {
transactions = createTestTransactions(storageEngine, commitProcess, transactionIdStore, databaseTracers, locks, clock, databaseAvailabilityGuard);
} else {
transactions = createTransactions(storageEngine, commitProcess, transactionIdStore, databaseTracers, locks, clock, databaseAvailabilityGuard, config);
}
transactions.start();
return transactions;
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class MetaDataStore method readAllFields.
private void readAllFields(PageCursor cursor) throws IOException {
do {
creationTimeField = getRecordValue(cursor, Position.TIME);
randomNumberField = getRecordValue(cursor, Position.RANDOM_NUMBER);
versionField = getRecordValue(cursor, Position.LOG_VERSION);
long lastCommittedTxId = getRecordValue(cursor, Position.LAST_TRANSACTION_ID);
lastCommittingTxField.set(lastCommittedTxId);
storeVersionField = getRecordValue(cursor, Position.STORE_VERSION);
getRecordValue(cursor, Position.FIRST_GRAPH_PROPERTY);
latestConstraintIntroducingTxField = getRecordValue(cursor, Position.LAST_CONSTRAINT_TRANSACTION);
upgradeTxIdField = getRecordValue(cursor, Position.UPGRADE_TRANSACTION_ID);
upgradeTxChecksumField = (int) getRecordValue(cursor, Position.UPGRADE_TRANSACTION_CHECKSUM);
upgradeTimeField = getRecordValue(cursor, Position.UPGRADE_TIME);
long lastClosedTransactionLogVersion = getRecordValue(cursor, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION);
long lastClosedTransactionLogByteOffset = getRecordValue(cursor, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET);
lastClosedTx.set(lastCommittedTxId, new long[] { lastClosedTransactionLogVersion, lastClosedTransactionLogByteOffset });
highestCommittedTransaction.set(lastCommittedTxId, (int) getRecordValue(cursor, Position.LAST_TRANSACTION_CHECKSUM), getRecordValue(cursor, Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, UNKNOWN_TX_COMMIT_TIMESTAMP));
upgradeCommitTimestampField = getRecordValue(cursor, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, BASE_TX_COMMIT_TIMESTAMP);
externalStoreUUID = readExternalStoreUUID(cursor);
databaseUUID = readDatabaseUUID(cursor);
upgradeTransaction = new TransactionId(upgradeTxIdField, upgradeTxChecksumField, upgradeCommitTimestampField);
checkpointLogVersionField = getRecordValue(cursor, CHECKPOINT_LOG_VERSION, 0);
kernelVersion = getRecordValue(cursor, KERNEL_VERSION);
} while (cursor.shouldRetry());
if (cursor.checkAndClearBoundsFlag()) {
throw new UnderlyingStorageException("Out of page bounds when reading all meta-data fields. The page in question is page " + cursor.getCurrentPageId() + " of file " + storageFile.toAbsolutePath() + ", which is " + cursor.getCurrentPageSize() + " bytes in size");
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method shouldAppendSingleTransaction.
@Test
void shouldAppendSingleTransaction() throws Exception {
// GIVEN
when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
long txId = 15;
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
TransactionAppender appender = life.add(createTransactionAppender());
// WHEN
TransactionRepresentation transaction = transaction(singleTestCommand(), new byte[] { 1, 2, 5 }, 12345, 4545, 12345 + 10);
appender.append(new TransactionToApply(transaction, NULL), logAppendEvent);
// THEN
final LogEntryReader logEntryReader = logEntryReader();
try (PhysicalTransactionCursor reader = new PhysicalTransactionCursor(channel, logEntryReader)) {
reader.next();
TransactionRepresentation tx = reader.get().getTransactionRepresentation();
assertArrayEquals(transaction.additionalHeader(), tx.additionalHeader());
assertEquals(transaction.getTimeStarted(), tx.getTimeStarted());
assertEquals(transaction.getTimeCommitted(), tx.getTimeCommitted());
assertEquals(transaction.getLatestCommittedTxWhenStarted(), tx.getLatestCommittedTxWhenStarted());
}
}
Aggregations