Skip to content

Commit

Permalink
Remove StoreIndexDescriptor.indexRule constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and ragadeeshu committed May 21, 2018
1 parent c424483 commit 21a7591
Show file tree
Hide file tree
Showing 47 changed files with 196 additions and 239 deletions.
Expand Up @@ -21,10 +21,13 @@

import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory;
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.kernel.impl.store.record.ConstraintRule;

import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;

public class SchemaRuleUtil
{
private SchemaRuleUtil()
Expand Down Expand Up @@ -52,8 +55,7 @@ public static ConstraintRule relPropertyExistenceConstraintRule( long ruleId, in
public static StoreIndexDescriptor indexRule( long ruleId, int labelId, int propertyId, IndexProvider.Descriptor
descriptor )
{
return StoreIndexDescriptor
.indexRule( ruleId, TestIndexDescriptorFactory.forLabel( labelId, propertyId ), descriptor );
return IndexDescriptorFactory.forSchema( forLabel( labelId, propertyId ), descriptor ).withId( ruleId );
}

public static StoreIndexDescriptor constraintIndexRule( long ruleId, int labelId, int propertyId,
Expand All @@ -67,7 +69,6 @@ public static StoreIndexDescriptor constraintIndexRule( long ruleId, int labelId
public static StoreIndexDescriptor constraintIndexRule( long ruleId, int labelId, int propertyId,
IndexProvider.Descriptor descriptor )
{
return StoreIndexDescriptor.indexRule( ruleId, TestIndexDescriptorFactory.uniqueForLabel( labelId, propertyId ),
descriptor );
return IndexDescriptorFactory.uniqueForSchema( forLabel( labelId, propertyId ), descriptor ).withId( ruleId );
}
}
Expand Up @@ -134,7 +134,8 @@
import static org.neo4j.kernel.api.StatementConstants.ANY_LABEL;
import static org.neo4j.kernel.api.StatementConstants.ANY_RELATIONSHIP_TYPE;
import static org.neo4j.kernel.api.labelscan.NodeLabelUpdate.labelChanges;
import static org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.index.IndexDescriptorFactory.forSchema;
import static org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory.uniqueForLabel;
import static org.neo4j.kernel.impl.store.AbstractDynamicStore.readFullByteArrayFromHeavyRecords;
import static org.neo4j.kernel.impl.store.DynamicArrayStore.allocateFromNumbers;
Expand Down Expand Up @@ -227,7 +228,7 @@ protected void generateInitialData( GraphDatabaseService db )
key1 = tokenWrite.propertyKeyGetOrCreateForName( PROP1 );
key2 = tokenWrite.propertyKeyGetOrCreateForName( PROP2 );
label3 = ktx.tokenRead().nodeLabel( "label3" );
ktx.schemaWrite().indexCreate( SchemaDescriptorFactory.forLabel( label3, key1, key2 ) );
ktx.schemaWrite().indexCreate( forLabel( label3, key1, key2 ) );
}

db.schema().constraintFor( label( "label4" ) ).assertPropertyIsUnique( PROP1 ).create();
Expand Down Expand Up @@ -2250,11 +2251,10 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
DynamicRecord recordBefore = new DynamicRecord( id );
DynamicRecord recordAfter = recordBefore.clone();

StoreIndexDescriptor
rule = StoreIndexDescriptor.indexRule( id, forLabel( labelId, propertyKeyIds ), DESCRIPTOR );
Collection<DynamicRecord> records = serializeRule( rule, recordAfter );
StoreIndexDescriptor index = forSchema( forLabel( labelId, propertyKeyIds ), DESCRIPTOR ).withId( id );
Collection<DynamicRecord> records = serializeRule( index, recordAfter );

tx.createSchema( singleton( recordBefore ), records, rule );
tx.createSchema( singleton( recordBefore ), records, index );
}
} );
}
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.labelscan.NodeLabelRange;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
Expand Down Expand Up @@ -84,6 +84,7 @@
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import static org.neo4j.consistency.report.ConsistencyReporter.NO_MONITOR;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.impl.store.counts.keys.CountsKeyFactory.nodeKey;

