Skip to content

Commit

Permalink
Additional name unification in new classes
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Mar 16, 2017
1 parent 88739ef commit ded1f55
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 45 deletions.
Expand Up @@ -39,7 +39,7 @@
/**
* Scans the entire tree and checks all GSPPs, replacing all CRASH gen GSPs with zeros.
*/
class CrashGenCleaner
class CrashGenerationCleaner
{
private final PagedFile pagedFile;
private final TreeNode<?,?> treeNode;
Expand All @@ -52,7 +52,7 @@ class CrashGenCleaner
private final Monitor monitor;
private final long internalMaxKeyCount;

CrashGenCleaner( PagedFile pagedFile, TreeNode<?,?> treeNode, long lowTreeNodeId, long highTreeNodeId,
CrashGenerationCleaner( PagedFile pagedFile, TreeNode<?,?> treeNode, long lowTreeNodeId, long highTreeNodeId,
long stableGeneration, long unstableGeneration, Monitor monitor )
{
this.pagedFile = pagedFile;
Expand Down
Expand Up @@ -864,7 +864,7 @@ public void finishRecovery() throws IOException
// and zero out all CRASH pointers.

long generation = this.generation;
new CrashGenCleaner( pagedFile, bTreeNode, IdSpace.MIN_TREE_NODE_ID,freeList.lastId() + 1,
new CrashGenerationCleaner( pagedFile, bTreeNode, IdSpace.MIN_TREE_NODE_ID,freeList.lastId() + 1,
stableGeneration( generation ), unstableGeneration( generation ), monitor ).clean();
}

Expand Down
Expand Up @@ -46,7 +46,7 @@
import static org.junit.Assert.assertEquals;
import static org.neo4j.test.rule.PageCacheRule.config;

public class CrashGenCleanerTest
public class CrashGenerationCleanerTest
{
private FileSystemRule fileSystemRule = new DefaultFileSystemRule();
private PageCacheRule pageCacheRule = new PageCacheRule();
Expand All @@ -62,25 +62,25 @@ public class CrashGenCleanerTest
private PagedFile pagedFile;
private final Layout<MutableLong,MutableLong> layout = new SimpleLongLayout();
private final CorruptableTreeNode corruptableTreeNode = new CorruptableTreeNode( PAGE_SIZE, layout );
private final int oldStableGen = 9;
private final int stableGen = 10;
private final int unstableGen = 12;
private final int crashGen = 11;
private final int oldStableGeneration = 9;
private final int stableGeneration = 10;
private final int unstableGeneration = 12;
private final int crashGeneration = 11;
private final int firstChildPos = 0;
private final int middleChildPos = corruptableTreeNode.internalMaxKeyCount() / 2;
private final int lastChildPos = corruptableTreeNode.internalMaxKeyCount();
private final List<PageCorruption> possibleCorruptionsInInternal = Arrays.asList(
crashed( leftSibling() ),
crashed( rightSibling() ),
crashed( newGen() ),
crashed( successor() ),
crashed( child( firstChildPos ) ),
crashed( child( middleChildPos ) ),
crashed( child( lastChildPos ) )
);
private final List<PageCorruption> possibleCorruptionsInLeaf = Arrays.asList(
crashed( leftSibling() ),
crashed( rightSibling() ),
crashed( newGen() )
crashed( successor() )
);

private class SimpleMonitor implements GBPTree.Monitor
Expand Down Expand Up @@ -123,7 +123,7 @@ public void shouldNotCrashOnEmptyFile() throws Exception

// WHEN
SimpleMonitor monitor = new SimpleMonitor();
crashGenCleaner( pagedFile, 0, pages.length, monitor ).clean();
crashGenerationCleaner( pagedFile, 0, pages.length, monitor ).clean();

// THEN
assertPagesVisisted( monitor, pages.length );
Expand All @@ -142,7 +142,7 @@ public void shouldNotReportErrorsOnCleanPages() throws Exception

// WHEN
SimpleMonitor monitor = new SimpleMonitor();
crashGenCleaner( pagedFile, 0, pages.length, monitor ).clean();
crashGenerationCleaner( pagedFile, 0, pages.length, monitor ).clean();

// THEN
assertPagesVisisted( monitor, 2 );
Expand All @@ -162,9 +162,9 @@ public void shouldCleanOneCrashPerPage() throws Exception
leafWith( crashed( rightSibling() ) ),
internalWith( crashed( rightSibling() ) ),

/* new gen */
leafWith( crashed( newGen() ) ),
internalWith( crashed( newGen() ) ),
/* successor */
leafWith( crashed( successor() ) ),
internalWith( crashed( successor() ) ),

/* child */
internalWith( crashed( child( firstChildPos ) ) ),
Expand All @@ -175,7 +175,7 @@ public void shouldCleanOneCrashPerPage() throws Exception

// WHEN
SimpleMonitor monitor = new SimpleMonitor();
crashGenCleaner( pagedFile, 0, pages.length, monitor ).clean();
crashGenerationCleaner( pagedFile, 0, pages.length, monitor ).clean();

// THEN
assertPagesVisisted( monitor, pages.length );
Expand All @@ -190,11 +190,11 @@ public void shouldCleanMultipleCrashPerPage() throws Exception
leafWith(
crashed( leftSibling() ),
crashed( rightSibling() ),
crashed( newGen() ) ),
crashed( successor() ) ),
internalWith(
crashed( leftSibling() ),
crashed( rightSibling() ),
crashed( newGen() ),
crashed( successor() ),
crashed( child( firstChildPos ) ),
crashed( child( middleChildPos ) ),
crashed( child( lastChildPos ) ) )
Expand All @@ -203,7 +203,7 @@ public void shouldCleanMultipleCrashPerPage() throws Exception

// WHEN
SimpleMonitor monitor = new SimpleMonitor();
crashGenCleaner( pagedFile, 0, pages.length, monitor ).clean();
crashGenerationCleaner( pagedFile, 0, pages.length, monitor ).clean();

// THEN
assertPagesVisisted( monitor, pages.length );
Expand All @@ -228,18 +228,18 @@ public void shouldCleanLargeFile() throws Exception

// WHEN
SimpleMonitor monitor = new SimpleMonitor();
crashGenCleaner( pagedFile, 0, numberOfPages, monitor ).clean();
crashGenerationCleaner( pagedFile, 0, numberOfPages, monitor ).clean();

// THEN
assertPagesVisisted( monitor, numberOfPages );
assertCleanedCrashPointers( monitor, totalNumberOfCorruptions.getValue() );
}

private CrashGenCleaner crashGenCleaner( PagedFile pagedFile, int lowTreeNodeId, int highTreeNodeId,
private CrashGenerationCleaner crashGenerationCleaner( PagedFile pagedFile, int lowTreeNodeId, int highTreeNodeId,
SimpleMonitor monitor )
{
return new CrashGenCleaner( pagedFile, corruptableTreeNode, lowTreeNodeId, highTreeNodeId,
stableGen, unstableGen, monitor );
return new CrashGenerationCleaner( pagedFile, corruptableTreeNode, lowTreeNodeId, highTreeNodeId,
stableGeneration, unstableGeneration, monitor );
}

private void initializeFile( PagedFile pagedFile, Page... pages ) throws IOException
Expand All @@ -249,7 +249,7 @@ private void initializeFile( PagedFile pagedFile, Page... pages ) throws IOExcep
for ( Page page : pages )
{
cursor.next();
page.write( cursor, corruptableTreeNode, stableGen, unstableGen, crashGen );
page.write( cursor, corruptableTreeNode, stableGeneration, unstableGeneration, crashGeneration );
}
}
}
Expand Down Expand Up @@ -333,12 +333,12 @@ private Page( PageType type, PageCorruption... pageCorruptions )
this.pageCorruptions = pageCorruptions;
}

