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);
}
}
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);
}
}
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));
}
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();
}
}
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);
}
}
Aggregations