use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand 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.kernel.impl.transaction.log.entry.LogEntryCommand in project neo4j by neo4j.
the class LogTruncationTest method assertHandlesLogTruncation.
private void assertHandlesLogTruncation(Command cmd) throws IOException {
inMemoryChannel.reset();
writer.serialize(new PhysicalTransactionRepresentation(Arrays.asList(cmd)));
int bytesSuccessfullyWritten = inMemoryChannel.writerPosition();
try {
LogEntry logEntry = logEntryReader.readLogEntry(inMemoryChannel);
StorageCommand command = ((LogEntryCommand) logEntry).getXaCommand();
assertEquals(cmd, command);
} catch (Exception e) {
throw new AssertionError("Failed to deserialize " + cmd.toString() + ", because: ", e);
}
bytesSuccessfullyWritten--;
while (bytesSuccessfullyWritten-- > 0) {
inMemoryChannel.reset();
writer.serialize(new PhysicalTransactionRepresentation(Arrays.asList(cmd)));
inMemoryChannel.truncateTo(bytesSuccessfullyWritten);
LogEntry deserialized = logEntryReader.readLogEntry(inMemoryChannel);
assertNull("Deserialization did not detect log truncation!" + "Record: " + cmd + ", deserialized: " + deserialized, deserialized);
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand in project neo4j by neo4j.
the class TxPullResponseEncodeDecodeTest method newCommittedTransactionRepresentation.
private CommittedTransactionRepresentation newCommittedTransactionRepresentation() {
final long arbitraryRecordId = 27L;
Command.NodeCommand command = new Command.NodeCommand(new NodeRecord(arbitraryRecordId), new NodeRecord(arbitraryRecordId));
PhysicalTransactionRepresentation physicalTransactionRepresentation = new PhysicalTransactionRepresentation(asList(new LogEntryCommand(command).getXaCommand()));
physicalTransactionRepresentation.setHeader(new byte[] {}, 0, 0, 0, 0, 0, 0);
LogEntryStart startEntry = new LogEntryStart(0, 0, 0L, 0L, new byte[] {}, LogPosition.UNSPECIFIED);
OnePhaseCommit commitEntry = new OnePhaseCommit(42, 0);
return new CommittedTransactionRepresentation(startEntry, physicalTransactionRepresentation, commitEntry);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand in project neo4j by neo4j.
the class PhysicalTransactionCursor method next.
@Override
public boolean next() throws IOException {
// Clear the previous deserialized transaction so that it won't have to be kept in heap while deserializing
// the next one. Could be problematic if both are really big.
current = null;
while (true) {
if (!logEntryCursor.next()) {
return false;
}
LogEntry entry = logEntryCursor.get();
if (entry instanceof LogEntryInlinedCheckPoint) {
// this is a good position anyhow
channel.getCurrentPosition(lastGoodPositionMarker);
continue;
}
assert entry instanceof LogEntryStart : "Expected Start entry, read " + entry + " instead";
LogEntryStart startEntry = (LogEntryStart) entry;
LogEntryCommit commitEntry;
List<StorageCommand> entries = new ArrayList<>();
while (true) {
if (!logEntryCursor.next()) {
return false;
}
entry = logEntryCursor.get();
if (entry instanceof LogEntryCommit) {
commitEntry = (LogEntryCommit) entry;
break;
}
LogEntryCommand command = (LogEntryCommand) entry;
entries.add(command.getCommand());
}
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(entries);
transaction.setHeader(startEntry.getAdditionalHeader(), startEntry.getTimeWritten(), startEntry.getLastCommittedTxWhenTransactionStarted(), commitEntry.getTimeWritten(), -1, ANONYMOUS);
current = new CommittedTransactionRepresentation(startEntry, transaction, commitEntry);
channel.getCurrentPosition(lastGoodPositionMarker);
return true;
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand 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;
}
Aggregations