Search in sources :

Example 21 with TransactionId

use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldAppendCommittedTransactions.

@Test
void shouldAppendCommittedTransactions() throws Exception {
    // GIVEN
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    long nextTxId = 15;
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(nextTxId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, databaseHealth));
    // WHEN
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = nextTxId - 5;
    long timeCommitted = timeStarted + 10;
    PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(singleTestCommand());
    transactionRepresentation.setHeader(additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1, ANONYMOUS);
    LogEntryStart start = new LogEntryStart(0L, latestCommittedTxWhenStarted, 0, null, LogPosition.UNSPECIFIED);
    LogEntryCommit commit = new LogEntryCommit(nextTxId, 0L, BASE_TX_CHECKSUM);
    CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);
    appender.append(new TransactionToApply(transactionRepresentation, transaction.getCommitEntry().getTxId(), NULL), logAppendEvent);
    // THEN
    LogEntryReader logEntryReader = logEntryReader();
    try (PhysicalTransactionCursor reader = new PhysicalTransactionCursor(channel, logEntryReader)) {
        reader.next();
        TransactionRepresentation result = reader.get().getTransactionRepresentation();
        assertArrayEquals(additionalHeader, result.additionalHeader());
        assertEquals(timeStarted, result.getTimeStarted());
        assertEquals(timeCommitted, result.getTimeCommitted());
        assertEquals(latestCommittedTxWhenStarted, result.getLatestCommittedTxWhenStarted());
    }
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) 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) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) Test(org.junit.jupiter.api.Test)

Example 22 with TransactionId

use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.

the class NeoStoresTest method shouldSetHighestTransactionIdWhenNeeded.

@Test
void shouldSetHighestTransactionIdWhenNeeded() {
    // GIVEN
    StoreFactory factory = getStoreFactory(Config.defaults(), databaseLayout, fs, LOG_PROVIDER);
    try (NeoStores neoStore = factory.openAllNeoStores(true)) {
        MetaDataStore store = neoStore.getMetaDataStore();
        store.setLastCommittedAndClosedTransactionId(40, 4444, BASE_TX_COMMIT_TIMESTAMP, CURRENT_FORMAT_LOG_HEADER_SIZE, 0, NULL);
        // WHEN
        store.transactionCommitted(42, 6666, BASE_TX_COMMIT_TIMESTAMP, NULL);
        // THEN
        assertEquals(new TransactionId(42, 6666, BASE_TX_COMMIT_TIMESTAMP), store.getLastCommittedTransaction());
        assertArrayEquals(new long[] { 40, 0, CURRENT_FORMAT_LOG_HEADER_SIZE }, store.getLastClosedTransaction());
    }
}
Also used : TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 23 with TransactionId

use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.

the class HighestTransactionIdTest method shouldHardSetHighest.

@Test
void shouldHardSetHighest() {
    // GIVEN
    HighestTransactionId highest = new HighestTransactionId(10, 10, 10);
    // WHEN
    highest.set(8, 1299128, 42);
    // THEN
    assertEquals(new TransactionId(8, 1299128, 42), highest.get());
}
Also used : TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 24 with TransactionId

use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.

the class MetaDataStoreTest method setStoreIdShouldSetAllRelatedFields.

@Test
void setStoreIdShouldSetAllRelatedFields() throws IOException {
    // given
    int creationTime = 1;
    int randomId = 2;
    long storeVersion = versionStringToLong(LATEST_STORE_VERSION);
    int upgradeTime = 4;
    int upgradeTxId = 5;
    int upgradeTxChecksum = 6;
    long upgradeTxCommitTimestamp = 7;
    StoreId storeId = new StoreId(creationTime, randomId, storeVersion, upgradeTime, upgradeTxId);
    // when
    try (MetaDataStore store = newMetaDataStore()) {
        MetaDataStore.setStoreId(pageCache, store.getStorageFile(), storeId, upgradeTxChecksum, upgradeTxCommitTimestamp, databaseLayout.getDatabaseName(), NULL);
    }
    // then
    try (MetaDataStore store = newMetaDataStore()) {
        assertEquals(creationTime, store.getCreationTime());
        assertEquals(randomId, store.getRandomNumber());
        assertEquals(storeVersion, store.getStoreVersion());
        assertEquals(upgradeTime, store.getUpgradeTime());
        TransactionId expectedTx = new TransactionId(upgradeTxId, upgradeTxChecksum, upgradeTxCommitTimestamp);
        assertEquals(expectedTx, store.getUpgradeTransaction());
    }
}
Also used : ExternalStoreId(org.neo4j.storageengine.api.ExternalStoreId) StoreId(org.neo4j.storageengine.api.StoreId) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 25 with TransactionId

use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.

the class MetaDataStoreTest method setUpgradeTransactionMustBeAtomic.

@Test
void setUpgradeTransactionMustBeAtomic() throws Throwable {
    try (MetaDataStore store = newMetaDataStore()) {
        PagedFile pf = store.pagedFile;
        store.setUpgradeTransaction(0, 0, 0, NULL);
        AtomicLong writeCount = new AtomicLong();
        AtomicLong fileReadCount = new AtomicLong();
        AtomicLong apiReadCount = new AtomicLong();
        int upperLimit = 10_000;
        int lowerLimit = 100;
        long endTime = currentTimeMillis() + SECONDS.toMillis(10);
        Race race = new Race();
        race.withEndCondition(() -> writeCount.get() >= upperLimit && fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit);
        race.withEndCondition(() -> writeCount.get() >= lowerLimit && fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit && currentTimeMillis() >= endTime);
        // writers
        race.addContestants(3, () -> {
            long count = writeCount.incrementAndGet();
            store.setUpgradeTransaction(count, (int) count, count, NULL);
        });
        // file readers
        race.addContestants(3, throwing(() -> {
            try (PageCursor cursor = pf.io(0, PagedFile.PF_SHARED_READ_LOCK, NULL)) {
                assertTrue(cursor.next());
                long id;
                long checksum;
                do {
                    id = store.getRecordValue(cursor, MetaDataStore.Position.UPGRADE_TRANSACTION_ID);
                    checksum = store.getRecordValue(cursor, MetaDataStore.Position.UPGRADE_TRANSACTION_CHECKSUM);
                } while (cursor.shouldRetry());
                assertIdEqualsChecksum(id, checksum, "file");
                fileReadCount.incrementAndGet();
            }
        }));
        race.addContestants(3, () -> {
            TransactionId transaction = store.getUpgradeTransaction();
            assertIdEqualsChecksum(transaction.transactionId(), transaction.checksum(), "API");
            apiReadCount.incrementAndGet();
        });
        race.go();
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PagedFile(org.neo4j.io.pagecache.PagedFile) DelegatingPagedFile(org.neo4j.io.pagecache.DelegatingPagedFile) Race(org.neo4j.test.Race) PageCursor(org.neo4j.io.pagecache.PageCursor) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) 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