Skip to content

Commit

Permalink
Fixed rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYtterbrink committed Feb 14, 2018
1 parent 729bcff commit fb4c1f1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 60 deletions.
Expand Up @@ -37,7 +37,6 @@
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
import org.neo4j.kernel.impl.index.schema.fusion.SpatialFusionSchemaIndexProvider;
import org.neo4j.values.storable.CoordinateReferenceSystem;
import org.neo4j.values.storable.Value;

Expand Down Expand Up @@ -121,17 +120,17 @@ public boolean indexExists()
return fs.fileExists( indexFile );
}

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

public InternalIndexState readState() throws IOException
public InternalIndexState readState( IndexDescriptor descriptor ) throws IOException
{
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader();
GBPTree.readHeader( pageCache, indexFile, new SpatialFusionSchemaIndexProvider.ReadOnlyMetaNumberLayout(), headerReader );
GBPTree.readHeader( pageCache, indexFile, layout( descriptor ), headerReader );
switch ( headerReader.state )
{
case BYTE_FAILED:
Expand All @@ -145,6 +144,23 @@ public InternalIndexState readState() throws IOException
}
}

private SpatialLayout layout( IndexDescriptor descriptor )
{
SpatialLayout layout;
switch ( descriptor.type() )
{
case GENERAL:
layout = new SpatialLayoutNonUnique( crs, curve );
break;
case UNIQUE:
layout = new SpatialLayoutUnique( crs, curve );
break;
default:
throw new UnsupportedOperationException( "Can not create index accessor of type " + descriptor.type() );
}
return layout;
}

private NativeSchemaIndexPopulator makeIndexPopulator( IndexDescriptor descriptor, IndexSamplingConfig samplingConfig )
{
switch ( descriptor.type() )
Expand Down Expand Up @@ -186,19 +202,8 @@ public void closePopulator( IndexDescriptor descriptor, IndexSamplingConfig samp

private SpatialSchemaIndexAccessor makeOnlineAccessor( IndexDescriptor descriptor, IndexSamplingConfig samplingConfig ) throws IOException
{
SpatialLayout layout;
switch ( descriptor.type() )
{
case GENERAL:
layout = new SpatialLayoutNonUnique( crs, curve );
break;
case UNIQUE:
layout = new SpatialLayoutUnique( crs, curve );
break;
default:
throw new UnsupportedOperationException( "Can not create index accessor of type " + descriptor.type() );
}
return new SpatialSchemaIndexAccessor<>( pageCache, fs, indexFile, layout, recoveryCleanupWorkCollector, monitor, descriptor, indexId, samplingConfig );
return new SpatialSchemaIndexAccessor<>( pageCache, fs, indexFile, layout( descriptor ),
recoveryCleanupWorkCollector, monitor, descriptor, indexId, samplingConfig );
}

public IndexAccessor getOnlineAccessor( IndexDescriptor descriptor, IndexSamplingConfig samplingConfig ) throws IOException
Expand Down
Expand Up @@ -67,13 +67,13 @@ public NativeSchemaValue newValue()
}

@Override
public int keySize()
public int keySize( SpatialSchemaKey key )
{
return SpatialSchemaKey.SIZE;
}

@Override
public int valueSize()
public int valueSize( NativeSchemaValue value )
{
return NativeSchemaValue.SIZE;
}
Expand All @@ -91,14 +91,20 @@ public void writeValue( PageCursor cursor, NativeSchemaValue value )
}

@Override
public void readKey( PageCursor cursor, SpatialSchemaKey into )
public void readKey( PageCursor cursor, SpatialSchemaKey into, int keySize )
{
into.rawValueBits = cursor.getLong();
into.setEntityId( cursor.getLong() );
}

@Override
public void readValue( PageCursor cursor, NativeSchemaValue into )
public void readValue( PageCursor cursor, NativeSchemaValue into, int valueSize )
{
}

@Override
public boolean fixedSize()
{
return true;
}
}
Expand Up @@ -101,7 +101,7 @@ public String getPopulationFailure( long indexId, IndexDescriptor descriptor ) t
String spatialFailure = null;
try
{
spatialFailure = spatialProvider.getPopulationFailure( indexId );
spatialFailure = spatialProvider.getPopulationFailure( indexId, descriptor );
}
catch ( IllegalStateException e )
{ // Just catch
Expand Down
Expand Up @@ -98,15 +98,15 @@ Map<CoordinateReferenceSystem,SpatialKnownIndex> indexesFor( long indexId )
}

