Skip to content

Commit

Permalink
FusionSchemaIndexProvider handles native string index
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Mar 12, 2018
1 parent 251e9a8 commit c5c4372
Show file tree
Hide file tree
Showing 18 changed files with 770 additions and 1,423 deletions.
Expand Up @@ -195,7 +195,7 @@ public void shouldPerformExactLookupInCompositeIndex() throws Exception
PrimitiveLongSet uniqueIds = Primitive.longSet() )
{
// when
IndexValueCapability valueCapability = index.valueCapability( ValueGroup.TEXT );
IndexValueCapability valueCapability = index.valueCapability( ValueGroup.TEXT, ValueGroup.TEXT );
read.nodeIndexSeek( index, node, IndexOrder.NONE, IndexQuery.exact( firstName, "Joe" ),
IndexQuery.exact( surname, "Dalton" ) );

Expand Down
Expand Up @@ -46,9 +46,9 @@ public class StringIndexProvider extends NativeIndexProvider<StringSchemaKey,Nat
static final IndexCapability CAPABILITY = new StringIndexCapability();
private static final Descriptor STRING_PROVIDER_DESCRIPTOR = new Descriptor( KEY, "1.0" );

StringIndexProvider( PageCache pageCache, FileSystemAbstraction fs,
IndexDirectoryStructure.Factory directoryStructure, Monitor monitor, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector,
boolean readOnly )
public StringIndexProvider( PageCache pageCache, FileSystemAbstraction fs,
IndexDirectoryStructure.Factory directoryStructure, Monitor monitor, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector,
boolean readOnly )
{
super( STRING_PROVIDER_DESCRIPTOR, 0, directoryStructure, pageCache, fs, monitor, recoveryCleanupWorkCollector, readOnly );
}
Expand Down
Expand Up @@ -156,6 +156,7 @@ public void writeString( String value )
@Override
public void writeString( char value )
{
throw new UnsupportedOperationException( "Not supported a.t.m. should it be?" );
// TODO more efficient impl
writeString( String.valueOf( value ) );
}
}
Expand Up @@ -21,7 +21,10 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.helpers.collection.BoundedIterable;
Expand All @@ -37,22 +40,26 @@
import org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider.Selector;
import org.neo4j.storageengine.api.schema.IndexReader;

import static java.util.Arrays.asList;
import static org.neo4j.helpers.collection.Iterators.array;
import static org.neo4j.helpers.collection.Iterators.concatResourceIterators;
import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexUtils.forAll;

