Search in sources :

Example 41 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class GBPTreeSingleWriterTest method trackPageCacheAccessOnPut.

@Test
void trackPageCacheAccessOnPut() throws IOException {
    var pageCacheTracer = new DefaultPageCacheTracer();
    var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("trackPageCacheAccessOnPut"));
    assertZeroCursor(cursorContext);
    try (var gbpTree = new GBPTreeBuilder<>(pageCache, directory.file("index"), layout).build();
        var treeWriter = gbpTree.writer(0, cursorContext)) {
        treeWriter.put(new MutableLong(0), new MutableLong(1));
        PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
        assertThat(cursorTracer.pins()).isEqualTo(5);
        assertThat(cursorTracer.unpins()).isEqualTo(4);
        assertThat(cursorTracer.hits()).isEqualTo(4);
        assertThat(cursorTracer.faults()).isEqualTo(1);
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 42 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class GBPTreeTest method trackPageCacheAccessOnTreeSeek.

@Test
void trackPageCacheAccessOnTreeSeek() throws IOException {
    var pageCacheTracer = new DefaultPageCacheTracer();
    try (PageCache pageCache = createPageCache((int) ByteUnit.kibiBytes(4));
        var tree = index(pageCache).with(pageCacheTracer).build()) {
        for (int i = 0; i < 1000; i++) {
            insert(tree, i, 1);
        }
        var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("trackPageCacheAccessOnTreeSeek"));
        try (var seeker = tree.seek(new MutableLong(0), new MutableLong(Integer.MAX_VALUE), cursorContext)) {
            while (seeker.next()) {
            // just scroll over the results
            }
        }
        var cursorTracer = cursorContext.getCursorTracer();
        assertThat(cursorTracer.hits()).isEqualTo(8);
        assertThat(cursorTracer.unpins()).isEqualTo(8);
        assertThat(cursorTracer.pins()).isEqualTo(8);
        assertThat(cursorTracer.faults()).isEqualTo(0);
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PageCache(org.neo4j.io.pagecache.PageCache) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 43 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class TransactionLogsRecovery method init.

@Override
public void init() throws Exception {
    RecoveryStartInformation recoveryStartInformation = recoveryService.getRecoveryStartInformation();
    if (!recoveryStartInformation.isRecoveryRequired()) {
        schemaLife.init();
        return;
    }
    Stopwatch recoveryStartTime = Stopwatch.start();
    LogPosition recoveryStartPosition = recoveryStartInformation.getTransactionLogPosition();
    monitor.recoveryRequired(recoveryStartPosition);
    LogPosition recoveryToPosition = recoveryStartPosition;
    LogPosition lastTransactionPosition = recoveryStartPosition;
    CommittedTransactionRepresentation lastTransaction = null;
    CommittedTransactionRepresentation lastReversedTransaction = null;
    if (!recoveryStartInformation.isMissingLogs()) {
        try {
            long lowestRecoveredTxId = TransactionIdStore.BASE_TX_ID;
            try (var transactionsToRecover = recoveryService.getTransactionsInReverseOrder(recoveryStartPosition);
                var recoveryVisitor = recoveryService.getRecoveryApplier(REVERSE_RECOVERY, pageCacheTracer, REVERSE_RECOVERY_TAG)) {
                while (transactionsToRecover.next()) {
                    recoveryStartupChecker.checkIfCanceled();
                    CommittedTransactionRepresentation transaction = transactionsToRecover.get();
                    if (lastReversedTransaction == null) {
                        lastReversedTransaction = transaction;
                        initProgressReporter(recoveryStartInformation, lastReversedTransaction);
                    }
                    recoveryVisitor.visit(transaction);
                    lowestRecoveredTxId = transaction.getCommitEntry().getTxId();
                    reportProgress();
                }
            }
            monitor.reverseStoreRecoveryCompleted(lowestRecoveredTxId);
            // We cannot initialise the schema (tokens, schema cache, indexing service, etc.) until we have returned the store to a consistent state.
            // We need to be able to read the store before we can even figure out what indexes, tokens, etc. we have. Hence we defer the initialisation
            // of the schema life until after we've done the reverse recovery.
            schemaLife.init();
            try (var transactionsToRecover = recoveryService.getTransactions(recoveryStartPosition);
                var recoveryVisitor = recoveryService.getRecoveryApplier(RECOVERY, pageCacheTracer, RECOVERY_TAG)) {
                while (transactionsToRecover.next()) {
                    recoveryStartupChecker.checkIfCanceled();
                    lastTransaction = transactionsToRecover.get();
                    long txId = lastTransaction.getCommitEntry().getTxId();
                    recoveryVisitor.visit(lastTransaction);
                    monitor.transactionRecovered(txId);
                    numberOfRecoveredTransactions++;
                    lastTransactionPosition = transactionsToRecover.position();
                    recoveryToPosition = lastTransactionPosition;
                    reportProgress();
                }
                recoveryToPosition = transactionsToRecover.position();
            }
        } catch (Error | ClosedByInterruptException | DatabaseStartAbortedException e) {
            // the users are able to workaround this if truncations is really needed.
            throw e;
        } catch (Throwable t) {
            if (failOnCorruptedLogFiles) {
                throwUnableToCleanRecover(t);
            }
            if (lastTransaction != null) {
                LogEntryCommit commitEntry = lastTransaction.getCommitEntry();
                monitor.failToRecoverTransactionsAfterCommit(t, commitEntry, recoveryToPosition);
            } else {
                monitor.failToRecoverTransactionsAfterPosition(t, recoveryStartPosition);
            }
        }
        progressReporter.completed();
        logsTruncator.truncate(recoveryToPosition);
    }
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(RECOVERY_COMPLETED_TAG))) {
        final boolean missingLogs = recoveryStartInformation.isMissingLogs();
        recoveryService.transactionsRecovered(lastTransaction, lastTransactionPosition, recoveryToPosition, recoveryStartInformation.getCheckpointPosition(), missingLogs, cursorContext);
    }
    monitor.recoveryCompleted(numberOfRecoveredTransactions, recoveryStartTime.elapsed(MILLISECONDS));
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) DatabaseStartAbortedException(org.neo4j.dbms.database.DatabaseStartAbortedException) Stopwatch(org.neo4j.time.Stopwatch) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 44 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class MetaDataStoreTest method tracePageCacheAccessOnGetRecord.

