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