use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.
the class RecoverIndexDropIT method appendDropTransactionToTransactionLog.
private void appendDropTransactionToTransactionLog(Path transactionLogsDirectory, CommittedTransactionRepresentation dropTransaction, StorageEngineFactory storageEngineFactory) throws IOException {
LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(transactionLogsDirectory, fs).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build();
LogFile logFile = logFiles.getLogFile();
try (ReadableLogChannel reader = logFile.getReader(logFile.extractHeader(0).getStartPosition())) {
LogEntryReader logEntryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
while (logEntryReader.readLogEntry(reader) != null) {
}
LogPosition position = logEntryReader.lastPosition();
StoreChannel storeChannel = fs.write(logFile.getLogFileForVersion(logFile.getHighestLogVersion()));
storeChannel.position(position.getByteOffset());
try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, new HeapScopedBuffer(100, INSTANCE))) {
new LogEntryWriter<>(writeChannel, KernelVersion.LATEST).serialize(dropTransaction);
}
}
}
use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.
the class DetachedCheckpointLogEntryWriterTest method longCheckpointReasonIsTrimmedToFit.
@Test
void longCheckpointReasonIsTrimmedToFit() throws IOException {
try (var buffer = new HeapScopedBuffer((int) kibiBytes(1), INSTANCE)) {
StoreChannel storeChannel = fs.write(directory.createFile("b"));
try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, buffer)) {
var checkpointLogEntryWriter = new DetachedCheckpointLogEntryWriter(writeChannel);
long initialPosition = writeChannel.position();
writeCheckpoint(checkpointLogEntryWriter, StringUtils.repeat("b", 1024));
long recordLength = writeChannel.position() - initialPosition;
assertThat(recordLength).isEqualTo(RECORD_LENGTH_BYTES);
}
}
}
use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.
the class DetachedCheckpointLogEntryWriterTest method detachedCheckpointEntryHasSpecificLength.
@Test
void detachedCheckpointEntryHasSpecificLength() throws IOException {
try (var buffer = new HeapScopedBuffer((int) kibiBytes(1), INSTANCE)) {
StoreChannel storeChannel = fs.write(directory.createFile("a"));
try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, buffer)) {
var checkpointLogEntryWriter = new DetachedCheckpointLogEntryWriter(writeChannel);
long initialPosition = writeChannel.position();
writeCheckpoint(checkpointLogEntryWriter, "checkpoint reason");
assertThat(writeChannel.position() - initialPosition).isEqualTo(RECORD_LENGTH_BYTES);
}
}
}
use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.
the class DetachedCheckpointLogEntryWriterTest method anyCheckpointEntryHaveTheSameSize.
@Test
void anyCheckpointEntryHaveTheSameSize() throws IOException {
try (var buffer = new HeapScopedBuffer((int) kibiBytes(1), INSTANCE)) {
StoreChannel storeChannel = fs.write(directory.createFile("b"));
try (PhysicalFlushableChecksumChannel writeChannel = new PhysicalFlushableChecksumChannel(storeChannel, buffer)) {
var checkpointLogEntryWriter = new DetachedCheckpointLogEntryWriter(writeChannel);
for (int i = 0; i < 100; i++) {
long initialPosition = writeChannel.position();
writeCheckpoint(checkpointLogEntryWriter, randomAlphabetic(10, 512));
long recordLength = writeChannel.position() - initialPosition;
assertThat(recordLength).isEqualTo(RECORD_LENGTH_BYTES);
}
}
}
}
use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.
the class PhysicalFlushableChecksumChannelTest method beginCehcksumShouldResetCalculations.
@Test
void beginCehcksumShouldResetCalculations() throws IOException {
final Path firstFile = directory.homePath().resolve("file1");
StoreChannel storeChannel = fileSystem.write(firstFile);
int channelChecksum;
try (PhysicalFlushableChecksumChannel channel = new PhysicalFlushableChecksumChannel(storeChannel, new HeapScopedBuffer(100, INSTANCE))) {
channel.put((byte) 5);
channel.beginChecksum();
channel.put((byte) 10);
channelChecksum = channel.putChecksum();
}
int fileSize = (int) fileSystem.getFileSize(firstFile);
assertEquals(Byte.BYTES + Byte.BYTES + Integer.BYTES, fileSize);
byte[] writtenBytes = new byte[fileSize];
try (InputStream in = Files.newInputStream(firstFile)) {
in.read(writtenBytes);
}
ByteBuffer buffer = ByteBuffer.wrap(writtenBytes);
Checksum checksum = CHECKSUM_FACTORY.get();
checksum.update(10);
assertEquals(checksum.getValue(), channelChecksum);
assertEquals(5, buffer.get());
assertEquals(10, buffer.get());
assertEquals(checksum.getValue(), buffer.getInt());
}
Aggregations