private void write( PageCursor cursor, CorruptableTreeNode node, int stableGen, int unstableGen, int crashGen )
throws IOException
private void write( PageCursor cursor, CorruptableTreeNode node, int stableGeneration, int unstableGeneration,
int crashGeneration ) throws IOException
{
type.write( cursor, node, oldStableGen, stableGen );
type.write( cursor, node, oldStableGeneration, stableGeneration );
Arrays.stream( pageCorruptions )
.forEach( pc -> pc.corrupt( cursor, node, stableGen, unstableGen, crashGen ) );
.forEach( pc -> pc.corrupt( cursor, node, stableGeneration, unstableGeneration, crashGeneration ) );
}
}

Expand All @@ -347,32 +347,32 @@ enum PageType
LEAF
{
@Override
void write( PageCursor cursor, CorruptableTreeNode corruptableTreeNode, int stableGen,
int unstableGen )
void write( PageCursor cursor, CorruptableTreeNode corruptableTreeNode, int stableGeneration,
int unstableGeneration )
{
corruptableTreeNode.initializeLeaf( cursor, stableGen, unstableGen );
corruptableTreeNode.initializeLeaf( cursor, stableGeneration, unstableGeneration );
}
},
INTERNAL
{
@Override
void write( PageCursor cursor, CorruptableTreeNode corruptableTreeNode, int stableGen,
int unstableGen )
void write( PageCursor cursor, CorruptableTreeNode corruptableTreeNode, int stableGeneration,
int unstableGeneration )
{
corruptableTreeNode.initializeInternal( cursor, stableGen, unstableGen );
corruptableTreeNode.initializeInternal( cursor, stableGeneration, unstableGeneration );
int maxKeyCount = corruptableTreeNode.internalMaxKeyCount();
long base = IdSpace.MIN_TREE_NODE_ID;
for ( int i = 0; i <= maxKeyCount; i++ )
{
long child = base + i;
corruptableTreeNode.setChildAt( cursor, child, i, stableGen, unstableGen );
corruptableTreeNode.setChildAt( cursor, child, i, stableGeneration, unstableGeneration );
}
corruptableTreeNode.setKeyCount( cursor, maxKeyCount );
}
};

