Search in sources :

Example 1 with MetaDataRecordFormat

use of org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat in project neo4j by neo4j.

the class MetaDataStore method getRecord.

/**
 * Reads a record from a neostore file.
 *
 * @param pageCache {@link PageCache} the {@code neostore} file lives in.
 * @param neoStore {@link Path} pointing to the neostore.
 * @param position record {@link Position}.
 * @param cursorContext underlying page cursor context.
 * @return the read record value specified by {@link Position}.
 */
public static long getRecord(PageCache pageCache, Path neoStore, Position position, String databaseName, CursorContext cursorContext) throws IOException {
    var recordFormat = new MetaDataRecordFormat();
    int pageSize = pageCache.pageSize();
    long value = FIELD_NOT_PRESENT;
    try (PagedFile pagedFile = pageCache.map(neoStore, pageSize, databaseName, immutable.empty(), DISABLED)) {
        if (pagedFile.getLastPageId() >= 0) {
            try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
                if (cursor.next()) {
                    MetaDataRecord record = new MetaDataRecord();
                    record.setId(position.id);
                    do {
                        recordFormat.read(record, cursor, RecordLoad.CHECK, RECORD_SIZE, pageSize / RECORD_SIZE);
                        if (record.inUse()) {
                            value = record.getValue();
                        } else {
                            value = FIELD_NOT_PRESENT;
                        }
                    } while (cursor.shouldRetry());
                    if (cursor.checkAndClearBoundsFlag()) {
                        int offset = offset(position);
                        throw new UnderlyingStorageException(buildOutOfBoundsExceptionMessage(record, 0, offset, RECORD_SIZE, pageSize, neoStore.toAbsolutePath().toString()));
                    }
                }
            }
        }
    }
    return value;
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) MetaDataRecordFormat(org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) MetaDataRecord(org.neo4j.kernel.impl.store.record.MetaDataRecord) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 2 with MetaDataRecordFormat

use of org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat in project neo4j by neo4j.

the class MetaDataStore method getRecord.

/**
     * Reads a record from a neostore file.
     *
     * @param pageCache {@link PageCache} the {@code neostore} file lives in.
     * @param neoStore {@link File} pointing to the neostore.
     * @param position record {@link Position}.
     * @return the read record value specified by {@link Position}.
     */
public static long getRecord(PageCache pageCache, File neoStore, Position position) throws IOException {
    MetaDataRecordFormat format = new MetaDataRecordFormat();
    int pageSize = getPageSize(pageCache);
    long value = FIELD_NOT_PRESENT;
    try (PagedFile pagedFile = pageCache.map(neoStore, pageSize)) {
        if (pagedFile.getLastPageId() >= 0) {
            try (PageCursor cursor = pagedFile.io(0, PF_SHARED_READ_LOCK)) {
                if (cursor.next()) {
                    MetaDataRecord record = new MetaDataRecord();
                    record.setId(position.id);
                    do {
                        format.read(record, cursor, RecordLoad.CHECK, RECORD_SIZE);
                        if (record.inUse()) {
                            value = record.getValue();
                        } else {
                            value = FIELD_NOT_PRESENT;
                        }
                    } while (cursor.shouldRetry());
                    if (cursor.checkAndClearBoundsFlag()) {
                        int offset = offset(position);
                        throw new UnderlyingStorageException(buildOutOfBoundsExceptionMessage(record, 0, offset, RECORD_SIZE, pageSize, neoStore.getAbsolutePath()));
                    }
                }
            }
        }
    }
    return value;
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) MetaDataRecordFormat(org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat) MetaDataRecord(org.neo4j.kernel.impl.store.record.MetaDataRecord) PageCursor(org.neo4j.io.pagecache.PageCursor)

Aggregations

PageCursor (org.neo4j.io.pagecache.PageCursor)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 MetaDataRecordFormat (org.neo4j.kernel.impl.store.format.standard.MetaDataRecordFormat)2 MetaDataRecord (org.neo4j.kernel.impl.store.record.MetaDataRecord)2 UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)1