use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.
the class CommonAbstractStore method initialiseNewStoreFile.
protected void initialiseNewStoreFile(CursorContext cursorContext) throws IOException {
if (getNumberOfReservedLowIds() > 0) {
try (PageCursor pageCursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK | PF_EAGER_FLUSH, cursorContext)) {
if (pageCursor.next()) {
pageCursor.setOffset(0);
storeHeaderFormat.writeHeader(pageCursor);
if (pageCursor.checkAndClearBoundsFlag()) {
throw new UnderlyingStorageException("Out of page bounds when writing header; page size too small: " + pageCache.pageSize() + " bytes.");
}
}
}
pagedFile.flushAndForce();
}
// Determine record size right after writing the header since some stores
// use it when initializing their stores to write some records.
recordSize = determineRecordSize();
}
use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.
the class CommonAbstractStore method readStoreHeaderAndDetermineRecordSize.
private HEADER readStoreHeaderAndDetermineRecordSize(PagedFile pagedFile, CursorContext cursorContext) throws IOException {
try (PageCursor pageCursor = pagedFile.io(0, PF_SHARED_READ_LOCK, cursorContext)) {
HEADER readHeader;
if (pageCursor.next()) {
do {
pageCursor.setOffset(0);
readHeader = readStoreHeaderAndDetermineRecordSize(pageCursor);
} while (pageCursor.shouldRetry());
if (pageCursor.checkAndClearBoundsFlag()) {
throw new UnderlyingStorageException("Out of page bounds when reading header; page size too small: " + pageCache.pageSize() + " bytes.");
}
return readHeader;
} else {
throw new StoreNotFoundException("Fail to read header record of store file: " + storageFile);
}
}
}
use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.
the class CommonAbstractStore method nextRecordByCursor.
@Override
public void nextRecordByCursor(RECORD record, RecordLoad mode, PageCursor cursor) throws UnderlyingStorageException {
if (cursor.getCurrentPageId() < -1) {
throw new IllegalArgumentException("Pages are assumed to be positive or -1 if not initialized");
}
try {
long id = record.getId() + 1;
record.setId(id);
long pageId = cursor.getCurrentPageId();
if ((cursor.getOffset() >= recordsEndOffset) || (pageId < 0)) {
if (!cursor.next()) {
verifyAfterNotRead(record, mode);
return;
}
}
readRecordFromPage(id, record, mode, cursor);
} catch (IOException e) {
throw new UnderlyingStorageException(e);
}
}
use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.
the class CommonAbstractStore method isInUse.
public boolean isInUse(long id, CursorContext cursorContext) {
long pageId = pageIdForRecord(id);
int offset = offsetForId(id);
try (PageCursor cursor = pagedFile.io(pageId, PF_SHARED_READ_LOCK, cursorContext)) {
boolean recordIsInUse = false;
if (cursor.next()) {
cursor.setOffset(offset);
cursor.mark();
do {
cursor.setOffsetToMark();
recordIsInUse = isInUse(cursor);
} while (cursor.shouldRetry());
checkForDecodingErrors(cursor, id, NORMAL);
}
return recordIsInUse;
} catch (IOException e) {
throw new UnderlyingStorageException(e);
}
}
use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.
the class MetaDataStore method transactionClosed.
@Override
public void transactionClosed(long transactionId, long logVersion, long byteOffset, CursorContext cursorContext) {
if (lastClosedTx.offer(transactionId, new long[] { logVersion, byteOffset })) {
long pageId = pageIdForRecord(Position.LAST_CLOSED_TRANSACTION_LOG_VERSION.id);
assert pageId == pageIdForRecord(Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET.id);
synchronized (transactionClosedLock) {
try (PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK, cursorContext)) {
if (cursor.next()) {
long[] lastClosedTransactionData = lastClosedTx.get();
setRecord(cursor, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, lastClosedTransactionData[1]);
setRecord(cursor, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, lastClosedTransactionData[2]);
}
} catch (IOException e) {
throw new UnderlyingStorageException(e);
}
}
}
}
Aggregations