Skip to content

Commit

Permalink
NativeLabelScanStore handles missing meta data page
Browse files Browse the repository at this point in the history
Also include some cleanup
  • Loading branch information
burqen committed Mar 14, 2018
1 parent b191eae commit 4d5ad10
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,11 @@ public void startupState( boolean clean )
* @param headerWriter writes header data if indexFile is created as a result of this call.
* @param recoveryCleanupWorkCollector collects recovery cleanup jobs for execution after recovery.
* @throws IOException on page cache error
* @throws MetadataMismatchException if meta information does not match constructor parameters or meta page is missing
*/
public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, int tentativePageSize,
Monitor monitor, Header.Reader headerReader, Consumer<PageCursor> headerWriter,
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws IOException
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws IOException, MetadataMismatchException
{
this.indexFile = indexFile;
this.monitor = monitor;
Expand Down Expand Up @@ -436,7 +437,7 @@ public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, i
// Create or load state
if ( created )
{
initializeAfterCreation( layout, headerWriter );
initializeAfterCreation( headerWriter );
}
else
{
Expand Down Expand Up @@ -467,7 +468,7 @@ public GBPTree( PageCache pageCache, File indexFile, Layout<KEY,VALUE> layout, i
}
}

private void initializeAfterCreation( Layout<KEY,VALUE> layout, Consumer<PageCursor> headerWriter ) throws IOException
private void initializeAfterCreation( Consumer<PageCursor> headerWriter ) throws IOException
{
// Initialize state
try ( PageCursor cursor = pagedFile.io( 0 /*ignored*/, PagedFile.PF_SHARED_WRITE_LOCK ) )
Expand All @@ -494,7 +495,7 @@ private void initializeAfterCreation( Layout<KEY,VALUE> layout, Consumer<PageCur
}

private PagedFile openOrCreate( PageCache pageCache, File indexFile,
int pageSizeForCreation ) throws IOException
int pageSizeForCreation ) throws IOException, MetadataMismatchException
{
try
{
Expand All @@ -506,7 +507,7 @@ private PagedFile openOrCreate( PageCache pageCache, File indexFile,
}
}

private static PagedFile openExistingIndexFile( PageCache pageCache, File indexFile ) throws IOException
private static PagedFile openExistingIndexFile( PageCache pageCache, File indexFile ) throws IOException, MetadataMismatchException
{
PagedFile pagedFile = pageCache.map( indexFile, pageCache.pageSize() );
// This index already exists, verify meta data aligns with expectations
Expand All @@ -522,7 +523,7 @@ private static PagedFile openExistingIndexFile( PageCache pageCache, File indexF
}
catch ( IllegalStateException e )
{
throw new IOException( "Index is not fully initialized since it's missing the meta page", e );
throw new MetadataMismatchException( "Index is not fully initialized since it's missing the meta page", e );
}
finally
{
Expand Down Expand Up @@ -583,8 +584,10 @@ private void loadState( PagedFile pagedFile, Header.Reader headerReader ) throws
* @param headerReader reads header data, previously written using {@link #checkpoint(IOLimiter, Consumer)}
* or {@link #close()}
* @throws IOException On page cache error
* @throws MetadataMismatchException if metadata does match given parameters
*/
public static void readHeader( PageCache pageCache, File indexFile, Layout<?,?> layout, Header.Reader headerReader ) throws IOException
public static void readHeader( PageCache pageCache, File indexFile, Layout<?,?> layout, Header.Reader headerReader )
throws IOException, MetadataMismatchException
{
try ( PagedFile pagedFile = openExistingIndexFile( pageCache, indexFile ) )
{
Expand Down Expand Up @@ -975,8 +978,6 @@ private void setRoot( long rootId, long rootGeneration )
* Bump unstable generation, increasing the gap between stable and unstable generation. All pointers and tree nodes
* with generation in this gap are considered to be 'crashed' and will be cleaned up by {@link CleanupJob}
* created in {@link #createCleanupJob(boolean)}.
*
* @throws IOException on {@link PageCache} error.
*/
private void bumpUnstableGeneration()
{
Expand All @@ -998,8 +999,6 @@ private void forceState() throws IOException

/**
* Called on start if tree was not clean.
*
* @throws IOException on {@link PageCache} error.
*/
private CleanupJob createCleanupJob( boolean needsCleaning )
{
Expand All @@ -1023,6 +1022,7 @@ private CleanupJob createCleanupJob( boolean needsCleaning )
}
}

@SuppressWarnings( "unused" )
void printTree() throws IOException
{
printTree( false, false, false, false );
Expand All @@ -1035,9 +1035,10 @@ void printTree() throws IOException
* @param printValues whether or not to print values in the leaf nodes.
* @param printPosition whether or not to print position for each key.
* @param printState whether or not to print the tree state.
* @param printHeader
* @param printHeader whether or not to print header of each tree node
* @throws IOException on I/O error.
*/
@SuppressWarnings( "SameParameterValue" )
void printTree( boolean printValues, boolean printPosition, boolean printState, boolean printHeader ) throws IOException
{
try ( PageCursor cursor = openRootCursor( PagedFile.PF_SHARED_READ_LOCK ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ public AllEntriesLabelScanReader allNodeLabelRanges()

/**
* @return store files, namely the single "neostore.labelscanstore.db" store file.
* @throws IOException on file access exceptions.
*/
@Override
public ResourceIterator<File> snapshotStoreFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,23 @@ public void shouldStartPopulationAgainIfNotCompletedFirstTime()
assertTrue( monitor.rebuiltCalled );
life.shutdown();
}

@Test
public void shouldRestartPopulationIfIndexFileWasNeverFullyInitialized() throws IOException
{
// given
File labelScanStoreFile = NativeLabelScanStore.getLabelScanStoreFile( dir );
fileSystemRule.create( labelScanStoreFile );
TrackingMonitor monitor = new TrackingMonitor();
LifeSupport life = new LifeSupport();

// when
life.add( createLabelScanStore( fileSystemRule.get(), dir, EMPTY, true, false, monitor ) );
life.start();

// then
assertTrue( monitor.corruptedIndex );
assertTrue( monitor.rebuildingCalled );
life.shutdown();
}
}

0 comments on commit 4d5ad10

Please sign in to comment.