@RunWith( Suite.class )
Expand Down Expand Up @@ -389,8 +390,7 @@ private Object parameter( Class<?> type )
}
if ( type == StoreIndexDescriptor.class )
{
return StoreIndexDescriptor.indexRule( 1, TestIndexDescriptorFactory.forLabel( 2, 3 ),
new IndexProvider.Descriptor( "provider", "version" ) );
return IndexDescriptorFactory.forSchema( forLabel( 2, 3 ), IndexProvider.UNDECIDED ).withId( 1 );
}
if ( type == SchemaRule.class )
{
Expand Down
Expand Up @@ -56,6 +56,12 @@ public static IndexDescriptor uniqueForSchema( SchemaDescriptor schema )
return new IndexDescriptor( schema, UNIQUE, Optional.empty(), IndexProvider.UNDECIDED );
}

public static IndexDescriptor uniqueForSchema( SchemaDescriptor schema,
IndexProvider.Descriptor providerDescriptor )
{
return new IndexDescriptor( schema, UNIQUE, Optional.empty(), providerDescriptor );
}

public static IndexDescriptor uniqueForSchema( SchemaDescriptor schema,
Optional<String> name,
IndexProvider.Descriptor providerDescriptor )
Expand Down
Expand Up @@ -64,12 +64,6 @@ public class StoreIndexDescriptor extends IndexDescriptor implements SchemaRule
this.owningConstraintId = owningConstraintId;
}

public static StoreIndexDescriptor indexRule( long id, IndexDescriptor descriptor,
IndexProvider.Descriptor providerDescriptor )
{
return new StoreIndexDescriptor( descriptor, id, null );
}

public static StoreIndexDescriptor constraintIndexRule( long id, IndexDescriptor descriptor,
IndexProvider.Descriptor providerDescriptor,
Long owningConstraint )
Expand Down
Expand Up @@ -93,7 +93,7 @@ public void setup()
public Compatibility( IndexProviderCompatibilityTestSuite testSuite, IndexDescriptor descriptor )
{
this.testSuite = testSuite;
this.descriptor = StoreIndexDescriptor.indexRule( 17, descriptor, indexProvider.getProviderDescriptor() );
this.descriptor = descriptor.withId( 17 );
this.valueSet1 = allValues(
testSuite.supportsSpatial(),
testSuite.supportsTemporal(),
Expand Down
Expand Up @@ -55,8 +55,7 @@
import org.neo4j.kernel.api.proc.Key;
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptor;
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory;
import org.neo4j.kernel.impl.api.index.inmemory.InMemoryIndexProviderFactory;
import org.neo4j.kernel.impl.factory.Edition;
import org.neo4j.kernel.impl.proc.Procedures;
Expand All @@ -81,6 +80,7 @@
import static org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTRelationship;
import static org.neo4j.kernel.api.proc.Context.KERNEL_TRANSACTION;
import static org.neo4j.kernel.api.proc.Context.SECURITY_CONTEXT;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;

public class BuiltInProceduresTest
{
Expand Down Expand Up @@ -415,7 +415,7 @@ private void givenIndex( String label, String propKey )
int propId = token( propKey, propKeys );

IndexReference index =
StoreIndexDescriptor.indexRule( 0, TestIndexDescriptorFactory.forLabel( labelId, propId ), InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR );
IndexDescriptorFactory.forSchema( forLabel( labelId, propId ), InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR );
indexes.add( index );
}

Expand All @@ -425,7 +425,7 @@ private void givenUniqueConstraint( String label, String propKey )
int propId = token( propKey, propKeys );

IndexReference index =
StoreIndexDescriptor.indexRule( 0, TestIndexDescriptorFactory.uniqueForLabel( labelId, propId ), InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR );
IndexDescriptorFactory.uniqueForSchema( forLabel( labelId, propId ), InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR );
uniqueIndexes.add( index );
constraints.add( ConstraintDescriptorFactory.uniqueForLabel( labelId, propId ) );
}
Expand Down
Expand Up @@ -81,8 +81,7 @@ public class ConstraintIndexCreatorTest

private final LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( LABEL_ID, PROPERTY_KEY_ID );
private final IndexDescriptor index = TestIndexDescriptorFactory.uniqueForLabel( 123, 456 );
private final IndexReference indexReference = StoreIndexDescriptor.indexRule( 0, TestIndexDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_KEY_ID ),
new IndexProvider.Descriptor( "foo", "1.872" ) );
private final IndexReference indexReference = TestIndexDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_KEY_ID );
private final SchemaRead schemaRead = schemaRead();
private final TokenRead tokenRead = mock( TokenRead.class );

