use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class CheckTxLogs method scan.
private <C extends Command, R extends AbstractBaseRecord> boolean scan(PhysicalLogFiles logFiles, InconsistenciesHandler handler, CheckType<C, R> check, boolean checkTxIds) throws IOException {
out.println("Checking logs for " + check.name() + " inconsistencies");
CommittedRecords<R> state = new CommittedRecords<>(check);
List<CommandAndLogVersion> txCommands = new ArrayList<>();
boolean validLogs = true;
long commandsRead = 0;
long lastSeenTxId = BASE_TX_ID;
try (LogEntryCursor logEntryCursor = LogTestUtils.openLogs(fs, logFiles)) {
while (logEntryCursor.next()) {
LogEntry entry = logEntryCursor.get();
if (entry instanceof LogEntryCommand) {
StorageCommand command = ((LogEntryCommand) entry).getXaCommand();
if (check.commandClass().isInstance(command)) {
long logVersion = logEntryCursor.getCurrentLogVersion();
txCommands.add(new CommandAndLogVersion(command, logVersion));
}
} else if (entry instanceof LogEntryCommit) {
long txId = ((LogEntryCommit) entry).getTxId();
if (checkTxIds) {
validLogs &= checkNoDuplicatedTxsInTheLog(lastSeenTxId, txId, handler);
lastSeenTxId = txId;
}
for (CommandAndLogVersion txCommand : txCommands) {
validLogs &= checkAndHandleInconsistencies(txCommand, check, state, txId, handler);
}
txCommands.clear();
}
commandsRead++;
}
}
out.println("Processed " + commandsRead + " commands");
out.println(state);
if (!txCommands.isEmpty()) {
out.println("Found " + txCommands.size() + " uncommitted commands at the end.");
for (CommandAndLogVersion txCommand : txCommands) {
validLogs &= checkAndHandleInconsistencies(txCommand, check, state, -1, handler);
}
txCommands.clear();
}
return validLogs;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry 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.kernel.impl.transaction.log.entry.LogEntry 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.LogEntry in project neo4j by neo4j.
the class LogEntrySortingCursor method perhapsFetchEntriesFromChannel.
private void perhapsFetchEntriesFromChannel() throws IOException {
if (idToFetchFrom > 0) {
// we still have entry to return from the map...
return;
}
LogEntry entry;
while ((entry = reader.readLogEntry(channel)) != null) {
if (!(entry instanceof IdentifiableLogEntry)) {
throw new IllegalStateException("reading from a log which is not a legacy one???");
}
final IdentifiableLogEntry identifiableLogEntry = (IdentifiableLogEntry) entry;
final int identifier = identifiableLogEntry.getIdentifier();
final LogEntry inner = identifiableLogEntry.getEntry();
List<LogEntry> list = provideList(idToEntries, identifier);
list.add(inner);
if (inner instanceof LogEntryCommit) {
idToFetchFrom = identifier;
break;
}
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LegacyLogEntryWriter method writeAllLogEntries.
public void writeAllLogEntries(LogVersionedStoreChannel channel, IOCursor<LogEntry> cursor) throws IOException {
try (PositionAwarePhysicalFlushableChannel writable = new PositionAwarePhysicalFlushableChannel(channel)) {
final LogEntryWriter writer = factory.apply(writable);
List<StorageCommand> commands = new ArrayList<>();
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
final LogEntryStart startEntry = entry.as();
writer.writeStartEntry(startEntry.getMasterId(), startEntry.getLocalId(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), startEntry.getAdditionalHeader());
} else if (entry instanceof LogEntryCommit) {
if (!commands.isEmpty()) {
writer.serialize(new PhysicalTransactionRepresentation(commands));
commands = new ArrayList<>();
}
final LogEntryCommit commitEntry = (LogEntryCommit) entry;
writer.writeCommitEntry(commitEntry.getTxId(), commitEntry.getTimeWritten());
} else if (entry instanceof LogEntryCommand) {
commands.add(((LogEntryCommand) entry).getXaCommand());
} else {
throw new IllegalStateException("Unknown entry: " + entry);
}
}
}
}
Aggregations