From f9402544f5e979d11413b01a9969a3e9086224be Mon Sep 17 00:00:00 2001 From: Olivia Ytterbrink Date: Mon, 26 Mar 2018 20:24:19 +0200 Subject: [PATCH] Don't share state between parts --- .../index/schema/SpatialIndexPopulator.java | 23 +++++----------- .../index/schema/TemporalIndexPopulator.java | 27 +++++++------------ 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java index 66efc500515f..af35d896fd57 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java @@ -22,7 +22,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.neo4j.gis.spatial.index.curves.SpaceFillingCurveConfiguration; import org.neo4j.io.fs.FileSystemAbstraction; @@ -78,14 +80,16 @@ public synchronized void drop() throws IOException @Override public void add( Collection> updates ) throws IOException, IndexEntryConflictException { + Map>> batchMap = new HashMap<>(); for ( IndexEntryUpdate update : updates ) { PointValue point = (PointValue) update.values()[0]; - select( point.getCoordinateReferenceSystem() ).batchUpdate( update ); + List> batch = batchMap.computeIfAbsent( point.getCoordinateReferenceSystem(), k -> new ArrayList<>() ); + batch.add( update ); } - for ( PartPopulator part : this ) + for ( Map.Entry>> entry : batchMap.entrySet() ) { - part.applyUpdateBatch(); + select( entry.getKey() ).add( entry.getValue() ); } } @@ -183,7 +187,6 @@ static class PartPopulator extends NativeSchemaIndexPopulator> updates = new ArrayList<>(); PartPopulator( PageCache pageCache, FileSystemAbstraction fs, SpatialIndexFiles.SpatialFileLayout fileLayout, IndexProvider.Monitor monitor, SchemaIndexDescriptor descriptor, long indexId, IndexSamplingConfig samplingConfig, @@ -194,18 +197,6 @@ static class PartPopulator extends NativeSchemaIndexPopulator update ) - { - updates.add( update ); - } - - void applyUpdateBatch() throws IOException, IndexEntryConflictException - { - List> batch = updates; - updates = new ArrayList<>(); - add( batch ); - } - @Override IndexReader newReader() { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java index 1402cd2e7d2d..445978afa1fe 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java @@ -22,7 +22,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.pagecache.PageCache; @@ -39,6 +42,7 @@ import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexSample; import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.ValueGroup; import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexBase.forAll; @@ -73,13 +77,16 @@ public synchronized void drop() throws IOException @Override public void add( Collection> updates ) throws IndexEntryConflictException, IOException { + Map>> batchMap = new HashMap<>(); for ( IndexEntryUpdate update : updates ) { - select( update.values()[0].valueGroup() ).batchUpdate( update ); + ValueGroup valueGroup = update.values()[0].valueGroup(); + List> batch = batchMap.computeIfAbsent( valueGroup, k -> new ArrayList<>() ); + batch.add( update ); } - for ( PartPopulator part : this ) + for ( Map.Entry>> entry : batchMap.entrySet() ) { - part.applyUpdateBatch(); + select( entry.getKey() ).add( entry.getValue() ); } } @@ -175,26 +182,12 @@ IndexSample sampleResult() static class PartPopulator extends NativeSchemaIndexPopulator { - List> updates = new ArrayList<>(); - PartPopulator( PageCache pageCache, FileSystemAbstraction fs, TemporalIndexFiles.FileLayout fileLayout, IndexProvider.Monitor monitor, SchemaIndexDescriptor descriptor, long indexId, IndexSamplingConfig samplingConfig ) { super( pageCache, fs, fileLayout.indexFile, fileLayout.layout, monitor, descriptor, indexId, samplingConfig ); } - void batchUpdate( IndexEntryUpdate update ) - { - updates.add( update ); - } - - void applyUpdateBatch() throws IOException, IndexEntryConflictException - { - List> batch = updates; - updates = new ArrayList<>(); - add( batch ); - } - @Override IndexReader newReader() {