use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class LegacyLogs method migrateLogs.
public void migrateLogs(File storeDir, File migrationDir) throws IOException {
File[] logFiles = fs.listFiles(storeDir, versionedLegacyLogFilesFilter);
for (File file : logFiles) {
final Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(file);
final LogHeader header = pair.first();
try (IOCursor<LogEntry> cursor = pair.other();
LogVersionedStoreChannel channel = writer.openWritableChannel(new File(migrationDir, file.getName()))) {
writer.writeLogHeader(channel, header);
writer.writeAllLogEntries(channel, cursor);
}
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class PhysicalLogFile method accept.
@Override
public void accept(LogHeaderVisitor visitor) throws IOException {
// Start from the where we're currently at and go backwards in time (versions)
long logVersion = logFiles.getHighestLogVersion();
long highTransactionId = lastCommittedId.get();
while (logFiles.versionExists(logVersion)) {
Long previousLogLastTxId = logHeaderCache.getLogHeader(logVersion);
if (previousLogLastTxId == null) {
LogHeader header = readLogHeader(fileSystem, logFiles.getLogFileForVersion(logVersion), false);
if (header != null) {
assert logVersion == header.logVersion;
logHeaderCache.putHeader(header.logVersion, header.lastCommittedTxId);
previousLogLastTxId = header.lastCommittedTxId;
}
}
if (previousLogLastTxId != null) {
long lowTransactionId = previousLogLastTxId + 1;
LogPosition position = LogPosition.start(logVersion);
if (!visitor.visit(position, lowTransactionId, highTransactionId)) {
break;
}
highTransactionId = previousLogLastTxId;
}
logVersion--;
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldOpenInFreshDirectoryAndFinallyAddHeader.
@Test
public void shouldOpenInFreshDirectoryAndFinallyAddHeader() throws Exception {
// GIVEN
String name = "log";
LifeSupport life = new LifeSupport();
FileSystemAbstraction fs = fileSystemRule.get();
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
life.add(new PhysicalLogFile(fs, logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
// WHEN
life.start();
life.shutdown();
// THEN
File file = new PhysicalLogFiles(directory.directory(), name, fs).getLogFileForVersion(1L);
LogHeader header = readLogHeader(fs, file);
assertEquals(1L, header.logVersion);
assertEquals(5L, header.lastCommittedTxId);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class LogTestUtils method filterNeostoreLogicalLog.
public static File filterNeostoreLogicalLog(FileSystemAbstraction fileSystem, File file, final LogHook<LogEntry> filter) throws IOException {
filter.file(file);
File tempFile = new File(file.getAbsolutePath() + ".tmp");
fileSystem.deleteFile(tempFile);
try (StoreChannel in = fileSystem.open(file, "r");
StoreChannel out = fileSystem.open(tempFile, "rw")) {
LogHeader logHeader = transferLogicalLogHeader(in, out, ByteBuffer.allocate(LOG_HEADER_SIZE));
PhysicalLogVersionedStoreChannel outChannel = new PhysicalLogVersionedStoreChannel(out, logHeader.logVersion, logHeader.logFormatVersion);
PhysicalLogVersionedStoreChannel inChannel = new PhysicalLogVersionedStoreChannel(in, logHeader.logVersion, logHeader.logFormatVersion);
ReadableLogChannel inBuffer = new ReadAheadLogChannel(inChannel, LogVersionBridge.NO_MORE_CHANNELS);
LogEntryReader<ReadableLogChannel> entryReader = new VersionAwareLogEntryReader<>();
LogEntry entry;
while ((entry = entryReader.readLogEntry(inBuffer)) != null) {
if (filter.test(entry)) {
// TODO allright, write to outBuffer
}
}
}
return tempFile;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class LegacyLogEntryWriterTest method shouldWriteTheHeaderInTheFile.
@Test
public void shouldWriteTheHeaderInTheFile() throws IOException {
// given
final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs);
final File output = new File(getLegacyLogFilename(3));
final LogHeader header = new LogHeader(CURRENT_LOG_VERSION, 1, 42L);
// when
try (LogVersionedStoreChannel channel = writer.openWritableChannel(output)) {
writer.writeLogHeader(channel, header);
}
// then
assertEquals(header, readLogHeader(fs, output));
}
Aggregations