use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.
the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInACommitToTheFile.
@Test
public void shouldWriteAllTheEntryInACommitToTheFile() 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 start = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
final LogEntryCommit commit = new OnePhaseCommit(42L, 43L);
// when
final IOCursor<LogEntry> cursor = mockCursor(start, command, commit);
writer.writeAllLogEntries(channel, cursor);
// then
verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected = new PhysicalTransactionRepresentation(Arrays.asList(command.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected));
verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
}
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());
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.
the class PhysicalLogicalTransactionStore method getMetadataFor.
@Override
public TransactionMetadata getMetadataFor(long transactionId) throws IOException {
if (transactionId <= BASE_TX_ID) {
return METADATA_FOR_EMPTY_STORE;
}
TransactionMetadata transactionMetadata = transactionMetadataCache.getTransactionMetadata(transactionId);
if (transactionMetadata == null) {
try (IOCursor<CommittedTransactionRepresentation> cursor = getTransactions(transactionId)) {
while (cursor.next()) {
CommittedTransactionRepresentation tx = cursor.get();
LogEntryCommit commitEntry = tx.getCommitEntry();
long committedTxId = commitEntry.getTxId();
long timeWritten = commitEntry.getTimeWritten();
TransactionMetadata metadata = transactionMetadataCache.cacheTransactionMetadata(committedTxId, tx.getStartEntry().getStartPosition(), tx.getStartEntry().getMasterId(), tx.getStartEntry().getLocalId(), LogEntryStart.checksum(tx.getStartEntry()), timeWritten);
if (committedTxId == transactionId) {
transactionMetadata = metadata;
}
}
}
if (transactionMetadata == null) {
throw new NoSuchTransactionException(transactionId);
}
}
return transactionMetadata;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit in project neo4j by neo4j.
the class LatestCheckPointFinder method extractFirstTxIdAfterPosition.
/**
* Extracts txId from first commit entry, when starting reading at the given {@code position}.
* If no commit entry found in the version, the reader will continue into next version(s) up till
* {@code maxLogVersion} until finding one.
*
* @param initialPosition {@link LogPosition} to start scan from.
* @param maxLogVersion max log version to scan.
* @return txId of closes commit entry to {@code initialPosition}, or {@link LatestCheckPoint#NO_TRANSACTION_ID}
* if not found.
* @throws IOException on I/O error.
*/
private long extractFirstTxIdAfterPosition(LogPosition initialPosition, long maxLogVersion) throws IOException {
LogPosition currentPosition = initialPosition;
while (currentPosition.getLogVersion() <= maxLogVersion) {
LogVersionedStoreChannel storeChannel = PhysicalLogFile.tryOpenForVersion(logFiles, fileSystem, currentPosition.getLogVersion(), false);
if (storeChannel != null) {
try {
storeChannel.position(currentPosition.getByteOffset());
try (ReadAheadLogChannel logChannel = new ReadAheadLogChannel(storeChannel, NO_MORE_CHANNELS);
LogEntryCursor cursor = new LogEntryCursor(logEntryReader, logChannel)) {
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryCommit) {
return ((LogEntryCommit) entry).getTxId();
}
}
}
} finally {
storeChannel.close();
}
}
currentPosition = LogPosition.start(currentPosition.getLogVersion() + 1);
}
return LatestCheckPoint.NO_TRANSACTION_ID;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit 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;
}
}
Aggregations