Skip to content

Commit

Permalink
NativeSchemaKey is generic
Browse files Browse the repository at this point in the history
  • Loading branch information
klaren committed Mar 21, 2018
1 parent 95c5f59 commit 17af4bf
Show file tree
Hide file tree
Showing 30 changed files with 66 additions and 69 deletions.
Expand Up @@ -34,7 +34,7 @@
*
* @param <VALUE> type of values being merged.
*/
class ConflictDetectingValueMerger<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> implements ValueMerger<KEY,VALUE>
class ConflictDetectingValueMerger<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> implements ValueMerger<KEY,VALUE>
{
private final boolean compareEntityIds;

Expand Down
Expand Up @@ -27,7 +27,7 @@
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.values.storable.Value;

class FilteringNativeHitIndexProgressor<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> extends NativeHitIndexProgressor<KEY,VALUE>
class FilteringNativeHitIndexProgressor<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> extends NativeHitIndexProgressor<KEY,VALUE>
{
private final IndexQuery[] filter;

Expand Down
Expand Up @@ -27,7 +27,7 @@
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.values.storable.Value;

class FilteringNativeHitIterator<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> extends NativeHitIterator<KEY,VALUE>
class FilteringNativeHitIterator<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> extends NativeHitIterator<KEY,VALUE>
{
private final IndexQuery[] filters;

Expand Down
Expand Up @@ -37,7 +37,7 @@
* @param <KEY> type of keys in tree.
* @param <VALUE> type of values in tree.
*/
class FullScanNonUniqueIndexSampler<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
class FullScanNonUniqueIndexSampler<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
extends NonUniqueIndexSampler.Adapter
{
private final GBPTree<KEY,VALUE> gbpTree;
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.neo4j.index.internal.gbptree.Hit;
import org.neo4j.index.internal.gbptree.Layout;

public class NativeAllEntriesReader<KEY extends NativeSchemaKey,VALUE extends NativeSchemaValue> implements BoundedIterable<Long>
public class NativeAllEntriesReader<KEY extends NativeSchemaKey<KEY>,VALUE extends NativeSchemaValue> implements BoundedIterable<Long>
{
private final GBPTree<KEY,VALUE> tree;
private final Layout<KEY,VALUE> layout;
Expand Down
Expand Up @@ -28,7 +28,7 @@
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.values.storable.Value;

public class NativeHitIndexProgressor<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> implements IndexProgressor
public class NativeHitIndexProgressor<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> implements IndexProgressor
{
final RawCursor<Hit<KEY,VALUE>,IOException> seeker;
final NodeValueClient client;
Expand Down
Expand Up @@ -36,7 +36,7 @@
* @param <KEY> type of {@link NumberSchemaKey}.
* @param <VALUE> type of {@link NativeSchemaValue}.
*/
public class NativeHitIterator<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
public class NativeHitIterator<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
extends PrimitiveLongCollections.PrimitiveLongBaseIterator
implements PrimitiveLongResourceIterator
{
Expand Down
Expand Up @@ -43,7 +43,7 @@
* @param <KEY> type of {@link NativeSchemaKey}
* @param <VALUE> type of {@link NativeSchemaValue}
*/
abstract class NativeIndexProvider<KEY extends NativeSchemaKey,VALUE extends NativeSchemaValue> extends IndexProvider
abstract class NativeIndexProvider<KEY extends NativeSchemaKey<KEY>,VALUE extends NativeSchemaValue> extends IndexProvider
{
protected final PageCache pageCache;
protected final FileSystemAbstraction fs;
Expand Down
Expand Up @@ -38,7 +38,7 @@
import static org.neo4j.helpers.collection.MapUtil.map;
import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_READER;

class NativeSchemaIndex<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
class NativeSchemaIndex<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
{
final PageCache pageCache;
final File storeFile;
Expand Down
Expand Up @@ -31,8 +31,8 @@
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.index.IndexAccessor;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;
import org.neo4j.kernel.impl.api.index.IndexUpdateMode;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
Expand All @@ -42,7 +42,7 @@
import static org.neo4j.helpers.collection.Iterators.iterator;
import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_WRITER;

public abstract class NativeSchemaIndexAccessor<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
public abstract class NativeSchemaIndexAccessor<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
extends NativeSchemaIndex<KEY,VALUE> implements IndexAccessor
{
private final NativeSchemaIndexUpdater<KEY,VALUE> singleUpdater;
Expand Down
Expand Up @@ -38,9 +38,9 @@
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;
import org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
Expand All @@ -59,7 +59,7 @@
* @param <KEY> type of {@link NativeSchemaKey}.
* @param <VALUE> type of {@link NativeSchemaValue}.
*/
abstract class NativeSchemaIndexPopulator<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
abstract class NativeSchemaIndexPopulator<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
extends NativeSchemaIndex<KEY,VALUE> implements IndexPopulator
{
static final byte BYTE_FAILED = 0;
Expand Down Expand Up @@ -297,7 +297,7 @@ private void markTreeAsOnline() throws IOException
tree.checkpoint( IOLimiter.unlimited(), pc -> pc.putByte( BYTE_ONLINE ) );
}

static class IndexUpdateApply<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
static class IndexUpdateApply<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
{
private final GBPTree<KEY,VALUE> tree;
private final KEY treeKey;
Expand All @@ -324,7 +324,7 @@ void process( Iterable<? extends IndexEntryUpdate<?>> indexEntryUpdates ) throws
}
}

static class IndexUpdateWork<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
static class IndexUpdateWork<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
implements Work<IndexUpdateApply<KEY,VALUE>,IndexUpdateWork<KEY,VALUE>>
{
private final Collection<? extends IndexEntryUpdate<?>> updates;
Expand All @@ -335,7 +335,7 @@ static class IndexUpdateWork<KEY extends NativeSchemaKey, VALUE extends NativeSc
}

@Override
public IndexUpdateWork<KEY,VALUE> combine( IndexUpdateWork work )
public IndexUpdateWork<KEY,VALUE> combine( IndexUpdateWork<KEY,VALUE> work )
{
ArrayList<IndexEntryUpdate<?>> combined = new ArrayList<>( updates );
combined.addAll( work.updates );
Expand Down
Expand Up @@ -40,7 +40,7 @@
import org.neo4j.storageengine.api.schema.IndexSampler;
import org.neo4j.values.storable.Value;

abstract class NativeSchemaIndexReader<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
abstract class NativeSchemaIndexReader<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
implements IndexReader
{
private final GBPTree<KEY,VALUE> tree;
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexUpdater;

class NativeSchemaIndexUpdater<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
class NativeSchemaIndexUpdater<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue>
implements IndexUpdater
{
private final KEY treeKey;
Expand Down Expand Up @@ -76,7 +76,7 @@ private void assertOpen()
}
}

static <KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> void processUpdate( KEY treeKey, VALUE treeValue,
static <KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> void processUpdate( KEY treeKey, VALUE treeValue,
IndexEntryUpdate<?> update, Writer<KEY,VALUE> writer, ConflictDetectingValueMerger<KEY,VALUE> conflictDetectingValueMerger )
throws IOException, IndexEntryConflictException
{
Expand All @@ -96,7 +96,7 @@ static <KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> void proce
}
}

private static <KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> void processRemove( KEY treeKey,
private static <KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> void processRemove( KEY treeKey,
IndexEntryUpdate<?> update, Writer<KEY,VALUE> writer ) throws IOException
{
// todo Do we need to verify that we actually removed something at all?
Expand All @@ -105,7 +105,7 @@ private static <KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> vo
writer.remove( treeKey );
}

private static <KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> void processChange( KEY treeKey, VALUE treeValue,
private static <KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> void processChange( KEY treeKey, VALUE treeValue,
IndexEntryUpdate<?> update, Writer<KEY,VALUE> writer,
ConflictDetectingValueMerger<KEY,VALUE> conflictDetectingValueMerger )
throws IOException, IndexEntryConflictException
Expand All @@ -121,7 +121,7 @@ private static <KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> vo
conflictDetectingValueMerger.checkConflict( update.values() );
}

static <KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> void processAdd( KEY treeKey, VALUE treeValue,
static <KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> void processAdd( KEY treeKey, VALUE treeValue,
IndexEntryUpdate<?> update, Writer<KEY,VALUE> writer,
ConflictDetectingValueMerger<KEY,VALUE> conflictDetectingValueMerger )
throws IOException, IndexEntryConflictException
Expand Down
Expand Up @@ -28,7 +28,7 @@
* This is the abstraction of what NativeSchemaIndex with friends need from a schema key.
* Note that it says nothing about how keys are compared, serialized, read, written, etc. That is the job of Layout.
*/
abstract class NativeSchemaKey<SELF extends NativeSchemaKey> extends ValueWriter.Adapter<RuntimeException>
abstract class NativeSchemaKey<SELF extends NativeSchemaKey<SELF>> extends ValueWriter.Adapter<RuntimeException>
{
static final boolean DEFAULT_COMPARE_ID = true;

Expand Down
Expand Up @@ -30,9 +30,9 @@
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

class NumberSchemaIndexReader<KEY extends NumberSchemaKey, VALUE extends NativeSchemaValue> extends NativeSchemaIndexReader<KEY,VALUE>
class NumberSchemaIndexReader<VALUE extends NativeSchemaValue> extends NativeSchemaIndexReader<NumberSchemaKey,VALUE>
{
NumberSchemaIndexReader( GBPTree<KEY,VALUE> tree, Layout<KEY,VALUE> layout, IndexSamplingConfig samplingConfig, SchemaIndexDescriptor descriptor )
NumberSchemaIndexReader( GBPTree<NumberSchemaKey,VALUE> tree, Layout<NumberSchemaKey,VALUE> layout, IndexSamplingConfig samplingConfig, SchemaIndexDescriptor descriptor )
{
super( tree, layout, samplingConfig, descriptor );
}
Expand All @@ -49,7 +49,7 @@ void validateQuery( IndexOrder indexOrder, IndexQuery[] predicates )
}

@Override
boolean initializeRangeForQuery( KEY treeKeyFrom, KEY treeKeyTo, IndexQuery[] predicates )
boolean initializeRangeForQuery( NumberSchemaKey treeKeyFrom, NumberSchemaKey treeKeyTo, IndexQuery[] predicates )
{
IndexQuery predicate = predicates[0];
switch ( predicate.type() )
Expand All @@ -74,7 +74,7 @@ boolean initializeRangeForQuery( KEY treeKeyFrom, KEY treeKeyTo, IndexQuery[] pr
return false;
}

private void initToForRange( RangePredicate rangePredicate, KEY treeKeyTo )
private void initToForRange( RangePredicate rangePredicate, NumberSchemaKey treeKeyTo )
{
Value toValue = rangePredicate.toValue();
if ( toValue == Values.NO_VALUE )
Expand All @@ -88,7 +88,7 @@ private void initToForRange( RangePredicate rangePredicate, KEY treeKeyTo )
}
}

private void initFromForRange( RangePredicate rangePredicate, KEY treeKeyFrom )
private void initFromForRange( RangePredicate rangePredicate, NumberSchemaKey treeKeyFrom )
{
Value fromValue = rangePredicate.fromValue();
if ( fromValue == Values.NO_VALUE )
Expand Down
Expand Up @@ -22,7 +22,7 @@
import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.io.pagecache.PageCursor;

abstract class SchemaLayout<KEY extends NativeSchemaKey> extends Layout.Adapter<KEY,NativeSchemaValue>
abstract class SchemaLayout<KEY extends NativeSchemaKey<KEY>> extends Layout.Adapter<KEY,NativeSchemaValue>
{
private final long identifier;
private final int majorVersion;
Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.neo4j.index.internal.gbptree.Hit;
import org.neo4j.values.storable.Value;

class SpatialHitIndexProgressor<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> extends NativeHitIndexProgressor<KEY, VALUE>
class SpatialHitIndexProgressor<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> extends NativeHitIndexProgressor<KEY, VALUE>
{
SpatialHitIndexProgressor( RawCursor<Hit<KEY,VALUE>,IOException> seeker, NodeValueClient client,
Collection<RawCursor<Hit<KEY,VALUE>,IOException>> toRemoveFromOnClose )
Expand Down
Expand Up @@ -204,7 +204,7 @@ static class PartAccessor extends NativeSchemaIndexAccessor<SpatialSchemaKey, Na
}

@Override
public SpatialIndexPartReader<SpatialSchemaKey,NativeSchemaValue> newReader()
public SpatialIndexPartReader<NativeSchemaValue> newReader()
{
return new SpatialIndexPartReader<>( tree, layout, samplingConfig, descriptor, searchConfiguration );
}
Expand Down
Expand Up @@ -44,12 +44,12 @@

import static java.lang.String.format;

public class SpatialIndexPartReader<KEY extends SpatialSchemaKey, VALUE extends NativeSchemaValue> extends NativeSchemaIndexReader<KEY,VALUE>
public class SpatialIndexPartReader<VALUE extends NativeSchemaValue> extends NativeSchemaIndexReader<SpatialSchemaKey,VALUE>
{
private final SpatialLayout spatial;
private final SpaceFillingCurveConfiguration configuration;

SpatialIndexPartReader( GBPTree<KEY,VALUE> tree, Layout<KEY,VALUE> layout, IndexSamplingConfig samplingConfig, SchemaIndexDescriptor descriptor,
SpatialIndexPartReader( GBPTree<SpatialSchemaKey,VALUE> tree, Layout<SpatialSchemaKey,VALUE> layout, IndexSamplingConfig samplingConfig, SchemaIndexDescriptor descriptor,
SpaceFillingCurveConfiguration configuration )
{
super( tree, layout, samplingConfig, descriptor );
Expand All @@ -74,7 +74,7 @@ void validateQuery( IndexOrder indexOrder, IndexQuery[] predicates )
}

@Override
boolean initializeRangeForQuery( KEY treeKeyFrom, KEY treeKeyTo, IndexQuery[] predicates )
boolean initializeRangeForQuery( SpatialSchemaKey treeKeyFrom, SpatialSchemaKey treeKeyTo, IndexQuery[] predicates )
{
throw new UnsupportedOperationException( "Cannot initialize 1D range in multidimensional spatial index reader" );
}
Expand Down Expand Up @@ -116,17 +116,17 @@ public void query( IndexProgressor.NodeValueClient cursor, IndexOrder indexOrder

private void startSeekForExists( IndexProgressor.NodeValueClient client, IndexQuery... predicates )
{
KEY treeKeyFrom = layout.newKey();
KEY treeKeyTo = layout.newKey();
SpatialSchemaKey treeKeyFrom = layout.newKey();
SpatialSchemaKey treeKeyTo = layout.newKey();
treeKeyFrom.initAsLowest();
treeKeyTo.initAsHighest();
startSeekForInitializedRange( client, treeKeyFrom, treeKeyTo, predicates, false );
}

private void startSeekForExact( IndexProgressor.NodeValueClient client, Value value, IndexQuery... predicates )
{
KEY treeKeyFrom = layout.newKey();
KEY treeKeyTo = layout.newKey();
SpatialSchemaKey treeKeyFrom = layout.newKey();
SpatialSchemaKey treeKeyTo = layout.newKey();
treeKeyFrom.from( Long.MIN_VALUE, value );
treeKeyTo.from( Long.MAX_VALUE, value );
startSeekForInitializedRange( client, treeKeyFrom, treeKeyTo, predicates, false );
Expand All @@ -146,11 +146,11 @@ private void startSeekForRange( IndexProgressor.NodeValueClient client, Geometry
List<SpaceFillingCurve.LongRange> ranges = curve.getTilesIntersectingEnvelope( envelope, configuration );
for ( SpaceFillingCurve.LongRange range : ranges )
{
KEY treeKeyFrom = layout.newKey();
KEY treeKeyTo = layout.newKey();
SpatialSchemaKey treeKeyFrom = layout.newKey();
SpatialSchemaKey treeKeyTo = layout.newKey();
treeKeyFrom.fromDerivedValue( Long.MIN_VALUE, range.min );
treeKeyTo.fromDerivedValue( Long.MAX_VALUE, range.max + 1 );
RawCursor<Hit<KEY,VALUE>,IOException> seeker = makeIndexSeeker( treeKeyFrom, treeKeyTo );
RawCursor<Hit<SpatialSchemaKey,VALUE>,IOException> seeker = makeIndexSeeker( treeKeyFrom, treeKeyTo );
IndexProgressor hitProgressor = new SpatialHitIndexProgressor<>( seeker, client, openSeekers );
multiProgressor.initialize( descriptor, hitProgressor, query );
}
Expand All @@ -167,7 +167,7 @@ private void startSeekForRange( IndexProgressor.NodeValueClient client, Geometry
}

@Override
void startSeekForInitializedRange( IndexProgressor.NodeValueClient client, KEY treeKeyFrom, KEY treeKeyTo, IndexQuery[] query, boolean needFilter )
void startSeekForInitializedRange( IndexProgressor.NodeValueClient client, SpatialSchemaKey treeKeyFrom, SpatialSchemaKey treeKeyTo, IndexQuery[] query, boolean needFilter )
{
if ( layout.compare( treeKeyFrom, treeKeyTo ) > 0 )
{
Expand All @@ -176,7 +176,7 @@ void startSeekForInitializedRange( IndexProgressor.NodeValueClient client, KEY t
}
try
{
RawCursor<Hit<KEY,VALUE>,IOException> seeker = makeIndexSeeker( treeKeyFrom, treeKeyTo );
RawCursor<Hit<SpatialSchemaKey,VALUE>,IOException> seeker = makeIndexSeeker( treeKeyFrom, treeKeyTo );
IndexProgressor hitProgressor = new SpatialHitIndexProgressor<>( seeker, client, openSeekers );
client.initialize( descriptor, hitProgressor, query );
}
Expand Down

0 comments on commit 17af4bf

Please sign in to comment.