use of org.neo4j.cursor.IOCursor in project neo4j by neo4j.
the class LegacyLogEntryReaderTest method shouldReadTheLogHeaderAndSetCurrentVersionAndABaseTxIdIfNegative.
@Test
public void shouldReadTheLogHeaderAndSetCurrentVersionAndABaseTxIdIfNegative() throws IOException {
// given
final LegacyLogEntryReader reader = new LegacyLogEntryReader(fs);
// when
final Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(input);
// then
// not null cursor
pair.other().close();
assertEquals(new LogHeader(CURRENT_LOG_VERSION, 3L, BASE_TX_ID), pair.first());
}
use of org.neo4j.cursor.IOCursor in project neo4j by neo4j.
the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.
private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
final AtomicBoolean success = new AtomicBoolean(false);
try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
boolean startFound = false;
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
if (startFound) {
throw new IllegalArgumentException("More than one start entry");
}
startFound = true;
}
if (startFound && entry instanceof LogEntryCommand) {
commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
}
if (entry instanceof LogEntryCommit) {
// The first COMMIT
assertTrue(startFound);
assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
assertEquals(1, createCommands.size());
success.set(true);
break;
}
}
}
assertTrue("Didn't find any commit record in log " + version, success.get());
}
use of org.neo4j.cursor.IOCursor in project neo4j by neo4j.
the class LegacyLogs method getTransactionInformation.
public Optional<TransactionId> getTransactionInformation(File storeDir, long transactionId) throws IOException {
List<File> logFiles = Arrays.asList(fs.listFiles(storeDir, versionedLegacyLogFilesFilter));
logFiles.sort(NEWEST_FIRST);
for (File file : logFiles) {
Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(file);
boolean hadAnyTransactions = false;
try (IOCursor<LogEntry> cursor = pair.other()) {
// The log entries will come sorted from this cursor, so no need to keep track of identifiers and such.
LogEntryStart startEntry = null;
while (cursor.next()) {
LogEntry logEntry = cursor.get();
if (logEntry instanceof LogEntryStart) {
startEntry = (LogEntryStart) logEntry;
} else if (logEntry instanceof LogEntryCommit) {
hadAnyTransactions = true;
LogEntryCommit commitEntry = logEntry.as();
if (commitEntry.getTxId() == transactionId) {
return Optional.of(new TransactionId(transactionId, startEntry.checksum(), commitEntry.getTimeWritten()));
}
}
}
}
if (hadAnyTransactions) {
// No need to go further back than this. We're looking for the last transaction
break;
}
}
return Optional.empty();
}
use of org.neo4j.cursor.IOCursor 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);
}
}
}
Aggregations