Search in sources :

Example 11 with UnderlyingStorageException

use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.

the class IndexUpdaterMap method close.

@Override
public void close() throws UnderlyingStorageException {
    Set<Pair<IndexDescriptor, UnderlyingStorageException>> exceptions = null;
    for (Map.Entry<IndexDescriptor, IndexUpdater> updaterEntry : updaterMap.entrySet()) {
        IndexUpdater updater = updaterEntry.getValue();
        try {
            updater.close();
        } catch (UncheckedIOException | IndexEntryConflictException e) {
            if (null == exceptions) {
                exceptions = new HashSet<>();
            }
            exceptions.add(Pair.of(updaterEntry.getKey(), new UnderlyingStorageException(e)));
        }
    }
    clear();
    if (null != exceptions) {
        throw new MultipleUnderlyingStorageExceptions(exceptions);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) Map(java.util.Map) HashMap(java.util.HashMap) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) MultipleUnderlyingStorageExceptions(org.neo4j.kernel.impl.store.MultipleUnderlyingStorageExceptions)

Example 12 with UnderlyingStorageException

use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.

the class RecoveryStartInformationProvider method get.

/**
 * Find the log position to start recovery from
 *
 * @return {@link LogPosition#UNSPECIFIED} if there is no need to recover otherwise the {@link LogPosition} to
 * start recovery from
 * @throws IOException if log files cannot be read
 */
@Override
public RecoveryStartInformation get() {
    LogTailInformation logTailInformation = logFiles.getTailInformation();
    CheckpointInfo lastCheckPoint = logTailInformation.lastCheckPoint;
    long txIdAfterLastCheckPoint = logTailInformation.firstTxIdAfterLastCheckPoint;
    if (!logTailInformation.isRecoveryRequired()) {
        monitor.noCommitsAfterLastCheckPoint(lastCheckPoint != null ? lastCheckPoint.getTransactionLogPosition() : null);
        return NO_RECOVERY_REQUIRED;
    }
    if (logTailInformation.logsMissing()) {
        return MISSING_LOGS;
    }
    if (logTailInformation.commitsAfterLastCheckpoint()) {
        if (lastCheckPoint == null) {
            long lowestLogVersion = logFiles.getLogFile().getLowestLogVersion();
            if (lowestLogVersion != INITIAL_LOG_VERSION) {
                throw new UnderlyingStorageException("No check point found in any log file from version " + lowestLogVersion + " to " + logTailInformation.currentLogVersion);
            }
            monitor.noCheckPointFound();
            LogPosition position = tryExtractHeaderSize();
            return createRecoveryInformation(position, new LogPosition(INITIAL_LOG_VERSION, CURRENT_FORMAT_LOG_HEADER_SIZE), txIdAfterLastCheckPoint);
        }
        LogPosition transactionLogPosition = lastCheckPoint.getTransactionLogPosition();
        monitor.commitsAfterLastCheckPoint(transactionLogPosition, txIdAfterLastCheckPoint);
        return createRecoveryInformation(transactionLogPosition, lastCheckPoint.getCheckpointEntryPosition(), txIdAfterLastCheckPoint);
    } else {
        throw new UnderlyingStorageException("Fail to determine recovery information Log tail info: " + logTailInformation);
    }
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) CheckpointInfo(org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointInfo) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 13 with UnderlyingStorageException

use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.

the class RecoveryStartInformationProviderTest method shouldFailIfThereAreNoCheckPointsAndOldestLogVersionInNotZero.

@Test
void shouldFailIfThereAreNoCheckPointsAndOldestLogVersionInNotZero() {
    // given
    long oldestLogVersionFound = 1L;
    when(logFile.getLowestLogVersion()).thenReturn(oldestLogVersionFound);
    when(logFiles.getTailInformation()).thenReturn(new LogTailInformation(true, 10L, false, currentLogVersion, LATEST.version()));
    // when
    UnderlyingStorageException storageException = assertThrows(UnderlyingStorageException.class, () -> new RecoveryStartInformationProvider(logFiles, monitor).get());
    final String expectedMessage = "No check point found in any log file from version " + oldestLogVersionFound + " to " + logVersion;
    assertEquals(expectedMessage, storageException.getMessage());
}
Also used : LogTailInformation(org.neo4j.kernel.impl.transaction.log.files.LogTailInformation) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) Test(org.junit.jupiter.api.Test)

Example 14 with UnderlyingStorageException

use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.

the class CommonAbstractStore method flush.

@Override
public void flush(CursorContext cursorContext) {
    try {
        pagedFile.flushAndForce();
        idGenerator.checkpoint(cursorContext);
    } catch (IOException e) {
        throw new UnderlyingStorageException("Failed to flush", e);
    }
}
Also used : IOException(java.io.IOException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException)

Example 15 with UnderlyingStorageException

use of org.neo4j.exceptions.UnderlyingStorageException in project neo4j by neo4j.

the class CommonAbstractStore method updateRecord.

@Override
public void updateRecord(RECORD record, IdUpdateListener idUpdateListener, PageCursor cursor, CursorContext cursorContext) {
    long id = record.getId();
    IdValidator.assertValidId(getIdType(), id, recordFormat.getMaxId());
    long pageId = pageIdForRecord(id);
    int offset = offsetForId(id);
    try {
        if (cursor.next(pageId)) {
            cursor.setOffset(offset);
            recordFormat.write(record, cursor, recordSize, recordsPerPage);
            // We don't free ids if something weird goes wrong
            checkForDecodingErrors(cursor, id, NORMAL);
            if (!record.inUse()) {
                idUpdateListener.markIdAsUnused(idType, idGenerator, id, cursorContext);
            } else if (record.isCreated()) {
                idUpdateListener.markIdAsUsed(idType, idGenerator, id, cursorContext);
            }
            if ((!record.inUse() || !record.requiresSecondaryUnit()) && record.hasSecondaryUnitId()) {
                // If record was just now deleted, or if the record used a secondary unit, but not anymore
                // then free the id of that secondary unit.
                idUpdateListener.markIdAsUnused(idType, idGenerator, record.getSecondaryUnitId(), cursorContext);
            }
            if (record.inUse() && record.isSecondaryUnitCreated()) {
                // Triggers on:
                // - (a) record got created right now and has a secondary unit, or
                // - (b) it already existed and just now grew into a secondary unit then mark the secondary unit as used
                idUpdateListener.markIdAsUsed(idType, idGenerator, record.getSecondaryUnitId(), cursorContext);
            }
        }
    } catch (IOException e) {
        throw new UnderlyingStorageException(e);
    }
}
Also used : IOException(java.io.IOException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException)

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