@Test
void tracePageCacheAccessOnGetRecord() throws IOException {
    var cacheTracer = new DefaultPageCacheTracer();
    var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAccessOnGetRecord"));
    try (var metaDataStore = newMetaDataStore()) {
        MetaDataStore.getRecord(pageCache, metaDataStore.getStorageFile(), MetaDataStore.Position.RANDOM_NUMBER, databaseLayout.getDatabaseName(), cursorContext);
        PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
        assertThat(cursorTracer.pins()).isOne();
        assertThat(cursorTracer.unpins()).isOne();
        assertThat(cursorTracer.hits()).isOne();
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 45 with CursorContext

use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.

the class MetaDataStoreTest method tracePageCacheAssessOnIncrementAndGetVersion.

@Test
void tracePageCacheAssessOnIncrementAndGetVersion() {
    var cacheTracer = new DefaultPageCacheTracer();
    var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAssessOnIncrementAndGetVersion"));
    try (var metaDataStore = newMetaDataStore()) {
        metaDataStore.incrementAndGetVersion(cursorContext);
        PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
        assertThat(cursorTracer.pins()).isEqualTo(1);
        assertThat(cursorTracer.unpins()).isEqualTo(1);
        assertThat(cursorTracer.hits()).isEqualTo(1);
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Aggregations

CursorContext (org.neo4j.io.pagecache.context.CursorContext)161 Test (org.junit.jupiter.api.Test)74 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)52 PageCursor (org.neo4j.io.pagecache.PageCursor)40 IOException (java.io.IOException)31 UncheckedIOException (java.io.UncheckedIOException)27 PageCursorTracer (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer)27 Path (java.nio.file.Path)17 PagedFile (org.neo4j.io.pagecache.PagedFile)17 ArrayList (java.util.ArrayList)16 PageCacheTest (org.neo4j.io.pagecache.PageCacheTest)15 MutableLong (org.apache.commons.lang3.mutable.MutableLong)13 MemoryTracker (org.neo4j.memory.MemoryTracker)12 PageCache (org.neo4j.io.pagecache.PageCache)11 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)10 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)10 List (java.util.List)9 RepeatedTest (org.junit.jupiter.api.RepeatedTest)9 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8