Search in sources :

Example 16 with TransactionId

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);
}
Also used : Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 17 with TransactionId

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());
}
Also used : Path(java.nio.file.Path) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) Config(org.neo4j.configuration.Config) NullLogService(org.neo4j.logging.internal.NullLogService) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogService(org.neo4j.logging.internal.LogService) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 18 with TransactionId

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;
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) DatabaseTracers(org.neo4j.kernel.database.DatabaseTracers) Monitors(org.neo4j.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TransactionId(org.neo4j.storageengine.api.TransactionId) Tracers(org.neo4j.kernel.monitoring.tracing.Tracers) DatabaseTracers(org.neo4j.kernel.database.DatabaseTracers)

Example 19 with TransactionId

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");
    }
}
Also used : UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) TransactionId(org.neo4j.storageengine.api.TransactionId)

Example 20 with TransactionId

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());
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionId (org.neo4j.storageengine.api.TransactionId)25 Test (org.junit.jupiter.api.Test)16 Path (java.nio.file.Path)4 DbmsLogEntryWriterFactory (org.neo4j.kernel.database.DbmsLogEntryWriterFactory)4 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)4 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)4 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)4 IOException (java.io.IOException)3 Config (org.neo4j.configuration.Config)3 PageCursor (org.neo4j.io.pagecache.PageCursor)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 LogService (org.neo4j.logging.internal.LogService)3 NullLogService (org.neo4j.logging.internal.NullLogService)3 SimpleLogService (org.neo4j.logging.internal.SimpleLogService)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)2 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)2 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)2