Skip to content

Commit

Permalink
Remember commit time when reading tx logs
Browse files Browse the repository at this point in the history
Previously code only memorized transaction start entry.
Also fixed assertion based on objects `#toString()`.
  • Loading branch information
lutovich committed Jul 1, 2016
1 parent c9bfae5 commit 01a4567
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static class TransactionPositionLocator implements LogFile.LogFileVisitor
private final long startTransactionId;
private final LogEntryReader<ReadableVersionableLogChannel> logEntryReader;
private LogEntryStart startEntryForFoundTransaction;
private long commitTimestamp;

public TransactionPositionLocator( long startTransactionId,
LogEntryReader<ReadableVersionableLogChannel> logEntryReader )
Expand All @@ -156,6 +157,7 @@ public boolean visit( LogPosition position, ReadableVersionableLogChannel channe
if ( commit.getTxId() == startTransactionId )
{
startEntryForFoundTransaction = startEntry;
commitTimestamp = commit.getTimeWritten();
return false;
}
default: // just skip commands
Expand All @@ -178,7 +180,7 @@ public LogPosition getAndCacheFoundLogPosition( TransactionMetadataCache transac
startEntryForFoundTransaction.getMasterId(),
startEntryForFoundTransaction.getLocalId(),
LogEntryStart.checksum( startEntryForFoundTransaction ),
startEntryForFoundTransaction.getTimeWritten()
commitTimestamp
);
return startEntryForFoundTransaction.getStartPosition();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@
import org.neo4j.kernel.recovery.Recovery;
import org.neo4j.test.TargetDirectory;

import static java.lang.String.format;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.DEFAULT_NAME;
import static org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache.TransactionMetadata;
import static org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_LOG_VERSION;
import static org.neo4j.kernel.impl.transaction.log.rotation.LogRotation.NO_ROTATION;
import static org.neo4j.kernel.impl.util.IdOrderingQueue.BYPASS;
Expand Down Expand Up @@ -229,7 +227,7 @@ public void recoveryRequired()
public void shouldExtractMetadataFromExistingTransaction() throws Exception
{
// GIVEN
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache( 10, 100 );
final byte[] additionalHeader = new byte[]{1, 2, 5};
final int masterId = 2, authorId = 1;
Expand All @@ -238,13 +236,13 @@ public void shouldExtractMetadataFromExistingTransaction() throws Exception
PhysicalLogFiles logFiles = new PhysicalLogFiles( testDir, DEFAULT_NAME, fs );
Monitor monitor = new Monitors().newMonitor( PhysicalLogFile.Monitor.class );
LogFile logFile = life.add( new PhysicalLogFile( fs, logFiles, 1000,
transactionIdStore, mock( LogVersionRepository.class ), monitor,
txIdStore, mock( LogVersionRepository.class ), monitor,
positionCache ) );

life.start();
try
{
addATransactionAndRewind( life, logFile, positionCache, transactionIdStore,
addATransactionAndRewind( life, logFile, positionCache, txIdStore,
additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted );
}
finally
Expand All @@ -257,7 +255,7 @@ transactionIdStore, mock( LogVersionRepository.class ), monitor,
authorId, timeStarted, timeCommitted, latestCommittedTxWhenStarted );
final LogFileRecoverer recoverer = new LogFileRecoverer( new VersionAwareLogEntryReader<>(), visitor );
logFile = life.add( new PhysicalLogFile( fs, logFiles, 1000,
transactionIdStore, mock( LogVersionRepository.class ), monitor,
txIdStore, mock( LogVersionRepository.class ), monitor,
positionCache ) );
final LogicalTransactionStore store = new PhysicalLogicalTransactionStore( logFile, positionCache );

Expand All @@ -269,10 +267,11 @@ transactionIdStore, mock( LogVersionRepository.class ), monitor,

positionCache.clear();

assertThat( store.getMetadataFor( transactionIdStore.getLastCommittedTransactionId() ).toString(),
equalTo(
format( "TransactionMetadata[masterId=%d, authorId=%d, startPosition=%s, checksum=%d]",
masterId, authorId, visitor.getStartPosition(), visitor.getChecksum() ) ) );
TransactionMetadata expectedMetadata = new TransactionMetadata( masterId, authorId,
visitor.getStartPosition(), visitor.getChecksum(), visitor.getTimeCommitted() );

TransactionMetadata actualMetadata = store.getMetadataFor( txIdStore.getLastCommittedTransactionId() );
assertEquals( expectedMetadata, actualMetadata );
}
finally
{
Expand Down Expand Up @@ -431,6 +430,11 @@ public long getChecksum()
return checksum;
}

public long getTimeCommitted()
{
return timeCommitted;
}

public LogPosition getStartPosition()
{
return startPosition;
Expand Down

0 comments on commit 01a4567

Please sign in to comment.