use of org.neo4j.index.internal.gbptree.GBPTree in project neo4j by neo4j.
the class IndexedIdGenerator method dump.
/**
* Dumps the contents of an {@link IndexedIdGenerator} as human-readable text.
*
* @param pageCache {@link PageCache} to map id generator in.
* @param path {@link Path} pointing to the id generator.
* @param cacheTracer underlying page cache tracer
* @throws IOException if the file was missing or some other I/O error occurred.
*/
public static void dump(PageCache pageCache, Path path, PageCacheTracer cacheTracer, boolean onlySummary) throws IOException {
try (var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("IndexDump"))) {
HeaderReader header = readHeader(pageCache, path, DEFAULT_DATABASE_NAME, cursorContext).orElseThrow(() -> new NoSuchFileException(path.toAbsolutePath().toString()));
IdRangeLayout layout = new IdRangeLayout(header.idsPerEntry);
try (GBPTree<IdRangeKey, IdRange> tree = new GBPTree<>(pageCache, path, layout, GBPTree.NO_MONITOR, NO_HEADER_READER, NO_HEADER_WRITER, immediate(), readOnly(), cacheTracer, immutable.empty(), DEFAULT_DATABASE_NAME, "Indexed ID generator")) {
System.out.println(header);
if (onlySummary) {
MutableLong numDeletedNotFreed = new MutableLong();
MutableLong numDeletedAndFreed = new MutableLong();
System.out.println("Calculating summary...");
tree.visit(new GBPTreeVisitor.Adaptor<>() {
@Override
public void value(IdRange value) {
for (int i = 0; i < 128; i++) {
IdRange.IdState state = value.getState(i);
if (state == IdRange.IdState.FREE) {
numDeletedAndFreed.increment();
} else if (state == IdRange.IdState.DELETED) {
numDeletedNotFreed.increment();
}
}
}
}, cursorContext);
System.out.println();
System.out.println("Number of IDs deleted and available for reuse: " + numDeletedAndFreed);
System.out.println("Number of IDs deleted, but not yet available for reuse: " + numDeletedNotFreed);
System.out.printf("NOTE: A deleted ID not yet available for reuse is buffered until all transactions that were open%n" + "at the time of its deletion have been closed, or the database is restarted");
} else {
tree.visit(new GBPTreeVisitor.Adaptor<>() {
private IdRangeKey key;
@Override
public void key(IdRangeKey key, boolean isLeaf, long offloadId) {
this.key = key;
}
@Override
public void value(IdRange value) {
System.out.println(format("%s [%d]", value, key.getIdRangeIdx()));
}
}, cursorContext);
}
}
}
}
use of org.neo4j.index.internal.gbptree.GBPTree in project neo4j by neo4j.
the class NativeIndex method instantiateTree.
void instantiateTree(RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, Consumer<PageCursor> headerWriter) {
ensureDirectoryExist();
GBPTree.Monitor monitor = treeMonitor();
Path storeFile = indexFiles.getStoreFile();
tree = new GBPTree<>(pageCache, storeFile, layout, monitor, NO_HEADER_READER, headerWriter, recoveryCleanupWorkCollector, readOnlyChecker, pageCacheTracer, immutable.empty(), databaseName, descriptor.getName());
afterTreeInstantiation(tree);
}
use of org.neo4j.index.internal.gbptree.GBPTree in project neo4j by neo4j.
the class NativeIndexReader method createSampler.
@Override
public IndexSampler createSampler() {
// For a unique index there's an optimization, knowing that all values in it are unique, to simply count
// the number of indexed values and create a sample for that count. The GBPTree doesn't have an O(1)
// count mechanism, it will have to manually count the indexed values in it to get it.
// For that reason this implementation opts for keeping complexity down by just using the existing
// non-unique sampler which scans the index and counts (potentially duplicates, of which there will
// be none in a unique index).
FullScanNonUniqueIndexSampler<KEY, VALUE> sampler = new FullScanNonUniqueIndexSampler<>(tree, layout);
return tracer -> {
try {
return sampler.sample(tracer);
} catch (UncheckedIOException e) {
if (getRootCause(e) instanceof FileIsNotMappedException) {
IndexNotFoundKernelException exception = new IndexNotFoundKernelException("Index dropped while sampling.");
exception.addSuppressed(e);
throw exception;
}
throw e;
}
};
}
Aggregations