Skip to content

Commit

Permalink
Cleanup in native schema index main and test
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen authored and tinwelint committed Jun 26, 2017
1 parent dfcbf62 commit c26c2b1
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 33 deletions.
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler;
Expand All @@ -42,7 +41,7 @@ class NativeNonUniqueSchemaNumberIndexPopulator<KEY extends NumberKey, VALUE ext
private NonUniqueIndexSampler sampler;

NativeNonUniqueSchemaNumberIndexPopulator( PageCache pageCache, File storeFile, Layout<KEY,VALUE> layout,
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, IndexSamplingConfig samplingConfig )
IndexSamplingConfig samplingConfig )
{
super( pageCache, storeFile, layout );
this.samplingConfig = samplingConfig;
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.neo4j.kernel.api.index.IndexAccessor;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.impl.api.index.IndexUpdateMode;
import org.neo4j.kernel.impl.index.GBPTreeUtil;
import org.neo4j.storageengine.api.schema.IndexReader;
Expand All @@ -45,14 +44,11 @@ public class NativeSchemaNumberIndexAccessor<KEY extends NumberKey, VALUE extend
extends NativeSchemaNumberIndex<KEY,VALUE> implements IndexAccessor
{
private final NativeSchemaNumberIndexUpdater<KEY,VALUE> singleUpdater;
private final IndexDescriptor indexDescriptor;

NativeSchemaNumberIndexAccessor( PageCache pageCache, File storeFile,
Layout<KEY,VALUE> layout, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector,
IndexDescriptor indexDescriptor ) throws IOException
Layout<KEY,VALUE> layout, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws IOException
{
super( pageCache, storeFile, layout );
this.indexDescriptor = indexDescriptor;
singleUpdater = new NativeSchemaNumberIndexUpdater<>( layout.newKey(), layout.newValue() );
instantiateTree( recoveryCleanupWorkCollector );
}
Expand Down Expand Up @@ -93,7 +89,7 @@ public void close() throws IOException
@Override
public IndexReader newReader()
{
return new NativeSchemaNumberIndexReader<>( tree, layout, indexDescriptor );
return new NativeSchemaNumberIndexReader<>( tree, layout );
}

@Override
Expand Down
Expand Up @@ -22,7 +22,6 @@
import java.io.File;

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.impl.api.index.sampling.UniqueIndexSampler;
Expand All @@ -36,8 +35,7 @@ class NativeUniqueSchemaNumberIndexPopulator<KEY extends NumberKey, VALUE extend
{
private final UniqueIndexSampler sampler;

NativeUniqueSchemaNumberIndexPopulator( PageCache pageCache, File storeFile, Layout<KEY,VALUE> layout,
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector )
NativeUniqueSchemaNumberIndexPopulator( PageCache pageCache, File storeFile, Layout<KEY,VALUE> layout )
{
super( pageCache, storeFile, layout );
this.sampler = new UniqueIndexSampler();
Expand Down
Expand Up @@ -40,7 +40,7 @@ public class NumberHitIterator<KEY extends NumberKey, VALUE extends NumberValue>
{
private final RawCursor<Hit<KEY,VALUE>,IOException> seeker;

public NumberHitIterator( RawCursor<Hit<KEY,VALUE>,IOException> seeker )
NumberHitIterator( RawCursor<Hit<KEY,VALUE>,IOException> seeker )
{
this.seeker = seeker;
}
Expand All @@ -50,7 +50,7 @@ protected boolean fetchNext()
{
try
{
return seeker.next() ? next( seeker.get().key().entityId ) : false;
return seeker.next() && next( seeker.get().key().entityId );
}
catch ( IOException e )
{
Expand Down
Expand Up @@ -53,6 +53,11 @@ abstract class LayoutTestUtil<KEY extends NumberKey, VALUE extends NumberValue>

protected abstract double fractionDuplicates();

IndexDescriptor indexDescriptor()
{
return indexDescriptor;
}

void copyValue( VALUE value, VALUE intoValue )
{
intoValue.type = value.type;
Expand Down
Expand Up @@ -38,7 +38,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.neo4j.helpers.ArrayUtil.array;
import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE;
import static org.neo4j.kernel.impl.index.schema.FullScanNonUniqueIndexSamplerTest.countUniqueValues;

public class NativeNonUniqueSchemaNumberIndexPopulatorTest
Expand All @@ -48,7 +47,7 @@ public class NativeNonUniqueSchemaNumberIndexPopulatorTest
NativeSchemaNumberIndexPopulator<NumberKey,NumberValue> createPopulator( PageCache pageCache, File indexFile,
Layout<NumberKey,NumberValue> layout, IndexSamplingConfig samplingConfig )
{
return new NativeNonUniqueSchemaNumberIndexPopulator<>( pageCache, indexFile, layout, IMMEDIATE, samplingConfig );
return new NativeNonUniqueSchemaNumberIndexPopulator<>( pageCache, indexFile, layout, samplingConfig );
}

@Test
Expand Down
Expand Up @@ -49,7 +49,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static org.neo4j.collection.primitive.PrimitiveLongCollections.EMPTY_LONG_ARRAY;
import static org.neo4j.function.Predicates.all;
import static org.neo4j.function.Predicates.alwaysTrue;
Expand All @@ -70,18 +69,14 @@
public abstract class NativeSchemaNumberIndexAccessorTest<KEY extends NumberKey, VALUE extends NumberValue>
extends SchemaNumberIndexTestUtil<KEY,VALUE>
{
private IndexDescriptor indexDescriptor;
NativeSchemaNumberIndexAccessor<KEY,VALUE> accessor;
private NativeSchemaNumberIndexAccessor<KEY,VALUE> accessor;

@Before
public void setupAccessor() throws IOException
{
indexDescriptor = createIndexDescriptor();
accessor = new NativeSchemaNumberIndexAccessor<>( pageCache, indexFile, layout, IMMEDIATE, indexDescriptor );
accessor = new NativeSchemaNumberIndexAccessor<>( pageCache, indexFile, layout, IMMEDIATE );
}

abstract IndexDescriptor createIndexDescriptor();

@After
public void closeAccessor() throws IOException
{
Expand Down Expand Up @@ -459,7 +454,7 @@ public void shouldHandleMultipleConsecutiveUpdaters() throws Exception
public void requestForSecondUpdaterMustThrow() throws Exception
{
// given
try ( IndexUpdater updater = accessor.newUpdater( ONLINE ) )
try ( IndexUpdater ignored = accessor.newUpdater( ONLINE ) )
{
// when
try
Expand Down Expand Up @@ -581,11 +576,11 @@ private long[] extractEntityIds( IndexEntryUpdate<?>[] updates, Predicate<Object
{
long[] entityIds = new long[updates.length];
int cursor = 0;
for ( int i = 0; i < updates.length; i++ )
for ( IndexEntryUpdate<?> update : updates )
{
if ( valueFilter.test( updates[i].values()[0] ) )
if ( valueFilter.test( update.values()[0] ) )
{
entityIds[cursor++] = updates[i].getEntityId();
entityIds[cursor++] = update.getEntityId();
}
}
return Arrays.copyOf( entityIds, cursor );
Expand Down
Expand Up @@ -61,7 +61,7 @@
public abstract class NativeSchemaNumberIndexPopulatorTest<KEY extends NumberKey,VALUE extends NumberValue>
extends SchemaNumberIndexTestUtil<KEY,VALUE>
{
static final int LARGE_AMOUNT_OF_UPDATES = 1_000;
private static final int LARGE_AMOUNT_OF_UPDATES = 1_000;
static final PropertyAccessor null_property_accessor = ( nodeId, propKeyId ) ->
{
throw new RuntimeException( "Did not expect an attempt to go to store" );
Expand Down Expand Up @@ -484,7 +484,7 @@ public void unsuccessfulCloseMustThrowAfterDrop() throws Exception
}
}

int interleaveLargeAmountOfUpdates( Random updaterRandom,
private int interleaveLargeAmountOfUpdates( Random updaterRandom,
Iterator<IndexEntryUpdate<IndexDescriptor>> updates ) throws IOException, IndexEntryConflictException
{
int count = 0;
Expand Down Expand Up @@ -562,7 +562,7 @@ private void applyInterleaved( IndexEntryUpdate<IndexDescriptor>[] updates, Inde
}
}

void verifyUpdates( Iterator<IndexEntryUpdate<IndexDescriptor>> indexEntryUpdateIterator, int count )
private void verifyUpdates( Iterator<IndexEntryUpdate<IndexDescriptor>> indexEntryUpdateIterator, int count )
throws IOException
{
@SuppressWarnings( "unchecked" )
Expand Down
Expand Up @@ -35,7 +35,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE;

public class NativeUniqueSchemaNumberIndexPopulatorTest extends NativeSchemaNumberIndexPopulatorTest<NumberKey,NumberValue>
{
Expand All @@ -44,7 +43,7 @@ NativeSchemaNumberIndexPopulator<NumberKey,NumberValue> createPopulator(
PageCache pageCache, File indexFile,
Layout<NumberKey,NumberValue> layout, IndexSamplingConfig samplingConfig )
{
return new NativeUniqueSchemaNumberIndexPopulator<>( pageCache, indexFile, layout, IMMEDIATE );
return new NativeUniqueSchemaNumberIndexPopulator<>( pageCache, indexFile, layout );
}

@Override
Expand Down
Expand Up @@ -67,6 +67,7 @@ public abstract class SchemaNumberIndexTestUtil<KEY extends NumberKey,VALUE exte
@Rule
public final RuleChain rules = outerRule( fs ).around( directory ).around( pageCacheRule ).around( random );

IndexDescriptor indexDescriptor;
LayoutTestUtil<KEY,VALUE> layoutUtil;
Layout<KEY,VALUE> layout;
File indexFile;
Expand All @@ -76,6 +77,7 @@ public abstract class SchemaNumberIndexTestUtil<KEY extends NumberKey,VALUE exte
public void setup()
{
layoutUtil = createLayoutTestUtil();
indexDescriptor = layoutUtil.indexDescriptor();
layout = layoutUtil.createLayout();
indexFile = directory.file( "index" );
pageCache = pageCacheRule.getPageCache( fs );
Expand Down Expand Up @@ -184,12 +186,12 @@ private Hit<KEY,VALUE> hit( final KEY key, final VALUE value )
return new SimpleHit( key, value );
}

protected void assertFilePresent()
void assertFilePresent()
{
assertTrue( fs.fileExists( indexFile ) );
}

protected void assertFileNotPresent()
void assertFileNotPresent()
{
assertFalse( fs.fileExists( indexFile ) );
}
Expand Down

0 comments on commit c26c2b1

Please sign in to comment.