Search in sources :

Example 16 with TransactionIdStore

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

the class DatabaseServiceBookmarkTest method throwsWhenTxAwaitDurationExpires.

@Test
void throwsWhenTxAwaitDurationExpires() {
    long lastClosedTransactionId = 100;
    TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
    var txAwaitDuration = Duration.ofSeconds(42);
    var clock = new FakeClock();
    var guard = new DatabaseAvailabilityGuard(DATABASE_ID, clock, NullLog.getInstance(), 0, mock(CompositeDatabaseAvailabilityGuard.class));
    var databaseAvailabilityGuard = spy(guard);
    when(databaseAvailabilityGuard.isAvailable()).then(invocation -> {
        // move clock forward on avery availability check
        // this check is executed on every tx id polling iteration
        clock.forward(1, SECONDS);
        return true;
    });
    var dbSpi = createDbSpi(txIdStore, txAwaitDuration, databaseAvailabilityGuard, clock);
    var resultFuture = executor.submit(() -> {
        begin(dbSpi, List.of(new BookmarkWithPrefix(lastClosedTransactionId + 42)));
        return null;
    });
    var e = assertThrows(ExecutionException.class, () -> resultFuture.get(20, SECONDS));
    assertThat(e.getCause()).isInstanceOf(TransactionIdTrackerException.class);
}
Also used : BookmarkWithPrefix(org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) CompositeDatabaseAvailabilityGuard(org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard) DatabaseAvailabilityGuard(org.neo4j.kernel.availability.DatabaseAvailabilityGuard) FakeClock(org.neo4j.time.FakeClock) CompositeDatabaseAvailabilityGuard(org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard) Test(org.junit.jupiter.api.Test)

Example 17 with TransactionIdStore

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

the class DatabaseServiceBookmarkTest method doesNotWaitWhenTxIdUpToDate.

@Test
void doesNotWaitWhenTxIdUpToDate() throws Exception {
    long lastClosedTransactionId = 100;
    TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
    var dbSpi = createDbSpi(txIdStore, Duration.ofSeconds(1), Clocks.fakeClock());
    var resultFuture = executor.submit(() -> {
        begin(dbSpi, List.of(new BookmarkWithPrefix(lastClosedTransactionId - 42)));
        return null;
    });
    assertNull(resultFuture.get(20, SECONDS));
}
Also used : BookmarkWithPrefix(org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) Test(org.junit.jupiter.api.Test)

Example 18 with TransactionIdStore

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

the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.

@Test
void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
    // GIVEN
    LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).withLogEntryReader(logEntryReader()).withStoreId(StoreId.UNKNOWN).build();
    life.add(logFiles);
    final AtomicBoolean end = new AtomicBoolean();
    AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
    TransactionIdStore txIdStore = new SimpleTransactionIdStore();
    TransactionMetadataCache metadataCache = new TransactionMetadataCache();
    monitoring.setLogFile(logFiles.getLogFile());
    Health health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
    LogRotation rotation = transactionLogRotation(logFiles, Clock.systemUTC(), health, monitoring);
    final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, health));
    // WHEN
    Race race = new Race();
    for (int i = 0; i < 4; i++) {
        race.addContestant(() -> {
            while (!end.get()) {
                try {
                    appender.append(new TransactionToApply(sillyTransaction(1_000), CursorContext.NULL), LogAppendEvent.NULL);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    end.set(true);
                    fail(e.getMessage(), e);
                }
            }
        });
    }
    race.addContestant(endAfterMax(250, MILLISECONDS, end, monitoring));
    race.go();
    // THEN
    assertTrue(monitoring.numberOfRotations() > 0);
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) Health(org.neo4j.monitoring.Health) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) DatabasePanicEventGenerator(org.neo4j.kernel.monitoring.DatabasePanicEventGenerator) LogVersionRepository(org.neo4j.storageengine.api.LogVersionRepository) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Race(org.neo4j.test.Race) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) FileLogRotation.transactionLogRotation(org.neo4j.kernel.impl.transaction.log.rotation.FileLogRotation.transactionLogRotation) Test(org.junit.jupiter.api.Test)

Example 19 with TransactionIdStore

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

the class PhysicalLogicalTransactionStoreTest method shouldExtractMetadataFromExistingTransaction.

@Test
void shouldExtractMetadataFromExistingTransaction() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache();
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = 4545;
    long timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final LogFiles logFiles = buildLogFiles(transactionIdStore);
    life.start();
    life.add(logFiles);
    try {
        addATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    life = new LifeSupport();
    life.add(logFiles);
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
    // WHEN
    life.start();
    try {
        verifyTransaction(positionCache, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
    } 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 20 with TransactionIdStore

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

the class PhysicalLogicalTransactionStoreTest method extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader.

@Test
void extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader() throws IOException {
    TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache();
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = 4545;
    long timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final LogFiles logFiles = buildLogFiles(transactionIdStore);
    life.add(logFiles);
    life.start();
    try {
        addATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    // create empty transaction log file and clear transaction cache to force re-read
    LogFile logFile = logFiles.getLogFile();
    fileSystem.write(logFile.getLogFileForVersion(logFile.getHighestLogVersion() + 1)).close();
    positionCache.clear();
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
    verifyTransaction(positionCache, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) 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)

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