use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class RecoveryTest method shouldSeeThatACleanDatabaseShouldNotRequireRecovery.
@Test
public void shouldSeeThatACleanDatabaseShouldNotRequireRecovery() throws Exception {
final PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), "log", fileSystemRule.get());
File file = logFiles.getLogFileForVersion(logVersion);
writeSomeData(file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException>() {
@Override
public boolean visit(Pair<LogEntryWriter, Consumer<LogPositionMarker>> pair) throws IOException {
LogEntryWriter writer = pair.first();
Consumer<LogPositionMarker> consumer = pair.other();
LogPositionMarker marker = new LogPositionMarker();
// last committed tx
consumer.accept(marker);
writer.writeStartEntry(0, 1, 2L, 3L, new byte[0]);
writer.writeCommitEntry(4L, 5L);
// check point
consumer.accept(marker);
writer.writeCheckPointEntry(marker.newPosition());
return true;
}
});
LifeSupport life = new LifeSupport();
Recovery.Monitor monitor = mock(Recovery.Monitor.class);
try {
StorageEngine storageEngine = mock(StorageEngine.class);
final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
LatestCheckPointFinder finder = new LatestCheckPointFinder(logFiles, fileSystemRule.get(), reader);
TransactionMetadataCache metadataCache = new TransactionMetadataCache(100);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 50, () -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository, mock(PhysicalLogFile.Monitor.class), logHeaderCache));
LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, metadataCache, reader);
life.add(new Recovery(new DefaultRecoverySPI(storageEngine, logFiles, fileSystemRule.get(), logVersionRepository, finder, transactionIdStore, txStore, NO_MONITOR) {
@Override
public Visitor<CommittedTransactionRepresentation, Exception> startRecovery() {
fail("Recovery should not be required");
// <-- to satisfy the compiler
return null;
}
}, monitor));
life.start();
verifyZeroInteractions(monitor);
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class NeoStoreDataSourceTest method logWithTransactions.
private PhysicalLogFiles logWithTransactions(long logVersion, long headerTxId) throws IOException {
PhysicalLogFiles files = mock(PhysicalLogFiles.class);
when(files.getLowestLogVersion()).thenReturn(logVersion);
when(files.hasAnyEntries(logVersion)).thenReturn(true);
when(files.versionExists(logVersion)).thenReturn(true);
when(files.extractHeader(logVersion)).thenReturn(new LogHeader(LogEntryVersion.CURRENT.byteCode(), logVersion, headerTxId));
return files;
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class PhysicalLogFilesTest method shouldReturnANegativeValueIfThereAreNoLogFiles.
@Test
public void shouldReturnANegativeValueIfThereAreNoLogFiles() {
// given
PhysicalLogFiles files = new PhysicalLogFiles(tmpDirectory, filename, fs);
final File[] filesOnDisk = new File[] { new File(tmpDirectory, "crap" + DEFAULT_VERSION_SUFFIX + "4"), new File(tmpDirectory, filename) };
when(fs.listFiles(tmpDirectory)).thenReturn(filesOnDisk);
// when
final long highestLogVersion = files.getHighestLogVersion();
// then
assertEquals(-1, highestLogVersion);
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class PhysicalLogFilesTest method shouldBeAbleToRetrieveTheHighestLogVersion.
@Test
public void shouldBeAbleToRetrieveTheHighestLogVersion() {
// given
PhysicalLogFiles files = new PhysicalLogFiles(tmpDirectory, filename, fs);
final File[] filesOnDisk = new File[] { new File(tmpDirectory, filename + DEFAULT_VERSION_SUFFIX + "1"), new File(tmpDirectory, "crap" + DEFAULT_VERSION_SUFFIX + "4"), new File(tmpDirectory, filename + DEFAULT_VERSION_SUFFIX + "3"), new File(tmpDirectory, filename) };
when(fs.listFiles(tmpDirectory)).thenReturn(filesOnDisk);
// when
final long highestLogVersion = files.getHighestLogVersion();
// then
assertEquals(3, highestLogVersion);
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class DumpLogicalLog method dump.
public void dump(String filenameOrDirectory, PrintStream out, Predicate<LogEntry[]> filter, Function<LogEntry, String> serializer) throws IOException {
File file = new File(filenameOrDirectory);
printFile(file, out);
File firstFile;
LogVersionBridge bridge;
if (file.isDirectory()) {
// Use natural log version bridging if a directory is supplied
final PhysicalLogFiles logFiles = new PhysicalLogFiles(file, fileSystem);
bridge = new ReaderLogVersionBridge(fileSystem, logFiles) {
@Override
public LogVersionedStoreChannel next(LogVersionedStoreChannel channel) throws IOException {
LogVersionedStoreChannel next = super.next(channel);
if (next != channel) {
printFile(logFiles.getLogFileForVersion(next.getVersion()), out);
}
return next;
}
};
firstFile = logFiles.getLogFileForVersion(logFiles.getLowestLogVersion());
} else {
// Use no bridging, simple reading this single log file if a file is supplied
firstFile = file;
bridge = NO_MORE_CHANNELS;
}
StoreChannel fileChannel = fileSystem.open(firstFile, "r");
ByteBuffer buffer = ByteBuffer.allocateDirect(LOG_HEADER_SIZE);
LogHeader logHeader;
try {
logHeader = readLogHeader(buffer, fileChannel, false, firstFile);
} catch (IOException ex) {
out.println("Unable to read timestamp information, no records in logical log.");
out.println(ex.getMessage());
fileChannel.close();
throw ex;
}
out.println("Logical log format: " + logHeader.logFormatVersion + " version: " + logHeader.logVersion + " with prev committed tx[" + logHeader.lastCommittedTxId + "]");
PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
ReadableClosablePositionAwareChannel logChannel = new ReadAheadLogChannel(channel, bridge, DEFAULT_READ_AHEAD_SIZE);
LogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>();
IOCursor<LogEntry> entryCursor = new LogEntryCursor(entryReader, logChannel);
TransactionLogEntryCursor transactionCursor = new TransactionLogEntryCursor(entryCursor);
try (IOCursor<LogEntry[]> cursor = filter == null ? transactionCursor : new FilteringIOCursor<>(transactionCursor, filter)) {
while (cursor.next()) {
for (LogEntry entry : cursor.get()) {
out.println(serializer.apply(entry));
}
}
}
}
Aggregations