use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit 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.LogEntryCommit 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);
}
}
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.
the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInSeveralCommitsToTheFile.
@Test
public void shouldWriteAllTheEntryInSeveralCommitsToTheFile() throws IOException {
// given
final LogVersionedStoreChannel channel = mock(LogVersionedStoreChannel.class);
final LogEntryWriter logEntryWriter = mock(LogEntryWriter.class);
final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs, liftToFactory(logEntryWriter));
final LogEntryStart start1 = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command1 = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
final LogEntryCommit commit1 = new OnePhaseCommit(42L, 43L);
final LogEntryStart start2 = new LogEntryStart(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command2 = new LogEntryCommand(new Command.RelationshipCommand(relRecord, relRecord));
final LogEntryCommit commit2 = new OnePhaseCommit(84L, 85L);
// when
IOCursor<LogEntry> cursor = mockCursor(start1, command1, commit1, start2, command2, commit2);
writer.writeAllLogEntries(channel, cursor);
// then
verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected1 = new PhysicalTransactionRepresentation(Arrays.asList(command1.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected1));
verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
verify(logEntryWriter, times(1)).writeStartEntry(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected2 = new PhysicalTransactionRepresentation(Arrays.asList(command2.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected2));
verify(logEntryWriter, times(1)).writeCommitEntry(84L, 85L);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.
the class TransactionLogAppendAndRotateIT method assertWholeTransactionsIn.
private static void assertWholeTransactionsIn(LogFile logFile, long logVersion) throws IOException {
try (ReadableLogChannel reader = logFile.getReader(new LogPosition(logVersion, LOG_HEADER_SIZE))) {
VersionAwareLogEntryReader<ReadableLogChannel> entryReader = new VersionAwareLogEntryReader<>();
LogEntry entry = null;
boolean inTx = false;
int transactions = 0;
while ((entry = entryReader.readLogEntry(reader)) != null) {
if (// Expects start entry
!inTx) {
assertTrue(entry instanceof LogEntryStart);
inTx = true;
} else // Expects command/commit entry
{
assertTrue(entry instanceof LogEntryCommand || entry instanceof LogEntryCommit);
if (entry instanceof LogEntryCommit) {
inTx = false;
transactions++;
}
}
}
assertFalse(inTx);
assertTrue(transactions > 0);
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method shouldAppendCommittedTransactions.
@Test
public void shouldAppendCommittedTransactions() throws Exception {
// GIVEN
when(logFile.getWriter()).thenReturn(channel);
long nextTxId = 15;
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId);
TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, databaseHealth));
// WHEN
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final int masterId = 2, authorId = 1;
final long timeStarted = 12345, latestCommittedTxWhenStarted = nextTxId - 5, timeCommitted = timeStarted + 10;
PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(singleCreateNodeCommand(0));
transactionRepresentation.setHeader(additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1);
LogEntryStart start = new LogEntryStart(0, 0, 0L, latestCommittedTxWhenStarted, null, LogPosition.UNSPECIFIED);
LogEntryCommit commit = new OnePhaseCommit(nextTxId, 0L);
CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);
appender.append(new TransactionToApply(transactionRepresentation, transaction.getCommitEntry().getTxId()), logAppendEvent);
// THEN
LogEntryReader<ReadableLogChannel> logEntryReader = new VersionAwareLogEntryReader<>();
try (PhysicalTransactionCursor<ReadableLogChannel> reader = new PhysicalTransactionCursor<>(channel, logEntryReader)) {
reader.next();
TransactionRepresentation result = reader.get().getTransactionRepresentation();
assertArrayEquals(additionalHeader, result.additionalHeader());
assertEquals(masterId, result.getMasterId());
assertEquals(authorId, result.getAuthorId());
assertEquals(timeStarted, result.getTimeStarted());
assertEquals(timeCommitted, result.getTimeCommitted());
assertEquals(latestCommittedTxWhenStarted, result.getLatestCommittedTxWhenStarted());
}
}
Aggregations