use of org.neo4j.kernel.impl.transaction.log.files.LogFile 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;
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile 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.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method addRandomBytesToLastLogFile.
private void addRandomBytesToLastLogFile(Supplier<Byte> byteSource) throws IOException {
try (Lifespan lifespan = new Lifespan()) {
LogFile transactionLogFile = logFiles.getLogFile();
lifespan.add(logFiles);
var channel = transactionLogFile.getTransactionLogWriter().getChannel();
for (int i = 0; i < 10; i++) {
channel.put(byteSource.get());
}
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class TestLogPruning method noPruning.
@Test
void noPruning() throws Exception {
newDb("true", 2);
for (int i = 0; i < 100; i++) {
doTransaction();
}
LogFile logFile = files.getLogFile();
long currentVersion = logFile.getHighestLogVersion();
for (long version = 0; version < currentVersion; version++) {
assertTrue(fs.fileExists(logFile.getLogFileForVersion(version)), "Version " + version + " has been unexpectedly pruned");
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.
the class TestLogPruning method aggregateLogData.
private int aggregateLogData(Extractor extractor) throws IOException {
int total = 0;
LogFile logFile = files.getLogFile();
for (long i = logFile.getHighestLogVersion(); i >= 0; i--) {
if (logFile.versionExists(i)) {
total += extractor.extract(i);
} else {
break;
}
}
return total;
}
Aggregations