Skip to content

Commit

Permalink
Naming cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed May 21, 2018
1 parent 58c04f3 commit fdc6d6d
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 45 deletions.
Expand Up @@ -77,7 +77,7 @@ public interface TransactionState extends ReadableTransactionState


// SCHEMA RELATED // SCHEMA RELATED


void indexRuleDoAdd( IndexDescriptor descriptor ); void indexDoAdd( IndexDescriptor descriptor );


void indexDoDrop( IndexDescriptor descriptor ); void indexDoDrop( IndexDescriptor descriptor );


Expand Down
Expand Up @@ -562,8 +562,7 @@ public LongDiffSets nodesWithLabelChanged( long label )
} }


@Override @Override
public void public void indexDoAdd( IndexDescriptor descriptor )
indexRuleDoAdd( IndexDescriptor descriptor )
{ {
DiffSets<IndexDescriptor> diff = indexChangesDiffSets(); DiffSets<IndexDescriptor> diff = indexChangesDiffSets();
if ( !diff.unRemove( descriptor ) ) if ( !diff.unRemove( descriptor ) )
Expand Down
Expand Up @@ -67,9 +67,9 @@ public SchemaCache( ConstraintSemantics constraintSemantics,
this.schemaCacheState = new SchemaCacheState( constraintSemantics, initialRules, indexProviderMap ); this.schemaCacheState = new SchemaCacheState( constraintSemantics, initialRules, indexProviderMap );
} }


public Iterable<CapableIndexDescriptor> indexRules() public Iterable<CapableIndexDescriptor> indexDescriptors()
{ {
return schemaCacheState.indexRules(); return schemaCacheState.indexDescriptors();
} }


public Iterable<ConstraintRule> constraintRules() public Iterable<ConstraintRule> constraintRules()
Expand All @@ -87,9 +87,9 @@ public boolean hasConstraintRule( ConstraintDescriptor descriptor )
return schemaCacheState.hasConstraintRule( descriptor ); return schemaCacheState.hasConstraintRule( descriptor );
} }


public boolean hasIndexRule( SchemaDescriptor descriptor ) public boolean hasIndex( SchemaDescriptor descriptor )
{ {
return schemaCacheState.hasIndexRule( descriptor ); return schemaCacheState.hasIndex( descriptor );
} }


public Iterator<ConstraintDescriptor> constraints() public Iterator<ConstraintDescriptor> constraints()
Expand Down Expand Up @@ -181,7 +181,7 @@ private static class SchemaCacheState
private final ConstraintSemantics constraintSemantics; private final ConstraintSemantics constraintSemantics;
private final IndexProviderMap indexProviderMap; private final IndexProviderMap indexProviderMap;
private final Set<ConstraintDescriptor> constraints; private final Set<ConstraintDescriptor> constraints;
private final MutableLongObjectMap<CapableIndexDescriptor> indexRuleById; private final MutableLongObjectMap<CapableIndexDescriptor> indexDescriptorById;
private final MutableLongObjectMap<ConstraintRule> constraintRuleById; private final MutableLongObjectMap<ConstraintRule> constraintRuleById;


private final Map<SchemaDescriptor,CapableIndexDescriptor> indexDescriptors; private final Map<SchemaDescriptor,CapableIndexDescriptor> indexDescriptors;
Expand All @@ -196,7 +196,7 @@ private static class SchemaCacheState
this.constraintSemantics = constraintSemantics; this.constraintSemantics = constraintSemantics;
this.indexProviderMap = indexProviderMap; this.indexProviderMap = indexProviderMap;
this.constraints = new HashSet<>(); this.constraints = new HashSet<>();
this.indexRuleById = new LongObjectHashMap<>(); this.indexDescriptorById = new LongObjectHashMap<>();
this.constraintRuleById = new LongObjectHashMap<>(); this.constraintRuleById = new LongObjectHashMap<>();


this.indexDescriptors = new HashMap<>(); this.indexDescriptors = new HashMap<>();
Expand All @@ -209,7 +209,7 @@ private static class SchemaCacheState
SchemaCacheState( SchemaCacheState schemaCacheState ) SchemaCacheState( SchemaCacheState schemaCacheState )
{ {
this.constraintSemantics = schemaCacheState.constraintSemantics; this.constraintSemantics = schemaCacheState.constraintSemantics;
this.indexRuleById = LongObjectHashMap.newMap( schemaCacheState.indexRuleById ); this.indexDescriptorById = LongObjectHashMap.newMap( schemaCacheState.indexDescriptorById );
this.constraintRuleById = LongObjectHashMap.newMap( schemaCacheState.constraintRuleById ); this.constraintRuleById = LongObjectHashMap.newMap( schemaCacheState.constraintRuleById );
this.constraints = new HashSet<>( schemaCacheState.constraints ); this.constraints = new HashSet<>( schemaCacheState.constraints );


Expand All @@ -228,9 +228,9 @@ private void load( Iterable<SchemaRule> schemaRuleIterator )
} }
} }


