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