Search in sources :

Example 1 with TransactionId

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

the class StoreMigratorTest method shouldGenerateTransactionInformationWhenLogsAreEmpty.

@Test
void shouldGenerateTransactionInformationWhenLogsAreEmpty() throws Exception {
    // given
    long txId = 1;
    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.BASE_TX_CHECKSUM, actual.checksum());
    assertEquals(TransactionIdStore.BASE_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 2 with TransactionId

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

the class NeoStoresTest method shouldNotSetHighestTransactionIdWhenNeeded.

@Test
void shouldNotSetHighestTransactionIdWhenNeeded() {
    // 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(39, 3333, BASE_TX_COMMIT_TIMESTAMP, NULL);
        // THEN
        assertEquals(new TransactionId(40, 4444, 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 3 with TransactionId

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

the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedAppendedTransaction.

@Test
void shouldNotCallTransactionClosedOnFailedAppendedTransaction() throws Exception {
    // GIVEN
    long txId = 3;
    String failureMessage = "Forces a failure";
    FlushablePositionAwareChecksumChannel channel = spy(new PositionAwarePhysicalFlushableChecksumChannel(mock(PhysicalLogVersionedStoreChannel.class), new HeapScopedBuffer(Long.BYTES * 2, INSTANCE)));
    IOException failure = new IOException(failureMessage);
    when(channel.putLong(anyLong())).thenThrow(failure);
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    Mockito.reset(databaseHealth);
    TransactionAppender appender = life.add(createTransactionAppender());
    // WHEN
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    var e = assertThrows(IOException.class, () -> appender.append(new TransactionToApply(transaction, NULL), logAppendEvent));
    assertSame(failure, e);
    verify(transactionIdStore).nextCommittingTransactionId();
    verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
    verify(databaseHealth).panic(failure);
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) IOException(java.io.IOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TransactionId(org.neo4j.storageengine.api.TransactionId) HeapScopedBuffer(org.neo4j.io.memory.HeapScopedBuffer) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) Test(org.junit.jupiter.api.Test)

Example 4 with TransactionId

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

the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedForceLogToDisk.

@Test
void shouldNotCallTransactionClosedOnFailedForceLogToDisk() throws Exception {
    // GIVEN
    long txId = 3;
    String failureMessage = "Forces a failure";
    FlushablePositionAwareChecksumChannel channel = spy(new InMemoryClosableChannel());
    IOException failure = new IOException(failureMessage);
    final Flushable flushable = mock(Flushable.class);
    doAnswer(invocation -> {
        invocation.callRealMethod();
        return flushable;
    }).when(channel).prepareForFlush();
    when(logFile.forceAfterAppend(any())).thenThrow(failure);
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    TransactionMetadataCache metadataCache = new TransactionMetadataCache();
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, metadataCache, transactionIdStore, databaseHealth));
    // WHEN
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    var e = assertThrows(IOException.class, () -> appender.append(new TransactionToApply(transaction, NULL), logAppendEvent));
    assertSame(failure, e);
    verify(transactionIdStore).nextCommittingTransactionId();
    verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) IOException(java.io.IOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Flushable(java.io.Flushable) TransactionId(org.neo4j.storageengine.api.TransactionId) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) Test(org.junit.jupiter.api.Test)

Example 5 with TransactionId

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

the class SimpleTransactionIdStore method setLastCommittedAndClosedTransactionId.

@Override
public void setLastCommittedAndClosedTransactionId(long transactionId, int checksum, long commitTimestamp, long byteOffset, long logVersion, CursorContext cursorContext) {
    committingTransactionId.set(transactionId);
    committedTransactionId.set(new TransactionId(transactionId, checksum, commitTimestamp));
    closedTransactionId.set(transactionId, new long[] { logVersion, byteOffset });
}
Also used : TransactionId(org.neo4j.storageengine.api.TransactionId)

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