Expand Down
Expand Up @@ -349,7 +349,8 @@ private static IndexPopulator addPopulator( BatchingMultipleIndexPopulator batch
flipper.setFlipTarget( indexProxyFactory );

batchingPopulator.addPopulator( populator,
StoreIndexDescriptor.indexRule( 1, descriptor, new IndexProvider.Descriptor( "foo", "1" ) ).withoutCapabilities(), flipper,
descriptor.withId( 1 ).withoutCapabilities(),
flipper,
failedIndexProxyFactory, "testIndex" );

return populator;
Expand Down
Expand Up @@ -26,15 +26,14 @@
import org.neo4j.internal.kernel.api.IndexCapability;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.schema.index.CapableIndexDescriptor;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.logging.AssertableLogProvider;
import org.neo4j.logging.NullLogProvider;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.index.IndexDescriptorFactory.forSchema;
import static org.neo4j.logging.AssertableLogProvider.inLog;

public class FailedIndexProxyTest
Expand All @@ -51,9 +50,8 @@ public void shouldRemoveIndexCountsWhenTheIndexItselfIsDropped() throws IOExcept
// given
String userDescription = "description";
FailedIndexProxy index =
new FailedIndexProxy( indexMeta( StoreIndexDescriptor
.indexRule( 1, TestIndexDescriptorFactory.forLabel( 1, 2 ), IndexProvider.UNDECIDED ) ),
userDescription, indexPopulator, indexPopulationFailure, indexCountsRemover, NullLogProvider.getInstance() );
new FailedIndexProxy( forSchema( forLabel( 1, 2 ), IndexProvider.UNDECIDED ).withId( 1 ).withoutCapabilities(),
userDescription, indexPopulator, indexPopulationFailure, indexCountsRemover, NullLogProvider.getInstance() );

// when
index.drop();
Expand All @@ -71,19 +69,13 @@ public void shouldLogReasonForDroppingIndex() throws IOException
AssertableLogProvider logProvider = new AssertableLogProvider();

// when
new FailedIndexProxy( indexMeta( StoreIndexDescriptor
.indexRule( 1, TestIndexDescriptorFactory.forLabel( 0, 0 ), IndexProvider.UNDECIDED ) ),
"foo", mock( IndexPopulator.class ), IndexPopulationFailure.failure( "it broke" ),
indexCountsRemover, logProvider ).drop();
new FailedIndexProxy( forSchema( forLabel( 0, 0 ), IndexProvider.UNDECIDED ).withId( 1 ).withoutCapabilities(),
"foo", mock( IndexPopulator.class ), IndexPopulationFailure.failure( "it broke" ),
indexCountsRemover, logProvider ).drop();

// then
logProvider.assertAtLeastOnce(
inLog( FailedIndexProxy.class ).info( "FailedIndexProxy#drop index on foo dropped due to:\nit broke" )
);
}

private CapableIndexDescriptor indexMeta( StoreIndexDescriptor descriptor )
{
return descriptor.withoutCapabilities();
}
}
Expand Up @@ -27,8 +27,8 @@
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.neo4j.kernel.api.schema.index.StoreIndexDescriptor.indexRule;
import static org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.index.IndexDescriptorFactory.forSchema;
import static org.neo4j.kernel.impl.api.index.TestIndexProviderDescriptor.PROVIDER_DESCRIPTOR;

