Search in sources :

Example 71 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project neo4j by neo4j.

the class ReaderLogVersionBridgeTest method shouldReturnOldChannelWhenThereIsNoNextChannel.

@Test
void shouldReturnOldChannelWhenThereIsNoNextChannel() throws IOException {
    // given
    final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(logFiles.getLogFile());
    when(channel.getVersion()).thenReturn(version);
    when(fs.read(any(Path.class))).thenThrow(new NoSuchFileException("mock"));
    // when
    final LogVersionedStoreChannel result = bridge.next(channel, false);
    // then
    assertEquals(channel, result);
    verify(channel, never()).close();
}
Also used : Path(java.nio.file.Path) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ReaderLogVersionBridge(org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge) NoSuchFileException(java.nio.file.NoSuchFileException) Test(org.junit.jupiter.api.Test)

Example 72 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project neo4j by neo4j.

the class CorruptedLogsTruncator method isRecoveredLogCorrupted.

private boolean isRecoveredLogCorrupted(long recoveredTransactionLogVersion, long recoveredTransactionOffset) throws IOException {
    try {
        LogFile logFile = logFiles.getLogFile();
        if (Files.size(logFile.getLogFileForVersion(recoveredTransactionLogVersion)) > recoveredTransactionOffset) {
            try (PhysicalLogVersionedStoreChannel channel = logFile.openForVersion(recoveredTransactionLogVersion);
                var scopedBuffer = new NativeScopedBuffer(safeCastLongToInt(kibiBytes(64)), memoryTracker)) {
                channel.position(recoveredTransactionOffset);
                ByteBuffer byteBuffer = scopedBuffer.getBuffer();
                while (channel.read(byteBuffer) >= 0) {
                    byteBuffer.flip();
                    while (byteBuffer.hasRemaining()) {
                        if (byteBuffer.get() != 0) {
                            return true;
                        }
                    }
                    byteBuffer.clear();
                }
            }
        }
        return false;
    } catch (NoSuchFileException ignored) {
        return false;
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) NoSuchFileException(java.nio.file.NoSuchFileException) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) NativeScopedBuffer(org.neo4j.io.memory.NativeScopedBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 73 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project neo4j by neo4j.

the class LoadCommandTest method shouldGiveAClearMessageIfTheArchiveDoesntExist.

@Test
void shouldGiveAClearMessageIfTheArchiveDoesntExist() throws IOException, IncorrectFormat {
    doThrow(new NoSuchFileException(archive.toString())).when(loader).load(any(), any());
    CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
    assertEquals("Archive does not exist: " + archive, commandFailed.getMessage());
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 74 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project neo4j by neo4j.

the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationFailingWithFileNotFoundException.

@Test
void shouldRequestIndexPopulationFailingWithFileNotFoundException() {
    // Given
    long faultyIndexId = 1;
    NoSuchFileException error = new NoSuchFileException("/some/path/somewhere");
    LuceneIndexProvider provider = newFaultyIndexProvider(faultyIndexId, error);
    // When
    IndexDescriptor descriptor = forSchema(forLabel(1, 1), provider.getProviderDescriptor()).withName("index_" + faultyIndexId).materialise(faultyIndexId);
    InternalIndexState initialState = provider.getInitialState(descriptor, NULL);
    // Then
    assertThat(initialState).isEqualTo(InternalIndexState.POPULATING);
    assertThat(logProvider).containsException(error);
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) NoSuchFileException(java.nio.file.NoSuchFileException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 75 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project neo4j by neo4j.

the class NeoStores method verifyRecordFormat.

private void verifyRecordFormat(StoreType[] storeTypes, CursorContext cursorContext) {
    String expectedStoreVersion = recordFormats.storeVersion();
    long existingFormat;
    if (!fileSystem.fileExists(layout.metadataStore())) {
        // If the meta data store doesn't even exist then look no further, there's nothing to verify
        return;
    }
    if (contains(storeTypes, StoreType.META_DATA)) {
        // We're going to open this store anyway so might as well do it here, like we open the others
        MetaDataStore metaDataStore = (MetaDataStore) getOrOpenStore(StoreType.META_DATA, cursorContext);
        existingFormat = metaDataStore.getRecord(STORE_VERSION.id(), metaDataStore.newRecord(), RecordLoad.CHECK, cursorContext).getValue();
    } else {
        // if we have createIfNotExists set, but don't have the meta data store in the list of stores to open
        try {
            existingFormat = MetaDataStore.getRecord(pageCache, layout.metadataStore(), STORE_VERSION, layout.getDatabaseName(), cursorContext);
        } catch (NoSuchFileException e) {
            // Weird that the file isn't here after we passed the exists check above. Regardless, treat this the same way as above.
            return;
        } catch (IOException e) {
            throw new UnderlyingStorageException(e);
        }
    }
    if (existingFormat != MetaDataRecordFormat.FIELD_NOT_PRESENT) {
        String actualStoreVersion = versionLongToString(existingFormat);
        RecordFormats actualStoreFormat = RecordFormatSelector.selectForVersion(actualStoreVersion);
        if (!isCompatibleFormats(actualStoreFormat)) {
            throw new UnexpectedStoreVersionException(actualStoreVersion, expectedStoreVersion);
        }
    }
}
Also used : RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) NoSuchFileException(java.nio.file.NoSuchFileException) MetaDataStore.versionLongToString(org.neo4j.kernel.impl.store.MetaDataStore.versionLongToString) IOException(java.io.IOException) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException)

Aggregations

NoSuchFileException (java.nio.file.NoSuchFileException)262 IOException (java.io.IOException)107 Path (java.nio.file.Path)104 FileNotFoundException (java.io.FileNotFoundException)41 Test (org.junit.Test)35 InputStream (java.io.InputStream)31 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)25 File (java.io.File)22 NotDirectoryException (java.nio.file.NotDirectoryException)19 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)18 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)16 OutputStream (java.io.OutputStream)15 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)15 FileChannel (java.nio.channels.FileChannel)14 AccessDeniedException (java.nio.file.AccessDeniedException)14 ByteBuffer (java.nio.ByteBuffer)13 HashMap (java.util.HashMap)13 Map (java.util.Map)12 SeekableByteChannel (java.nio.channels.SeekableByteChannel)11