class FusionIndexAccessor implements IndexAccessor
{
private final IndexAccessor stringAccessor;
private final IndexAccessor numberAccessor;
private final IndexAccessor spatialAccessor;
private final IndexAccessor temporalAccessor;
private final IndexAccessor luceneAccessor;
private final IndexAccessor[] accessors;
private final Selector selector;
private final long indexId;
private final SchemaIndexDescriptor descriptor;
private final DropAction dropAction;

FusionIndexAccessor( IndexAccessor numberAccessor,
FusionIndexAccessor(
IndexAccessor stringAccessor,
IndexAccessor numberAccessor,
IndexAccessor spatialAccessor,
IndexAccessor temporalAccessor,
IndexAccessor luceneAccessor,
Expand All @@ -61,10 +68,12 @@ class FusionIndexAccessor implements IndexAccessor
SchemaIndexDescriptor descriptor,
DropAction dropAction )
{
this.stringAccessor = stringAccessor;
this.numberAccessor = numberAccessor;
this.spatialAccessor = spatialAccessor;
this.temporalAccessor = temporalAccessor;
this.luceneAccessor = luceneAccessor;
this.accessors = array( stringAccessor, numberAccessor, spatialAccessor, temporalAccessor, luceneAccessor );
this.selector = selector;
this.indexId = indexId;
this.descriptor = descriptor;
Expand All @@ -74,14 +83,15 @@ class FusionIndexAccessor implements IndexAccessor
@Override
public void drop() throws IOException
{
forAll( IndexAccessor::drop, numberAccessor, spatialAccessor, temporalAccessor, luceneAccessor );
forAll( IndexAccessor::drop, accessors );
dropAction.drop( indexId );
}

@Override
public IndexUpdater newUpdater( IndexUpdateMode mode )
{
return new FusionIndexUpdater(
stringAccessor.newUpdater( mode ),
numberAccessor.newUpdater( mode ),
spatialAccessor.newUpdater( mode ),
temporalAccessor.newUpdater( mode ),
Expand All @@ -91,31 +101,26 @@ public IndexUpdater newUpdater( IndexUpdateMode mode )
@Override
public void force( IOLimiter ioLimiter ) throws IOException
{
numberAccessor.force( ioLimiter );
spatialAccessor.force( ioLimiter );
temporalAccessor.force( ioLimiter );
luceneAccessor.force( ioLimiter );
forAll( accessor -> accessor.force( ioLimiter ), accessors );
}

@Override
public void refresh() throws IOException
{
numberAccessor.refresh();
spatialAccessor.refresh();
temporalAccessor.refresh();
luceneAccessor.refresh();
forAll( IndexAccessor::refresh, accessors );
}

@Override
public void close() throws IOException
{
forAll( IndexAccessor::close, numberAccessor, spatialAccessor, temporalAccessor, luceneAccessor );
forAll( IndexAccessor::close, accessors );
}

@Override
public IndexReader newReader()
{
return new FusionIndexReader(
stringAccessor.newReader(),
numberAccessor.newReader(),
spatialAccessor.newReader(),
temporalAccessor.newReader(),
Expand All @@ -127,6 +132,7 @@ public IndexReader newReader()
@Override
public BoundedIterable<Long> newAllEntriesReader()
{
BoundedIterable<Long> stringAllEntries = stringAccessor.newAllEntriesReader();
BoundedIterable<Long> numberAllEntries = numberAccessor.newAllEntriesReader();
BoundedIterable<Long> spatialAllEntries = spatialAccessor.newAllEntriesReader();
BoundedIterable<Long> temporalAllEntries = temporalAccessor.newAllEntriesReader();
Expand All @@ -136,12 +142,13 @@ public BoundedIterable<Long> newAllEntriesReader()
@Override
public long maxCount()
{
long stringMaxCount = stringAllEntries.maxCount();
long numberMaxCount = numberAllEntries.maxCount();
long spatialMaxCount = spatialAllEntries.maxCount();
long temporalMaxCount = temporalAllEntries.maxCount();
long luceneMaxCount = luceneAllEntries.maxCount();
return existsUnknownMaxCount( numberMaxCount, spatialMaxCount, temporalMaxCount, luceneMaxCount ) ?
UNKNOWN_MAX_COUNT : numberMaxCount + spatialMaxCount + temporalMaxCount + luceneMaxCount;
return existsUnknownMaxCount( stringMaxCount, numberMaxCount, spatialMaxCount, temporalMaxCount, luceneMaxCount ) ?
UNKNOWN_MAX_COUNT : stringMaxCount + numberMaxCount + spatialMaxCount + temporalMaxCount + luceneMaxCount;
}

private boolean existsUnknownMaxCount( long... maxCounts )
Expand All @@ -160,40 +167,41 @@ private boolean existsUnknownMaxCount( long... maxCounts )
@Override
public void close() throws Exception
{
forAll( BoundedIterable::close, numberAllEntries, spatialAllEntries, temporalAllEntries, luceneAllEntries );
forAll( BoundedIterable::close, stringAllEntries, numberAllEntries, spatialAllEntries, temporalAllEntries, luceneAllEntries );
}

@Override
public Iterator<Long> iterator()
{
return Iterables.concat( numberAllEntries, spatialAllEntries, temporalAllEntries, luceneAllEntries ).iterator();
return Iterables.concat( stringAllEntries, numberAllEntries, spatialAllEntries, temporalAllEntries, luceneAllEntries ).iterator();
}
};
}

@Override
public ResourceIterator<File> snapshotFiles() throws IOException
{
return concatResourceIterators(
asList( numberAccessor.snapshotFiles(),
spatialAccessor.snapshotFiles(),
temporalAccessor.snapshotFiles(),
luceneAccessor.snapshotFiles() ).iterator() );
List<ResourceIterator<File>> snapshots = new ArrayList<>();
for ( IndexAccessor accessor : accessors )
{
snapshots.add( accessor.snapshotFiles() );
}
return concatResourceIterators( snapshots.iterator() );
}

@Override
public void verifyDeferredConstraints( PropertyAccessor propertyAccessor )
throws IndexEntryConflictException, IOException
{
numberAccessor.verifyDeferredConstraints( propertyAccessor );
spatialAccessor.verifyDeferredConstraints( propertyAccessor );
temporalAccessor.verifyDeferredConstraints( propertyAccessor );
luceneAccessor.verifyDeferredConstraints( propertyAccessor );
for ( IndexAccessor accessor : accessors )
{
accessor.verifyDeferredConstraints( propertyAccessor );
}
}

@Override
public boolean isDirty()
{
return numberAccessor.isDirty() || spatialAccessor.isDirty() || temporalAccessor.isDirty() || luceneAccessor.isDirty();
return Arrays.stream( accessors ).anyMatch( IndexAccessor::isDirty );
}
}
Expand Up @@ -32,26 +32,31 @@
import org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider.Selector;
import org.neo4j.storageengine.api.schema.IndexSample;

import static org.neo4j.helpers.collection.Iterators.array;
import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexUtils.combineSamples;
import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexUtils.forAll;
import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider.combineSamples;

class FusionIndexPopulator implements IndexPopulator
{
private final IndexPopulator stringPopulator;
private final IndexPopulator numberPopulator;
private final IndexPopulator spatialPopulator;
private final IndexPopulator temporalPopulator;
private final IndexPopulator lucenePopulator;
private final IndexPopulator[] populators;
private final Selector selector;
private final long indexId;
private final DropAction dropAction;

FusionIndexPopulator( IndexPopulator numberPopulator, IndexPopulator spatialPopulator, IndexPopulator temporalPopulator,
FusionIndexPopulator( IndexPopulator stringPopulator, IndexPopulator numberPopulator, IndexPopulator spatialPopulator, IndexPopulator temporalPopulator,
IndexPopulator lucenePopulator, Selector selector, long indexId, DropAction dropAction )
{
this.stringPopulator = stringPopulator;
this.numberPopulator = numberPopulator;
this.spatialPopulator = spatialPopulator;
this.temporalPopulator = temporalPopulator;
this.lucenePopulator = lucenePopulator;
this.populators = array( stringPopulator, numberPopulator, spatialPopulator, temporalPopulator, lucenePopulator );
this.selector = selector;
this.indexId = indexId;
this.dropAction = dropAction;
Expand All @@ -60,50 +65,50 @@ class FusionIndexPopulator implements IndexPopulator
@Override
public void create() throws IOException
{
numberPopulator.create();
spatialPopulator.create();
temporalPopulator.create();
lucenePopulator.create();
FusionIndexUtils.forAll( IndexPopulator::create, populators );
}

@Override
public void drop() throws IOException
{
forAll( IndexPopulator::drop, numberPopulator, spatialPopulator, temporalPopulator, lucenePopulator );
forAll( IndexPopulator::drop, populators );
dropAction.drop( indexId );
}

@Override
public void add( Collection<? extends IndexEntryUpdate<?>> updates ) throws IndexEntryConflictException, IOException
{
Collection<IndexEntryUpdate<?>> luceneBatch = new ArrayList<>();
Collection<IndexEntryUpdate<?>> stringBatch = new ArrayList<>();
Collection<IndexEntryUpdate<?>> numberBatch = new ArrayList<>();
Collection<IndexEntryUpdate<?>> spatialBatch = new ArrayList<>();
Collection<IndexEntryUpdate<?>> temporalBatch = new ArrayList<>();
Collection<IndexEntryUpdate<?>> numberBatch = new ArrayList<>();
Collection<IndexEntryUpdate<?>> luceneBatch = new ArrayList<>();
for ( IndexEntryUpdate<?> update : updates )
{
selector.select( numberBatch, spatialBatch, temporalBatch, luceneBatch, update.values() ).add( update );
selector.select( stringBatch, numberBatch, spatialBatch, temporalBatch, luceneBatch, update.values() ).add( update );
}
lucenePopulator.add( luceneBatch );
stringPopulator.add( stringBatch );
numberPopulator.add( numberBatch );
spatialPopulator.add( spatialBatch );
temporalPopulator.add( temporalBatch );
numberPopulator.add( numberBatch );
lucenePopulator.add( luceneBatch );
}

@Override
public void verifyDeferredConstraints( PropertyAccessor propertyAccessor )
throws IndexEntryConflictException, IOException
{
numberPopulator.verifyDeferredConstraints( propertyAccessor );
spatialPopulator.verifyDeferredConstraints( propertyAccessor );
temporalPopulator.verifyDeferredConstraints( propertyAccessor );
lucenePopulator.verifyDeferredConstraints( propertyAccessor );
for ( IndexPopulator populator : populators )
{
populator.verifyDeferredConstraints( propertyAccessor );
}
}

@Override
public IndexUpdater newPopulatingUpdater( PropertyAccessor accessor ) throws IOException
{
return new FusionIndexUpdater(
stringPopulator.newPopulatingUpdater( accessor ),
numberPopulator.newPopulatingUpdater( accessor ),
spatialPopulator.newPopulatingUpdater( accessor ),
temporalPopulator.newPopulatingUpdater( accessor ),
Expand All @@ -113,25 +118,26 @@ public IndexUpdater newPopulatingUpdater( PropertyAccessor accessor ) throws IOE
@Override
public void close( boolean populationCompletedSuccessfully ) throws IOException
{
forAll( populator -> populator.close( populationCompletedSuccessfully ), numberPopulator, spatialPopulator, temporalPopulator, lucenePopulator );
forAll( populator -> populator.close( populationCompletedSuccessfully ), populators );
}

@Override
public void markAsFailed( String failure ) throws IOException
{
forAll( populator -> populator.markAsFailed( failure ), numberPopulator, spatialPopulator, temporalPopulator, lucenePopulator );
forAll( populator -> populator.markAsFailed( failure ), populators );
}

@Override
public void includeSample( IndexEntryUpdate<?> update )
{
selector.select( numberPopulator, spatialPopulator, temporalPopulator, lucenePopulator, update.values() ).includeSample( update );
selector.select( stringPopulator, numberPopulator, spatialPopulator, temporalPopulator, lucenePopulator, update.values() ).includeSample( update );
}

@Override
public IndexSample sampleResult()
{
return combineSamples(
stringPopulator.sampleResult(),
numberPopulator.sampleResult(),
spatialPopulator.sampleResult(),
temporalPopulator.sampleResult(),
Expand Down

0 comments on commit c5c4372

Please sign in to comment.