public class IndexMapReferenceTest
Expand Down Expand Up @@ -97,7 +97,7 @@ private IndexProxy[] mockedIndexProxies( int base, int count )
{
existing[i] = mock( IndexProxy.class );
when( existing[i].getDescriptor() ).thenReturn(
indexRule( i, forLabel( base + i, 1 ), PROVIDER_DESCRIPTOR ).withoutCapabilities() );
forSchema( forLabel( base + i, 1 ), PROVIDER_DESCRIPTOR ).withId( i ).withoutCapabilities() );
}
return existing;
}
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException;
import org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
Expand All @@ -54,8 +55,7 @@
import org.neo4j.kernel.api.labelscan.NodeLabelUpdate;
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.api.DatabaseSchemaState;
import org.neo4j.kernel.impl.api.index.inmemory.InMemoryIndexProvider;
Expand Down Expand Up @@ -585,8 +585,7 @@ private IndexPopulator inMemoryPopulator( boolean constraint )
{
IndexSamplingConfig samplingConfig = new IndexSamplingConfig( Config.defaults() );
IndexDescriptor descriptor = indexDescriptor( FIRST, name, constraint );
return new InMemoryIndexProvider().getPopulator( StoreIndexDescriptor
.indexRule( 21, descriptor, PROVIDER_DESCRIPTOR ), samplingConfig );
return new InMemoryIndexProvider().getPopulator( descriptor.withId( 21 ), samplingConfig );
}

private IndexPopulationJob newIndexPopulationJob( IndexPopulator populator,
Expand Down Expand Up @@ -619,7 +618,7 @@ private IndexPopulationJob newIndexPopulationJob( FailedIndexProxyFactory failur

MultipleIndexPopulator multiPopulator = new MultipleIndexPopulator( storeView, logProvider );
IndexPopulationJob job = new IndexPopulationJob( multiPopulator, NO_MONITOR, stateHolder );
job.addPopulator( populator, StoreIndexDescriptor.indexRule( indexId, descriptor, PROVIDER_DESCRIPTOR ).withoutCapabilities(),
job.addPopulator( populator, descriptor.withId( indexId ).withoutCapabilities(),
format( ":%s(%s)", FIRST.name(), name ), flipper, failureDelegateFactory );
return job;
}
Expand All @@ -631,9 +630,10 @@ private IndexDescriptor indexDescriptor( Label label, String propertyKey, boolea
{
int labelId = tx.tokenWrite().labelGetOrCreateForName( label.name() );
int propertyKeyId = tx.tokenWrite().propertyKeyGetOrCreateForName( propertyKey );
SchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, propertyKeyId );
IndexDescriptor descriptor = constraint ?
TestIndexDescriptorFactory.uniqueForLabel( labelId, propertyKeyId ) :
TestIndexDescriptorFactory.forLabel( labelId, propertyKeyId );
IndexDescriptorFactory.uniqueForSchema( schema, PROVIDER_DESCRIPTOR ) :
IndexDescriptorFactory.forSchema( schema, PROVIDER_DESCRIPTOR );
tx.success();
return descriptor;
}
Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory;
import org.neo4j.kernel.api.schema.index.CapableIndexDescriptor;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.storageengine.api.schema.PopulationProgress;
Expand Down Expand Up @@ -144,7 +143,7 @@ public void acceptUpdate( MultipleIndexPopulator.MultipleIndexUpdater updater, I

private CapableIndexDescriptor dummyMeta()
{
return StoreIndexDescriptor.indexRule( 0, TestIndexDescriptorFactory.forLabel( 0, 0 ), TestIndexProviderDescriptor.PROVIDER_DESCRIPTOR ).withoutCapabilities();
return TestIndexDescriptorFactory.forLabel( 0, 0 ).withId( 0 ).withoutCapabilities();
}

private IndexEntryUpdate<LabelSchemaDescriptor> someUpdate()
Expand Down

0 comments on commit 21a7591

Please sign in to comment.