Skip to content

Commit

Permalink
Refactor native index
Browse files Browse the repository at this point in the history
Separate generic parts to prepare for String and Spatial indexing.
  • Loading branch information
OliviaYtterbrink authored and burqen committed Jan 11, 2018
1 parent 54c5ae8 commit 90757bb
Show file tree
Hide file tree
Showing 42 changed files with 694 additions and 442 deletions.
Expand Up @@ -30,7 +30,7 @@
*
* @param <VALUE> type of values being merged.
*/
class ConflictDetectingValueMerger<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue> implements ValueMerger<KEY,VALUE>
public class ConflictDetectingValueMerger<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> implements ValueMerger<KEY,VALUE>
{
private boolean conflict;
private long existingNodeId;
Expand All @@ -51,7 +51,7 @@ public VALUE merge( KEY existingKey, KEY newKey, VALUE existingValue, VALUE newV
/**
* @return whether or not merge conflicted with an existing key. This call also clears the conflict flag.
*/
boolean wasConflict()
public boolean wasConflict()
{
boolean result = conflict;
if ( conflict )
Expand All @@ -61,12 +61,12 @@ boolean wasConflict()
return result;
}

long existingNodeId()
public long existingNodeId()
{
return existingNodeId;
}

long addedNodeId()
public long addedNodeId()
{
return addedNodeId;
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ class FailureHeaderWriter implements Consumer<PageCursor>
public void accept( PageCursor cursor )
{
byte[] bytesToWrite = failureBytes;
cursor.putByte( NativeSchemaNumberIndexPopulator.BYTE_FAILED );
cursor.putByte( NativeSchemaIndexPopulator.BYTE_FAILED );
int availableSpace = cursor.getCurrentPageSize() - cursor.getOffset();
if ( bytesToWrite.length + HEADER_LENGTH_FIELD_LENGTH > availableSpace )
{
Expand Down
Expand Up @@ -37,14 +37,14 @@
* @param <KEY> type of keys in tree.
* @param <VALUE> type of values in tree.
*/
class FullScanNonUniqueIndexSampler<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue>
public class FullScanNonUniqueIndexSampler<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
extends NonUniqueIndexSampler.Adapter
{
private final GBPTree<KEY,VALUE> gbpTree;
private final Layout<KEY,VALUE> layout;
private final IndexSamplingConfig samplingConfig;

FullScanNonUniqueIndexSampler( GBPTree<KEY,VALUE> gbpTree, Layout<KEY,VALUE> layout,
public FullScanNonUniqueIndexSampler( GBPTree<KEY,VALUE> gbpTree, Layout<KEY,VALUE> layout,
IndexSamplingConfig samplingConfig )
{
this.gbpTree = gbpTree;
Expand Down
Expand Up @@ -30,13 +30,13 @@
import org.neo4j.index.internal.gbptree.Hit;
import org.neo4j.index.internal.gbptree.Layout;

public class NumberAllEntriesReader<KEY extends SchemaNumberKey,VALUE extends SchemaNumberValue> implements BoundedIterable<Long>
public class NativeAllEntriesReader<KEY extends NativeSchemaKey,VALUE extends NativeSchemaValue> implements BoundedIterable<Long>
{
private final GBPTree<KEY,VALUE> tree;
private final Layout<KEY,VALUE> layout;
private RawCursor<Hit<KEY,VALUE>,IOException> seeker;

NumberAllEntriesReader( GBPTree<KEY,VALUE> tree, Layout<KEY,VALUE> layout )
public NativeAllEntriesReader( GBPTree<KEY,VALUE> tree, Layout<KEY,VALUE> layout )
{
this.tree = tree;
this.layout = layout;
Expand Down
Expand Up @@ -27,14 +27,14 @@
import org.neo4j.index.internal.gbptree.Hit;
import org.neo4j.storageengine.api.schema.IndexProgressor;

public class NumberHitIndexProgressor<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue> implements IndexProgressor
public class NativeHitIndexProgressor<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> implements IndexProgressor
{
private final RawCursor<Hit<KEY,VALUE>,IOException> seeker;
private final NodeValueClient client;
private final Collection<RawCursor<Hit<KEY,VALUE>,IOException>> toRemoveFromOnClose;
private boolean closed;

NumberHitIndexProgressor( RawCursor<Hit<KEY,VALUE>,IOException> seeker, NodeValueClient client,
public NativeHitIndexProgressor( RawCursor<Hit<KEY,VALUE>,IOException> seeker, NodeValueClient client,
Collection<RawCursor<Hit<KEY,VALUE>,IOException>> toRemoveFromOnClose )
{
this.seeker = seeker;
Expand Down
Expand Up @@ -35,16 +35,16 @@
import org.neo4j.storageengine.api.schema.IndexSample;

/**
* {@link NativeSchemaNumberIndexPopulator} which can accept duplicate values (for different entity ids).
* {@link NativeSchemaIndexPopulator} which can accept duplicate values (for different entity ids).
*/
class NativeNonUniqueSchemaNumberIndexPopulator<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue>
extends NativeSchemaNumberIndexPopulator<KEY,VALUE>
public class NativeNonUniqueSchemaIndexPopulator<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
extends NativeSchemaIndexPopulator<KEY,VALUE>
{
private final IndexSamplingConfig samplingConfig;
private boolean updateSampling;
private NonUniqueIndexSampler sampler;

NativeNonUniqueSchemaNumberIndexPopulator( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout,
public NativeNonUniqueSchemaIndexPopulator( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout,
IndexSamplingConfig samplingConfig, SchemaIndexProvider.Monitor monitor, IndexDescriptor descriptor, long indexId )
{
super( pageCache, fs, storeFile, layout, monitor, descriptor, indexId );
Expand Down
Expand Up @@ -38,19 +38,19 @@
import static org.neo4j.helpers.collection.MapUtil.map;
import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_READER;

class NativeSchemaNumberIndex<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue>
public class NativeSchemaIndex<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
{
final PageCache pageCache;
final File storeFile;
final Layout<KEY,VALUE> layout;
final GBPTreeFileUtil gbpTreeFileUtil;
final IndexDescriptor descriptor;
protected final File storeFile;
protected final Layout<KEY,VALUE> layout;
protected final GBPTreeFileUtil gbpTreeFileUtil;
protected final IndexDescriptor descriptor;
private final long indexId;
private final SchemaIndexProvider.Monitor monitor;

GBPTree<KEY,VALUE> tree;
protected GBPTree<KEY,VALUE> tree;

NativeSchemaNumberIndex( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout,
public NativeSchemaIndex( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout,
SchemaIndexProvider.Monitor monitor, IndexDescriptor descriptor, long indexId )
{
this.pageCache = pageCache;
Expand All @@ -62,7 +62,7 @@ class NativeSchemaNumberIndex<KEY extends SchemaNumberKey, VALUE extends SchemaN
this.monitor = monitor;
}

void instantiateTree( RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, Consumer<PageCursor> headerWriter )
public void instantiateTree( RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, Consumer<PageCursor> headerWriter )
throws IOException
{
ensureDirectoryExist();
Expand Down Expand Up @@ -92,12 +92,12 @@ private void ensureDirectoryExist() throws IOException
gbpTreeFileUtil.mkdirs( storeFile.getParentFile() );
}

void closeTree() throws IOException
public void closeTree() throws IOException
{
tree = closeIfPresent( tree );
}

<T extends Closeable> T closeIfPresent( T closeable ) throws IOException
public <T extends Closeable> T closeIfPresent( T closeable ) throws IOException
{
if ( closeable != null )
{
Expand All @@ -106,7 +106,7 @@ <T extends Closeable> T closeIfPresent( T closeable ) throws IOException
return null;
}

void assertOpen()
public void assertOpen()
{
if ( tree == null )
{
Expand Down
Expand Up @@ -44,13 +44,13 @@
import static org.neo4j.helpers.collection.Iterators.iterator;
import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_WRITER;

public class NativeSchemaNumberIndexAccessor<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue>
extends NativeSchemaNumberIndex<KEY,VALUE> implements IndexAccessor
public abstract class NativeSchemaIndexAccessor<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
extends NativeSchemaIndex<KEY,VALUE> implements IndexAccessor
{
private final NativeSchemaNumberIndexUpdater<KEY,VALUE> singleUpdater;
private final IndexSamplingConfig samplingConfig;
private final NativeSchemaIndexUpdater<KEY,VALUE> singleUpdater;
protected final IndexSamplingConfig samplingConfig;

NativeSchemaNumberIndexAccessor(
NativeSchemaIndexAccessor(
PageCache pageCache,
FileSystemAbstraction fs,
File storeFile,
Expand All @@ -62,7 +62,7 @@ public class NativeSchemaNumberIndexAccessor<KEY extends SchemaNumberKey, VALUE
IndexSamplingConfig samplingConfig ) throws IOException
{
super( pageCache, fs, storeFile, layout, monitor, descriptor, indexId );
singleUpdater = new NativeSchemaNumberIndexUpdater<>( layout.newKey(), layout.newValue() );
singleUpdater = new NativeSchemaIndexUpdater<>( layout.newKey(), layout.newValue() );
this.samplingConfig = samplingConfig;
instantiateTree( recoveryCleanupWorkCollector, NO_HEADER_WRITER );
}
Expand Down Expand Up @@ -107,17 +107,12 @@ public void close() throws IOException
closeTree();
}

@Override
public IndexReader newReader()
{
assertOpen();
return new NativeSchemaNumberIndexReader<>( tree, layout, samplingConfig, descriptor );
}
public abstract IndexReader newReader();

@Override
public BoundedIterable<Long> newAllEntriesReader()
{
return new NumberAllEntriesReader<>( tree, layout );
return new NativeAllEntriesReader<>( tree, layout );
}

@Override
Expand Down
Expand Up @@ -24,12 +24,12 @@

import org.neo4j.index.internal.gbptree.Header;

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

class NativeSchemaIndexHeaderReader implements Header.Reader
public class NativeSchemaIndexHeaderReader implements Header.Reader
{
byte state;
String failureMessage;
public byte state;
public String failureMessage;

@Override
public void read( ByteBuffer headerData )
Expand Down
Expand Up @@ -27,11 +27,11 @@
/**
* Writes index state in the {@link GBPTree} header.
*/
class NativeSchemaIndexHeaderWriter implements Consumer<PageCursor>
public class NativeSchemaIndexHeaderWriter implements Consumer<PageCursor>
{
private final byte state;

NativeSchemaIndexHeaderWriter( byte state )
public NativeSchemaIndexHeaderWriter( byte state )
{
this.state = state;
}
Expand Down
Expand Up @@ -49,15 +49,15 @@
/**
* {@link IndexPopulator} backed by a {@link GBPTree}.
*
* @param <KEY> type of {@link SchemaNumberKey}.
* @param <VALUE> type of {@link SchemaNumberValue}.
* @param <KEY> type of {@link NativeSchemaKey}.
* @param <VALUE> type of {@link NativeSchemaValue}.
*/
public abstract class NativeSchemaNumberIndexPopulator<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue>
extends NativeSchemaNumberIndex<KEY,VALUE> implements IndexPopulator
public abstract class NativeSchemaIndexPopulator<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
extends NativeSchemaIndex<KEY,VALUE> implements IndexPopulator
{
static final byte BYTE_FAILED = 0;
static final byte BYTE_ONLINE = 1;
static final byte BYTE_POPULATING = 2;
public static final byte BYTE_FAILED = 0;
public static final byte BYTE_ONLINE = 1;
public static final byte BYTE_POPULATING = 2;

private final KEY treeKey;
private final VALUE treeValue;
Expand All @@ -68,7 +68,7 @@ public abstract class NativeSchemaNumberIndexPopulator<KEY extends SchemaNumberK
private byte[] failureBytes;
private boolean dropped;

NativeSchemaNumberIndexPopulator( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout,
NativeSchemaIndexPopulator( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout,
SchemaIndexProvider.Monitor monitor, IndexDescriptor descriptor, long indexId )
{
super( pageCache, fs, storeFile, layout, monitor, descriptor, indexId );
Expand Down Expand Up @@ -242,7 +242,7 @@ void closeWriter() throws IOException
singleTreeWriter = closeIfPresent( singleTreeWriter );
}

private static class IndexUpdateApply<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue>
private static class IndexUpdateApply<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
{
private final KEY treeKey;
private final VALUE treeValue;
Expand All @@ -260,11 +260,11 @@ private static class IndexUpdateApply<KEY extends SchemaNumberKey, VALUE extends

public void process( IndexEntryUpdate<?> indexEntryUpdate ) throws Exception
{
NativeSchemaNumberIndexUpdater.processUpdate( treeKey, treeValue, indexEntryUpdate, writer, conflictDetectingValueMerger );
NativeSchemaIndexUpdater.processUpdate( treeKey, treeValue, indexEntryUpdate, writer, conflictDetectingValueMerger );
}
}

private static class IndexUpdateWork<KEY extends SchemaNumberKey, VALUE extends SchemaNumberValue>
private static class IndexUpdateWork<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
implements Work<IndexUpdateApply<KEY,VALUE>,IndexUpdateWork<KEY,VALUE>>
{
private final Collection<? extends IndexEntryUpdate<?>> updates;
Expand Down

0 comments on commit 90757bb

Please sign in to comment.