Search in sources :

Example 1 with TransactionIdStore

use of org.neo4j.storageengine.api.TransactionIdStore 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 2 with TransactionIdStore

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

the class PhysicalLogicalTransactionStoreTest method shouldOpenCleanStore.

@Test
void shouldOpenCleanStore() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache();
    LifeSupport life = new LifeSupport();
    final LogFiles logFiles = buildLogFiles(transactionIdStore);
    life.add(logFiles);
    life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, DATABASE_HEALTH));
    try {
        // WHEN
        life.start();
    } finally {
        life.shutdown();
    }
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.jupiter.api.Test)

Example 3 with TransactionIdStore

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

the class LogFilesBuilder method lastCommittedIdSupplier.

private LongSupplier lastCommittedIdSupplier() throws IOException {
    if (lastCommittedTransactionIdSupplier != null) {
        return lastCommittedTransactionIdSupplier;
    }
    if (transactionIdStore != null) {
        return transactionIdStore::getLastCommittedTransactionId;
    }
    if (fileBasedOperationsOnly) {
        return () -> {
            throw new UnsupportedOperationException("Current version of log files can't perform any " + "operation that require availability of transaction id store. Please build full version of log files " + "to be able to use them.");
        };
    }
    if (readOnly) {
        requireNonNull(pageCache, "Read only log files require page cache to be able to read committed " + "transaction info from store store.");
        requireNonNull(databaseLayout, "Store directory is required.");
        TransactionIdStore transactionIdStore = readOnlyTransactionIdStore();
        return transactionIdStore::getLastCommittedTransactionId;
    } else {
        requireNonNull(dependencies, TransactionIdStore.class.getSimpleName() + " is required. " + "Please provide an instance or a dependencies where it can be found.");
        return () -> resolveDependency(TransactionIdStore.class).getLastCommittedTransactionId();
    }
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore)

Example 4 with TransactionIdStore

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

the class LogFilesBuilder method committingIdSupplier.

private LongSupplier committingIdSupplier() throws IOException {
    if (transactionIdStore != null) {
        return transactionIdStore::committingTransactionId;
    }
    if (fileBasedOperationsOnly) {
        return () -> {
            throw new UnsupportedOperationException("Current version of log files can't perform any " + "operation that require availability of transaction id store. Please build full version of log files " + "to be able to use them.");
        };
    }
    if (readOnly) {
        requireNonNull(pageCache, "Read only log files require page cache to be able to read committed " + "transaction info from store store.");
        requireNonNull(databaseLayout, "Store directory is required.");
        TransactionIdStore transactionIdStore = readOnlyTransactionIdStore();
        return transactionIdStore::committingTransactionId;
    } else {
        requireNonNull(dependencies, TransactionIdStore.class.getSimpleName() + " is required. " + "Please provide an instance or a dependencies where it can be found.");
        return () -> resolveDependency(TransactionIdStore.class).committingTransactionId();
    }
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore)

Example 5 with TransactionIdStore

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

the class GraphStoreFixture method startDatabaseAndExtractComponents.

private void startDatabaseAndExtractComponents() {
    managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setFileSystem(testDirectory.getFileSystem()).setConfig(GraphDatabaseSettings.record_format, formatName).setConfig(GraphDatabaseInternalSettings.label_block_size, 60).setConfig(GraphDatabaseInternalSettings.consistency_check_on_apply, false).setConfig(getConfig()).build();
    database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    commitProcess = new InternalTransactionCommitProcess(dependencyResolver.resolveDependency(TransactionAppender.class), dependencyResolver.resolveDependency(StorageEngine.class));
    transactionIdStore = database.getDependencyResolver().resolveDependency(TransactionIdStore.class);
    storageEngine = dependencyResolver.resolveDependency(RecordStorageEngine.class);
    neoStores = storageEngine.testAccessNeoStores();
    indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    directStoreAccess = new DirectStoreAccess(neoStores, dependencyResolver.resolveDependency(IndexProviderMap.class), dependencyResolver.resolveDependency(TokenHolders.class), dependencyResolver.resolveDependency(IndexStatisticsStore.class), dependencyResolver.resolveDependency(IdGeneratorFactory.class));
    countsStore = storageEngine.countsAccessor();
    groupDegreesStore = storageEngine.relationshipGroupDegreesStore();
    pageCache = dependencyResolver.resolveDependency(PageCache.class);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) DirectStoreAccess(org.neo4j.consistency.store.DirectStoreAccess) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) PageCache(org.neo4j.io.pagecache.PageCache) DependencyResolver(org.neo4j.common.DependencyResolver)

Aggregations

TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)22 Test (org.junit.jupiter.api.Test)12 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)10 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 IOException (java.io.IOException)3 TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)3 Path (java.nio.file.Path)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 BookmarkWithPrefix (org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix)2 DependencyResolver (org.neo4j.common.DependencyResolver)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 TestableTransactionAppender (org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender)2 StorageEngine (org.neo4j.storageengine.api.StorageEngine)2 TransactionId (org.neo4j.storageengine.api.TransactionId)2