use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class LatestCheckPointFinder method extractFirstTxIdAfterPosition.
/**
* Extracts txId from first commit entry, when starting reading at the given {@code position}.
* If no commit entry found in the version, the reader will continue into next version(s) up till
* {@code maxLogVersion} until finding one.
*
* @param initialPosition {@link LogPosition} to start scan from.
* @param maxLogVersion max log version to scan.
* @return txId of closes commit entry to {@code initialPosition}, or {@link LatestCheckPoint#NO_TRANSACTION_ID}
* if not found.
* @throws IOException on I/O error.
*/
private long extractFirstTxIdAfterPosition(LogPosition initialPosition, long maxLogVersion) throws IOException {
LogPosition currentPosition = initialPosition;
while (currentPosition.getLogVersion() <= maxLogVersion) {
LogVersionedStoreChannel storeChannel = PhysicalLogFile.tryOpenForVersion(logFiles, fileSystem, currentPosition.getLogVersion(), false);
if (storeChannel != null) {
try {
storeChannel.position(currentPosition.getByteOffset());
try (ReadAheadLogChannel logChannel = new ReadAheadLogChannel(storeChannel, NO_MORE_CHANNELS);
LogEntryCursor cursor = new LogEntryCursor(logEntryReader, logChannel)) {
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryCommit) {
return ((LogEntryCommit) entry).getTxId();
}
}
}
} finally {
storeChannel.close();
}
}
currentPosition = LogPosition.start(currentPosition.getLogVersion() + 1);
}
return LatestCheckPoint.NO_TRANSACTION_ID;
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class TransactionLogCatchUpWriterTest method verifyTransactionsInLog.
private void verifyTransactionsInLog(long fromTxId, long endTxId) throws IOException {
long expectedTxId = fromTxId;
PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
LogVersionedStoreChannel versionedStoreChannel = PhysicalLogFile.openForVersion(logFiles, fs, 0, false);
try (ReadableLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, LogVersionBridge.NO_MORE_CHANNELS, 1024)) {
try (PhysicalTransactionCursor<ReadableLogChannel> txCursor = new PhysicalTransactionCursor<>(channel, new VersionAwareLogEntryReader<>())) {
while (txCursor.next()) {
CommittedTransactionRepresentation tx = txCursor.get();
long txId = tx.getCommitEntry().getTxId();
assertThat(expectedTxId, lessThanOrEqualTo(endTxId));
assertEquals(expectedTxId, txId);
expectedTxId++;
}
}
}
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class ReadAheadLogChannelTest method shouldReadFromMultipleChannels.
@Test
void shouldReadFromMultipleChannels() throws Exception {
// GIVEN
writeSomeData(file(0), element -> {
for (int i = 0; i < 10; i++) {
element.putLong(i);
}
return true;
});
writeSomeData(file(1), element -> {
for (int i = 10; i < 20; i++) {
element.putLong(i);
}
return true;
});
StoreChannel storeChannel = fileSystem.read(file(0));
PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, -1, /* ignored */
(byte) -1, file(0), nativeChannelAccessor);
try (ReadAheadLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, new LogVersionBridge() {
private boolean returned;
@Override
public LogVersionedStoreChannel next(LogVersionedStoreChannel channel, boolean raw) throws IOException {
if (!returned) {
returned = true;
channel.close();
return new PhysicalLogVersionedStoreChannel(fileSystem.read(file(1)), -1, /* ignored */
(byte) -1, file(1), nativeChannelAccessor);
}
return channel;
}
}, INSTANCE)) {
// THEN
for (long i = 0; i < 20; i++) {
assertEquals(i, channel.getLong());
}
}
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class ReaderLogVersionBridgeTest method shouldReturnOldChannelWhenThereIsNoNextChannel.
@Test
void shouldReturnOldChannelWhenThereIsNoNextChannel() throws IOException {
// given
final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(logFiles.getLogFile());
when(channel.getVersion()).thenReturn(version);
when(fs.read(any(Path.class))).thenThrow(new NoSuchFileException("mock"));
// when
final LogVersionedStoreChannel result = bridge.next(channel, false);
// then
assertEquals(channel, result);
verify(channel, never()).close();
}
use of org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel in project neo4j by neo4j.
the class ReaderLogVersionBridgeTest method shouldReturnOldChannelWhenNextChannelHasNotGottenCompleteHeaderYet.
@Test
void shouldReturnOldChannelWhenNextChannelHasNotGottenCompleteHeaderYet() throws Exception {
// given
final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(logFiles.getLogFile());
final StoreChannel nextVersionWithIncompleteHeader = mock(StoreChannel.class);
when(nextVersionWithIncompleteHeader.read(any(ByteBuffer.class))).thenReturn(CURRENT_FORMAT_LOG_HEADER_SIZE / 2);
when(channel.getVersion()).thenReturn(version);
when(fs.fileExists(any(Path.class))).thenReturn(true);
when(fs.read(any(Path.class))).thenReturn(nextVersionWithIncompleteHeader);
// when
final LogVersionedStoreChannel result = bridge.next(channel, false);
// then
assertEquals(channel, result);
verify(channel, never()).close();
}
Aggregations