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.
Expand Up @@ -131,6 +131,7 @@ public static class TransactionPositionLocator implements LogFile.LogFileVisitor
private final long startTransactionId; private final long startTransactionId;
private final LogEntryReader<ReadableVersionableLogChannel> logEntryReader; private final LogEntryReader<ReadableVersionableLogChannel> logEntryReader;
private LogEntryStart startEntryForFoundTransaction; private LogEntryStart startEntryForFoundTransaction;
private long commitTimestamp;


public TransactionPositionLocator( long startTransactionId, public TransactionPositionLocator( long startTransactionId,
LogEntryReader<ReadableVersionableLogChannel> logEntryReader ) LogEntryReader<ReadableVersionableLogChannel> logEntryReader )
Expand All @@ -156,6 +157,7 @@ public boolean visit( LogPosition position, ReadableVersionableLogChannel channe
if ( commit.getTxId() == startTransactionId ) if ( commit.getTxId() == startTransactionId )
{ {
startEntryForFoundTransaction = startEntry; startEntryForFoundTransaction = startEntry;
commitTimestamp = commit.getTimeWritten();
return false; return false;
} }
default: // just skip commands default: // just skip commands
Expand All @@ -178,7 +180,7 @@ public LogPosition getAndCacheFoundLogPosition( TransactionMetadataCache transac
startEntryForFoundTransaction.getMasterId(), startEntryForFoundTransaction.getMasterId(),
startEntryForFoundTransaction.getLocalId(), startEntryForFoundTransaction.getLocalId(),
LogEntryStart.checksum( startEntryForFoundTransaction ), LogEntryStart.checksum( startEntryForFoundTransaction ),
startEntryForFoundTransaction.getTimeWritten() commitTimestamp
); );
return startEntryForFoundTransaction.getStartPosition(); return startEntryForFoundTransaction.getStartPosition();
} }
Expand Down
Expand Up @@ -50,17 +50,15 @@
import org.neo4j.kernel.recovery.Recovery; import org.neo4j.kernel.recovery.Recovery;
import org.neo4j.test.TargetDirectory; 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.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; 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.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.entry.LogVersions.CURRENT_LOG_VERSION;
import static org.neo4j.kernel.impl.transaction.log.rotation.LogRotation.NO_ROTATION; import static org.neo4j.kernel.impl.transaction.log.rotation.LogRotation.NO_ROTATION;
import static org.neo4j.kernel.impl.util.IdOrderingQueue.BYPASS; 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 public void shouldExtractMetadataFromExistingTransaction() throws Exception
{ {
// GIVEN // GIVEN
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore(); TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache( 10, 100 ); TransactionMetadataCache positionCache = new TransactionMetadataCache( 10, 100 );
final byte[] additionalHeader = new byte[]{1, 2, 5}; final byte[] additionalHeader = new byte[]{1, 2, 5};
final int masterId = 2, authorId = 1; 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 ); PhysicalLogFiles logFiles = new PhysicalLogFiles( testDir, DEFAULT_NAME, fs );
Monitor monitor = new Monitors().newMonitor( PhysicalLogFile.Monitor.class ); Monitor monitor = new Monitors().newMonitor( PhysicalLogFile.Monitor.class );
LogFile logFile = life.add( new PhysicalLogFile( fs, logFiles, 1000, LogFile logFile = life.add( new PhysicalLogFile( fs, logFiles, 1000,
transactionIdStore, mock( LogVersionRepository.class ), monitor, txIdStore, mock( LogVersionRepository.class ), monitor,
positionCache ) ); positionCache ) );


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


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


positionCache.clear(); positionCache.clear();


assertThat( store.getMetadataFor( transactionIdStore.getLastCommittedTransactionId() ).toString(), TransactionMetadata expectedMetadata = new TransactionMetadata( masterId, authorId,
equalTo( visitor.getStartPosition(), visitor.getChecksum(), visitor.getTimeCommitted() );
format( "TransactionMetadata[masterId=%d, authorId=%d, startPosition=%s, checksum=%d]",
masterId, authorId, visitor.getStartPosition(), visitor.getChecksum() ) ) ); TransactionMetadata actualMetadata = store.getMetadataFor( txIdStore.getLastCommittedTransactionId() );
assertEquals( expectedMetadata, actualMetadata );
} }
finally finally
{ {
Expand Down Expand Up @@ -431,6 +430,11 @@ public long getChecksum()
return checksum; return checksum;
} }


public long getTimeCommitted()
{
return timeCommitted;
}

public LogPosition getStartPosition() public LogPosition getStartPosition()
{ {
return startPosition; return startPosition;
Expand Down

0 comments on commit 01a4567

Please sign in to comment.