Skip to content

Commit

Permalink
Address PR comments, various cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Mar 14, 2017
1 parent 191c10c commit 5fff2a2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
Expand Up @@ -47,9 +47,9 @@ class CrashGenCleaner
private final long stableGeneration; private final long stableGeneration;
private final long unstableGeneration; private final long unstableGeneration;
private final Monitor monitor; private final Monitor monitor;
private final long maxKeyCount; private final long internalMaxKeyCount;


public CrashGenCleaner( PagedFile pagedFile, TreeNode<?,?> treeNode, long lowTreeNodeId, long highTreeNodeId, CrashGenCleaner( PagedFile pagedFile, TreeNode<?,?> treeNode, long lowTreeNodeId, long highTreeNodeId,
long stableGeneration, long unstableGeneration, Monitor monitor ) long stableGeneration, long unstableGeneration, Monitor monitor )
{ {
this.pagedFile = pagedFile; this.pagedFile = pagedFile;
Expand All @@ -59,7 +59,7 @@ public CrashGenCleaner( PagedFile pagedFile, TreeNode<?,?> treeNode, long lowTre
this.stableGeneration = stableGeneration; this.stableGeneration = stableGeneration;
this.unstableGeneration = unstableGeneration; this.unstableGeneration = unstableGeneration;
this.monitor = monitor; this.monitor = monitor;
this.maxKeyCount = treeNode.internalMaxKeyCount(); this.internalMaxKeyCount = treeNode.internalMaxKeyCount();
} }


// === Methods about the execution and threading === // === Methods about the execution and threading ===
Expand Down Expand Up @@ -130,11 +130,6 @@ private Runnable cleaner( AtomicLong nextId, AtomicReference<Throwable> error, A
break; break;
} }


// TODO: we should try to figure out if the disk backing this paged file
// is good at concurrent random reads (i.e. if it's an SSD).
// If it's not it'd likely be beneficial to let other threads wait until
// goTo completes before letting others read. This will have reads be
// 100% sequential.
PageCursorUtil.goTo( cursor, "clean", id ); PageCursorUtil.goTo( cursor, "clean", id );


if ( hasCrashedGSPP( treeNode, cursor ) ) if ( hasCrashedGSPP( treeNode, cursor ) )
Expand Down Expand Up @@ -171,6 +166,7 @@ private boolean hasCrashedGSPP( TreeNode<?,?> treeNode, PageCursor cursor ) thro
keyCount = treeNode.keyCount( cursor ); keyCount = treeNode.keyCount( cursor );
} }
while ( cursor.shouldRetry() ); while ( cursor.shouldRetry() );
PageCursorUtil.checkOutOfBounds( cursor );


if ( !isTreeNode ) if ( !isTreeNode )
{ {
Expand All @@ -187,13 +183,14 @@ private boolean hasCrashedGSPP( TreeNode<?,?> treeNode, PageCursor cursor ) thro


if ( !hasCrashed && TreeNode.isInternal( cursor ) ) if ( !hasCrashed && TreeNode.isInternal( cursor ) )
{ {
for ( int i = 0; i <= keyCount && i <= maxKeyCount && !hasCrashed; i++ ) for ( int i = 0; i <= keyCount && i <= internalMaxKeyCount && !hasCrashed; i++ )
{ {
hasCrashed |= hasCrashedGSPP( cursor, treeNode.childOffset( i ) ); hasCrashed = hasCrashedGSPP( cursor, treeNode.childOffset( i ) );
} }
} }
} }
while ( cursor.shouldRetry() ); while ( cursor.shouldRetry() );
PageCursorUtil.checkOutOfBounds( cursor );
return hasCrashed; return hasCrashed;
} }