Iterable<CapableIndexDescriptor> indexRules() Iterable<CapableIndexDescriptor> indexDescriptors()
{ {
return indexRuleById.values(); return indexDescriptorById.values();
} }


Iterable<ConstraintRule> constraintRules() Iterable<ConstraintRule> constraintRules()
Expand All @@ -248,7 +248,7 @@ boolean hasConstraintRule( ConstraintDescriptor descriptor )
return constraints.contains( descriptor ); return constraints.contains( descriptor );
} }


boolean hasIndexRule( SchemaDescriptor descriptor ) boolean hasIndex( SchemaDescriptor descriptor )
{ {
return indexDescriptors.containsKey( descriptor ); return indexDescriptors.containsKey( descriptor );
} }
Expand Down Expand Up @@ -291,7 +291,7 @@ void addSchemaRule( SchemaRule rule )
else if ( rule instanceof StoreIndexDescriptor ) else if ( rule instanceof StoreIndexDescriptor )
{ {
CapableIndexDescriptor index = ((StoreIndexDescriptor) rule).withCapabilities( indexProviderMap ); CapableIndexDescriptor index = ((StoreIndexDescriptor) rule).withCapabilities( indexProviderMap );
indexRuleById.put( index.getId(), index ); indexDescriptorById.put( index.getId(), index );
SchemaDescriptor schemaDescriptor = index.schema(); SchemaDescriptor schemaDescriptor = index.schema();
indexDescriptors.put( schemaDescriptor, index ); indexDescriptors.put( schemaDescriptor, index );


Expand All @@ -315,9 +315,9 @@ void removeSchemaRule( long id )
ConstraintRule rule = constraintRuleById.remove( id ); ConstraintRule rule = constraintRuleById.remove( id );
constraints.remove( rule.getConstraintDescriptor() ); constraints.remove( rule.getConstraintDescriptor() );
} }
else if ( indexRuleById.containsKey( id ) ) else if ( indexDescriptorById.containsKey( id ) )
{ {
CapableIndexDescriptor index = indexRuleById.remove( id ); CapableIndexDescriptor index = indexDescriptorById.remove( id );
SchemaDescriptor schema = index.schema(); SchemaDescriptor schema = index.schema();
indexDescriptors.remove( schema ); indexDescriptors.remove( schema );


Expand Down
Expand Up @@ -892,7 +892,7 @@ public IndexReference indexCreate( SchemaDescriptor descriptor,
IndexDescriptorFactory.forSchema( descriptor, IndexDescriptorFactory.forSchema( descriptor,
name, name,
providerDescriptor ); providerDescriptor );
ktx.txState().indexRuleDoAdd( index ); ktx.txState().indexDoAdd( index );
return index; return index;
} }


Expand All @@ -904,7 +904,7 @@ public IndexDescriptor indexUniqueCreate( SchemaDescriptor schema, Optional<Stri
IndexDescriptorFactory.uniqueForSchema( schema, IndexDescriptorFactory.uniqueForSchema( schema,
Optional.empty(), Optional.empty(),
providerDescriptor ); providerDescriptor );
ktx.txState().indexRuleDoAdd( index ); ktx.txState().indexDoAdd( index );
return index; return index;
} }


Expand Down
Expand Up @@ -284,7 +284,7 @@ public Iterator<CapableIndexDescriptor> indexesGetForLabel( int labelId )
@Override @Override
public Iterator<CapableIndexDescriptor> indexesGetAll() public Iterator<CapableIndexDescriptor> indexesGetAll()
{ {
return schemaCache.indexRules().iterator(); return schemaCache.indexDescriptors().iterator();
} }


@Override @Override
Expand Down Expand Up @@ -672,7 +672,7 @@ public void degrees( NodeItem nodeItem, DegreeVisitor visitor )


