Search in sources :

Example 6 with StoreFileChannel

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

the class RecoveryCorruptedTransactionLogIT method startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled.

@Test
void startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled() throws IOException {
    DatabaseManagementService managementService = databaseFactory.build();
    GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    logFiles = buildDefaultLogFiles(getStoreId(database));
    generateTransaction(database);
    managementService.shutdown();
    long originalLogDataLength;
    Path firstLogFile;
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        LogFile logFile = logFiles.getLogFile();
        LogPosition readablePosition = getLastReadablePosition(logFile);
        firstLogFile = logFiles.getLogFile().getHighestLogFile();
        originalLogDataLength = readablePosition.getByteOffset();
        logFile.rotate();
        // append zeros in the end of previous file causing illegal suffix
        try (StoreFileChannel writeChannel = fileSystem.write(firstLogFile)) {
            writeChannel.position(writeChannel.size());
            for (int i = 0; i < 10; i++) {
                writeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0 }));
            }
        }
    }
    startStopDbRecoveryOfCorruptedLogs();
    assertEquals(originalLogDataLength, fileSystem.getFileSize(firstLogFile));
    assertThat(logProvider).containsMessages("Recovery required from position LogPosition{logVersion=0, byteOffset=" + (996 + txOffsetAfterStart) + "}").assertExceptionForLogMessage("Fail to read transaction log version 0.").hasMessage("Transaction log files with version 0 has 50 unreadable bytes. Was able to read upto " + (996 + txOffsetAfterStart) + " but " + (1046 + txOffsetAfterStart) + " is available.");
}
Also used : Path(java.nio.file.Path) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with StoreFileChannel

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

the class RecoveryCorruptedTransactionLogIT method startWithoutProblemsIfRotationForcedBeforeFileEndAndCorruptedLogFilesRecoveryEnabled.

@Test
void startWithoutProblemsIfRotationForcedBeforeFileEndAndCorruptedLogFilesRecoveryEnabled() 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();
    }
    startStopDbRecoveryOfCorruptedLogs();
    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)

Example 8 with StoreFileChannel

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

the class SingleFilePageSwapperTest method mustUnlockFileWhenThePageSwapperIsClosed.

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

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