Search in sources :

Example 11 with TransactionId

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

the class MetaDataStore method setUpgradeTransaction.

public void setUpgradeTransaction(long id, int checksum, long timestamp, CursorContext cursorContext) {
    long pageId = pageIdForRecord(Position.UPGRADE_TRANSACTION_ID.id);
    assert pageId == pageIdForRecord(Position.UPGRADE_TRANSACTION_CHECKSUM.id);
    synchronized (upgradeTransactionLock) {
        try (PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK, cursorContext)) {
            if (!cursor.next()) {
                throw new UnderlyingStorageException("Could not access MetaDataStore page " + pageId);
            }
            setRecord(cursor, Position.UPGRADE_TRANSACTION_ID, id);
            setRecord(cursor, Position.UPGRADE_TRANSACTION_CHECKSUM, checksum);
            setRecord(cursor, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, timestamp);
            upgradeTxIdField = id;
            upgradeTxChecksumField = checksum;
            upgradeCommitTimestampField = timestamp;
            upgradeTransaction = new TransactionId(id, checksum, timestamp);
        } catch (IOException e) {
            throw new UnderlyingStorageException(e);
        }
    }
}
Also used : IOException(java.io.IOException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) PageCursor(org.neo4j.io.pagecache.PageCursor) TransactionId(org.neo4j.storageengine.api.TransactionId)

Example 12 with TransactionId

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

the class HighestTransactionId method offer.

/**
 * Offers a transaction id. Will be accepted if this is higher than the current highest.
 * This method is thread-safe.
 *
 * @param transactionId transaction id to compare for highest.
 * @param checksum checksum of the transaction.
 * @param commitTimestamp commit time for transaction with {@code transactionId}.
 * @return {@code true} if the given transaction id was higher than the current highest,
 * {@code false}.
 */
public boolean offer(long transactionId, int checksum, long commitTimestamp) {
    TransactionId high = highest.get();
    if (transactionId < high.transactionId()) {
        // a higher id has already been offered
        return false;
    }
    TransactionId update = new TransactionId(transactionId, checksum, commitTimestamp);
    while (!highest.compareAndSet(high, update)) {
        high = highest.get();
        if (high.transactionId() >= transactionId) {
            // apparently someone else set a higher id while we were trying to set this id
            return false;
        }
    }
    // we set our id as the highest
    return true;
}
Also used : TransactionId(org.neo4j.storageengine.api.TransactionId)

Example 13 with TransactionId

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

the class NeoStoresTest method shouldAddUpgradeFieldsToTheNeoStoreIfNotPresent.

@Test
void shouldAddUpgradeFieldsToTheNeoStoreIfNotPresent() throws IOException {
    StoreFactory factory = newStoreFactory(databaseLayout, pageCache, fs);
    long recordVersion = defaultStoreVersion();
    try (NeoStores neoStores = factory.openAllNeoStores(true)) {
        MetaDataStore metaDataStore = neoStores.getMetaDataStore();
        metaDataStore.setCreationTime(3, NULL);
        metaDataStore.setRandomNumber(4, NULL);
        metaDataStore.setCurrentLogVersion(5, NULL);
        metaDataStore.setLastCommittedAndClosedTransactionId(6, 42, BASE_TX_COMMIT_TIMESTAMP, 43, 44, NULL);
        metaDataStore.setStoreVersion(recordVersion, NULL);
        metaDataStore.setLatestConstraintIntroducingTx(9, NULL);
    }
    Path file = databaseLayout.metadataStore();
    assertNotEquals(10, MetaDataStore.getRecord(pageCache, file, Position.UPGRADE_TRANSACTION_ID, databaseLayout.getDatabaseName(), NULL));
    assertNotEquals(11, MetaDataStore.getRecord(pageCache, file, Position.UPGRADE_TRANSACTION_CHECKSUM, databaseLayout.getDatabaseName(), NULL));
    MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_ID, 10, databaseLayout.getDatabaseName(), NULL);
    MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_CHECKSUM, 11, databaseLayout.getDatabaseName(), NULL);
    MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TIME, 12, databaseLayout.getDatabaseName(), NULL);
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        MetaDataStore metaDataStore = neoStores.getMetaDataStore();
        assertEquals(3, metaDataStore.getCreationTime());
        assertEquals(4, metaDataStore.getRandomNumber());
        assertEquals(5, metaDataStore.getCurrentLogVersion());
        assertEquals(6, metaDataStore.getLastCommittedTransactionId());
        assertEquals(recordVersion, metaDataStore.getStoreVersion());
        assertEquals(9, metaDataStore.getLatestConstraintIntroducingTx());
        assertEquals(new TransactionId(10, 11, BASE_TX_COMMIT_TIMESTAMP), metaDataStore.getUpgradeTransaction());
        assertEquals(12, metaDataStore.getUpgradeTime());
        assertArrayEquals(new long[] { 6, 44, 43 }, metaDataStore.getLastClosedTransaction());
    }
    MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, 13, databaseLayout.getDatabaseName(), NULL);
    try (NeoStores neoStores = factory.openAllNeoStores()) {
        MetaDataStore metaDataStore = neoStores.getMetaDataStore();
        assertEquals(new TransactionId(10, 11, 13), metaDataStore.getUpgradeTransaction());
    }
}
Also used : Path(java.nio.file.Path) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 14 with TransactionId

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

the class TransactionLogInitializerTest method shouldResetMetaDataStoreWithTransactionId.

@Test
void shouldResetMetaDataStoreWithTransactionId() throws Exception {
    // Given
    var metaStore = mock(MetadataProvider.class);
    var txn = new TransactionId(3, -1322858814, currentTimeMillis());
    when(metaStore.getStoreId()).thenReturn(new StoreId(versionStringToLong(LATEST_STORE_VERSION)));
    when(metaStore.getLastClosedTransaction()).thenReturn(new long[] { txn.transactionId(), 0, 1613 });
    when(metaStore.getLastCommittedTransaction()).thenReturn(txn);
    when(metaStore.getLastCommittedTransactionId()).thenReturn(txn.transactionId());
    when(metaStore.getLastClosedTransactionId()).thenReturn(txn.transactionId());
    DatabaseLayout databaseLayout = Neo4jLayout.of(testDirectory.homePath()).databaseLayout(DEFAULT_DATABASE_NAME);
    // When
    var initializer = new TransactionLogInitializer(testDirectory.getFileSystem(), metaStore, INSTANCE, PageCacheTracer.NULL);
    initializer.initializeEmptyLogFile(databaseLayout, databaseLayout.getTransactionLogsDirectory(), "LostFiles");
    // Then
    verify(metaStore).resetLastClosedTransaction(eq(txn.transactionId()), eq(txn.transactionId()), eq((long) CURRENT_FORMAT_LOG_HEADER_SIZE), eq(true), any());
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) TransactionId(org.neo4j.storageengine.api.TransactionId) Test(org.junit.jupiter.api.Test)

Example 15 with TransactionId

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

the class StoreMigratorTest method writeAndReadLastTxInformation.

@Test
void writeAndReadLastTxInformation() throws IOException {
    RecordStorageMigrator migrator = newStoreMigrator();
    TransactionId writtenTxId = new TransactionId(random.nextLong(), random.nextInt(), random.nextLong());
    migrator.writeLastTxInformation(databaseLayout, writtenTxId);
    TransactionId readTxId = migrator.readLastTxInformation(databaseLayout);
    assertEquals(writtenTxId, readTxId);
}
Also used : 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