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.");
}
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.");
}
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();
}
}
Aggregations