abstract void write( PageCursor cursor, CorruptableTreeNode corruptableTreeNode,
int stableGen, int unstableGen );
int stableGeneration, int unstableGeneration );
}

/* GSPPType */
Expand All @@ -386,9 +386,9 @@ private GSPPType rightSibling()
return SimpleGSPPType.RIGHT_SIBLING;
}

private GSPPType newGen()
private GSPPType successor()
{
return SimpleGSPPType.NEW_GEN;
return SimpleGSPPType.SUCCESSOR;
}

private GSPPType child( int pos )
Expand Down Expand Up @@ -419,7 +419,7 @@ public int offset( TreeNode node )
return TreeNode.BYTE_POS_RIGHTSIBLING;
}
},
NEW_GEN
SUCCESSOR
{
@Override
public int offset( TreeNode node )
Expand All @@ -437,14 +437,14 @@ private GSPPType childGSPPType( int pos )
/* PageCorruption */
private PageCorruption crashed( GSPPType gsppType )
{
return ( pageCursor, node, stableGen, unstableGen, crashGen ) ->
node.crashGSPP( pageCursor, gsppType.offset( node ), crashGen );
return ( pageCursor, node, stableGeneration, unstableGeneration, crashGeneration ) ->
node.crashGSPP( pageCursor, gsppType.offset( node ), crashGeneration );
}

private interface PageCorruption
{
void corrupt( PageCursor pageCursor, CorruptableTreeNode node, int stableGen,
int unstableGen, int crashGen );
void corrupt( PageCursor pageCursor, CorruptableTreeNode node, int stableGeneration,
int unstableGeneration, int crashGeneration );
}

class CorruptableTreeNode extends TreeNode<MutableLong,MutableLong>
Expand All @@ -454,10 +454,10 @@ class CorruptableTreeNode extends TreeNode<MutableLong,MutableLong>
super( pageSize, layout );
}

void crashGSPP( PageCursor pageCursor, int offset, int crashGen )
void crashGSPP( PageCursor pageCursor, int offset, int crashGeneration )
{
pageCursor.setOffset( offset );
GenerationSafePointerPair.write( pageCursor, 42, stableGen, crashGen );
GenerationSafePointerPair.write( pageCursor, 42, stableGeneration, crashGeneration );
}
}
}

0 comments on commit ded1f55

Please sign in to comment.