private StoreIndexDescriptor getStoreIndexDescriptor( IndexDescriptor index ) private StoreIndexDescriptor getStoreIndexDescriptor( IndexDescriptor index )
{ {
for ( StoreIndexDescriptor descriptor : schemaCache.indexRules() ) for ( StoreIndexDescriptor descriptor : schemaCache.indexDescriptors() )
{ {
if ( descriptor.equals( index ) ) if ( descriptor.equals( index ) )
{ {
Expand Down
Expand Up @@ -28,7 +28,7 @@


public class ConstraintRule implements SchemaRule, ConstraintDescriptor.Supplier public class ConstraintRule implements SchemaRule, ConstraintDescriptor.Supplier
{ {
private final Long ownedIndexRule; private final Long ownedIndex;
private final String name; private final String name;
private final long id; private final long id;
private final ConstraintDescriptor descriptor; private final ConstraintDescriptor descriptor;
Expand Down Expand Up @@ -57,24 +57,24 @@ public static ConstraintRule constraintRule(
return new ConstraintRule( id, descriptor, ownedIndexRule, name ); return new ConstraintRule( id, descriptor, ownedIndexRule, name );
} }


ConstraintRule( long id, ConstraintDescriptor descriptor, Long ownedIndexRule ) ConstraintRule( long id, ConstraintDescriptor descriptor, Long ownedIndex )
{ {
this( id, descriptor, ownedIndexRule, null ); this( id, descriptor, ownedIndex, null );
} }


ConstraintRule( long id, ConstraintDescriptor descriptor, Long ownedIndexRule, String name ) ConstraintRule( long id, ConstraintDescriptor descriptor, Long ownedIndex, String name )
{ {
this.id = id; this.id = id;
this.descriptor = descriptor; this.descriptor = descriptor;
this.ownedIndexRule = ownedIndexRule; this.ownedIndex = ownedIndex;
this.name = SchemaRule.nameOrDefault( name, "constraint_" + id ); this.name = SchemaRule.nameOrDefault( name, "constraint_" + id );
} }


@Override @Override
public String toString() public String toString()
{ {
return "ConstraintRule[id=" + id + ", descriptor=" + descriptor.userDescription( idTokenNameLookup ) + ", " + return "ConstraintRule[id=" + id + ", descriptor=" + descriptor.userDescription( idTokenNameLookup ) + ", " +
"ownedIndex=" + ownedIndexRule + "]"; "ownedIndex=" + ownedIndex + "]";
} }


@Override @Override
Expand All @@ -92,11 +92,11 @@ public ConstraintDescriptor getConstraintDescriptor()
@SuppressWarnings( "NumberEquality" ) @SuppressWarnings( "NumberEquality" )
public long getOwnedIndex() public long getOwnedIndex()
{ {
if ( ownedIndexRule == null ) if ( ownedIndex == null )
{ {
throw new IllegalStateException( "This constraint does not own an index." ); throw new IllegalStateException( "This constraint does not own an index." );
} }
return ownedIndexRule; return ownedIndex;
} }


@Override @Override
Expand Down
Expand Up @@ -107,4 +107,4 @@ public void accept( Consumer<IndexProvider> visitor )
{ {
indexProviders.values().forEach( visitor ); indexProviders.values().forEach( visitor );
} }
} }
Expand Up @@ -436,7 +436,7 @@ private void verifyIndexOrUniquenessConstraintCanBeCreated( int labelId, int[] p
LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ); LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds );
ConstraintDescriptor constraintDescriptor = ConstraintDescriptorFactory.uniqueForSchema( schemaDescriptor ); ConstraintDescriptor constraintDescriptor = ConstraintDescriptorFactory.uniqueForSchema( schemaDescriptor );
ConstraintDescriptor nodeKeyDescriptor = ConstraintDescriptorFactory.nodeKeyForSchema( schemaDescriptor ); ConstraintDescriptor nodeKeyDescriptor = ConstraintDescriptorFactory.nodeKeyForSchema( schemaDescriptor );
if ( schemaCache.hasIndexRule( schemaDescriptor ) || if ( schemaCache.hasIndex( schemaDescriptor ) ||
schemaCache.hasConstraintRule( constraintDescriptor ) || schemaCache.hasConstraintRule( constraintDescriptor ) ||
schemaCache.hasConstraintRule( nodeKeyDescriptor ) ) schemaCache.hasConstraintRule( nodeKeyDescriptor ) )
{ {
Expand Down Expand Up @@ -466,7 +466,7 @@ private void validateRelationshipConstraintCanBeCreated( int relTypeId, int prop
} }
} }


private void createIndexRule( int labelId, int[] propertyKeyIds ) private void createIndex( int labelId, int[] propertyKeyIds )
{ {
LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ); LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds );
StoreIndexDescriptor schemaRule = StoreIndexDescriptor schemaRule =
Expand Down Expand Up @@ -584,7 +584,7 @@ public void close() throws IOException
private StoreIndexDescriptor[] getIndexesNeedingPopulation() private StoreIndexDescriptor[] getIndexesNeedingPopulation()
{ {
List<StoreIndexDescriptor> indexesNeedingPopulation = new ArrayList<>(); List<StoreIndexDescriptor> indexesNeedingPopulation = new ArrayList<>();
for ( StoreIndexDescriptor rule : schemaCache.indexRules() ) for ( StoreIndexDescriptor rule : schemaCache.indexDescriptors() )
{ {
IndexProvider provider = indexProviderMap.lookup( rule.providerDescriptor() ); IndexProvider provider = indexProviderMap.lookup( rule.providerDescriptor() );
if ( provider.getInitialState( rule ) != InternalIndexState.FAILED ) if ( provider.getInitialState( rule ) != InternalIndexState.FAILED )
Expand Down Expand Up @@ -1161,7 +1161,7 @@ public IndexDefinition createIndexDefinition( Label label, String... propertyKey


validateIndexCanBeCreated( labelId, propertyKeyIds ); validateIndexCanBeCreated( labelId, propertyKeyIds );


createIndexRule( labelId, propertyKeyIds ); createIndex( labelId, propertyKeyIds );
return new IndexDefinitionImpl( this, label, propertyKeys, false ); return new IndexDefinitionImpl( this, label, propertyKeys, false );
} }


Expand Down
Expand Up @@ -319,7 +319,6 @@ public void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception
verifyNoMoreInteractions( schemaRead ); verifyNoMoreInteractions( schemaRead );
} }



private class StubKernel implements Kernel, Session private class StubKernel implements Kernel, Session
{ {
private final List<KernelTransactionImplementation> transactions = new ArrayList<>(); private final List<KernelTransactionImplementation> transactions = new ArrayList<>();
Expand Down
Expand Up @@ -234,8 +234,8 @@ public void shouldMapFromRemovedLabelToNodes()
public void shouldAddAndGetByLabel() public void shouldAddAndGetByLabel()
{ {
// WHEN // WHEN
state.indexRuleDoAdd( indexOn_1_1 ); state.indexDoAdd( indexOn_1_1 );
state.indexRuleDoAdd( indexOn_2_1 ); state.indexDoAdd( indexOn_2_1 );


// THEN // THEN
assertEquals( asSet( indexOn_1_1 ), assertEquals( asSet( indexOn_1_1 ),
Expand All @@ -246,7 +246,7 @@ public void shouldAddAndGetByLabel()
public void shouldAddAndGetByRuleId() public void shouldAddAndGetByRuleId()
{ {
// GIVEN // GIVEN
state.indexRuleDoAdd( indexOn_1_1 ); state.indexDoAdd( indexOn_1_1 );


// THEN // THEN
assertEquals( asSet( indexOn_1_1 ), state.indexChanges().getAdded() ); assertEquals( asSet( indexOn_1_1 ), state.indexChanges().getAdded() );
Expand Down
Expand Up @@ -32,11 +32,11 @@
import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor; import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor;
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory; import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory;
import org.neo4j.kernel.api.schema.index.IndexDescriptor; 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.TestIndexDescriptorFactory;
import org.neo4j.kernel.impl.api.index.IndexProviderMap; import org.neo4j.kernel.impl.api.index.IndexProviderMap;
import org.neo4j.kernel.impl.constraints.StandardConstraintSemantics; import org.neo4j.kernel.impl.constraints.StandardConstraintSemantics;
import org.neo4j.kernel.impl.store.record.ConstraintRule; import org.neo4j.kernel.impl.store.record.ConstraintRule;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor;
import org.neo4j.storageengine.api.schema.SchemaRule; import org.neo4j.storageengine.api.schema.SchemaRule;
import org.neo4j.test.Race; import org.neo4j.test.Race;


Expand All @@ -49,7 +49,6 @@
import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.helpers.collection.Iterators.asSet;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel; import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory.uniqueForLabel; import static org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory.uniqueForLabel;
import static org.neo4j.kernel.impl.api.index.TestIndexProviderDescriptor.PROVIDER_DESCRIPTOR;
import static org.neo4j.kernel.impl.store.record.ConstraintRule.constraintRule; import static org.neo4j.kernel.impl.store.record.ConstraintRule.constraintRule;


public class SchemaCacheTest public class SchemaCacheTest
Expand All @@ -67,7 +66,7 @@ public void should_construct_schema_cache()
SchemaCache cache = new SchemaCache( new ConstraintSemantics(), rules, IndexProviderMap.EMPTY ); SchemaCache cache = new SchemaCache( new ConstraintSemantics(), rules, IndexProviderMap.EMPTY );


// THEN // THEN
assertEquals( asSet( hans, gretel ), Iterables.asSet( cache.indexRules() ) ); assertEquals( asSet( hans, gretel ), Iterables.asSet( cache.indexDescriptors() ) );
assertEquals( asSet( witch, robot ), Iterables.asSet( cache.constraintRules() ) ); assertEquals( asSet( witch, robot ), Iterables.asSet( cache.constraintRules() ) );
} }


Expand All @@ -85,7 +84,7 @@ public void addRemoveIndexes()
cache.removeSchemaRule( hans.getId() ); cache.removeSchemaRule( hans.getId() );
cache.removeSchemaRule( witch.getId() ); cache.removeSchemaRule( witch.getId() );


assertEquals( asSet( gretel, rule1, rule2 ), Iterables.asSet( cache.indexRules() ) ); assertEquals( asSet( gretel, rule1, rule2 ), Iterables.asSet( cache.indexDescriptors() ) );
assertEquals( asSet( robot ), Iterables.asSet( cache.constraintRules() ) ); assertEquals( asSet( robot ), Iterables.asSet( cache.constraintRules() ) );
} }


Expand All @@ -102,7 +101,7 @@ public void addSchemaRules()
cache.addSchemaRule( robot ); cache.addSchemaRule( robot );


// THEN // THEN
assertEquals( asSet( hans, gretel ), Iterables.asSet( cache.indexRules() ) ); assertEquals( asSet( hans, gretel ), Iterables.asSet( cache.indexDescriptors() ) );
assertEquals( asSet( witch, robot ), Iterables.asSet( cache.constraintRules() ) ); assertEquals( asSet( witch, robot ), Iterables.asSet( cache.constraintRules() ) );
} }


Expand Down Expand Up @@ -298,7 +297,7 @@ public void concurrentSchemaRuleAdd() throws Throwable
} }
race.go(); race.go();


assertEquals( indexNumber, Iterables.count( cache.indexRules() ) ); assertEquals( indexNumber, Iterables.count( cache.indexDescriptors() ) );
for ( int labelId = 0; labelId < indexNumber; labelId++ ) for ( int labelId = 0; labelId < indexNumber; labelId++ )
{ {
assertEquals( 1, Iterators.count( cache.indexDescriptorsForLabel( labelId ) ) ); assertEquals( 1, Iterators.count( cache.indexDescriptorsForLabel( labelId ) ) );
Expand Down Expand Up @@ -327,7 +326,7 @@ public void concurrentSchemaRuleRemove() throws Throwable
} }
race.go(); race.go();


assertEquals( indexNumber - numberOfDeletions, Iterables.count( cache.indexRules() ) ); assertEquals( indexNumber - numberOfDeletions, Iterables.count( cache.indexDescriptors() ) );
for ( int labelId = numberOfDeletions; labelId < indexNumber; labelId++ ) for ( int labelId = numberOfDeletions; labelId < indexNumber; labelId++ )
{ {
assertEquals( 1, Iterators.count( cache.indexDescriptorsForLabel( labelId ) ) ); assertEquals( 1, Iterators.count( cache.indexDescriptorsForLabel( labelId ) ) );
Expand Down
Expand Up @@ -101,7 +101,7 @@ private void addIndex( GraphDatabaseService database )
KernelTransaction kernelTransaction = statementBridge.getKernelTransactionBoundToThisThread( true ); KernelTransaction kernelTransaction = statementBridge.getKernelTransactionBoundToThisThread( true );
LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( 0, 0 ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( 0, 0 );
IndexDescriptor index = IndexDescriptorFactory.uniqueForSchema( descriptor ); IndexDescriptor index = IndexDescriptorFactory.uniqueForSchema( descriptor );
((KernelTransactionImplementation) kernelTransaction).txState().indexRuleDoAdd( index ); ((KernelTransactionImplementation) kernelTransaction).txState().indexDoAdd( index );
transaction.success(); transaction.success();
} }
} }
Expand Down

0 comments on commit fdc6d6d

Please sign in to comment.