Search in sources :

Example 11 with TransactionIdStore

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

the class RecoveryCorruptedTransactionLogIT method evenTruncateNewerTransactionLogFile.

@Test
void evenTruncateNewerTransactionLogFile() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    TransactionIdStore transactionIdStore = getTransactionIdStore(database);
    long lastClosedTransactionBeforeStart = transactionIdStore.getLastClosedTransactionId();
    for (int i = 0; i < 10; i++) {
        generateTransaction(database);
    }
    long numberOfClosedTransactions = getTransactionIdStore(database).getLastClosedTransactionId() - lastClosedTransactionBeforeStart;
    managementService.shutdown();
    removeLastCheckpointRecordFromLastLogFile();
    addRandomBytesToLastLogFile(this::randomNonZeroBytes);
    startStopDbRecoveryOfCorruptedLogs();
    assertEquals(numberOfClosedTransactions, recoveryMonitor.getNumberOfRecoveredTransactions());
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with TransactionIdStore

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

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

the class InternalTransactionCommitProcessTest method shouldSuccessfullyCommitTransactionWithNoCommands.

@Test
void shouldSuccessfullyCommitTransactionWithNoCommands() throws Exception {
    // GIVEN
    long txId = 11;
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    TransactionAppender appender = new TestableTransactionAppender(transactionIdStore);
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    StorageEngine storageEngine = mock(StorageEngine.class);
    TransactionCommitProcess commitProcess = new InternalTransactionCommitProcess(appender, storageEngine);
    PhysicalTransactionRepresentation noCommandTx = new PhysicalTransactionRepresentation(Collections.emptyList());
    noCommandTx.setHeader(new byte[0], -1, -1, -1, -1, ANONYMOUS);
    // WHEN
    commitProcess.commit(new TransactionToApply(noCommandTx, NULL), commitEvent, INTERNAL);
    verify(transactionIdStore).transactionCommitted(txId, FakeCommitment.CHECKSUM, FakeCommitment.TIMESTAMP, NULL);
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) StorageEngine(org.neo4j.storageengine.api.StorageEngine) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.jupiter.api.Test)

Example 14 with TransactionIdStore

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

the class EagerResultIT method setUp.

@BeforeEach
void setUp() {
    storeDir = testDirectory.homePath();
    testContextSupplier = new TestTransactionVersionContextSupplier();
    database = startRestartableDatabase();
    prepareData();
    TransactionIdStore transactionIdStore = getTransactionIdStore();
    testContextSupplier.setTestVersionContextSupplier(() -> {
        var context = new TestVersionContext(transactionIdStore::getLastClosedTransactionId);
        context.setWrongLastClosedTxId(false);
        return context;
    });
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) TestTransactionVersionContextSupplier(org.neo4j.snapshot.TestTransactionVersionContextSupplier) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with TransactionIdStore

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

the class LogFilesBuilder method closePositionSupplier.

private Supplier<LogPosition> closePositionSupplier() throws IOException {
    if (lastClosedPositionSupplier != null) {
        return lastClosedPositionSupplier;
    }
    if (transactionIdStore != null) {
        return () -> {
            long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
            return new LogPosition(lastClosedTransaction[1], lastClosedTransaction[2]);
        };
    }
    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 () -> {
            long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
            return new LogPosition(lastClosedTransaction[1], lastClosedTransaction[2]);
        };
    } else {
        requireNonNull(dependencies, TransactionIdStore.class.getSimpleName() + " is required. " + "Please provide an instance or a dependencies where it can be found.");
        return () -> {
            long[] lastClosedTransaction = resolveDependency(TransactionIdStore.class).getLastClosedTransaction();
            return new LogPosition(lastClosedTransaction[1], lastClosedTransaction[2]);
        };
    }
}
Also used : TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

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