Search in sources :

Example 26 with LogEntry

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;
}
Also used : LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 27 with LogEntry

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();
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) IOCursor(org.neo4j.cursor.IOCursor) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) File(java.io.File) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) TransactionId(org.neo4j.kernel.impl.store.TransactionId)

Example 28 with LogEntry

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);
        }
    }
}
Also used : IOCursor(org.neo4j.cursor.IOCursor) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) File(java.io.File) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 29 with LogEntry

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;
        }
    }
}
Also used : LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry)

Example 30 with LogEntry

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);
            }
        }
    }
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) PositionAwarePhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) ArrayList(java.util.ArrayList) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Aggregations

LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)44 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)14 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)14 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)12 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)12 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)12 Test (org.junit.Test)10 File (java.io.File)9 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)9 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)8 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)7 IdentifiableLogEntry (org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry)7 ArrayList (java.util.ArrayList)6 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)5 StorageCommand (org.neo4j.storageengine.api.StorageCommand)5 IOException (java.io.IOException)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 StoreChannel (org.neo4j.io.fs.StoreChannel)4