Expand All @@ -220,7 +217,7 @@ private void cleanTreeNode( TreeNode<?,?> treeNode, PageCursor cursor, AtomicInt
if ( TreeNode.isInternal( cursor ) ) if ( TreeNode.isInternal( cursor ) )
{ {
int keyCount = treeNode.keyCount( cursor ); int keyCount = treeNode.keyCount( cursor );
for ( int i = 0; i <= keyCount && i <= maxKeyCount; i++ ) for ( int i = 0; i <= keyCount && i <= internalMaxKeyCount; i++ )
{ {
cleanCrashedGSPP( cursor, treeNode.childOffset( i ), cleanedPointers ); cleanCrashedGSPP( cursor, treeNode.childOffset( i ), cleanedPointers );
} }
Expand Down
Expand Up @@ -848,7 +848,7 @@ public void prepareForRecovery() throws IOException
* *
* @throws IOException on {@link PageCache} error. * @throws IOException on {@link PageCache} error.
*/ */
public void completeRecovery() throws IOException public void cleanCrashPointers() throws IOException
{ {
// For the time being there's an issue where update that come in before a crash // For the time being there's an issue where update that come in before a crash
// may be applied in a different order than when they get recovered. // may be applied in a different order than when they get recovered.
Expand Down
Expand Up @@ -28,7 +28,6 @@
import org.junit.rules.RuleChain; import org.junit.rules.RuleChain;


import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
Expand Down Expand Up @@ -70,19 +69,19 @@ public class CrashGenCleanerTest
private final int firstChildPos = 0; private final int firstChildPos = 0;
private final int middleChildPos = corruptableTreeNode.internalMaxKeyCount() / 2; private final int middleChildPos = corruptableTreeNode.internalMaxKeyCount() / 2;
private final int lastChildPos = corruptableTreeNode.internalMaxKeyCount(); private final int lastChildPos = corruptableTreeNode.internalMaxKeyCount();
private final List<PageCorruption> possibleCorruptionsInInternal = new ArrayList<>( Arrays.asList( private final List<PageCorruption> possibleCorruptionsInInternal = Arrays.asList(
crashed( leftSibling() ), crashed( leftSibling() ),
crashed( rightSibling() ), crashed( rightSibling() ),
crashed( newGen() ), crashed( newGen() ),
crashed( child( firstChildPos ) ), crashed( child( firstChildPos ) ),
crashed( child( middleChildPos ) ), crashed( child( middleChildPos ) ),
crashed( child( lastChildPos ) ) crashed( child( lastChildPos ) )
) ); );
private final List<PageCorruption> possibleCorruptionsInLeaf = new ArrayList<>( Arrays.asList( private final List<PageCorruption> possibleCorruptionsInLeaf = Arrays.asList(
crashed( leftSibling() ), crashed( leftSibling() ),
crashed( rightSibling() ), crashed( rightSibling() ),
crashed( newGen() ) crashed( newGen() )
) ); );


private class SimpleMonitor implements GBPTree.Monitor private class SimpleMonitor implements GBPTree.Monitor
{ {
Expand Down
Expand Up @@ -100,7 +100,7 @@ public void shouldRecoverFromCrashBeforeFirstCheckpoint() throws Exception
{ {
// this is the mimic:ed recovery // this is the mimic:ed recovery
index.prepareForRecovery(); index.prepareForRecovery();
index.completeRecovery(); index.cleanCrashPointers();


try ( Writer<MutableLong,MutableLong> writer = index.writer() ) try ( Writer<MutableLong,MutableLong> writer = index.writer() )
{ {
Expand Down Expand Up @@ -231,7 +231,7 @@ private void doShouldRecoverFromAnything( boolean replayRecoveryExactlyFromCheck
GBPTree<MutableLong,MutableLong> index = createIndex( pageCache, file ) ) GBPTree<MutableLong,MutableLong> index = createIndex( pageCache, file ) )
{ {
recover( recoveryActions, index ); recover( recoveryActions, index );
index.completeRecovery(); index.cleanCrashPointers();


// THEN // THEN
// we should end up with a consistent index containing all the stuff load says // we should end up with a consistent index containing all the stuff load says
Expand Down
Expand Up @@ -40,7 +40,7 @@ public RandomAdversary( double mischiefRate, double failureRate, double errorRat
assert 0 <= errorRate && errorRate < 1.0 : assert 0 <= errorRate && errorRate < 1.0 :
"Expected error rate in [0.0; 1.0[ but was " + errorRate; "Expected error rate in [0.0; 1.0[ but was " + errorRate;
assert mischiefRate + errorRate + failureRate < 1.0 : assert mischiefRate + errorRate + failureRate < 1.0 :
"Expected error rate + failure rate in [0.0; 1.0[ but was " + "Expected mischief rate + error rate + failure rate in [0.0; 1.0[ but was " +
(mischiefRate + errorRate + failureRate); (mischiefRate + errorRate + failureRate);


this.mischiefRate = mischiefRate; this.mischiefRate = mischiefRate;
Expand Down
Expand Up @@ -391,7 +391,7 @@ private void maybeCompleteRecovery() throws IOException
{ {
if ( recoveryStarted ) if ( recoveryStarted )
{ {
index.completeRecovery(); index.cleanCrashPointers();
recoveryStarted = false; recoveryStarted = false;
} }
} }
Expand Down

0 comments on commit 5fff2a2

Please sign in to comment.