Search in sources :

Example 1 with StoreFileChannel

use of org.neo4j.io.fs.StoreFileChannel in project neo4j by neo4j.

the class SingleFilePageSwapperTest method creatingSwapperForInternallyLockedFileMustThrow.

@Test
@DisabledOnOs(OS.WINDOWS)
void creatingSwapperForInternallyLockedFileMustThrow() throws Exception {
    PageSwapperFactory factory = createSwapperFactory(fileSystem);
    Path file = testDir.file("file");
    StoreFileChannel channel = fileSystem.write(file);
    try (FileLock fileLock = channel.tryLock()) {
        assertThat(fileLock).isNotNull();
        assertThrows(FileLockException.class, () -> createSwapper(factory, file, 4, NO_CALLBACK, true));
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) FileLock(java.nio.channels.FileLock) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 2 with StoreFileChannel

use of org.neo4j.io.fs.StoreFileChannel in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method writeRandomBytesAfterLastCommandInLastLogFile.

private void writeRandomBytesAfterLastCommandInLastLogFile(Supplier<ByteBuffer> source) throws IOException {
    int someRandomPaddingAfterEndOfDataInLogFile = random.nextInt(1, 10);
    try (Lifespan lifespan = new Lifespan()) {
        LogFile transactionLogFile = logFiles.getLogFile();
        lifespan.add(logFiles);
        LogPosition position = getLastReadablePosition(transactionLogFile);
        try (StoreFileChannel writeChannel = fileSystem.write(logFiles.getLogFile().getHighestLogFile())) {
            writeChannel.position(position.getByteOffset() + someRandomPaddingAfterEndOfDataInLogFile);
            for (int i = 0; i < 10; i++) {
                writeChannel.writeAll(source.get());
            }
        }
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 3 with StoreFileChannel

use of org.neo4j.io.fs.StoreFileChannel in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method failToStartWithNotLastTransactionLogHavingZerosInTheEnd.

@Test
void failToStartWithNotLastTransactionLogHavingZerosInTheEnd() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    generateTransaction(database);
    managementService.shutdown();
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        Path originalFile = logFiles.getLogFile().getHighestLogFile();
        logFiles.getLogFile().rotate();
        // append zeros in the end of previous file causing illegal suffix
        try (StoreFileChannel writeChannel = fileSystem.write(originalFile)) {
            writeChannel.position(writeChannel.size());
            for (int i = 0; i < 10; i++) {
                writeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0 }));
            }
        }
    }
    startStopDatabase();
    assertThat(logProvider).assertExceptionForLogMessage("Fail to read transaction log version 0.").hasMessageContaining("Transaction log files with version 0 has 50 unreadable bytes");
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with StoreFileChannel

use of org.neo4j.io.fs.StoreFileChannel in project neo4j by neo4j.

the class EphemeralFileSystemAbstraction method create.

@Override
public synchronized StoreChannel create(File fileName) throws IOException {
    File parentFile = fileName.getParentFile();
    if (parentFile != null && /*means that this is the 'default location'*/
    !fileExists(parentFile)) {
        throw new FileNotFoundException("'" + fileName + "' (The system cannot find the path specified)");
    }
    EphemeralFileData data = new EphemeralFileData(clock);
    Optional.ofNullable(files.put(canonicalFile(fileName), data)).ifPresent(EphemeralFileData::free);
    return new StoreFileChannel(new EphemeralFileChannel(data, new FileStillOpenException(fileName.getPath())));
}
Also used : StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 5 with StoreFileChannel

use of org.neo4j.io.fs.StoreFileChannel in project neo4j by neo4j.

the class RecoveryCorruptedTransactionLogIT method startWithoutProblemsIfRotationForcedBeforeFileEnd.

@Test
void startWithoutProblemsIfRotationForcedBeforeFileEnd() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    generateTransaction(database);
    managementService.shutdown();
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        Path originalFile = logFiles.getLogFile().getHighestLogFile();
        // in it its current position.
        try (StoreFileChannel writeChannel = fileSystem.write(originalFile)) {
            writeChannel.position(writeChannel.size());
            for (int i = 0; i < 10; i++) {
                writeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0 }));
            }
        }
        logFiles.getLogFile().rotate();
    }
    startStopDatabase();
    assertThat(logProvider).doesNotContainMessage("Fail to read transaction log version 0.");
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

StoreFileChannel (org.neo4j.io.fs.StoreFileChannel)8 Path (java.nio.file.Path)6 Test (org.junit.jupiter.api.Test)6 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 FileLock (java.nio.channels.FileLock)2 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)2 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)2 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)2 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1