Search in sources :

Example 6 with LogEntryCommit

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit 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());
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Iterators(org.neo4j.helpers.collection.Iterators) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOCursor(org.neo4j.cursor.IOCursor) Node(org.neo4j.graphdb.Node) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ArrayList(java.util.ArrayList) StorageCommand(org.neo4j.storageengine.api.StorageCommand) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) After(org.junit.After) Transaction(org.neo4j.graphdb.Transaction) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Rule(org.junit.Rule) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Assert.assertFalse(org.junit.Assert.assertFalse) FilteringIterator(org.neo4j.helpers.collection.FilteringIterator) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Assert.assertEquals(org.junit.Assert.assertEquals) Index(org.neo4j.graphdb.index.Index) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ArrayList(java.util.ArrayList) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 7 with LogEntryCommit

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.

the class BatchingTxApplierTest method createTxWithId.

private CommittedTransactionRepresentation createTxWithId(long txId) {
    CommittedTransactionRepresentation tx = mock(CommittedTransactionRepresentation.class);
    LogEntryCommit commitEntry = mock(LogEntryCommit.class);
    when(commitEntry.getTxId()).thenReturn(txId);
    TransactionRepresentation txRep = mock(TransactionRepresentation.class);
    when(tx.getTransactionRepresentation()).thenReturn(txRep);
    when(tx.getCommitEntry()).thenReturn(commitEntry);
    return tx;
}
Also used : CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)

Example 8 with LogEntryCommit

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.

the class CommittedTransactionSerializer method visit.

@Override
public boolean visit(CommittedTransactionRepresentation tx) throws IOException {
    LogEntryStart startEntry = tx.getStartEntry();
    writer.writeStartEntry(startEntry.getMasterId(), startEntry.getLocalId(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), startEntry.getAdditionalHeader());
    writer.serialize(tx.getTransactionRepresentation());
    LogEntryCommit commitEntry = tx.getCommitEntry();
    writer.writeCommitEntry(commitEntry.getTxId(), commitEntry.getTimeWritten());
    return false;
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)

Example 9 with LogEntryCommit

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit 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 10 with LogEntryCommit

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit 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)

Aggregations

LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)15 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)10 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)10 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)7 Test (org.junit.Test)5 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)5 ArrayList (java.util.ArrayList)4 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)4 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)4 StorageCommand (org.neo4j.storageengine.api.StorageCommand)4 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)3 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)3 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)3 IOCursor (org.neo4j.cursor.IOCursor)2 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 Command (org.neo4j.kernel.impl.transaction.command.Command)2 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)2 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 File (java.io.File)1