@Override
public String getPopulationFailure( long indexId ) throws IllegalStateException
public String getPopulationFailure( long indexId, IndexDescriptor descriptor ) throws IllegalStateException
{
try
{
// This assumes a previous call to getInitialState returned that at least one index was failed
// We find the first failed index failure message
for ( SpatialKnownIndex index : indexesFor( indexId ).values() )
{
String indexFailure = index.readPopulationFailure();
String indexFailure = index.readPopulationFailure( descriptor );
if ( indexFailure != null )
{
return indexFailure;
Expand Down Expand Up @@ -136,7 +136,7 @@ public InternalIndexState getInitialState( long indexId, IndexDescriptor descrip
{
try
{
switch ( index.readState() )
switch ( index.readState( descriptor ) )
{
case FAILED:
return InternalIndexState.FAILED;
Expand Down Expand Up @@ -225,16 +225,4 @@ private void findAndCreateKnownSpatialIndexes()
}
}
}

public static class ReadOnlyMetaNumberLayout extends Layout.ReadOnlyMetaLayout
{
@Override
public boolean compatibleWith( long layoutIdentifier, int majorVersion, int minorVersion )
{
return (layoutIdentifier == SpatialLayoutUnique.IDENTIFIER && majorVersion == SpatialLayoutUnique.MAJOR_VERSION &&
minorVersion == SpatialLayoutUnique.MINOR_VERSION) ||
(layoutIdentifier == SpatialLayoutNonUnique.IDENTIFIER && majorVersion == SpatialLayoutNonUnique.MAJOR_VERSION &&
minorVersion == SpatialLayoutNonUnique.MINOR_VERSION);
}
}
}
Expand Up @@ -237,7 +237,7 @@ private void stringRangeQuery( IndexDescriptor descriptor, IndexQuery.StringRang
if ( read.hasTxStateWithChanges() )
{
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = read.txState().indexUpdatesForRangeSeekByString(
PrimitiveLongReadableDiffSets changes = txState.indexUpdatesForRangeSeekByString(
descriptor, predicate.from(), predicate.fromInclusive(), predicate.to(),
predicate.toInclusive() );
added = changes.augment( emptyIterator() );
Expand All @@ -251,7 +251,7 @@ private void numericRangeQuery( IndexDescriptor descriptor, IndexQuery.NumberRan
if ( read.hasTxStateWithChanges() )
{
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = read.txState().indexUpdatesForRangeSeekByNumber(
PrimitiveLongReadableDiffSets changes = txState.indexUpdatesForRangeSeekByNumber(
descriptor, predicate.from(), predicate.fromInclusive(), predicate.to(),
predicate.toInclusive() );
added = changes.augment( emptyIterator() );
Expand All @@ -263,10 +263,12 @@ private void geometricRangeQuery( IndexDescriptor descriptor, IndexQuery.Geometr
{
if ( read.hasTxStateWithChanges() )
{
changes = read.txState().indexUpdatesForRangeSeekByGeometry(
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = txState.indexUpdatesForRangeSeekByGeometry(
descriptor, predicate.from(), predicate.fromInclusive(), predicate.to(),
predicate.toInclusive() );
added = changes.augment( emptyIterator() );
removed = removed( txState, changes );
}
}

Expand All @@ -276,7 +278,7 @@ private void scanQuery( IndexDescriptor descriptor )
if ( read.hasTxStateWithChanges() )
{
TransactionState txState = read.txState();
PrimitiveLongReadableDiffSets changes = read.txState().indexUpdatesForScan( descriptor );
PrimitiveLongReadableDiffSets changes = txState.indexUpdatesForScan( descriptor );
added = changes.augment( emptyIterator() );
removed = removed( txState, changes );
}
Expand Down
Expand Up @@ -163,7 +163,7 @@ public void getPopulationFailureMustThrowIfNoFailure()
IllegalStateException spatialThrow = new IllegalStateException( "no spatial failure" );
IllegalStateException luceneThrow = new IllegalStateException( "no lucene failure" );
when( nativeProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( nativeThrow );
when( spatialProvider.getPopulationFailure( anyLong() ) ).thenThrow( spatialThrow );
when( spatialProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( spatialThrow );
when( luceneProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( luceneThrow );
// then
try
Expand All @@ -187,7 +187,7 @@ public void getPopulationFailureMustReportFailureWhenNativeFailure()
IllegalStateException spatialThrow = new IllegalStateException( "no spatial failure" );
IllegalStateException luceneThrow = new IllegalStateException( "no lucene failure" );
when( nativeProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( nativeFailure );
when( spatialProvider.getPopulationFailure( anyLong() ) ).thenThrow( spatialThrow );
when( spatialProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( spatialThrow );
when( luceneProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( luceneThrow );
// then
assertThat( fusionSchemaIndexProvider.getPopulationFailure( 0, forLabel( 0, 0 ) ), containsString( nativeFailure ) );
Expand All @@ -203,11 +203,11 @@ public void getPopulationFailureMustReportFailureWhenSpatialFailure() throws Exc
IllegalStateException nativeThrow = new IllegalStateException( "no native failure" );
String spatialFailure = "spatial failure";
IllegalStateException luceneThrow = new IllegalStateException( "no lucene failure" );
when( nativeProvider.getPopulationFailure( anyLong() ) ).thenThrow( nativeThrow );
when( spatialProvider.getPopulationFailure( anyLong() ) ).thenReturn( spatialFailure );
when( luceneProvider.getPopulationFailure( anyLong() ) ).thenThrow( luceneThrow );
when( nativeProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( nativeThrow );
when( spatialProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( spatialFailure );
when( luceneProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( luceneThrow );
// then
assertThat( fusionSchemaIndexProvider.getPopulationFailure( 0 ), containsString( spatialFailure ) );
assertThat( fusionSchemaIndexProvider.getPopulationFailure( 0, forLabel( 0, 0 ) ), containsString( spatialFailure ) );
}

@Test
Expand All @@ -221,7 +221,7 @@ public void getPopulationFailureMustReportFailureWhenLuceneFailure()
IllegalStateException spatialThrow = new IllegalStateException( "no spatial failure" );
String luceneFailure = "lucene failure";
when( nativeProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( nativeThrow );
when( spatialProvider.getPopulationFailure( anyLong() ) ).thenThrow( spatialThrow );
when( spatialProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( spatialThrow );
when( luceneProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( luceneFailure );
// then
assertThat( fusionSchemaIndexProvider.getPopulationFailure( 0, forLabel( 0, 0 ) ), containsString( luceneFailure ) );
Expand All @@ -237,11 +237,11 @@ public void getPopulationFailureMustReportFailureWhenBothNativeAndLuceneFail()
String nativeFailure = "native failure";
IllegalStateException spatialThrow = new IllegalStateException( "no spatial failure" );
String luceneFailure = "lucene failure";
when( nativeProvider.getPopulationFailure( anyLong() ) ).thenReturn( nativeFailure );
when( spatialProvider.getPopulationFailure( anyLong() ) ).thenThrow( spatialThrow );
when( luceneProvider.getPopulationFailure( anyLong() ) ).thenReturn( luceneFailure );
when( nativeProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( nativeFailure );
when( spatialProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenThrow( spatialThrow );
when( luceneProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( luceneFailure );
// then
String populationFailure = fusionSchemaIndexProvider.getPopulationFailure( 0 );
String populationFailure = fusionSchemaIndexProvider.getPopulationFailure( 0, forLabel( 0, 0 ) );
assertThat( populationFailure, containsString( nativeFailure ) );
assertThat( populationFailure, containsString( luceneFailure ) );
}
Expand All @@ -257,7 +257,7 @@ public void getPopulationFailureMustReportFailureWhenAllFail() throws Exception
String spatialFailure = "native failure";
String luceneFailure = "lucene failure";
when( nativeProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( nativeFailure );
when( spatialProvider.getPopulationFailure( anyLong() ) ).thenReturn( spatialFailure );
when( spatialProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( spatialFailure );
when( luceneProvider.getPopulationFailure( anyLong(), any( IndexDescriptor.class ) ) ).thenReturn( luceneFailure );
// then
String populationFailure = fusionSchemaIndexProvider.getPopulationFailure( 0, forLabel( 0, 0 ) );
Expand Down
Expand Up @@ -53,6 +53,7 @@ public class SpatialFusionSchemaIndexProviderTest

private Map<CoordinateReferenceSystem, SpatialKnownIndex> indexMap;
private SpatialFusionSchemaIndexProvider provider;
private IndexDescriptor descriptor = IndexDescriptorFactory.forLabel( 1, 1 );

@Before
public void setup()
Expand All @@ -72,8 +73,6 @@ public void setup()
@Test
public void shouldReportPopulatingIfAnyIsPopulating() throws Exception
{
IndexDescriptor indexDescriptor = IndexDescriptorFactory.forLabel( 1, 1 );

for ( InternalIndexState state : array( InternalIndexState.ONLINE, InternalIndexState.POPULATING ) )
{
// when
Expand All @@ -86,7 +85,7 @@ public void shouldReportPopulatingIfAnyIsPopulating() throws Exception
{
setInitialState( index, InternalIndexState.POPULATING );
// then
assertEquals( InternalIndexState.POPULATING, provider.getInitialState( 0, indexDescriptor ) );
assertEquals( InternalIndexState.POPULATING, provider.getInitialState( 0, descriptor ) );
setInitialState( index, state );
}
}
Expand All @@ -99,12 +98,12 @@ public void getPopulationFailureMustThrowIfNoFailure() throws Exception
// ... no failure
for ( SpatialKnownIndex index : indexMap.values() )
{
when( index.readPopulationFailure() ).thenReturn( null );
when( index.readPopulationFailure( descriptor ) ).thenReturn( null );
}
// then
try
{
provider.getPopulationFailure( 0 );
provider.getPopulationFailure( 0, descriptor );
fail( "Should have failed" );
}
catch ( IllegalStateException e )
Expand All @@ -129,6 +128,6 @@ public void mustSelectCorrectTargetForValues() throws Exception
private void setInitialState( SpatialKnownIndex mockedIndex, InternalIndexState state ) throws IOException
{
when( mockedIndex.indexExists() ).thenReturn( true );
when( mockedIndex.readState() ).thenReturn( state );
when( mockedIndex.readState( descriptor ) ).thenReturn( state );
}
}

0 comments on commit fb4c1f1

Please sign in to comment.