Search in sources :

Example 16 with UnderlyingStorageException

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();
}
Also used : UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 17 with UnderlyingStorageException

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);
        }
    }
}
Also used : UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 18 with UnderlyingStorageException

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);
    }
}
Also used : IOException(java.io.IOException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException)

Example 19 with UnderlyingStorageException

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);
    }
}
Also used : IOException(java.io.IOException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 20 with UnderlyingStorageException

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);
            }
        }
    }
}
Also used : IOException(java.io.IOException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) PageCursor(org.neo4j.io.pagecache.PageCursor)

Aggregations

UnderlyingStorageException (org.neo4j.exceptions.UnderlyingStorageException)22 IOException (java.io.IOException)13 PageCursor (org.neo4j.io.pagecache.PageCursor)10 MetaDataRecord (org.neo4j.kernel.impl.store.record.MetaDataRecord)3 NoSuchFileException (java.nio.file.NoSuchFileException)2 Test (org.junit.jupiter.api.Test)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)2 TransactionId (org.neo4j.storageengine.api.TransactionId)2 UncheckedIOException (java.io.UncheckedIOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 KernelException (org.neo4j.exceptions.KernelException)1 Pair (org.neo4j.internal.helpers.collection.Pair)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)1 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)1 MetaDataStore.versionLongToString (org.neo4j.kernel.impl.store.MetaDataStore.versionLongToString)1 MultipleUnderlyingStorageExceptions (org.neo4j.kernel.impl.store.MultipleUnderlyingStorageExceptions)1