Skip to content

Commit

Permalink
Add helper methods for reading initial index state and failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYtterbrink authored and fickludd committed Mar 1, 2018
1 parent 478f20e commit ea8b033
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 38 deletions.
Expand Up @@ -105,7 +105,7 @@ public String getPopulationFailure( long indexId, IndexDescriptor descriptor ) t
{ {
try try
{ {
String failureMessage = readPopulationFailure( indexId, descriptor ); String failureMessage = NativeSchemaIndexes.readFailureMessage( pageCache, nativeIndexFileFromIndexId( indexId ), layout( descriptor ) );
if ( failureMessage == null ) if ( failureMessage == null )
{ {
throw new IllegalStateException( "Index " + indexId + " isn't failed" ); throw new IllegalStateException( "Index " + indexId + " isn't failed" );
Expand All @@ -123,19 +123,7 @@ public InternalIndexState getInitialState( long indexId, IndexDescriptor descrip
{ {
try try
{ {
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader(); return NativeSchemaIndexes.readState( pageCache, nativeIndexFileFromIndexId( indexId ), layout( descriptor ) );
GBPTree.readHeader( pageCache, nativeIndexFileFromIndexId( indexId ), layout( descriptor ), headerReader );
switch ( headerReader.state )
{
case BYTE_FAILED:
return InternalIndexState.FAILED;
case BYTE_ONLINE:
return InternalIndexState.ONLINE;
case BYTE_POPULATING:
return InternalIndexState.POPULATING;
default:
throw new IllegalStateException( "Unexpected initial state byte value " + headerReader.state );
}
} }
catch ( IOException e ) catch ( IOException e )
{ {
Expand All @@ -152,13 +140,6 @@ public StoreMigrationParticipant storeMigrationParticipant( FileSystemAbstractio
return StoreMigrationParticipant.NOT_PARTICIPATING; return StoreMigrationParticipant.NOT_PARTICIPATING;
} }


private String readPopulationFailure( long indexId, IndexDescriptor descriptor ) throws IOException
{
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader();
GBPTree.readHeader( pageCache, nativeIndexFileFromIndexId( indexId ), layout( descriptor ), headerReader );
return headerReader.failureMessage;
}

private Layout<KEY,VALUE> layout( IndexDescriptor descriptor ) private Layout<KEY,VALUE> layout( IndexDescriptor descriptor )
{ {
switch ( descriptor.type() ) switch ( descriptor.type() )
Expand Down
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.index.schema;

import java.io.File;
import java.io.IOException;

import org.neo4j.index.internal.gbptree.GBPTree;
import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.internal.kernel.api.InternalIndexState;
import org.neo4j.io.pagecache.PageCache;

import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_FAILED;
import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_ONLINE;
import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_POPULATING;

public class NativeSchemaIndexes
{
private NativeSchemaIndexes()
{}

public static InternalIndexState readState( PageCache pageCache, File indexFile, Layout<?,?> layout ) throws IOException
{
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader();
GBPTree.readHeader( pageCache, indexFile, layout, headerReader );
switch ( headerReader.state )
{
case BYTE_FAILED:
return InternalIndexState.FAILED;
case BYTE_ONLINE:
return InternalIndexState.ONLINE;
case BYTE_POPULATING:
return InternalIndexState.POPULATING;
default:
throw new IllegalStateException( "Unexpected initial state byte value " + headerReader.state );
}
}

public static String readFailureMessage( PageCache pageCache, File indexFile, Layout<?,?> layout )
throws IOException
{
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader();
GBPTree.readHeader( pageCache, indexFile, layout, headerReader );
return headerReader.failureMessage;
}
}
Expand Up @@ -57,7 +57,6 @@
import static org.neo4j.helpers.collection.Iterators.asResourceIterator; import static org.neo4j.helpers.collection.Iterators.asResourceIterator;
import static org.neo4j.helpers.collection.Iterators.iterator; import static org.neo4j.helpers.collection.Iterators.iterator;
import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_WRITER; import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_WRITER;
import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_FAILED;
import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_ONLINE; import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_ONLINE;
import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_POPULATING; import static org.neo4j.kernel.impl.index.schema.NativeSchemaIndexPopulator.BYTE_POPULATING;


Expand Down Expand Up @@ -329,26 +328,12 @@ public boolean indexExists()


public String readPopulationFailure( IndexDescriptor descriptor ) throws IOException public String readPopulationFailure( IndexDescriptor descriptor ) throws IOException
{ {
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader(); return NativeSchemaIndexes.readFailureMessage( pageCache, indexFile, layout( descriptor ) );
GBPTree.readHeader( pageCache, indexFile, layout( descriptor ), headerReader );
return headerReader.failureMessage;
} }


public InternalIndexState readState( IndexDescriptor descriptor ) throws IOException public InternalIndexState readState( IndexDescriptor descriptor ) throws IOException
{ {
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader(); return NativeSchemaIndexes.readState( pageCache, indexFile, layout( descriptor ) );
GBPTree.readHeader( pageCache, indexFile, layout( descriptor ), headerReader );
switch ( headerReader.state )
{
case BYTE_FAILED:
return InternalIndexState.FAILED;
case BYTE_ONLINE:
return InternalIndexState.ONLINE;
case BYTE_POPULATING:
return InternalIndexState.POPULATING;
default:
throw new IllegalStateException( "Unexpected initial state byte value " + headerReader.state );
}
} }


private synchronized void create() throws IOException private synchronized void create() throws IOException
Expand Down

0 comments on commit ea8b033

Please sign in to comment.