Search in sources :

Example 1 with GBPTree

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);
            }
        }
    }
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) MutableLong(org.apache.commons.lang3.mutable.MutableLong) GBPTreeVisitor(org.neo4j.index.internal.gbptree.GBPTreeVisitor) GBPTree(org.neo4j.index.internal.gbptree.GBPTree)

Example 2 with GBPTree

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);
}
Also used : Path(java.nio.file.Path) GBPTree(org.neo4j.index.internal.gbptree.GBPTree)

Example 3 with GBPTree

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;
        }
    };
}
Also used : IndexOrder(org.neo4j.internal.schema.IndexOrder) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) Seeker(org.neo4j.index.internal.gbptree.Seeker) CursorContext(org.neo4j.io.pagecache.context.CursorContext) FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) ExceptionUtils.getRootCause(org.apache.commons.lang3.exception.ExceptionUtils.getRootCause) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IOException(java.io.IOException) Value(org.neo4j.values.storable.Value) UncheckedIOException(java.io.UncheckedIOException) GBPTree(org.neo4j.index.internal.gbptree.GBPTree) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) QueryContext(org.neo4j.internal.kernel.api.QueryContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NEUTRAL(org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.NEUTRAL) FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) UncheckedIOException(java.io.UncheckedIOException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)

Aggregations

GBPTree (org.neo4j.index.internal.gbptree.GBPTree)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 ExceptionUtils.getRootCause (org.apache.commons.lang3.exception.ExceptionUtils.getRootCause)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 GBPTreeVisitor (org.neo4j.index.internal.gbptree.GBPTreeVisitor)1 Seeker (org.neo4j.index.internal.gbptree.Seeker)1 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)1 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)1 QueryContext (org.neo4j.internal.kernel.api.QueryContext)1 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexOrder (org.neo4j.internal.schema.IndexOrder)1 FileIsNotMappedException (org.neo4j.io.pagecache.impl.FileIsNotMappedException)1 IndexProgressor (org.neo4j.kernel.api.index.IndexProgressor)1 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)1 ValueIndexReader (org.neo4j.kernel.api.index.ValueIndexReader)1