From 3a3c41882fd90a9b59314bfb89b963b131dac195 Mon Sep 17 00:00:00 2001 From: fickludd Date: Tue, 7 Feb 2017 10:36:13 +0100 Subject: [PATCH] Pushed IndexDescriptor boundary in ReadOperations and SchemaReadOperations. --- .../TransactionBoundGraphStatistics.scala | 12 +-- .../TransactionBoundGraphStatistics.scala | 4 +- .../TransactionBoundGraphStatistics.scala | 4 +- .../org/neo4j/kernel/api/ReadOperations.java | 40 +++++---- .../IndexBelongsToConstraintException.java | 12 +-- .../schema/NoSuchIndexException.java | 10 ++- .../schema/SchemaRuleException.java | 2 +- .../kernel/api/schema_new/SchemaUtil.java | 20 ++--- .../builtinprocs/BuiltInProcedures.java | 10 +-- .../kernel/builtinprocs/IndexProcedures.java | 16 ++-- .../kernel/builtinprocs/SchemaProcedure.java | 9 +- .../ConstraintEnforcingEntityOperations.java | 8 +- ...ntegrityValidatingStatementOperations.java | 34 +++---- .../impl/api/LockingStatementOperations.java | 27 +++--- .../kernel/impl/api/OperationsFacade.java | 39 ++++---- .../api/StateHandlingStatementOperations.java | 83 ++++++++--------- ...emoveOrphanConstraintIndexesOnStartup.java | 12 ++- .../api/operations/SchemaReadOperations.java | 27 +++--- .../api/state/ConstraintIndexCreator.java | 2 +- .../kernel/impl/api/store/StorageLayer.java | 8 +- .../coreapi/schema/PropertyNameUtils.java | 88 +++++-------------- .../impl/coreapi/schema/SchemaImpl.java | 69 +++++++++++---- .../impl/factory/GraphDatabaseFacade.java | 6 +- .../impl/store/record/ConstraintRule.java | 4 +- .../kernel/impl/store/record/IndexRule.java | 4 +- .../DbStructureArgumentFormatter.java | 23 ++++- .../dbstructure/DbStructureCollector.java | 30 ++++--- .../util/dbstructure/DbStructureVisitor.java | 7 +- .../dbstructure/GraphDbStructureGuide.java | 14 ++- .../storageengine/api/StoreReadLayer.java | 5 +- .../neo4j/graphdb/IndexingAcceptanceTest.java | 4 +- .../builtinprocs/AwaitIndexProcedureTest.java | 12 +-- .../builtinprocs/BuiltInProceduresTest.java | 22 +++-- .../ResampleIndexProcedureTest.java | 10 ++- ...rityValidatingStatementOperationsTest.java | 46 +++++----- .../api/KernelSchemaStateFlushingTest.java | 18 ++-- .../api/LockingStatementOperationsTest.java | 5 +- .../kernel/impl/api/OperationsFacadeTest.java | 5 +- .../ConstraintIndexCreatorTest.java | 6 +- .../neo4j/kernel/impl/api/index/IndexIT.java | 15 ++-- .../impl/api/index/IndexStatisticsTest.java | 65 +++++++------- .../impl/api/index/SchemaIndexTestHelper.java | 5 +- .../NodeGetUniqueFromIndexSeekIT.java | 18 ++-- .../UniquenessConstraintValidationIT.java | 22 +++-- ...nstraintEnforcingEntityOperationsTest.java | 6 +- .../api/state/SchemaTransactionStateTest.java | 50 +++++------ .../util/dbstructure/CineastsDbStructure.java | 11 +-- .../dbstructure/DbStructureCollectorTest.java | 5 +- ...uctureInvocationTracingAcceptanceTest.java | 5 +- .../GraphDbStructureGuideTest.java | 12 ++- .../util/dbstructure/QMULDbStructure.java | 3 +- 51 files changed, 513 insertions(+), 461 deletions(-) diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundGraphStatistics.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundGraphStatistics.scala index 6a9789503b3c..2bb7968b4757 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundGraphStatistics.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v2_3/TransactionBoundGraphStatistics.scala @@ -22,9 +22,9 @@ package org.neo4j.cypher.internal.spi.v2_3 import org.neo4j.cypher.internal.compiler.v2_3.planner.logical.{Cardinality, Selectivity} import org.neo4j.cypher.internal.compiler.v2_3.spi.{GraphStatistics, StatisticsCompletingGraphStatistics} import org.neo4j.cypher.internal.frontend.v2_3.{LabelId, NameId, PropertyKeyId, RelTypeId} -import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException import org.neo4j.kernel.api.ReadOperations -import org.neo4j.kernel.api.schema.{IndexDescriptorFactory, NodePropertyDescriptor} +import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory object TransactionBoundGraphStatistics { def apply(ops: ReadOperations) = new StatisticsCompletingGraphStatistics(new BaseTransactionBoundGraphStatistics(ops)) @@ -35,11 +35,11 @@ object TransactionBoundGraphStatistics { def indexSelectivity(label: LabelId, property: PropertyKeyId): Option[Selectivity] = try { - val indexDescriptor = IndexDescriptorFactory.of( label, property ) + val indexDescriptor = NewIndexDescriptorFactory.forLabel( label, property ) val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble // Probability of any node with the given label, to have a property with a given value - val indexEntrySelectivity = operations.indexUniqueValuesSelectivity( indexDescriptor ) + val indexEntrySelectivity = operations.indexUniqueValuesSelectivity(indexDescriptor) val frequencyOfNodesWithSameValue = 1.0 / indexEntrySelectivity val indexSelectivity = frequencyOfNodesWithSameValue / labeledNodes @@ -51,11 +51,11 @@ object TransactionBoundGraphStatistics { def indexPropertyExistsSelectivity(label: LabelId, property: PropertyKeyId): Option[Selectivity] = try { - val indexDescriptor = IndexDescriptorFactory.of( label, property ) + val indexDescriptor = NewIndexDescriptorFactory.forLabel( label, property ) val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble // Probability of any node with the given label, to have a given property - val indexSize = operations.indexSize( indexDescriptor ) + val indexSize = operations.indexSize(indexDescriptor) val indexSelectivity = indexSize / labeledNodes Selectivity.of(indexSelectivity) diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/TransactionBoundGraphStatistics.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/TransactionBoundGraphStatistics.scala index 7a95ffd5fe22..d77be047fea1 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/TransactionBoundGraphStatistics.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_1/TransactionBoundGraphStatistics.scala @@ -39,7 +39,7 @@ object TransactionBoundGraphStatistics { val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble // Probability of any node with the given label, to have a property with a given value - val indexEntrySelectivity = operations.indexUniqueValuesSelectivity( indexDescriptor ) + val indexEntrySelectivity = operations.indexUniqueValuesSelectivity(indexDescriptor) val frequencyOfNodesWithSameValue = 1.0 / indexEntrySelectivity val indexSelectivity = frequencyOfNodesWithSameValue / labeledNodes @@ -55,7 +55,7 @@ object TransactionBoundGraphStatistics { val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble // Probability of any node with the given label, to have a given property - val indexSize = operations.indexSize( indexDescriptor ) + val indexSize = operations.indexSize(indexDescriptor) val indexSelectivity = indexSize / labeledNodes Selectivity.of(indexSelectivity) diff --git a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_2/TransactionBoundGraphStatistics.scala b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_2/TransactionBoundGraphStatistics.scala index 7a9f0c50b208..4ab30ffebc47 100644 --- a/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_2/TransactionBoundGraphStatistics.scala +++ b/community/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/spi/v3_2/TransactionBoundGraphStatistics.scala @@ -39,7 +39,7 @@ object TransactionBoundGraphStatistics { val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble // Probability of any node with the given label, to have a property with a given value - val indexEntrySelectivity = operations.indexUniqueValuesSelectivity( indexDescriptor ) + val indexEntrySelectivity = operations.indexUniqueValuesSelectivity(indexDescriptor) val frequencyOfNodesWithSameValue = 1.0 / indexEntrySelectivity val indexSelectivity = frequencyOfNodesWithSameValue / labeledNodes @@ -55,7 +55,7 @@ object TransactionBoundGraphStatistics { val labeledNodes = operations.countsForNodeWithoutTxState( label ).toDouble // Probability of any node with the given label, to have a given property - val indexSize = operations.indexSize( indexDescriptor ) + val indexSize = operations.indexSize(indexDescriptor) val indexSelectivity = indexSize / labeledNodes Selectivity.of(indexSelectivity) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java index cbaf5e91b15d..f9501f9ce64f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/ReadOperations.java @@ -49,6 +49,7 @@ import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.RelationshipVisitor; import org.neo4j.kernel.impl.api.store.RelationshipIterator; import org.neo4j.register.Register.DoubleLongRegister; @@ -266,39 +267,44 @@ void relationshipVisit( long relId, RelationshipVi //=========================================== /** Returns the index rule for the given labelId and propertyKey. */ - IndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) + NewIndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) throws SchemaRuleNotFoundException; /** Get all indexes for a label. */ - Iterator indexesGetForLabel( int labelId ); + Iterator indexesGetForLabel( int labelId ); /** Returns all indexes. */ - Iterator indexesGetAll(); + Iterator indexesGetAll(); /** Returns the constraint index for the given labelId and propertyKey. */ - IndexDescriptor uniqueIndexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) + NewIndexDescriptor uniqueIndexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException; /** Get all constraint indexes for a label. */ - Iterator uniqueIndexesGetForLabel( int labelId ); + Iterator uniqueIndexesGetForLabel( int labelId ); /** Returns all constraint indexes. */ - Iterator uniqueIndexesGetAll(); + Iterator uniqueIndexesGetAll(); - /** Retrieve the state of an index. */ - InternalIndexState indexGetState( IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + /** Retrieve the state of an index. + * @param descriptor*/ + InternalIndexState indexGetState( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; - /** Retrieve the population progress of an index. */ - PopulationProgress indexGetPopulationProgress( IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + /** Retrieve the population progress of an index. + * @param descriptor*/ + PopulationProgress indexGetPopulationProgress( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; - /** Get the index size. */ - long indexSize( IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + /** Get the index size. + * @param descriptor*/ + long indexSize( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; - /** Calculate the index unique values percentage (range: {@code 0.0} exclusive to {@code 1.0} inclusive). */ - double indexUniqueValuesSelectivity( IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + /** Calculate the index unique values percentage (range: {@code 0.0} exclusive to {@code 1.0} inclusive). + * @param descriptor*/ + double indexUniqueValuesSelectivity( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; - /** Returns the failure description of a failed index. */ - String indexGetFailure( IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + /** Returns the failure description of a failed index. + * @param descriptor*/ + String indexGetFailure( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; /** * Get all constraints applicable to label and propertyKey. There are only {@link NodePropertyConstraint} @@ -334,7 +340,7 @@ Iterator constraintsGetForRelationshipTypeAndPro /** * Get the owning constraint for a constraint index. Returns null if the index does not have an owning constraint. */ - Long indexGetOwningUniquenessConstraintId( IndexDescriptor index ) throws SchemaRuleNotFoundException; + Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) throws SchemaRuleNotFoundException; V schemaStateGetOrCreate( K key, Function creator ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/IndexBelongsToConstraintException.java b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/IndexBelongsToConstraintException.java index 918a957a646c..55a1ed421468 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/IndexBelongsToConstraintException.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/IndexBelongsToConstraintException.java @@ -19,26 +19,26 @@ */ package org.neo4j.kernel.api.exceptions.schema; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.exceptions.Status; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import static java.lang.String.format; public class IndexBelongsToConstraintException extends SchemaKernelException { - private final NodePropertyDescriptor index; + private final LabelSchemaDescriptor descriptor; private static final String message = "Index belongs to constraint: %s"; - public IndexBelongsToConstraintException( NodePropertyDescriptor index ) + public IndexBelongsToConstraintException( LabelSchemaDescriptor descriptor ) { - super( Status.Schema.ForbiddenOnConstraintIndex, format( "Index belongs to constraint: %s", index ) ); - this.index = index; + super( Status.Schema.ForbiddenOnConstraintIndex, format( "Index belongs to constraint: %s", descriptor ) ); + this.descriptor = descriptor; } @Override public String getUserMessage( TokenNameLookup tokenNameLookup ) { - return format( message, index.userDescription( tokenNameLookup ) ); + return format( message, descriptor.userDescription( tokenNameLookup ) ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/NoSuchIndexException.java b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/NoSuchIndexException.java index ba9972f6c281..bcb43e06d7d7 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/NoSuchIndexException.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/NoSuchIndexException.java @@ -19,20 +19,22 @@ */ package org.neo4j.kernel.api.exceptions.schema; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.exceptions.Status; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaUtil; import static java.lang.String.format; public class NoSuchIndexException extends SchemaKernelException { - private final NodePropertyDescriptor descriptor; + private final LabelSchemaDescriptor descriptor; private static final String message = "No such INDEX ON %s."; - public NoSuchIndexException( NodePropertyDescriptor descriptor ) + public NoSuchIndexException( LabelSchemaDescriptor descriptor ) { - super( Status.Schema.IndexNotFound, format( message, descriptor ) ); + super( Status.Schema.IndexNotFound, format( message, + descriptor.userDescription( SchemaUtil.idTokenNameLookup ) ) ); this.descriptor = descriptor; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/SchemaRuleException.java b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/SchemaRuleException.java index 13fb0ae89887..09024d5c8b76 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/SchemaRuleException.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/SchemaRuleException.java @@ -44,7 +44,7 @@ protected SchemaRuleException( Status status, String messageTemplate, SchemaRule SchemaDescriptor descriptor ) { super( status, format( messageTemplate, kind.userString().toLowerCase(), - descriptor.userDescription( SchemaUtil.noopTokenNameLookup ) ) ); + descriptor.userDescription( SchemaUtil.idTokenNameLookup ) ) ); this.descriptor = descriptor; this.messageTemplate = messageTemplate; this.kind = kind; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaUtil.java b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaUtil.java index b4c0caaf01e6..05d696b62791 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaUtil.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/api/schema_new/SchemaUtil.java @@ -21,6 +21,8 @@ import org.neo4j.kernel.api.TokenNameLookup; +import static java.lang.String.format; + public class SchemaUtil { private SchemaUtil() @@ -37,32 +39,24 @@ public static String niceProperties( TokenNameLookup tokenNameLookup, int[] prop return String.join( ", ", properties ); } - public static TokenNameLookup noopTokenNameLookup = new PrefixTokenName( "" ); - public static class PrefixTokenName implements TokenNameLookup - { - private final String prefix; - - public PrefixTokenName( String prefix ) - { - this.prefix = prefix; - } + public static TokenNameLookup idTokenNameLookup = new TokenNameLookup() { @Override public String labelGetName( int labelId ) { - return prefix + labelId; + return format( "label[%d]", labelId ); } @Override public String relationshipTypeGetName( int relationshipTypeId ) { - return prefix + relationshipTypeId; + return format( "relType[%d]", relationshipTypeId ); } @Override public String propertyKeyGetName( int propertyKeyId ) { - return prefix + propertyKeyId; + return format( "property[%d]", propertyKeyId ); } - } + }; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java index e31be84b8858..b68567998d6a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java @@ -38,6 +38,7 @@ import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.TokenAccess; import org.neo4j.kernel.impl.api.index.IndexingService; import org.neo4j.kernel.internal.GraphDatabaseAPI; @@ -101,15 +102,14 @@ public Stream listIndexes() throws ProcedureException ReadOperations operations = statement.readOperations(); TokenNameLookup tokens = new StatementTokenNameLookup( operations ); - List indexes = - asList( operations.indexesGetAll() ); + List indexes = asList( operations.indexesGetAll() ); - Set uniqueIndexes = asSet( operations.uniqueIndexesGetAll() ); + Set uniqueIndexes = asSet( operations.uniqueIndexesGetAll() ); indexes.addAll( uniqueIndexes ); indexes.sort( Comparator.comparing( a -> a.userDescription( tokens ) ) ); ArrayList result = new ArrayList<>(); - for ( IndexDescriptor index : indexes ) + for ( NewIndexDescriptor index : indexes ) { try { @@ -123,7 +123,7 @@ public Stream listIndexes() throws ProcedureException type = IndexType.NODE_LABEL_PROPERTY.typeName(); } - result.add( new IndexResult( "INDEX ON " + index.userDescription( tokens ), + result.add( new IndexResult( "INDEX ON " + index.schema().userDescription( tokens ), operations.indexGetState( index ).toString(), type ) ); } catch ( IndexNotFoundKernelException e ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java index 1dec036b9a4b..53aa569b2564 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java @@ -33,6 +33,8 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.index.InternalIndexState; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.index.IndexingService; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode; @@ -106,7 +108,7 @@ private int getPropertyKeyId( String propertyKeyName ) throws ProcedureException return propertyKeyId; } - private IndexDescriptor getIndex( int labelId, int propertyKeyId, IndexSpecifier index ) throws + private NewIndexDescriptor getIndex( int labelId, int propertyKeyId, IndexSpecifier index ) throws ProcedureException { try @@ -119,8 +121,8 @@ private IndexDescriptor getIndex( int labelId, int propertyKeyId, IndexSpecifier } } - private void waitUntilOnline( IndexDescriptor index, IndexSpecifier indexDescription, long timeout, TimeUnit - timeoutUnits ) + private void waitUntilOnline( NewIndexDescriptor index, IndexSpecifier indexDescription, + long timeout, TimeUnit timeoutUnits ) throws ProcedureException { try @@ -134,7 +136,7 @@ private void waitUntilOnline( IndexDescriptor index, IndexSpecifier indexDescrip } } - private boolean isOnline( IndexSpecifier indexDescription, IndexDescriptor index ) throws ProcedureException + private boolean isOnline( IndexSpecifier indexDescription, NewIndexDescriptor index ) throws ProcedureException { InternalIndexState state = getState( indexDescription, index ); switch ( state ) @@ -151,7 +153,7 @@ private boolean isOnline( IndexSpecifier indexDescription, IndexDescriptor index } } - private InternalIndexState getState( IndexSpecifier indexDescription, IndexDescriptor index ) + private InternalIndexState getState( IndexSpecifier indexDescription, NewIndexDescriptor index ) throws ProcedureException { try @@ -164,9 +166,9 @@ private InternalIndexState getState( IndexSpecifier indexDescription, IndexDescr } } - private void triggerSampling( IndexDescriptor index ) throws IndexNotFoundKernelException + private void triggerSampling( NewIndexDescriptor index ) throws IndexNotFoundKernelException { - indexingService.triggerIndexSampling( index, IndexSamplingMode.TRIGGER_REBUILD_ALL ); + indexingService.triggerIndexSampling( IndexBoundary.map( index ), IndexSamplingMode.TRIGGER_REBUILD_ALL ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaProcedure.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaProcedure.java index cedceeb5146a..46c4e8648df6 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaProcedure.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/SchemaProcedure.java @@ -44,6 +44,7 @@ import org.neo4j.kernel.api.StatementTokenNameLookup; import org.neo4j.kernel.api.constraints.NodePropertyConstraint; import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.coreapi.schema.PropertyNameUtils; import org.neo4j.kernel.internal.GraphDatabaseAPI; @@ -78,14 +79,14 @@ public GraphResult buildSchemaGraph() Label label = labelsInDatabase.next(); Map properties = new HashMap<>(); - Iterator indexDescriptorIterator = + Iterator indexDescriptorIterator = readOperations.indexesGetForLabel( readOperations.labelGetForName( label.name() ) ); ArrayList indexes = new ArrayList<>(); while ( indexDescriptorIterator.hasNext() ) { - IndexDescriptor index = indexDescriptorIterator.next(); - String[] propertyNames = - PropertyNameUtils.getPropertyKeys( statementTokenNameLookup, index.descriptor() ); + NewIndexDescriptor index = indexDescriptorIterator.next(); + String[] propertyNames = PropertyNameUtils.getPropertyKeys( + statementTokenNameLookup, index.schema().getPropertyIds() ); indexes.add( String.join( ",", propertyNames ) ); } properties.put( "indexes", indexes ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java index b8124e455d95..4e0d31a0f42f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/ConstraintEnforcingEntityOperations.java @@ -50,6 +50,8 @@ import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.operations.EntityOperations; import org.neo4j.kernel.impl.api.operations.EntityReadOperations; import org.neo4j.kernel.impl.api.operations.EntityWriteOperations; @@ -144,7 +146,7 @@ private void validateNoExistingNodeWithLabelAndProperty( KernelStatement state, { // TODO: Support composite constraints IndexDescriptor index = constraint.indexDescriptor(); - assertIndexOnline( state, index ); + assertIndexOnline( state, IndexBoundary.map( index ) ); state.locks().optimistic().acquireExclusive( state.lockTracer(), INDEX_ENTRY, indexEntryResourceId( index.getLabelId(), index.getPropertyKeyId(), Strings.prettyPrint( value ) ) ); @@ -163,7 +165,7 @@ private void validateNoExistingNodeWithLabelAndProperty( KernelStatement state, } } - private void assertIndexOnline( KernelStatement state, IndexDescriptor indexDescriptor ) + private void assertIndexOnline( KernelStatement state, NewIndexDescriptor indexDescriptor ) throws IndexNotFoundKernelException, IndexBrokenKernelException { switch ( schemaReadOperations.indexGetState( state, indexDescriptor ) ) @@ -311,7 +313,7 @@ public long nodeGetFromUniqueIndexSeek( Object value ) throws IndexNotFoundKernelException, IndexBrokenKernelException { - assertIndexOnline( state, index ); + assertIndexOnline( state, IndexBoundary.map( index ) ); // TODO: Support composite index, either by allowing value to be an array, or by creating a new method int labelId = index.getLabelId(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperations.java index 15e892bc9356..791d0636d5b7 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperations.java @@ -43,6 +43,9 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaKernelException.OperationContext; import org.neo4j.kernel.api.exceptions.schema.TooManyLabelsException; import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaBoundary; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.operations.KeyWriteOperations; import org.neo4j.kernel.impl.api.operations.SchemaReadOperations; import org.neo4j.kernel.impl.api.operations.SchemaWriteOperations; @@ -121,9 +124,10 @@ public void indexDrop( KernelStatement state, IndexDescriptor index ) throws Dro { try { - assertIsNotUniqueIndex( index, schemaReadDelegate.uniqueIndexesGetForLabel( + NewIndexDescriptor newIndex = IndexBoundary.map( index ); + assertIsNotUniqueIndex( newIndex, schemaReadDelegate.uniqueIndexesGetForLabel( state, index.getLabelId() ) ); - assertIndexExists( index, schemaReadDelegate.indexesGetForLabel( state, index.getLabelId() ) ); + assertIndexExists( newIndex, schemaReadDelegate.indexesGetForLabel( state, index.getLabelId() ) ); } catch ( IndexBelongsToConstraintException | NoSuchIndexException e ) { @@ -234,18 +238,19 @@ private void checkIndexExistence( KernelStatement state, OperationContext contex NodePropertyDescriptor descriptor ) throws AlreadyIndexedException, AlreadyConstrainedException { - for ( IndexDescriptor index : loop( schemaReadDelegate.indexesGetForLabel( state, descriptor.getLabelId() ) ) ) + for ( NewIndexDescriptor index : + loop( schemaReadDelegate.indexesGetForLabel( state, descriptor.getLabelId() ) ) ) { - if ( index.equals( descriptor ) ) + if ( SchemaBoundary.map( descriptor ).equals( index.schema() ) ) { - throw new AlreadyIndexedException( index.descriptor(), context ); + throw new AlreadyIndexedException( descriptor, context ); } } - for ( IndexDescriptor index : loop( - schemaReadDelegate.uniqueIndexesGetForLabel( state, descriptor.getLabelId() ) ) ) + for ( NewIndexDescriptor index : + loop( schemaReadDelegate.uniqueIndexesGetForLabel( state, descriptor.getLabelId() ) ) ) { - if ( index.equals( descriptor ) ) + if ( SchemaBoundary.map( descriptor ).equals( index.schema() ) ) { throw new AlreadyConstrainedException( new UniquenessConstraint( descriptor ), context, @@ -263,31 +268,30 @@ private String checkValidTokenName( String name ) throws IllegalTokenNameExcepti return name; } - private void assertIsNotUniqueIndex( IndexDescriptor index, Iterator uniqueIndexes ) + private void assertIsNotUniqueIndex( NewIndexDescriptor index, Iterator uniqueIndexes ) throws IndexBelongsToConstraintException { - while ( uniqueIndexes.hasNext() ) + for ( NewIndexDescriptor uniqueIndex : loop( uniqueIndexes ) ) { - IndexDescriptor uniqueIndex = uniqueIndexes.next(); if ( uniqueIndex.equals( index ) ) { - throw new IndexBelongsToConstraintException( index.descriptor() ); + throw new IndexBelongsToConstraintException( index.schema() ); } } } - private void assertIndexExists( IndexDescriptor index, Iterator indexes ) + private void assertIndexExists( NewIndexDescriptor index, Iterator indexes ) throws NoSuchIndexException { - for ( IndexDescriptor existing : loop( indexes ) ) + for ( NewIndexDescriptor existing : loop( indexes ) ) { if ( existing.equals( index ) ) { return; } } - throw new NoSuchIndexException( index.descriptor() ); + throw new NoSuchIndexException( index.schema() ); } private void assertConstraintExists( C constraint, Iterator existingConstraints ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LockingStatementOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LockingStatementOperations.java index 63978dfe8c6d..cb0c0cdb1935 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LockingStatementOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/LockingStatementOperations.java @@ -57,12 +57,9 @@ import org.neo4j.kernel.impl.api.operations.SchemaReadOperations; import org.neo4j.kernel.impl.api.operations.SchemaStateOperations; import org.neo4j.kernel.impl.api.operations.SchemaWriteOperations; -import org.neo4j.kernel.impl.locking.Locks; import org.neo4j.kernel.impl.locking.ResourceTypes; -import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.storageengine.api.lock.ResourceType; import org.neo4j.storageengine.api.schema.PopulationProgress; -import org.neo4j.storageengine.api.schema.SchemaRule; import static java.lang.Math.max; import static java.lang.Math.min; @@ -180,7 +177,7 @@ public void schemaStateFlush( KernelStatement state ) } @Override - public Iterator indexesGetForLabel( KernelStatement state, int labelId ) + public Iterator indexesGetForLabel( KernelStatement state, int labelId ) { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -188,7 +185,7 @@ public Iterator indexesGetForLabel( KernelStatement state, int } @Override - public IndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, NodePropertyDescriptor descriptor ) + public NewIndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, NodePropertyDescriptor descriptor ) { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -196,7 +193,7 @@ public IndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, No } @Override - public Iterator indexesGetAll( KernelStatement state ) + public Iterator indexesGetAll( KernelStatement state ) { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -204,7 +201,7 @@ public Iterator indexesGetAll( KernelStatement state ) } @Override - public InternalIndexState indexGetState( KernelStatement state, IndexDescriptor descriptor ) + public InternalIndexState indexGetState( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { acquireSharedSchemaLock( state ); @@ -213,7 +210,7 @@ public InternalIndexState indexGetState( KernelStatement state, IndexDescriptor } @Override - public PopulationProgress indexGetPopulationProgress( KernelStatement state, IndexDescriptor descriptor ) + public PopulationProgress indexGetPopulationProgress( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { acquireSharedSchemaLock( state ); @@ -222,7 +219,7 @@ public PopulationProgress indexGetPopulationProgress( KernelStatement state, Ind } @Override - public long indexSize( KernelStatement state, IndexDescriptor descriptor ) throws IndexNotFoundKernelException + public long indexSize( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -231,7 +228,7 @@ public long indexSize( KernelStatement state, IndexDescriptor descriptor ) throw @Override public double indexUniqueValuesPercentage( KernelStatement state, - IndexDescriptor descriptor ) throws IndexNotFoundKernelException + NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -239,7 +236,7 @@ public double indexUniqueValuesPercentage( KernelStatement state, } @Override - public Long indexGetOwningUniquenessConstraintId( KernelStatement state, IndexDescriptor index ) throws SchemaRuleNotFoundException + public Long indexGetOwningUniquenessConstraintId( KernelStatement state, NewIndexDescriptor index ) throws SchemaRuleNotFoundException { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -247,7 +244,7 @@ public Long indexGetOwningUniquenessConstraintId( KernelStatement state, IndexDe } @Override - public long indexGetCommittedId( KernelStatement state, IndexDescriptor index, Predicate filter ) + public long indexGetCommittedId( KernelStatement state, NewIndexDescriptor index, NewIndexDescriptor.Filter filter ) throws SchemaRuleNotFoundException { acquireSharedSchemaLock( state ); @@ -256,7 +253,7 @@ public long indexGetCommittedId( KernelStatement state, IndexDescriptor index, P } @Override - public Iterator uniqueIndexesGetForLabel( KernelStatement state, int labelId ) + public Iterator uniqueIndexesGetForLabel( KernelStatement state, int labelId ) { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -264,7 +261,7 @@ public Iterator uniqueIndexesGetForLabel( KernelStatement state } @Override - public Iterator uniqueIndexesGetAll( KernelStatement state ) + public Iterator uniqueIndexesGetAll( KernelStatement state ) { acquireSharedSchemaLock( state ); state.assertOpen(); @@ -533,7 +530,7 @@ public void releaseShared( KernelStatement state, ResourceType type, long resour // === TODO Below is unnecessary delegate methods @Override - public String indexGetFailure( Statement state, IndexDescriptor descriptor ) + public String indexGetFailure( Statement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { return schemaReadDelegate.indexGetFailure( state, descriptor ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java index db6b6907ccc5..9e0b7a78e86f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/OperationsFacade.java @@ -82,7 +82,9 @@ import org.neo4j.kernel.api.proc.UserFunctionSignature; import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.schema_new.SchemaBoundary; import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.api.security.AccessMode; import org.neo4j.kernel.api.security.SecurityContext; import org.neo4j.kernel.impl.api.operations.CountsOperations; @@ -612,11 +614,11 @@ public Cursor relationshipCursorById( long relId ) throws Enti // @Override - public IndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) + public NewIndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) throws SchemaRuleNotFoundException { statement.assertOpen(); - IndexDescriptor indexDescriptor = schemaRead().indexGetForLabelAndPropertyKey( statement, descriptor ); + NewIndexDescriptor indexDescriptor = schemaRead().indexGetForLabelAndPropertyKey( statement, descriptor ); if ( indexDescriptor == null ) { throw new SchemaRuleNotFoundException( SchemaRule.Kind.INDEX_RULE, @@ -626,30 +628,30 @@ public IndexDescriptor indexGetForLabelAndPropertyKey( NodePropertyDescriptor de } @Override - public Iterator indexesGetForLabel( int labelId ) + public Iterator indexesGetForLabel( int labelId ) { statement.assertOpen(); return schemaRead().indexesGetForLabel( statement, labelId ); } @Override - public Iterator indexesGetAll() + public Iterator indexesGetAll() { statement.assertOpen(); return schemaRead().indexesGetAll( statement ); } @Override - public IndexDescriptor uniqueIndexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) + public NewIndexDescriptor uniqueIndexGetForLabelAndPropertyKey( NodePropertyDescriptor descriptor ) throws SchemaRuleNotFoundException, DuplicateSchemaRuleException { - IndexDescriptor result = null; - Iterator indexes = uniqueIndexesGetForLabel( descriptor.getLabelId() ); + NewIndexDescriptor result = null; + Iterator indexes = uniqueIndexesGetForLabel( descriptor.getLabelId() ); while ( indexes.hasNext() ) { - IndexDescriptor index = indexes.next(); - if ( index.equals( descriptor ) ) + NewIndexDescriptor index = indexes.next(); + if ( index.schema().equals( SchemaBoundary.map( descriptor ) ) ) { if ( null == result ) { @@ -657,8 +659,7 @@ public IndexDescriptor uniqueIndexGetForLabelAndPropertyKey( NodePropertyDescrip } else { - throw new DuplicateSchemaRuleException( SchemaRule.Kind.CONSTRAINT_INDEX_RULE, - SchemaDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() ) ); + throw new DuplicateSchemaRuleException( SchemaRule.Kind.CONSTRAINT_INDEX_RULE, index.schema() ); } } } @@ -673,56 +674,56 @@ public IndexDescriptor uniqueIndexGetForLabelAndPropertyKey( NodePropertyDescrip } @Override - public Iterator uniqueIndexesGetForLabel( int labelId ) + public Iterator uniqueIndexesGetForLabel( int labelId ) { statement.assertOpen(); return schemaRead().uniqueIndexesGetForLabel( statement, labelId ); } @Override - public Long indexGetOwningUniquenessConstraintId( IndexDescriptor index ) throws SchemaRuleNotFoundException + public Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) throws SchemaRuleNotFoundException { statement.assertOpen(); return schemaRead().indexGetOwningUniquenessConstraintId( statement, index ); } @Override - public Iterator uniqueIndexesGetAll() + public Iterator uniqueIndexesGetAll() { statement.assertOpen(); return schemaRead().uniqueIndexesGetAll( statement ); } @Override - public InternalIndexState indexGetState( IndexDescriptor descriptor ) throws IndexNotFoundKernelException + public InternalIndexState indexGetState( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { statement.assertOpen(); return schemaRead().indexGetState( statement, descriptor ); } @Override - public PopulationProgress indexGetPopulationProgress( IndexDescriptor descriptor ) throws IndexNotFoundKernelException + public PopulationProgress indexGetPopulationProgress( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { statement.assertOpen(); return schemaRead().indexGetPopulationProgress( statement, descriptor ); } @Override - public long indexSize( IndexDescriptor descriptor ) throws IndexNotFoundKernelException + public long indexSize( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { statement.assertOpen(); return schemaRead().indexSize( statement, descriptor ); } @Override - public double indexUniqueValuesSelectivity( IndexDescriptor descriptor ) throws IndexNotFoundKernelException + public double indexUniqueValuesSelectivity( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { statement.assertOpen(); return schemaRead().indexUniqueValuesPercentage( statement, descriptor ); } @Override - public String indexGetFailure( IndexDescriptor descriptor ) throws IndexNotFoundKernelException + public String indexGetFailure( NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { statement.assertOpen(); return schemaRead().indexGetFailure( statement, descriptor ); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java index 8be1ad33e18d..dc2f5b75145e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/StateHandlingStatementOperations.java @@ -28,7 +28,6 @@ import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongResourceIterator; import org.neo4j.cursor.Cursor; -import org.neo4j.helpers.collection.Iterators; import org.neo4j.kernel.api.DataWriteOperations; import org.neo4j.kernel.api.LegacyIndex; import org.neo4j.kernel.api.LegacyIndexHits; @@ -87,7 +86,6 @@ import org.neo4j.kernel.impl.api.store.RelationshipIterator; import org.neo4j.kernel.impl.index.IndexEntityType; import org.neo4j.kernel.impl.index.LegacyIndexStore; -import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.kernel.impl.util.Validators; import org.neo4j.register.Register.DoubleLongRegister; import org.neo4j.storageengine.api.EntityType; @@ -306,7 +304,7 @@ public boolean nodeAddLabel( KernelStatement state, long nodeId, int labelId ) t PropertyItem propertyItem = properties.get(); NodePropertyDescriptor nodePropDescriptor = new NodePropertyDescriptor( labelId, propertyItem.propertyKeyId() ); - IndexDescriptor descriptor = indexGetForLabelAndPropertyKey( state, nodePropDescriptor ); + NewIndexDescriptor descriptor = indexGetForLabelAndPropertyKey( state, nodePropDescriptor ); if ( descriptor != null ) { DefinedProperty after = Property.property( propertyItem.propertyKeyId(), @@ -532,12 +530,12 @@ public void constraintDrop( KernelStatement state, RelationshipPropertyConstrain } @Override - public IndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, NodePropertyDescriptor descriptor ) + public NewIndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, NodePropertyDescriptor descriptor ) { return indexGetForLabelAndPropertyKey( state, SchemaBoundary.map( descriptor ) ); } - private IndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, LabelSchemaDescriptor descriptor ) + private NewIndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, LabelSchemaDescriptor descriptor ) { NewIndexDescriptor indexDescriptor = storeLayer.indexGetForLabelAndPropertyKey( descriptor ); Iterator rules = iterator( indexDescriptor ); @@ -547,41 +545,42 @@ private IndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, L descriptor::isSame, state.txState().indexDiffSetsByLabel( descriptor.getLabelId(), GENERAL ).apply( rules ) ); } - return singleOrNull( IndexBoundary.map( rules ) ); + return singleOrNull( rules ); } @Override - public InternalIndexState indexGetState( KernelStatement state, IndexDescriptor descriptor ) + public InternalIndexState indexGetState( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { // If index is in our state, then return populating if ( state.hasTxStateWithChanges() ) { - if ( checkIndexState( IndexBoundary.map( descriptor ), - state.txState().indexDiffSetsByLabel( descriptor.getLabelId(), NewIndexDescriptor.Filter.ANY ) ) ) + if ( checkIndexState( descriptor, state.txState().indexDiffSetsByLabel( descriptor.schema().getLabelId(), + NewIndexDescriptor.Filter.ANY ) ) ) { return InternalIndexState.POPULATING; } } - return storeLayer.indexGetState( SchemaBoundary.map( descriptor.descriptor() ) ); + return storeLayer.indexGetState( descriptor.schema() ); } @Override - public PopulationProgress indexGetPopulationProgress( KernelStatement state, IndexDescriptor descriptor ) throws + public PopulationProgress indexGetPopulationProgress( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { // If index is in our state, then return 0% if ( state.hasTxStateWithChanges() ) { - if ( checkIndexState( IndexBoundary.map( descriptor ), - state.txState().indexDiffSetsByLabel( descriptor.getLabelId(), NewIndexDescriptor.Filter.ANY ) ) ) + if ( checkIndexState( descriptor, + state.txState().indexDiffSetsByLabel( descriptor.schema().getLabelId(), + NewIndexDescriptor.Filter.ANY ) ) ) { return PopulationProgress.NONE; } } - return storeLayer.indexGetPopulationProgress( SchemaBoundary.map( descriptor.descriptor() ) ); + return storeLayer.indexGetPopulationProgress( descriptor.schema() ); } private boolean checkIndexState( NewIndexDescriptor index, ReadableDiffSets diffSet ) @@ -594,58 +593,54 @@ private boolean checkIndexState( NewIndexDescriptor index, ReadableDiffSets indexesGetForLabel( KernelStatement state, int labelId ) + public Iterator indexesGetForLabel( KernelStatement state, int labelId ) { if ( state.hasTxStateWithChanges() ) { - return IndexBoundary.map( state.txState().indexDiffSetsByLabel( labelId, GENERAL ) - .apply( storeLayer.indexesGetForLabel( labelId ) ) ); + return state.txState().indexDiffSetsByLabel( labelId, GENERAL ) + .apply( storeLayer.indexesGetForLabel( labelId ) ); } - return IndexBoundary.map( storeLayer.indexesGetForLabel( labelId ) ); + return storeLayer.indexesGetForLabel( labelId ); } @Override - public Iterator indexesGetAll( KernelStatement state ) + public Iterator indexesGetAll( KernelStatement state ) { if ( state.hasTxStateWithChanges() ) { - return IndexBoundary.map( state.txState().indexChanges( GENERAL ).apply( storeLayer.indexesGetAll() ) ); + return state.txState().indexChanges( GENERAL ).apply( storeLayer.indexesGetAll() ); } - return IndexBoundary.map( storeLayer.indexesGetAll() ); + return storeLayer.indexesGetAll(); } @Override - public Iterator uniqueIndexesGetForLabel( KernelStatement state, int labelId ) + public Iterator uniqueIndexesGetForLabel( KernelStatement state, int labelId ) { if ( state.hasTxStateWithChanges() ) { - return IndexBoundary.map( - state.txState().indexDiffSetsByLabel( labelId, UNIQUE ) - .apply( storeLayer.uniquenessIndexesGetForLabel( labelId ) ) - ); + return state.txState().indexDiffSetsByLabel( labelId, UNIQUE ) + .apply( storeLayer.uniquenessIndexesGetForLabel( labelId ) ); } - return IndexBoundary.map( storeLayer.uniquenessIndexesGetForLabel( labelId ) ); + return storeLayer.uniquenessIndexesGetForLabel( labelId ); } @Override - public Iterator uniqueIndexesGetAll( KernelStatement state ) + public Iterator uniqueIndexesGetAll( KernelStatement state ) { if ( state.hasTxStateWithChanges() ) { - return IndexBoundary.map( - state.txState().indexChanges( UNIQUE ).apply( storeLayer.uniquenessIndexesGetAll() ) - ); + return state.txState().indexChanges( UNIQUE ).apply( storeLayer.uniquenessIndexesGetAll() ); } - return IndexBoundary.map( storeLayer.uniquenessIndexesGetAll() ); + return storeLayer.uniquenessIndexesGetAll(); } @Override @@ -1017,7 +1012,7 @@ private void indexUpdateProperty( KernelStatement state, long nodeId, LabelSchem DefinedProperty before, DefinedProperty after ) { // TODO: Update this to handle composite indexes - IndexDescriptor indexDescriptor = indexGetForLabelAndPropertyKey( state, descriptor ); + NewIndexDescriptor indexDescriptor = indexGetForLabelAndPropertyKey( state, descriptor ); if ( descriptor != null && indexDescriptor != null ) { if (after != null) @@ -1134,17 +1129,17 @@ public long countsForRelationshipWithoutTxState( KernelStatement statement, int } @Override - public long indexSize( KernelStatement statement, IndexDescriptor descriptor ) + public long indexSize( KernelStatement statement, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { - return storeLayer.indexSize( SchemaBoundary.map( descriptor.descriptor() ) ); + return storeLayer.indexSize( descriptor.schema() ); } @Override - public double indexUniqueValuesPercentage( KernelStatement statement, IndexDescriptor descriptor ) + public double indexUniqueValuesPercentage( KernelStatement statement, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { - return storeLayer.indexUniqueValuesPercentage( SchemaBoundary.map( descriptor.descriptor() ) ); + return storeLayer.indexUniqueValuesPercentage( descriptor.schema() ); } @Override @@ -1166,24 +1161,24 @@ public DoubleLongRegister indexSample( KernelStatement statement, IndexDescripto // @Override - public Long indexGetOwningUniquenessConstraintId( KernelStatement state, IndexDescriptor index ) + public Long indexGetOwningUniquenessConstraintId( KernelStatement state, NewIndexDescriptor index ) throws SchemaRuleNotFoundException { - return storeLayer.indexGetOwningUniquenessConstraintId( IndexBoundary.map( index ) ); + return storeLayer.indexGetOwningUniquenessConstraintId( index ); } @Override - public long indexGetCommittedId( KernelStatement state, IndexDescriptor index, Predicate filter ) + public long indexGetCommittedId( KernelStatement state, NewIndexDescriptor index, NewIndexDescriptor.Filter filter ) throws SchemaRuleNotFoundException { - return storeLayer.indexGetCommittedId( IndexBoundary.map( index ), filter ); + return storeLayer.indexGetCommittedId( index, filter ); } @Override - public String indexGetFailure( Statement state, IndexDescriptor descriptor ) + public String indexGetFailure( Statement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException { - return storeLayer.indexGetFailure( SchemaBoundary.map( descriptor.descriptor() ) ); + return storeLayer.indexGetFailure( descriptor.schema() ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/RemoveOrphanConstraintIndexesOnStartup.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/RemoveOrphanConstraintIndexesOnStartup.java index e1256b191540..777475c6234c 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/RemoveOrphanConstraintIndexesOnStartup.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/index/RemoveOrphanConstraintIndexesOnStartup.java @@ -19,16 +19,16 @@ */ package org.neo4j.kernel.impl.api.index; -import java.util.Iterator; - import org.neo4j.kernel.api.KernelAPI; import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.exceptions.KernelException; -import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.logging.Log; import org.neo4j.logging.LogProvider; +import static org.neo4j.helpers.collection.Iterators.loop; import static org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED; /** @@ -52,14 +52,12 @@ public void perform() try ( KernelTransaction transaction = kernel.newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); Statement statement = transaction.acquireStatement() ) { - for ( Iterator indexes = statement.readOperations().uniqueIndexesGetAll(); - indexes.hasNext(); ) + for ( NewIndexDescriptor index : loop( statement.readOperations().uniqueIndexesGetAll() ) ) { - IndexDescriptor index = indexes.next(); if ( statement.readOperations().indexGetOwningUniquenessConstraintId( index ) == null ) { log.info( "Removing orphan constraint index: " + index ); - statement.schemaWriteOperations().uniqueIndexDrop( index ); + statement.schemaWriteOperations().uniqueIndexDrop( IndexBoundary.map( index ) ); } } transaction.success(); diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/SchemaReadOperations.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/SchemaReadOperations.java index 369dfb41c2fd..d2cdb7141f2e 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/SchemaReadOperations.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/operations/SchemaReadOperations.java @@ -30,66 +30,63 @@ import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; -import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.KernelStatement; -import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.storageengine.api.schema.PopulationProgress; -import org.neo4j.storageengine.api.schema.SchemaRule; public interface SchemaReadOperations { /** * Returns the descriptor for the given labelId and propertyKey. */ - IndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, NodePropertyDescriptor descriptor ); + NewIndexDescriptor indexGetForLabelAndPropertyKey( KernelStatement state, NodePropertyDescriptor descriptor ); /** * Get all indexes for a label. */ - Iterator indexesGetForLabel( KernelStatement state, int labelId ); + Iterator indexesGetForLabel( KernelStatement state, int labelId ); /** * Returns all indexes. */ - Iterator indexesGetAll( KernelStatement state ); + Iterator indexesGetAll( KernelStatement state ); /** * Get all constraint indexes for a label. */ - Iterator uniqueIndexesGetForLabel( KernelStatement state, int labelId ); + Iterator uniqueIndexesGetForLabel( KernelStatement state, int labelId ); /** * Returns all constraint indexes. */ - Iterator uniqueIndexesGetAll( KernelStatement state ); + Iterator uniqueIndexesGetAll( KernelStatement state ); /** * Retrieve the state of an index. */ - InternalIndexState indexGetState( KernelStatement state, IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + InternalIndexState indexGetState( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; /** * Retrieve the population progress of an index. */ - PopulationProgress indexGetPopulationProgress( KernelStatement state, IndexDescriptor descriptor ) throws + PopulationProgress indexGetPopulationProgress( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; /** * Get the index size. **/ - long indexSize( KernelStatement state, IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + long indexSize( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; /** * Calculate the index unique values percentage. **/ - double indexUniqueValuesPercentage( KernelStatement state, IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + double indexUniqueValuesPercentage( KernelStatement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; /** * Returns the failure description of a failed index. */ - String indexGetFailure( Statement state, IndexDescriptor descriptor ) throws IndexNotFoundKernelException; + String indexGetFailure( Statement state, NewIndexDescriptor descriptor ) throws IndexNotFoundKernelException; /** * Get all constraints applicable to label and propertyKeys. There are only {@link NodePropertyConstraint} @@ -126,12 +123,12 @@ Iterator constraintsGetForRelationshipTypeAndPro /** * Get the owning constraint for a constraint index. Returns null if the index does not have an owning constraint. */ - Long indexGetOwningUniquenessConstraintId( KernelStatement state, IndexDescriptor index ) throws SchemaRuleNotFoundException; + Long indexGetOwningUniquenessConstraintId( KernelStatement state, NewIndexDescriptor index ) throws SchemaRuleNotFoundException; /** * Get the index id (the id or the schema rule record) for a committed index * - throws exception for indexes that aren't committed. */ - long indexGetCommittedId( KernelStatement state, IndexDescriptor index, Predicate filter ) + long indexGetCommittedId( KernelStatement state, NewIndexDescriptor index, NewIndexDescriptor.Filter filter ) throws SchemaRuleNotFoundException; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/ConstraintIndexCreator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/ConstraintIndexCreator.java index 1b3bf0ffc6e4..e5b8485f85eb 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/ConstraintIndexCreator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/state/ConstraintIndexCreator.java @@ -68,7 +68,7 @@ public long createUniquenessConstraintIndex( KernelStatement state, SchemaReadOp boolean success = false; try { - long indexId = schema.indexGetCommittedId( state, IndexBoundary.map( index ), NewIndexDescriptor.Filter.UNIQUE ); + long indexId = schema.indexGetCommittedId( state, index, NewIndexDescriptor.Filter.UNIQUE ); awaitConstrainIndexPopulation( constraint, indexId ); success = true; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java index 16c9823eb4b5..2c63afd764c7 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/api/store/StorageLayer.java @@ -216,7 +216,7 @@ public Iterator uniquenessIndexesGetAll() @Override public Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) throws SchemaRuleNotFoundException { - IndexRule rule = indexRule( index, Predicates.alwaysTrue() ); + IndexRule rule = indexRule( index, NewIndexDescriptor.Filter.ANY ); if ( rule != null ) { return rule.getOwningConstraint(); @@ -225,7 +225,7 @@ public Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) thr } @Override - public long indexGetCommittedId( NewIndexDescriptor index, Predicate filter ) + public long indexGetCommittedId( NewIndexDescriptor index, NewIndexDescriptor.Filter filter ) throws SchemaRuleNotFoundException { IndexRule rule = indexRule( index, filter ); @@ -519,11 +519,11 @@ public void degrees( StorageStatement statement, NodeItem nodeItem, DegreeVisito } } - private IndexRule indexRule( NewIndexDescriptor index, Predicate filter ) + private IndexRule indexRule( NewIndexDescriptor index, NewIndexDescriptor.Filter filter ) { for ( IndexRule rule : schemaCache.indexRules() ) { - if ( filter.test( rule ) && rule.getSchemaDescriptor().equals( index.schema() ) ) + if ( filter.test( rule.getIndexDescriptor() ) && rule.schema().equals( index.schema() ) ) { return rule; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/PropertyNameUtils.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/PropertyNameUtils.java index 7125f2ca7452..85622350b71f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/PropertyNameUtils.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/PropertyNameUtils.java @@ -21,24 +21,14 @@ import java.util.ArrayList; -import org.neo4j.graphdb.Label; -import org.neo4j.graphdb.NotFoundException; import org.neo4j.graphdb.schema.IndexDefinition; import org.neo4j.helpers.collection.Iterables; -import org.neo4j.kernel.api.TokenWriteOperations; -import org.neo4j.kernel.api.schema.IndexDescriptorFactory; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.ReadOperations; -import org.neo4j.kernel.api.SchemaWriteOperations; import org.neo4j.kernel.api.TokenNameLookup; +import org.neo4j.kernel.api.TokenWriteOperations; import org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException; import org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException; -import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; -import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.impl.api.operations.KeyReadOperations; - -import static java.lang.String.format; -import static java.util.Arrays.asList; +import org.neo4j.kernel.api.schema.NodePropertyDescriptor; public class PropertyNameUtils { @@ -46,59 +36,6 @@ private PropertyNameUtils() { } - private static String getPropertyKeyNameAt( Iterable properties, int propertyKeyIndex ) - { - for ( String propertyKey : properties ) - { - if ( propertyKeyIndex == 0 ) - { - return propertyKey; - } - propertyKeyIndex--; - } - return null; - } - - static IndexDescriptor getIndexDescriptor( ReadOperations readOperations, IndexDefinition index ) - throws SchemaRuleNotFoundException - { - int labelId = readOperations.labelGetForName( index.getLabel().name() ); - int[] propertyKeyIds = getPropertyKeyIds( readOperations, index.getPropertyKeys() ); - NodePropertyDescriptor descriptor = - checkValidLabelAndProperties( index.getLabel(), labelId, propertyKeyIds, index.getPropertyKeys() ); - return readOperations.indexGetForLabelAndPropertyKey( descriptor ); - } - - private static NodePropertyDescriptor checkValidLabelAndProperties( Label label, int labelId, int[] propertyKeyIds, - Iterable properties ) - { - if ( labelId == KeyReadOperations.NO_SUCH_LABEL ) - { - throw new NotFoundException( format( "Label %s not found", label.name() ) ); - } - - for ( int i = 0; i < propertyKeyIds.length; i++ ) - { - if ( propertyKeyIds[i] == KeyReadOperations.NO_SUCH_PROPERTY_KEY ) - { - throw new NotFoundException( - format( "Property key %s not found", getPropertyKeyNameAt( properties, i ) ) ); - } - } - return IndexDescriptorFactory.getNodePropertyDescriptor( labelId, propertyKeyIds ); - } - - static IndexDescriptor getIndexDescriptor( ReadOperations readOperations, Label label, - String[] propertyKeys ) - throws SchemaRuleNotFoundException - { - int labelId = readOperations.labelGetForName( label.name() ); - int[] propertyKeyIds = getPropertyKeyIds( readOperations, propertyKeys ); - NodePropertyDescriptor descriptor = - checkValidLabelAndProperties( label, labelId, propertyKeyIds, asList( propertyKeys ) ); - return readOperations.indexGetForLabelAndPropertyKey( descriptor ); - } - public static String[] getPropertyKeys( ReadOperations readOperations, NodePropertyDescriptor descriptor ) throws PropertyKeyIdNotFoundKernelException { @@ -124,6 +61,27 @@ public static String[] getPropertyKeys( TokenNameLookup tokenNameLookup, NodePro return propertyKeys; } + public static String[] getPropertyKeys( ReadOperations readOperations, int[] propertyIds ) + throws PropertyKeyIdNotFoundKernelException + { + String[] propertyKeys = new String[propertyIds.length]; + for ( int i = 0; i < propertyIds.length; i++ ) + { + propertyKeys[i] = readOperations.propertyKeyGetName( propertyIds[i] ); + } + return propertyKeys; + } + + public static String[] getPropertyKeys( TokenNameLookup tokenNameLookup, int[] propertyIds ) + { + String[] propertyKeys = new String[propertyIds.length]; + for ( int i = 0; i < propertyIds.length; i++ ) + { + propertyKeys[i] = tokenNameLookup.propertyKeyGetName( propertyIds[i] ); + } + return propertyKeys; + } + public static int[] getPropertyKeyIds( ReadOperations statement, String[] propertyKeys ) { int[] propertyKeyIds = new int[propertyKeys.length]; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java index d0e4ef664b67..cdc42709052a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java @@ -37,9 +37,8 @@ import org.neo4j.graphdb.schema.IndexCreator; import org.neo4j.graphdb.schema.IndexDefinition; import org.neo4j.graphdb.schema.Schema; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.helpers.collection.Iterables; import org.neo4j.kernel.api.ReadOperations; -import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.StatementTokenNameLookup; import org.neo4j.kernel.api.constraints.NodePropertyConstraint; @@ -61,9 +60,12 @@ import org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException; import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; import org.neo4j.kernel.api.exceptions.schema.TooManyLabelsException; -import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.index.InternalIndexState; +import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.operations.KeyReadOperations; import org.neo4j.storageengine.api.schema.PopulationProgress; @@ -77,7 +79,6 @@ import static org.neo4j.helpers.collection.Iterators.asCollection; import static org.neo4j.helpers.collection.Iterators.map; import static org.neo4j.kernel.api.schema.IndexDescriptorFactory.getOrCreateTokens; -import static org.neo4j.kernel.impl.coreapi.schema.PropertyNameUtils.getIndexDescriptor; import static org.neo4j.kernel.impl.coreapi.schema.PropertyNameUtils.getPropertyKeys; public class SchemaImpl implements Schema @@ -126,14 +127,14 @@ public Iterable getIndexes() } } - private IndexDefinition descriptorToDefinition( final ReadOperations statement, IndexDescriptor index, + private IndexDefinition descriptorToDefinition( final ReadOperations statement, NewIndexDescriptor index, final boolean constraintIndex ) { try { - Label label = label( statement.labelGetName( index.getLabelId() ) ); + Label label = label( statement.labelGetName( index.schema().getLabelId() ) ); return new IndexDefinitionImpl( actions, label, - getPropertyKeys( statement, index.descriptor() ), constraintIndex ); + PropertyNameUtils.getPropertyKeys( statement, index.schema().getPropertyIds() ), constraintIndex ); } catch ( LabelNotFoundKernelException | PropertyKeyIdNotFoundKernelException e ) { @@ -142,7 +143,7 @@ private IndexDefinition descriptorToDefinition( final ReadOperations statement, } private void addDefinitions( List definitions, final ReadOperations statement, - Iterator indexes, final boolean constraintIndex ) + Iterator indexes, final boolean constraintIndex ) { addToCollection( map( index -> descriptorToDefinition( statement, index, constraintIndex ), indexes ), @@ -208,8 +209,9 @@ public IndexState getIndexState( final IndexDefinition index ) actions.assertInOpenTransaction(); try ( Statement statement = statementContextSupplier.get() ) { - IndexDescriptor descriptor = getIndexDescriptor( statement.readOperations(), index ); - InternalIndexState indexState = statement.readOperations().indexGetState( descriptor ); + ReadOperations readOps = statement.readOperations(); + NewIndexDescriptor descriptor = getIndexDescriptor( readOps, index ); + InternalIndexState indexState = readOps.indexGetState( descriptor ); switch ( indexState ) { case POPULATING: @@ -235,8 +237,9 @@ public IndexPopulationProgress getIndexPopulationProgress( IndexDefinition index actions.assertInOpenTransaction(); try ( Statement statement = statementContextSupplier.get() ) { - IndexDescriptor descriptor = getIndexDescriptor( statement.readOperations(), index ); - PopulationProgress progress = statement.readOperations().indexGetPopulationProgress( descriptor ); + ReadOperations readOps = statement.readOperations(); + NewIndexDescriptor descriptor = getIndexDescriptor( readOps, index ); + PopulationProgress progress = readOps.indexGetPopulationProgress( descriptor ); return new IndexPopulationProgress( progress.getCompleted(), progress.getTotal() ); } catch ( SchemaRuleNotFoundException | IndexNotFoundKernelException e ) @@ -252,8 +255,9 @@ public String getIndexFailure( IndexDefinition index ) actions.assertInOpenTransaction(); try ( Statement statement = statementContextSupplier.get() ) { - IndexDescriptor descriptor = getIndexDescriptor( statement.readOperations(), index ); - return statement.readOperations().indexGetFailure( descriptor ); + ReadOperations readOps = statement.readOperations(); + NewIndexDescriptor descriptor = getIndexDescriptor( readOps, index ); + return readOps.indexGetFailure( descriptor ); } catch ( SchemaRuleNotFoundException | IndexNotFoundKernelException e ) { @@ -314,6 +318,37 @@ public Iterable getConstraints( RelationshipType type ) } } + private static NewIndexDescriptor getIndexDescriptor( ReadOperations readOperations, IndexDefinition index ) + throws SchemaRuleNotFoundException + { + int labelId = readOperations.labelGetForName( index.getLabel().name() ); + int[] propertyKeyIds = PropertyNameUtils.getPropertyKeyIds( readOperations, index.getPropertyKeys() ); + assertValidLabel( index.getLabel(), labelId ); + assertValidProperties( index.getPropertyKeys(), propertyKeyIds ); + return readOperations.indexGetForLabelAndPropertyKey( + IndexDescriptorFactory.getNodePropertyDescriptor( labelId, propertyKeyIds ) ); + } + + private static void assertValidLabel( Label label, int labelId ) + { + if ( labelId == KeyReadOperations.NO_SUCH_LABEL ) + { + throw new NotFoundException( format( "Label %s not found", label.name() ) ); + } + } + + private static void assertValidProperties( Iterable properties , int[] propertyIds ) + { + for ( int i = 0; i < propertyIds.length; i++ ) + { + if ( propertyIds[i] == KeyReadOperations.NO_SUCH_PROPERTY_KEY ) + { + throw new NotFoundException( + format( "Property key %s not found", Iterables.asArray( String.class, properties )[i] ) ); + } + } + } + private Iterable asConstraintDefinitions( Iterator constraints, ReadOperations readOperations ) { @@ -414,8 +449,8 @@ public void dropIndexDefinitions( IndexDefinition indexDefinition ) { try { - statement.schemaWriteOperations() - .indexDrop( getIndexDescriptor( statement.readOperations(), indexDefinition ) ); + statement.schemaWriteOperations().indexDrop( + IndexBoundary.map( getIndexDescriptor( statement.readOperations(), indexDefinition ) ) ); } catch ( NotFoundException e ) { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/GraphDatabaseFacade.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/GraphDatabaseFacade.java index 323ca572af32..d43d38f39a69 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/GraphDatabaseFacade.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/factory/GraphDatabaseFacade.java @@ -71,6 +71,8 @@ import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.legacyindex.AutoIndexing; import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.api.security.SecurityContext; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.guard.Guard; @@ -612,13 +614,13 @@ private IndexDescriptor findAnyIndexByLabelAndProperty( ReadOperations readOps, { try { - IndexDescriptor descriptor = + NewIndexDescriptor descriptor = readOps.indexGetForLabelAndPropertyKey( new NodePropertyDescriptor( labelId, propertyId ) ); if ( readOps.indexGetState( descriptor ) == InternalIndexState.ONLINE ) { // Ha! We found an index - let's use it to find matching nodes - return descriptor; + return IndexBoundary.map( descriptor ); } } catch ( SchemaRuleNotFoundException | IndexNotFoundKernelException e ) diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java index 98e5c20dc460..29cc680a5997 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/ConstraintRule.java @@ -25,7 +25,7 @@ import org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor; import org.neo4j.storageengine.api.schema.SchemaRule; -import static org.neo4j.kernel.api.schema_new.SchemaUtil.noopTokenNameLookup; +import static org.neo4j.kernel.api.schema_new.SchemaUtil.idTokenNameLookup; public class ConstraintRule implements SchemaRule, ConstraintDescriptor.Supplier { @@ -61,7 +61,7 @@ public static ConstraintRule constraintRule( @Override public String toString() { - return "ConstraintRule[id=" + id + ", descriptor=" + descriptor.userDescription( noopTokenNameLookup ) + ", " + + return "ConstraintRule[id=" + id + ", descriptor=" + descriptor.userDescription( idTokenNameLookup ) + ", " + "ownedIndex=" + ownedIndexRule + "]"; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java index c627c84add8d..12559f2c4a4a 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/store/record/IndexRule.java @@ -27,7 +27,7 @@ import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.storageengine.api.schema.SchemaRule; -import static org.neo4j.kernel.api.schema_new.SchemaUtil.noopTokenNameLookup; +import static org.neo4j.kernel.api.schema_new.SchemaUtil.idTokenNameLookup; /** * A {@link Label} can have zero or more index rules which will have data specified in the rules indexed. @@ -134,7 +134,7 @@ public String toString() ownerString = ", owner=" + owningConstraint; } - return "IndexRule[id=" + id + ", descriptor=" + descriptor.userDescription( noopTokenNameLookup ) + + return "IndexRule[id=" + id + ", descriptor=" + descriptor.userDescription( idTokenNameLookup ) + ", provider=" + providerDescriptor + ownerString + "]"; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureArgumentFormatter.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureArgumentFormatter.java index 4da3c4964e1d..c8dde6c44853 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureArgumentFormatter.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureArgumentFormatter.java @@ -23,8 +23,11 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import org.neo4j.helpers.Strings; +import org.neo4j.helpers.collection.Iterables; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.schema.RelationshipPropertyDescriptor; import org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint; @@ -32,6 +35,8 @@ import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import static java.lang.String.format; @@ -43,7 +48,8 @@ public enum DbStructureArgumentFormatter implements ArgumentFormatter UniquenessConstraint.class.getCanonicalName(), NodePropertyDescriptor.class.getCanonicalName(), IndexDescriptorFactory.class.getCanonicalName(), - IndexDescriptor.class.getCanonicalName() + IndexDescriptor.class.getCanonicalName(), + NewIndexDescriptorFactory.class.getCanonicalName() ); @Override @@ -89,7 +95,14 @@ else if ( arg instanceof IndexDescriptor ) { NodePropertyDescriptor descriptor = (NodePropertyDescriptor) arg; int labelId = descriptor.getLabelId(); - builder.append( format( "IndexDescriptorFactory.of( %s, %s )", labelId, descriptor.propertyIdText( ) ) ); + builder.append( format( "IndexDescriptorFactory.of( %d, %s )", labelId, descriptor.propertyIdText( ) ) ); + } + else if ( arg instanceof NewIndexDescriptor ) + { + NewIndexDescriptor descriptor = (NewIndexDescriptor) arg; + int labelId = descriptor.schema().getLabelId(); + builder.append( format( "NewIndexDescriptorFactory.forLabel( %d, %s )", + labelId, asString( descriptor.schema().getPropertyIds( ) ) ) ); } else if ( arg instanceof NodePropertyDescriptor ) { @@ -124,4 +137,10 @@ else if ( arg instanceof RelationshipPropertyExistenceConstraint ) ) ); } } + + private String asString( int[] propertyIds ) + { + List strings = Arrays.stream( propertyIds ).mapToObj( i -> "" + i ).collect( Collectors.toList() ); + return String.join( ",", strings ); + } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollector.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollector.java index 2b9c44eb55bf..db181ba392f8 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollector.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollector.java @@ -33,6 +33,9 @@ import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import static java.lang.String.format; @@ -131,7 +134,7 @@ public long cardinalityByLabelsAndRelationshipType( int fromLabelId, int relType public double indexSelectivity( int labelId, int propertyKeyId ) { //TODO: Support composite indexes - NodePropertyDescriptor descriptor = new NodePropertyDescriptor( labelId, propertyKeyId ); + LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyId ); IndexStatistics result1 = regularIndices.getIndex( descriptor ); IndexStatistics result2 = result1 == null ? uniqueIndices.getIndex( descriptor ) : result1; return result2 == null ? Double.NaN : result2.uniqueValuesPercentage; @@ -141,7 +144,7 @@ public double indexSelectivity( int labelId, int propertyKeyId ) public double indexPropertyExistsSelectivity( int labelId, int propertyKeyId ) { //TODO: Support composite indexes - NodePropertyDescriptor descriptor = new NodePropertyDescriptor( labelId, propertyKeyId ); + LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyId ); IndexStatistics result1 = regularIndices.getIndex( descriptor ); IndexStatistics result2 = result1 == null ? uniqueIndices.getIndex( descriptor ) : result1; return result2 == null ? Double.NaN : result2.size; @@ -168,15 +171,16 @@ public void visitRelationshipType( int relTypeId, String relTypeName ) } @Override - public void visitIndex( IndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ) + public void visitIndex( NewIndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long + size ) { - regularIndices.putIndex( descriptor, userDescription, uniqueValuesPercentage, size ); + regularIndices.putIndex( descriptor.schema(), userDescription, uniqueValuesPercentage, size ); } @Override - public void visitUniqueIndex( IndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ) + public void visitUniqueIndex( NewIndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ) { - uniqueIndices.putIndex( descriptor, userDescription, uniqueValuesPercentage, size ); + uniqueIndices.putIndex( descriptor.schema(), userDescription, uniqueValuesPercentage, size ); } @Override @@ -313,14 +317,14 @@ private IndexStatistics(double uniqueValuesPercentage, long size) private class IndexDescriptorMap implements Iterable> { private final String indexType; - private final Map indexMap = new HashMap<>(); + private final Map indexMap = new HashMap<>(); public IndexDescriptorMap( String indexType ) { this.indexType = indexType; } - public void putIndex( IndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ) + public void putIndex( LabelSchemaDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ) { if ( indexMap.containsKey( descriptor ) ) { @@ -333,14 +337,14 @@ public void putIndex( IndexDescriptor descriptor, String userDescription, double indexMap.put( descriptor, new IndexStatistics(uniqueValuesPercentage, size) ); } - public IndexStatistics getIndex( NodePropertyDescriptor descriptor ) + public IndexStatistics getIndex( LabelSchemaDescriptor descriptor ) { - return indexMap.get( IndexDescriptorFactory.of( descriptor ) ); + return indexMap.get( descriptor ); } public Iterator> iterator() { - final Iterator iterator = indexMap.keySet().iterator(); + final Iterator iterator = indexMap.keySet().iterator(); return new Iterator>() { @Override @@ -353,9 +357,9 @@ public boolean hasNext() public Pair next() { //TODO: Add support for composite indexes - IndexDescriptor next = iterator.next(); + LabelSchemaDescriptor next = iterator.next(); String label = labels.byIdOrFail( next.getLabelId() ); - String propertyKey = propertyKeys.byIdOrFail( next.getPropertyKeyId() ); + String propertyKey = propertyKeys.byIdOrFail( next.getPropertyIds()[0] ); return Pair.of( label, propertyKey ); } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureVisitor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureVisitor.java index 232d63d9f012..651a93add234 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureVisitor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureVisitor.java @@ -22,7 +22,7 @@ import org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint; import org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint; import org.neo4j.kernel.api.constraints.UniquenessConstraint; -import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; public interface DbStructureVisitor { @@ -30,8 +30,9 @@ public interface DbStructureVisitor void visitPropertyKey( int propertyKeyId, String propertyKeyName ); void visitRelationshipType( int relTypeId, String relTypeName ); - void visitIndex( IndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ); - void visitUniqueIndex( IndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ); + void visitIndex( NewIndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long size ); + void visitUniqueIndex( NewIndexDescriptor descriptor, String userDescription, double uniqueValuesPercentage, long + size ); void visitUniqueConstraint( UniquenessConstraint constraint, String userDescription ); void visitNodePropertyExistenceConstraint( NodePropertyExistenceConstraint constraint, String userDescription ); void visitRelationshipPropertyExistenceConstraint( RelationshipPropertyExistenceConstraint constraint, diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuide.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuide.java index 8d580f79afb6..8733e8735cf9 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuide.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuide.java @@ -38,10 +38,12 @@ import org.neo4j.kernel.api.exceptions.KernelException; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.internal.GraphDatabaseAPI; import static java.lang.String.format; +import static org.neo4j.helpers.collection.Iterators.loop; import static org.neo4j.kernel.api.ReadOperations.ANY_LABEL; import static org.neo4j.kernel.api.ReadOperations.ANY_RELATIONSHIP_TYPE; @@ -139,11 +141,9 @@ private void showSchema( DbStructureVisitor visitor, ReadOperations read ) throw private void showIndices( DbStructureVisitor visitor, ReadOperations read, TokenNameLookup nameLookup ) throws IndexNotFoundKernelException { - Iterator indexDescriptors = read.indexesGetAll(); - while ( indexDescriptors.hasNext() ) + for ( NewIndexDescriptor descriptor : loop( read.indexesGetAll() ) ) { - IndexDescriptor descriptor = indexDescriptors.next(); - String userDescription = descriptor.userDescription( nameLookup ); + String userDescription = descriptor.schema().userDescription( nameLookup ); double uniqueValuesPercentage = read.indexUniqueValuesSelectivity( descriptor ); long size = read.indexSize( descriptor ); visitor.visitIndex( descriptor, userDescription , uniqueValuesPercentage, size ); @@ -153,11 +153,9 @@ private void showIndices( DbStructureVisitor visitor, ReadOperations read, Token private void showUniqueIndices( DbStructureVisitor visitor, ReadOperations read, TokenNameLookup nameLookup ) throws IndexNotFoundKernelException { - Iterator indexDescriptors = read.uniqueIndexesGetAll(); - while ( indexDescriptors.hasNext() ) + for ( NewIndexDescriptor descriptor : loop( read.uniqueIndexesGetAll() ) ) { - IndexDescriptor descriptor = indexDescriptors.next(); - String userDescription = descriptor.userDescription( nameLookup ); + String userDescription = descriptor.schema().userDescription( nameLookup ); double uniqueValuesPercentage = read.indexUniqueValuesSelectivity( descriptor ); long size = read.indexSize( descriptor ); visitor.visitUniqueIndex( descriptor, userDescription, uniqueValuesPercentage, size ); diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java index 746908fed7a3..410a5d843044 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/StoreReadLayer.java @@ -20,7 +20,6 @@ package org.neo4j.storageengine.api; import java.util.Iterator; -import java.util.function.Predicate; import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator; @@ -35,14 +34,12 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; import org.neo4j.kernel.api.exceptions.schema.TooManyLabelsException; import org.neo4j.kernel.api.index.InternalIndexState; -import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.DegreeVisitor; import org.neo4j.kernel.impl.api.RelationshipVisitor; import org.neo4j.kernel.impl.api.store.RelationshipIterator; -import org.neo4j.kernel.impl.store.record.IndexRule; import org.neo4j.register.Register.DoubleLongRegister; import org.neo4j.storageengine.api.schema.PopulationProgress; @@ -93,7 +90,7 @@ Long indexGetOwningUniquenessConstraintId( NewIndexDescriptor index ) * @return schema rule id for matching index. * @throws SchemaRuleNotFoundException if no such index exists in storage. */ - long indexGetCommittedId( NewIndexDescriptor index, Predicate filter ) + long indexGetCommittedId( NewIndexDescriptor index, NewIndexDescriptor.Filter filter ) throws SchemaRuleNotFoundException; /** diff --git a/community/kernel/src/test/java/org/neo4j/graphdb/IndexingAcceptanceTest.java b/community/kernel/src/test/java/org/neo4j/graphdb/IndexingAcceptanceTest.java index 6e4fe4ca0558..fc1e654d6ab2 100644 --- a/community/kernel/src/test/java/org/neo4j/graphdb/IndexingAcceptanceTest.java +++ b/community/kernel/src/test/java/org/neo4j/graphdb/IndexingAcceptanceTest.java @@ -38,6 +38,8 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.test.mockito.matcher.Neo4jMatchers; @@ -605,7 +607,7 @@ private IndexDescriptor indexDescriptor(ReadOperations readOperations, IndexDefi throws SchemaRuleNotFoundException { NodePropertyDescriptor descriptor = IndexDescriptorFactory.getTokens( readOperations, index ); - return readOperations.indexGetForLabelAndPropertyKey( descriptor ); + return IndexBoundary.map( readOperations.indexGetForLabelAndPropertyKey( descriptor ) ); } private Statement getStatement( GraphDatabaseAPI db ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java index 355800c6ecbd..75dd3d4f0b46 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java @@ -37,6 +37,8 @@ import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; @@ -63,7 +65,7 @@ public class AwaitIndexProcedureTest private final IndexProcedures procedure = new IndexProcedures( new StubKernelTransaction( operations ), null ); private final NodePropertyDescriptor descriptor = new NodePropertyDescriptor( 123, 456 ); private final NodePropertyDescriptor anyDescriptor = new NodePropertyDescriptor( 0, 0 ); - private final IndexDescriptor anyIndex = IndexDescriptorFactory.of( anyDescriptor ); + private final NewIndexDescriptor anyIndex = IndexBoundary.map( anyDescriptor ); @Test public void shouldThrowAnExceptionIfTheLabelDoesntExist() throws ProcedureException @@ -104,7 +106,7 @@ public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() when( operations.labelGetForName( anyString() ) ).thenReturn( descriptor.getLabelId() ); when( operations.propertyKeyGetForName( anyString() ) ).thenReturn( descriptor.getPropertyKeyId() ); when( operations.indexGetForLabelAndPropertyKey( anyObject() ) ).thenReturn( anyIndex ); - when( operations.indexGetState( any( IndexDescriptor.class ) ) ).thenReturn( ONLINE ); + when( operations.indexGetState( any( NewIndexDescriptor.class ) ) ).thenReturn( ONLINE ); procedure.awaitIndex( ":Person(name)", timeout, timeoutUnits ); @@ -119,7 +121,7 @@ public void shouldThrowAnExceptionIfTheIndexHasFailed() when( operations.labelGetForName( anyString() ) ).thenReturn( 0 ); when( operations.propertyKeyGetForName( anyString() ) ).thenReturn( 0 ); when( operations.indexGetForLabelAndPropertyKey( anyObject() ) ).thenReturn( anyIndex ); - when( operations.indexGetState( any( IndexDescriptor.class ) ) ).thenReturn( FAILED ); + when( operations.indexGetState( any( NewIndexDescriptor.class ) ) ).thenReturn( FAILED ); try { @@ -162,7 +164,7 @@ public void shouldBlockUntilTheIndexIsOnline() throws SchemaRuleNotFoundExceptio when( operations.indexGetForLabelAndPropertyKey( anyObject() ) ).thenReturn( anyIndex ); AtomicReference state = new AtomicReference<>( POPULATING ); - when( operations.indexGetState( any( IndexDescriptor.class ) ) ).then( new Answer() + when( operations.indexGetState( any( NewIndexDescriptor.class ) ) ).then( new Answer() { @Override public InternalIndexState answer( InvocationOnMock invocationOnMock ) throws Throwable @@ -199,7 +201,7 @@ public void shouldTimeoutIfTheIndexTakesTooLongToComeOnline() when( operations.labelGetForName( anyString() ) ).thenReturn( 0 ); when( operations.propertyKeyGetForName( anyString() ) ).thenReturn( 0 ); when( operations.indexGetForLabelAndPropertyKey( anyObject() ) ).thenReturn( anyIndex ); - when( operations.indexGetState( any( IndexDescriptor.class ) ) ).thenReturn( POPULATING ); + when( operations.indexGetState( any( NewIndexDescriptor.class ) ) ).thenReturn( POPULATING ); AtomicReference exception = new AtomicReference<>(); new Thread( () -> diff --git a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java index 7f274b66850e..f2cb0b96efd5 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java @@ -36,19 +36,22 @@ import org.neo4j.graphdb.Relationship; import org.neo4j.helpers.collection.Iterators; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint; import org.neo4j.kernel.api.constraints.PropertyConstraint; import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.exceptions.ProcedureException; -import org.neo4j.kernel.api.schema.IndexDescriptor; -import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.proc.BasicContext; import org.neo4j.kernel.api.proc.Key; import org.neo4j.kernel.api.proc.ProcedureSignature; +import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema_new.SchemaBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.impl.factory.Edition; import org.neo4j.kernel.impl.proc.Procedures; import org.neo4j.kernel.impl.proc.TypeMappers; @@ -72,8 +75,8 @@ public class BuiltInProceduresTest { - private final List indexes = new LinkedList<>(); - private final List uniqueIndexes = new LinkedList<>(); + private final List indexes = new LinkedList<>(); + private final List uniqueIndexes = new LinkedList<>(); private final List constraints = new LinkedList<>(); private final Map labels = new HashMap<>(); private final Map propKeys = new HashMap<>(); @@ -223,7 +226,7 @@ private void givenIndex( String label, String propKey ) int labelId = token( label, labels ); int propId = token( propKey, propKeys ); - IndexDescriptor index = IndexDescriptorFactory.of( labelId, propId ); + NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel( labelId, propId ); indexes.add( index ); } @@ -232,9 +235,10 @@ private void givenUniqueConstraint( String label, String propKey ) int labelId = token( label, labels ); int propId = token( propKey, propKeys ); - IndexDescriptor index = IndexDescriptorFactory.of( labelId, propId ); + NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForLabel( labelId, propId ); uniqueIndexes.add( index ); - constraints.add( new UniquenessConstraint( index.descriptor() ) ); + constraints.add( new UniquenessConstraint( + IndexDescriptorFactory.getNodePropertyDescriptor( labelId, propId ) ) ); } private void givenNodePropExistenceConstraint( String label, String propKey ) @@ -323,7 +327,7 @@ public void setup() throws Exception when(read.constraintsGetForLabel( anyInt() )).thenReturn( emptyIterator() ); when(read.countsForNode( anyInt() )).thenReturn( 1L ); when(read.countsForRelationship( anyInt(), anyInt(), anyInt() )).thenReturn( 1L ); - when(read.indexGetState( any( IndexDescriptor.class) )).thenReturn( InternalIndexState.ONLINE ); + when(read.indexGetState( any( NewIndexDescriptor.class) )).thenReturn( InternalIndexState.ONLINE ); } private Answer> asTokens( Map tokens ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/ResampleIndexProcedureTest.java b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/ResampleIndexProcedureTest.java index b5b3bb3cf6ab..b2823fb99c44 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/ResampleIndexProcedureTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/ResampleIndexProcedureTest.java @@ -30,6 +30,9 @@ import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.impl.api.index.IndexingService; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode; @@ -87,7 +90,7 @@ public void shouldThrowAnExceptionIfThePropertyKeyDoesntExist() throws Procedure public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws ProcedureException, SchemaRuleNotFoundException, IndexNotFoundKernelException { - IndexDescriptor index = IndexDescriptorFactory.of( 0, 0 ); + NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel( 0, 0 ); when( operations.labelGetForName( anyString() ) ).thenReturn( 123 ); when( operations.propertyKeyGetForName( anyString() ) ).thenReturn( 456 ); when( operations.indexGetForLabelAndPropertyKey( anyObject() ) ).thenReturn( index ); @@ -122,11 +125,12 @@ public void shouldThrowAnExceptionIfTheIndexDoesNotExist() public void shouldTriggerResampling() throws SchemaRuleNotFoundException, ProcedureException, IndexNotFoundKernelException { - IndexDescriptor index = IndexDescriptorFactory.of( 123, 456 ); + NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel( 123, 456 ); when( operations.indexGetForLabelAndPropertyKey( anyObject() ) ).thenReturn( index ); procedure.resampleIndex( ":Person(name)" ); - verify( indexingService ).triggerIndexSampling( index, IndexSamplingMode.TRIGGER_REBUILD_ALL ); + verify( indexingService ).triggerIndexSampling( IndexBoundary.map( index ), + IndexSamplingMode.TRIGGER_REBUILD_ALL ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperationsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperationsTest.java index f055e809eb67..5a62dfe65285 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperationsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/DataIntegrityValidatingStatementOperationsTest.java @@ -27,6 +27,7 @@ import java.util.Iterator; +import org.neo4j.helpers.collection.Iterators; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException; import org.neo4j.kernel.api.exceptions.schema.AlreadyIndexedException; @@ -37,6 +38,9 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.impl.api.operations.KeyWriteOperations; import org.neo4j.kernel.impl.api.operations.SchemaReadOperations; import org.neo4j.kernel.impl.api.operations.SchemaWriteOperations; @@ -44,6 +48,8 @@ import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -58,17 +64,17 @@ public class DataIntegrityValidatingStatementOperationsTest public ExpectedException exception = ExpectedException.none(); NodePropertyDescriptor descriptor = new NodePropertyDescriptor( 0, 7 ); + NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel( 0, 7 ); @Test public void shouldDisallowReAddingIndex() throws Exception { // GIVEN - IndexDescriptor rule = IndexDescriptorFactory.of( descriptor ); SchemaReadOperations innerRead = mock( SchemaReadOperations.class ); SchemaWriteOperations innerWrite = mock( SchemaWriteOperations.class ); DataIntegrityValidatingStatementOperations ctx = new DataIntegrityValidatingStatementOperations( null, innerRead, innerWrite ); - when( innerRead.indexesGetForLabel( state, rule.getLabelId() ) ).thenAnswer( withIterator( rule ) ); + when( innerRead.indexesGetForLabel( state, index.schema().getLabelId() ) ).thenAnswer( withIterator( index ) ); // WHEN try @@ -89,13 +95,12 @@ public void shouldDisallowReAddingIndex() throws Exception public void shouldDisallowAddingIndexWhenConstraintIndexExists() throws Exception { // GIVEN - IndexDescriptor rule = IndexDescriptorFactory.of( descriptor ); SchemaReadOperations innerRead = mock( SchemaReadOperations.class ); SchemaWriteOperations innerWrite = mock( SchemaWriteOperations.class ); DataIntegrityValidatingStatementOperations ctx = new DataIntegrityValidatingStatementOperations( null, innerRead, innerWrite ); - when( innerRead.indexesGetForLabel( state, rule.getLabelId() ) ).thenAnswer( withIterator( ) ); - when( innerRead.uniqueIndexesGetForLabel( state, rule.getLabelId() ) ).thenAnswer( withIterator( rule ) ); + when( innerRead.indexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator() ); + when( innerRead.uniqueIndexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator( index ) ); // WHEN try @@ -116,18 +121,17 @@ public void shouldDisallowAddingIndexWhenConstraintIndexExists() throws Exceptio public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception { // GIVEN - IndexDescriptor indexDescriptor = IndexDescriptorFactory.of( descriptor ); SchemaReadOperations innerRead = mock( SchemaReadOperations.class ); SchemaWriteOperations innerWrite = mock( SchemaWriteOperations.class ); DataIntegrityValidatingStatementOperations ctx = new DataIntegrityValidatingStatementOperations( null, innerRead, innerWrite ); - when( innerRead.uniqueIndexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( withIterator( ) ); - when( innerRead.indexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( withIterator( ) ); + when( innerRead.uniqueIndexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator( ) ); + when( innerRead.indexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator( ) ); // WHEN try { - ctx.indexDrop( state, indexDescriptor ); + ctx.indexDrop( state, IndexBoundary.map( index ) ); fail( "Should have thrown exception." ); } catch ( DropIndexFailureException e ) @@ -143,19 +147,17 @@ public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception public void shouldDisallowDroppingIndexWhenConstraintIndexExists() throws Exception { // GIVEN - IndexDescriptor indexDescriptor = IndexDescriptorFactory.of( descriptor ); SchemaReadOperations innerRead = mock( SchemaReadOperations.class ); SchemaWriteOperations innerWrite = mock( SchemaWriteOperations.class ); DataIntegrityValidatingStatementOperations ctx = new DataIntegrityValidatingStatementOperations( null, innerRead, innerWrite ); - when( innerRead.uniqueIndexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( - withIterator( indexDescriptor ) ); - when( innerRead.indexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( withIterator() ); + when( innerRead.uniqueIndexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator( index ) ); + when( innerRead.indexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator() ); // WHEN try { - ctx.indexDrop( state, indexDescriptor ); + ctx.indexDrop( state, IndexBoundary.map( index ) ); fail( "Should have thrown exception." ); } catch ( DropIndexFailureException e ) @@ -171,19 +173,17 @@ public void shouldDisallowDroppingIndexWhenConstraintIndexExists() throws Except public void shouldDisallowDroppingConstraintIndexThatDoesNotExists() throws Exception { // GIVEN - IndexDescriptor indexDescriptor = IndexDescriptorFactory.of( descriptor ); SchemaReadOperations innerRead = mock( SchemaReadOperations.class ); SchemaWriteOperations innerWrite = mock( SchemaWriteOperations.class ); DataIntegrityValidatingStatementOperations ctx = new DataIntegrityValidatingStatementOperations( null, innerRead, innerWrite ); - when( innerRead.uniqueIndexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( - withIterator( indexDescriptor ) ); - when( innerRead.indexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( withIterator() ); + when( innerRead.uniqueIndexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator( index ) ); + when( innerRead.indexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator( ) ); // WHEN try { - ctx.indexDrop( state, indexDescriptor ); + ctx.indexDrop( state, IndexBoundary.map( index ) ); fail( "Should have thrown exception." ); } catch ( DropIndexFailureException e ) @@ -199,19 +199,17 @@ public void shouldDisallowDroppingConstraintIndexThatDoesNotExists() throws Exce public void shouldDisallowDroppingConstraintIndexThatIsReallyJustRegularIndex() throws Exception { // GIVEN - IndexDescriptor indexDescriptor = IndexDescriptorFactory.of( descriptor ); SchemaReadOperations innerRead = mock( SchemaReadOperations.class ); SchemaWriteOperations innerWrite = mock( SchemaWriteOperations.class ); DataIntegrityValidatingStatementOperations ctx = new DataIntegrityValidatingStatementOperations( null, innerRead, innerWrite ); - when( innerRead.uniqueIndexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( - withIterator( indexDescriptor ) ); - when( innerRead.indexesGetForLabel( state, indexDescriptor.getLabelId() ) ).thenAnswer( withIterator() ); + when( innerRead.uniqueIndexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator( index ) ); + when( innerRead.indexesGetForLabel( state, descriptor.getLabelId() ) ).thenAnswer( withIterator() ); // WHEN try { - ctx.indexDrop( state, indexDescriptor ); + ctx.indexDrop( state, IndexBoundary.map( index ) ); fail( "Should have thrown exception." ); } catch ( DropIndexFailureException e ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java index 7c93a28637ce..b055386c0bb1 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/KernelSchemaStateFlushingTest.java @@ -35,6 +35,8 @@ import org.neo4j.kernel.api.exceptions.TransactionFailureException; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.schema.IndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.test.rule.ImpermanentDatabaseRule; @@ -74,9 +76,7 @@ public void shouldInvalidateSchemaStateOnCreateIndex() throws Exception // given commitToSchemaState( "test", "before" ); - IndexDescriptor descriptor = createIndex(); - - awaitIndexOnline( descriptor, "test" ); + awaitIndexOnline( createIndex(), "test" ); // when String after = commitToSchemaState( "test", "after" ); @@ -88,7 +88,7 @@ public void shouldInvalidateSchemaStateOnCreateIndex() throws Exception @Test public void shouldInvalidateSchemaStateOnDropIndex() throws Exception { - IndexDescriptor descriptor = createIndex(); + NewIndexDescriptor descriptor = createIndex(); awaitIndexOnline( descriptor, "test" ); @@ -157,28 +157,28 @@ private void dropConstraint( UniquenessConstraint descriptor ) throws KernelExce } } - private IndexDescriptor createIndex() throws KernelException + private NewIndexDescriptor createIndex() throws KernelException { try ( KernelTransaction transaction = kernel.newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); Statement statement = transaction.acquireStatement() ) { IndexDescriptor descriptor = statement.schemaWriteOperations().indexCreate( descriptor1 ); transaction.success(); - return descriptor; + return IndexBoundary.map( descriptor ); } } - private void dropIndex( IndexDescriptor descriptor ) throws KernelException + private void dropIndex( NewIndexDescriptor descriptor ) throws KernelException { try ( KernelTransaction transaction = kernel.newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); Statement statement = transaction.acquireStatement() ) { - statement.schemaWriteOperations().indexDrop( descriptor ); + statement.schemaWriteOperations().indexDrop( IndexBoundary.map( descriptor ) ); transaction.success(); } } - private void awaitIndexOnline( IndexDescriptor descriptor, String keyForProbing ) + private void awaitIndexOnline( NewIndexDescriptor descriptor, String keyForProbing ) throws IndexNotFoundKernelException, TransactionFailureException { try ( KernelTransaction transaction = kernel.newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java index 6559dc48d364..27e914e8d364 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/LockingStatementOperationsTest.java @@ -39,6 +39,7 @@ import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.properties.Property; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.api.txstate.LegacyIndexTransactionState; import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.api.txstate.TxStateHolder; @@ -237,11 +238,11 @@ public void shouldAcquireSchemaWriteLockBeforeRemovingIndexRule() throws Excepti public void shouldAcquireSchemaReadLockBeforeGettingIndexRules() throws Exception { // given - Iterator rules = Collections.emptyIterator(); + Iterator rules = Collections.emptyIterator(); when( schemaReadOps.indexesGetAll( state ) ).thenReturn( rules ); // when - Iterator result = lockingOps.indexesGetAll( state ); + Iterator result = lockingOps.indexesGetAll( state ); // then assertSame( rules, result ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeTest.java index 1a3347d136f1..2dabfd982398 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeTest.java @@ -36,6 +36,9 @@ import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.impl.api.operations.SchemaReadOperations; import org.neo4j.test.mockito.matcher.KernelExceptionUserMessageMatcher; @@ -85,7 +88,7 @@ public void testThrowExceptionWhenDuplicateUniqueIndexFound() throws SchemaRuleNotFoundException, DuplicateSchemaRuleException { SchemaReadOperations readOperations = setupSchemaReadOperations(); - IndexDescriptor index = IndexDescriptorFactory.of( descriptor ); + NewIndexDescriptor index = IndexBoundary.map( descriptor ); Mockito.when( readOperations .uniqueIndexesGetForLabel( Mockito.any( KernelStatement.class ), Mockito.eq( descriptor.getLabelId() ) ) ) .thenReturn( Iterators.iterator( index, index ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java index 87e17fb7fcb5..2341753adb3a 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/constraints/ConstraintIndexCreatorTest.java @@ -68,6 +68,7 @@ public class ConstraintIndexCreatorTest { private final NodePropertyDescriptor descriptor = new NodePropertyDescriptor( 123, 456 ); + private final NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForLabel( 123, 456 ); @Test public void shouldCreateIndexInAnotherTransaction() throws Exception @@ -76,7 +77,6 @@ public void shouldCreateIndexInAnotherTransaction() throws Exception StatementOperationParts constraintCreationContext = mockedParts(); StatementOperationParts indexCreationContext = mockedParts(); - IndexDescriptor index = IndexDescriptorFactory.of( descriptor ); KernelStatement state = mockedState(); IndexingService indexingService = mock( IndexingService.class ); @@ -95,7 +95,7 @@ public void shouldCreateIndexInAnotherTransaction() throws Exception // then assertEquals( 2468L, indexId ); assertEquals( 1, kernel.statements.size() ); - verify( kernel.statements.get( 0 ).txState() ).indexRuleDoAdd( eq( IndexBoundary.mapUnique( index ) ) ); + verify( kernel.statements.get( 0 ).txState() ).indexRuleDoAdd( eq( index ) ); verifyNoMoreInteractions( indexCreationContext.schemaWriteOperations() ); verify( constraintCreationContext.schemaReadOperations() ).indexGetCommittedId( state, index, UNIQUE ); verifyNoMoreInteractions( constraintCreationContext.schemaReadOperations() ); @@ -109,8 +109,6 @@ public void shouldDropIndexIfPopulationFails() throws Exception StatementOperationParts constraintCreationContext = mockedParts(); KernelStatement state = mockedState(); - IndexDescriptor index = IndexDescriptorFactory.of( descriptor ); - IndexingService indexingService = mock( IndexingService.class ); StubKernel kernel = new StubKernel(); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java index cbf1d5ebd0ec..a5545de67ba2 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexIT.java @@ -37,7 +37,10 @@ import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.security.AnonymousContext; import org.neo4j.kernel.api.security.SecurityContext; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest; +import org.neo4j.kernel.impl.api.operations.SchemaReadOperations; import org.neo4j.kernel.impl.api.state.ConstraintIndexCreator; import static org.junit.Assert.assertEquals; @@ -73,7 +76,7 @@ public void addIndexRuleInATransaction() throws Exception SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction(); // WHEN - IndexDescriptor expectedRule = schemaWriteOperations.indexCreate( descriptor ); + NewIndexDescriptor expectedRule = IndexBoundary.map( schemaWriteOperations.indexCreate( descriptor ) ); commit(); // THEN @@ -88,14 +91,16 @@ public void committedAndTransactionalIndexRulesShouldBeMerged() throws Exception { // GIVEN SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction(); - IndexDescriptor existingRule = schemaWriteOperations.indexCreate( descriptor ); + NewIndexDescriptor existingRule = IndexBoundary.map( schemaWriteOperations.indexCreate( descriptor ) ); commit(); // WHEN + NewIndexDescriptor addedRule; + Set indexRulesInTx; Statement statement = statementInNewTransaction( AnonymousContext.AUTH_DISABLED ); - IndexDescriptor addedRule = - statement.schemaWriteOperations().indexCreate( new NodePropertyDescriptor( labelId, 10 ) ); - Set indexRulesInTx = asSet( statement.readOperations().indexesGetForLabel( labelId ) ); + addedRule = IndexBoundary.map( statement.schemaWriteOperations().indexCreate( + new NodePropertyDescriptor( labelId, 10 ) ) ); + indexRulesInTx = asSet( statement.readOperations().indexesGetForLabel( labelId ) ); commit(); // THEN diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexStatisticsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexStatisticsTest.java index bc64ead39b3e..56eb2b39b14f 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexStatisticsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/IndexStatisticsTest.java @@ -54,6 +54,8 @@ import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine; import org.neo4j.kernel.impl.store.NeoStores; @@ -133,7 +135,7 @@ public void shouldProvideIndexStatisticsForDataCreatedWhenPopulationBeforeTheInd createSomePersons(); // when - IndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); + NewIndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); // then assertEquals( 0.75d, indexSelectivity( index ), DOUBLE_ERROR_TOLERANCE ); @@ -145,7 +147,7 @@ public void shouldProvideIndexStatisticsForDataCreatedWhenPopulationBeforeTheInd public void shouldNotSeeDataCreatedAfterPopulation() throws KernelException { // given - IndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); + NewIndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); // when createSomePersons(); @@ -162,7 +164,7 @@ public void shouldProvideIndexStatisticsForDataSeenDuringPopulationAndIgnoreData { // given createSomePersons(); - IndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); + NewIndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); // when createSomePersons(); @@ -178,7 +180,7 @@ public void shouldRemoveIndexStatisticsAfterIndexIsDeleted() throws KernelExcept { // given createSomePersons(); - IndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); + NewIndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); long indexId = indexId( index ); // when @@ -208,7 +210,7 @@ public void shouldProvideIndexSelectivityWhenThereAreManyDuplicates() throws Exc int created = repeatCreateNamedPeopleFor( NAMES.length * CREATION_MULTIPLIER ).length; // when - IndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); + NewIndexDescriptor index = awaitOnline( createIndex( "Person", "name" ) ); // then double expectedSelectivity = UNIQUE_NAMES / (created); @@ -224,7 +226,7 @@ public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurre int initialNodes = repeatCreateNamedPeopleFor( NAMES.length * CREATION_MULTIPLIER ).length; // when populating while creating - IndexDescriptor index = createIndex( "Person", "name" ); + NewIndexDescriptor index = createIndex( "Person", "name" ); final UpdatesTracker updatesTracker = executeCreations( index, CREATION_MULTIPLIER ); awaitOnline( index ); @@ -244,7 +246,7 @@ public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurre int initialNodes = nodes.length; // when populating while creating - IndexDescriptor index = createIndex( "Person", "name" ); + NewIndexDescriptor index = createIndex( "Person", "name" ); UpdatesTracker updatesTracker = executeCreationsAndDeletions( nodes, index, CREATION_MULTIPLIER ); awaitOnline( index ); @@ -266,7 +268,7 @@ public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurre int initialNodes = nodes.length; // when populating while creating - IndexDescriptor index = createIndex( "Person", "name" ); + NewIndexDescriptor index = createIndex( "Person", "name" ); UpdatesTracker updatesTracker = executeCreationsAndUpdates( nodes, index, CREATION_MULTIPLIER ); awaitOnline( index ); @@ -288,7 +290,7 @@ public void shouldWorkWhileHavingHeavyConcurrentUpdates() throws Exception ExecutorService executorService = Executors.newFixedThreadPool( threads ); // when populating while creating - final IndexDescriptor index = createIndex( "Person", "name" ); + final NewIndexDescriptor index = createIndex( "Person", "name" ); final Collection> jobs = new ArrayList<>( threads ); for ( int i = 0; i < threads; i++ ) @@ -423,31 +425,31 @@ public Void call() throws Exception return nodes; } - private void dropIndex( IndexDescriptor index ) throws KernelException + private void dropIndex( NewIndexDescriptor index ) throws KernelException { try ( Transaction tx = db.beginTx() ) { Statement statement = bridge.get(); - statement.schemaWriteOperations().indexDrop( index ); + statement.schemaWriteOperations().indexDrop( IndexBoundary.map( index ) ); tx.success(); } } - private long indexSize( IndexDescriptor descriptor ) throws KernelException + private long indexSize( NewIndexDescriptor descriptor ) throws KernelException { return ((GraphDatabaseAPI) db).getDependencyResolver() .resolveDependency( IndexingService.class ) - .indexUpdatesAndSize( descriptor ).readSecond(); + .indexUpdatesAndSize( IndexBoundary.map( descriptor ) ).readSecond(); } - private long indexUpdates( IndexDescriptor descriptor ) throws KernelException + private long indexUpdates( NewIndexDescriptor descriptor ) throws KernelException { return ((GraphDatabaseAPI) db).getDependencyResolver() .resolveDependency( IndexingService.class ) - .indexUpdatesAndSize( descriptor ).readFirst(); + .indexUpdatesAndSize( IndexBoundary.map( descriptor ) ).readFirst(); } - private double indexSelectivity( IndexDescriptor descriptor ) throws KernelException + private double indexSelectivity( NewIndexDescriptor descriptor ) throws KernelException { try ( Transaction tx = db.beginTx() ) { @@ -488,7 +490,7 @@ private long createNode( Statement statement, String labelName, String propertyK return nodeId; } - private IndexDescriptor createIndex( String labelName, String propertyKeyName ) throws KernelException + private NewIndexDescriptor createIndex( String labelName, String propertyKeyName ) throws KernelException { try ( Transaction tx = db.beginTx() ) { @@ -498,16 +500,14 @@ private IndexDescriptor createIndex( String labelName, String propertyKeyName ) NodePropertyDescriptor descriptor = new NodePropertyDescriptor( labelId, propertyKeyId ); IndexDescriptor index = statement.schemaWriteOperations().indexCreate( descriptor ); tx.success(); - return index; + return IndexBoundary.map( index ); } } - private long indexId( IndexDescriptor index ) + private long indexId( NewIndexDescriptor index ) { SchemaStorage storage = new SchemaStorage( neoStores().getSchemaStore() ); - LabelSchemaDescriptor descriptor = - SchemaDescriptorFactory.forLabel( index.getLabelId(), index.getPropertyKeyId() ); - return storage.indexGetForSchema( descriptor ).getId(); + return storage.indexGetForSchema( index.schema() ).getId(); } private NeoStores neoStores() @@ -516,7 +516,7 @@ private NeoStores neoStores() .testAccessNeoStores(); } - private IndexDescriptor awaitOnline( IndexDescriptor index ) throws KernelException + private NewIndexDescriptor awaitOnline( NewIndexDescriptor index ) throws KernelException { long start = System.currentTimeMillis(); long end = start + 20_000; @@ -551,34 +551,34 @@ private IndexDescriptor awaitOnline( IndexDescriptor index ) throws KernelExcept throw new IllegalStateException( "Index did not become ONLINE within reasonable time" ); } - private UpdatesTracker executeCreations( IndexDescriptor index, int numberOfCreations ) throws KernelException + private UpdatesTracker executeCreations( NewIndexDescriptor index, int numberOfCreations ) throws KernelException { return internalExecuteCreationsDeletionsAndUpdates( null, index, numberOfCreations, false, false ); } private UpdatesTracker executeCreationsAndDeletions( long[] nodes, - IndexDescriptor index, + NewIndexDescriptor index, int numberOfCreations ) throws KernelException { return internalExecuteCreationsDeletionsAndUpdates( nodes, index, numberOfCreations, true, false ); } private UpdatesTracker executeCreationsAndUpdates( long[] nodes, - IndexDescriptor index, + NewIndexDescriptor index, int numberOfCreations ) throws KernelException { return internalExecuteCreationsDeletionsAndUpdates( nodes, index, numberOfCreations, false, true ); } private UpdatesTracker executeCreationsDeletionsAndUpdates( long[] nodes, - IndexDescriptor index, + NewIndexDescriptor index, int numberOfCreations ) throws KernelException { return internalExecuteCreationsDeletionsAndUpdates( nodes, index, numberOfCreations, true, true ); } private UpdatesTracker internalExecuteCreationsDeletionsAndUpdates( long[] nodes, - IndexDescriptor index, + NewIndexDescriptor index, int numberOfCreations, boolean allowDeletions, boolean allowUpdates ) throws KernelException @@ -593,7 +593,9 @@ private UpdatesTracker internalExecuteCreationsDeletionsAndUpdates( long[] nodes updatesTracker.increaseCreated( created ); // check index online - if ( !updatesTracker.isPopulationCompleted() && indexOnlineMonitor.isIndexOnline( index ) ) + IndexDescriptor oldIndex = IndexBoundary.map( index ); + if ( !updatesTracker.isPopulationCompleted() && + indexOnlineMonitor.isIndexOnline( oldIndex ) ) { updatesTracker.notifyPopulationCompleted(); } @@ -613,7 +615,8 @@ private UpdatesTracker internalExecuteCreationsDeletionsAndUpdates( long[] nodes } // check again index online - if ( !updatesTracker.isPopulationCompleted() && indexOnlineMonitor.isIndexOnline( index ) ) + if ( !updatesTracker.isPopulationCompleted() && + indexOnlineMonitor.isIndexOnline( oldIndex ) ) { updatesTracker.notifyPopulationCompleted(); } @@ -633,7 +636,7 @@ private UpdatesTracker internalExecuteCreationsDeletionsAndUpdates( long[] nodes } // check again index online - if ( !updatesTracker.isPopulationCompleted() && indexOnlineMonitor.isIndexOnline( index ) ) + if ( !updatesTracker.isPopulationCompleted() && indexOnlineMonitor.isIndexOnline( oldIndex ) ) { updatesTracker.notifyPopulationCompleted(); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java index 2062f4bdd567..0519c4c8bdec 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/index/SchemaIndexTestHelper.java @@ -31,6 +31,7 @@ import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.index.InternalIndexState; import org.neo4j.kernel.api.index.SchemaIndexProvider; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.extension.KernelExtensionFactory; import org.neo4j.kernel.impl.spi.KernelContext; @@ -110,13 +111,13 @@ public static boolean awaitLatch( CountDownLatch latch ) } } - public static void awaitIndexOnline( ReadOperations readOperations, IndexDescriptor indexRule ) + public static void awaitIndexOnline( ReadOperations readOperations, NewIndexDescriptor index ) throws IndexNotFoundKernelException { long start = System.currentTimeMillis(); while(true) { - if ( readOperations.indexGetState( indexRule ) == InternalIndexState.ONLINE ) + if ( readOperations.indexGetState( index ) == InternalIndexState.ONLINE ) { break; } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java index 72a96b68bcc7..c219fa4b9f88 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/NodeGetUniqueFromIndexSeekIT.java @@ -36,6 +36,8 @@ import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.security.SecurityContext; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.impl.locking.Locks; import org.neo4j.test.DoubleLatch; @@ -76,13 +78,13 @@ public void createKeys() throws Exception public void shouldFindMatchingNode() throws Exception { // given - IndexDescriptor index = createUniquenessConstraint(); + NewIndexDescriptor index = createUniquenessConstraint(); String value = "value"; long nodeId = createNodeWithValue( value ); // when looking for it ReadOperations readOperations = readOperationsInNewTransaction(); - long foundId = readOperations.nodeGetFromUniqueIndexSeek( index, value ); + long foundId = readOperations.nodeGetFromUniqueIndexSeek( IndexBoundary.map( index ), value ); commit(); // then @@ -93,13 +95,13 @@ public void shouldFindMatchingNode() throws Exception public void shouldNotFindNonMatchingNode() throws Exception { // given - IndexDescriptor index = createUniquenessConstraint(); + NewIndexDescriptor index = createUniquenessConstraint(); String value = "value"; createNodeWithValue( "other_" + value ); // when looking for it ReadOperations readOperations = readOperationsInNewTransaction(); - long foundId = readOperations.nodeGetFromUniqueIndexSeek( index, value ); + long foundId = readOperations.nodeGetFromUniqueIndexSeek( IndexBoundary.map( index ), value ); commit(); // then @@ -126,7 +128,7 @@ public void shouldBlockUniqueIndexSeekFromCompetingTransaction() throws Exceptio // assert that we complete before timeout final DoubleLatch latch = new DoubleLatch(); - final IndexDescriptor index = createUniquenessConstraint(); + final NewIndexDescriptor index = createUniquenessConstraint(); final String value = "value"; DataWriteOperations dataStatement = dataWriteOperationsInNewTransaction(); @@ -143,7 +145,7 @@ public void shouldBlockUniqueIndexSeekFromCompetingTransaction() throws Exceptio { try ( Statement statement1 = statementContextSupplier.get() ) { - statement1.readOperations().nodeGetFromUniqueIndexSeek( index, value ); + statement1.readOperations().nodeGetFromUniqueIndexSeek( IndexBoundary.map( index ), value ); } tx.success(); } @@ -190,12 +192,12 @@ private long createNodeWithValue( String value ) throws KernelException return nodeId; } - private IndexDescriptor createUniquenessConstraint() throws Exception + private NewIndexDescriptor createUniquenessConstraint() throws Exception { Statement statement = statementInNewTransaction( SecurityContext.AUTH_DISABLED ); NodePropertyDescriptor descriptor = new NodePropertyDescriptor( labelId, propertyKeyId ); statement.schemaWriteOperations().uniquePropertyConstraintCreate( descriptor ); - IndexDescriptor result = statement.readOperations().uniqueIndexGetForLabelAndPropertyKey( descriptor ); + NewIndexDescriptor result = statement.readOperations().uniqueIndexGetForLabelAndPropertyKey( descriptor ); commit(); return result; } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintValidationIT.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintValidationIT.java index 113f9fc00810..4a7f42326a13 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintValidationIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/integrationtest/UniquenessConstraintValidationIT.java @@ -21,6 +21,7 @@ import org.junit.Test; +import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.SchemaWriteOperations; import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.StatementTokenNameLookup; @@ -29,8 +30,9 @@ import org.neo4j.kernel.api.exceptions.KernelException; import org.neo4j.kernel.api.exceptions.schema.UniquePropertyConstraintViolationKernelException; import org.neo4j.kernel.api.properties.DefinedProperty; -import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.NodePropertyDescriptor; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; import org.neo4j.kernel.api.security.AnonymousContext; import static org.hamcrest.CoreMatchers.containsString; @@ -324,16 +326,17 @@ public void unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck( } Statement statement = statementInNewTransaction( AnonymousContext.writeToken() ); - int person = statement.readOperations().labelGetForName( "Person" ); - int id = statement.readOperations().propertyKeyGetForName( "id" ); - IndexDescriptor idx = statement.readOperations() + ReadOperations readOps = statement.readOperations(); + int person = readOps.labelGetForName( "Person" ); + int id = readOps.propertyKeyGetForName( "id" ); + NewIndexDescriptor idx = readOps .uniqueIndexGetForLabelAndPropertyKey( new NodePropertyDescriptor( person, id ) ); // when createLabeledNode( statement, "Item", "id", 2 ); // then I should find the original node - assertThat( statement.readOperations().nodeGetFromUniqueIndexSeek( idx, 1 ), equalTo( ourNode ) ); + assertThat( readOps.nodeGetFromUniqueIndexSeek( IndexBoundary.map( idx ), 1 ), equalTo( ourNode ) ); } @Test @@ -350,16 +353,17 @@ public void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exc } Statement statement = statementInNewTransaction( AnonymousContext.writeToken() ); - int person = statement.readOperations().labelGetForName( "Person" ); - int id = statement.readOperations().propertyKeyGetForName( "id" ); - IndexDescriptor idx = statement.readOperations() + ReadOperations readOps = statement.readOperations(); + int person = readOps.labelGetForName( "Person" ); + int id = readOps.propertyKeyGetForName( "id" ); + NewIndexDescriptor idx = readOps .uniqueIndexGetForLabelAndPropertyKey( new NodePropertyDescriptor( person, id ) ); // when createLabeledNode( statement, "Person", "id", 2 ); // then I should find the original node - assertThat( statement.readOperations().nodeGetFromUniqueIndexSeek( idx, 1 ), equalTo( ourNode )); + assertThat( readOps.nodeGetFromUniqueIndexSeek( IndexBoundary.map( idx ), 1 ), equalTo( ourNode )); } private long constrainedNode( String labelName, String propertyKey, Object propertyValue ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/operations/ConstraintEnforcingEntityOperationsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/operations/ConstraintEnforcingEntityOperationsTest.java index cabf2a4fcd29..1c817399aae8 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/operations/ConstraintEnforcingEntityOperationsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/operations/ConstraintEnforcingEntityOperationsTest.java @@ -26,6 +26,9 @@ import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.index.InternalIndexState; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations; import org.neo4j.kernel.impl.api.KernelStatement; import org.neo4j.kernel.impl.constraints.StandardConstraintSemantics; @@ -62,7 +65,8 @@ public void given_ConstraintEnforcingEntityOperations_with_OnlineIndex() throws SchemaReadOperations schemaReadOps = mock( SchemaReadOperations.class ); SchemaWriteOperations schemaWriteOps = mock( SchemaWriteOperations.class ); this.state = mock( KernelStatement.class ); - when( schemaReadOps.indexGetState( state, indexDescriptor ) ).thenReturn( InternalIndexState.ONLINE ); + when( schemaReadOps.indexGetState( state, IndexBoundary.map( indexDescriptor ) ) ) + .thenReturn( InternalIndexState.ONLINE ); this.locks = mock( Locks.Client.class ); when( state.locks() ).thenReturn( new SimpleStatementLocks( locks ) ); when( state.lockTracer() ).thenReturn( LockTracer.NONE ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java index 3f7297f536a3..02b55e4c7695 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/api/state/SchemaTransactionStateTest.java @@ -62,14 +62,14 @@ public class SchemaTransactionStateTest { - private static IndexDescriptor indexCreate( StateHandlingStatementOperations txContext, KernelStatement state, + private static NewIndexDescriptor indexCreate( StateHandlingStatementOperations txContext, KernelStatement state, int labelId, int propertyKey ) { - return txContext.indexCreate( state, new NodePropertyDescriptor( labelId, propertyKey ) ); + return IndexBoundary.map( txContext.indexCreate( state, new NodePropertyDescriptor( labelId, propertyKey ) ) ); } - private static IndexDescriptor indexGetForLabelAndPropertyKey( StateHandlingStatementOperations txContext, KernelStatement state, - int labelId, int propertyKey ) + private static NewIndexDescriptor indexGetForLabelAndPropertyKey( + StateHandlingStatementOperations txContext, KernelStatement state, int labelId, int propertyKey ) { return txContext.indexGetForLabelAndPropertyKey( state, new NodePropertyDescriptor( labelId, propertyKey ) ); } @@ -86,13 +86,13 @@ public void addedRuleShouldBeVisibleInTx() throws Exception commitNoLabels(); // WHEN - IndexDescriptor rule = indexCreate( txContext, state, labelId1, key1 ); + NewIndexDescriptor index = indexCreate( txContext, state, labelId1, key1 ); // THEN - assertEquals( asSet( rule ), Iterators.asSet( txContext.indexesGetForLabel( state, labelId1 ) ) ); + assertEquals( asSet( index ), Iterators.asSet( txContext.indexesGetForLabel( state, labelId1 ) ) ); verify( store ).indexesGetForLabel( labelId1 ); - assertEquals( asSet( rule ), Iterators.asSet( txContext.indexesGetAll( state ) ) ); + assertEquals( asSet( index ), Iterators.asSet( txContext.indexesGetAll( state ) ) ); verify( store ).indexesGetAll(); verifyNoMoreInteractions( store ); @@ -105,8 +105,8 @@ public void addedRulesShouldBeVisibleInTx() throws Exception commitNoLabels(); // WHEN - IndexDescriptor rule1 = indexCreate( txContext, state, labelId1, key1 ); - IndexDescriptor rule2 = indexCreate( txContext, state, labelId2, key2 ); + NewIndexDescriptor rule1 = indexCreate( txContext, state, labelId1, key1 ); + NewIndexDescriptor rule2 = indexCreate( txContext, state, labelId2, key2 ); // THEN assertEquals( asSet( rule1 ), Iterators.asSet( txContext.indexesGetForLabel( state, labelId1 ) ) ); @@ -128,8 +128,8 @@ public void addedAdditionalRuleShouldBeVisibleInTx() throws Exception commitNoLabels(); // WHEN - IndexDescriptor rule1 = indexCreate( txContext, state, labelId1, key1 ); - IndexDescriptor rule2 = indexCreate( txContext, state, labelId1, key2 ); + NewIndexDescriptor rule1 = indexCreate( txContext, state, labelId1, key1 ); + NewIndexDescriptor rule2 = indexCreate( txContext, state, labelId1, key2 ); // THEN assertEquals( asSet( rule1, rule2 ), Iterators.asSet( txContext.indexesGetForLabel( state, labelId1 ) ) ); @@ -140,7 +140,7 @@ public void creatingAnIndexShouldBePopulatingStateWithinTX() throws Exception { // GIVEN commitLabels( labelId1 ); - IndexDescriptor rule = indexCreate( txContext, state, labelId1, key1 ); + NewIndexDescriptor rule = indexCreate( txContext, state, labelId1, key1 ); // THEN assertEquals( InternalIndexState.POPULATING, txContext.indexGetState( state, rule ) ); @@ -154,12 +154,12 @@ public void shouldReturnNonExistentRuleAddedInTransaction() throws Exception indexCreate( txContext, state, labelId1, key1 ); // WHEN - IndexDescriptor rule = indexGetForLabelAndPropertyKey( txContext, state, labelId1, key1 ); - Iterator labelRules = txContext.indexesGetForLabel( state, labelId1 ); + NewIndexDescriptor index = indexGetForLabelAndPropertyKey( txContext, state, labelId1, key1 ); + Iterator labelRules = txContext.indexesGetForLabel( state, labelId1 ); // THEN - IndexDescriptor expectedRule = IndexDescriptorFactory.of( labelId1, key1 ); - assertEquals(expectedRule, rule); + NewIndexDescriptor expectedRule = NewIndexDescriptorFactory.forLabel( labelId1, key1 ); + assertEquals( expectedRule, index ); assertEquals( asSet( expectedRule ), asSet( labelRules ) ); } @@ -173,14 +173,14 @@ public void shouldReturnNonExistentRuleAddedInTransactionFromLookup() throws Exc // -- the store already have an index on a different label with the same property NewIndexDescriptor existingRule2 = NewIndexDescriptorFactory.forLabel( labelId2, key2 ); when( indexGetForLabelAndPropertyKey( store, labelId2, key2 ) ).thenReturn( existingRule2 ); - // -- a non-existent rule has been added in the transaction + // -- a non-existent index has been added in the transaction indexCreate( txContext, state, labelId1, key2 ); // WHEN - IndexDescriptor rule = indexGetForLabelAndPropertyKey( txContext, state, labelId1, key2 ); + NewIndexDescriptor index = indexGetForLabelAndPropertyKey( txContext, state, labelId1, key2 ); // THEN - assertEquals( IndexDescriptorFactory.of( labelId1, key2 ), rule ); + assertEquals( NewIndexDescriptorFactory.forLabel( labelId1, key2 ), index ); } @Test @@ -197,12 +197,12 @@ public void shouldNotReturnRulesAddedInTransactionWithDifferentLabelOrPropertyFr indexCreate( txContext, state, labelId1, key2 ); // WHEN - IndexDescriptor lookupRule1 = indexGetForLabelAndPropertyKey( txContext, state, labelId1, key1 ); - IndexDescriptor lookupRule2 = indexGetForLabelAndPropertyKey( txContext, state, labelId2, key2 ); + NewIndexDescriptor lookupRule1 = indexGetForLabelAndPropertyKey( txContext, state, labelId1, key1 ); + NewIndexDescriptor lookupRule2 = indexGetForLabelAndPropertyKey( txContext, state, labelId2, key2 ); // THEN - assertEquals( existingIndex1, IndexBoundary.map( lookupRule1 ) ); - assertEquals( existingIndex2, IndexBoundary.map( lookupRule2 ) ); + assertEquals( existingIndex1, lookupRule1 ); + assertEquals( existingIndex2, lookupRule2 ); } @Test @@ -217,10 +217,10 @@ public void shouldNotReturnExistentRuleDroppedInTransaction() throws Exception // WHEN assertNull( indexGetForLabelAndPropertyKey( txContext, state, labelId1, key1 ) ); - Iterator rulesByLabel = txContext.indexesGetForLabel( state, labelId1 ); + Iterator rulesByLabel = txContext.indexesGetForLabel( state, labelId1 ); // THEN - assertEquals( emptySetOf( IndexDescriptor.class ), asSet( rulesByLabel ) ); + assertEquals( emptySetOf( NewIndexDescriptor.class ), asSet( rulesByLabel ) ); } // exists diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/CineastsDbStructure.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/CineastsDbStructure.java index 3fcfe53fc1fa..db7906d36ae3 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/CineastsDbStructure.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/CineastsDbStructure.java @@ -23,6 +23,7 @@ import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; // // GENERATED FILE. DO NOT EDIT. @@ -78,11 +79,11 @@ public void accept( DbStructureVisitor visitor ) visitor.visitRelationshipType( 2, "ACTS_IN" ); visitor.visitRelationshipType( 3, "RATED" ); visitor.visitRelationshipType( 4, "ROOT" ); - visitor.visitIndex( IndexDescriptorFactory.of( 0, 9 ), ":Movie(title)", 1.0d, 12462L ); - visitor.visitIndex( IndexDescriptorFactory.of( 1, 5 ), ":Person(name)", 1.0d, 49845L ); - visitor.visitIndex( IndexDescriptorFactory.of( 3, 5 ), ":Actor(name)", 1.0d, 44689L ); - visitor.visitIndex( IndexDescriptorFactory.of( 4, 5 ), ":Director(name)", 1.0d, 6010L ); - visitor.visitUniqueIndex( IndexDescriptorFactory.of( 2, 3 ), ":User(login)", 1.0d, 45L ); + visitor.visitIndex( NewIndexDescriptorFactory.forLabel( 0, 9 ), ":Movie(title)", 1.0d, 12462L ); + visitor.visitIndex( NewIndexDescriptorFactory.forLabel( 1, 5 ), ":Person(name)", 1.0d, 49845L ); + visitor.visitIndex( NewIndexDescriptorFactory.forLabel( 3, 5 ), ":Actor(name)", 1.0d, 44689L ); + visitor.visitIndex( NewIndexDescriptorFactory.forLabel( 4, 5 ), ":Director(name)", 1.0d, 6010L ); + visitor.visitUniqueIndex( NewIndexDescriptorFactory.forLabel( 2, 3 ), ":User(login)", 1.0d, 45L ); visitor.visitUniqueConstraint( new UniquenessConstraint( new NodePropertyDescriptor( 2, 3 ) ), "CONSTRAINT ON ( user:User ) ASSERT user.login IS UNIQUE" ); visitor.visitAllNodesCount( 63042L ); visitor.visitNodeCount( 0, "Movie", 12862L ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollectorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollectorTest.java index 4162afbcb553..b55fa56c076f 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollectorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureCollectorTest.java @@ -25,6 +25,7 @@ import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import static java.util.Arrays.asList; import static org.junit.Assert.assertEquals; @@ -43,9 +44,9 @@ public void collectsDbStructure() collector.visitPropertyKey( 2, "income" ); collector.visitRelationshipType( 1, "LIVES_IN" ); collector.visitRelationshipType( 2, "FRIEND" ); - collector.visitUniqueIndex( IndexDescriptorFactory.of( 1, 1 ), ":Person(name)", 1.0d, 1L ); + collector.visitUniqueIndex( NewIndexDescriptorFactory.forLabel( 1, 1 ), ":Person(name)", 1.0d, 1L ); collector.visitUniqueConstraint( new UniquenessConstraint( new NodePropertyDescriptor( 2, 1 ) ), ":Person(name)" ); - collector.visitIndex( IndexDescriptorFactory.of( 2, 2 ), ":City(income)", 0.2d, 1L ); + collector.visitIndex( NewIndexDescriptorFactory.forLabel( 2, 2 ), ":City(income)", 0.2d, 1L ); collector.visitAllNodesCount( 50 ); collector.visitNodeCount( 1, "Person", 20 ); collector.visitNodeCount( 2, "City", 30 ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureInvocationTracingAcceptanceTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureInvocationTracingAcceptanceTest.java index 7c827b24e1b5..b3a252aecd48 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureInvocationTracingAcceptanceTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/DbStructureInvocationTracingAcceptanceTest.java @@ -48,6 +48,7 @@ import org.neo4j.kernel.api.schema.NodePropertyDescriptor; import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -131,8 +132,8 @@ private void exerciseVisitor( Function visitor ) visitor.apply( null ).visitPropertyKey( 1, "age" ); visitor.apply( null ).visitRelationshipType( 0, "ACCEPTS" ); visitor.apply( null ).visitRelationshipType( 1, "REJECTS" ); - visitor.apply( null ).visitIndex( IndexDescriptorFactory.of( 0, 1 ), ":Person(age)", 0.5d, 1L ); - visitor.apply( null ).visitUniqueIndex( IndexDescriptorFactory.of( 0, 0 ), ":Person(name)", 0.5d, 1L ); + visitor.apply( null ).visitIndex( NewIndexDescriptorFactory.forLabel( 0, 1 ), ":Person(age)", 0.5d, 1L ); + visitor.apply( null ).visitUniqueIndex( NewIndexDescriptorFactory.forLabel( 0, 0 ), ":Person(name)", 0.5d, 1L ); visitor.apply( null ).visitUniqueConstraint( new UniquenessConstraint( new NodePropertyDescriptor( 1, 0) ), ":Party(name)" ); visitor.apply( null ).visitAllNodesCount( 55 ); visitor.apply( null ).visitNodeCount( 0, "Person", 50 ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuideTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuideTest.java index 1ba40ca844aa..f40b942586c9 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuideTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/GraphDbStructureGuideTest.java @@ -40,10 +40,14 @@ import org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException; import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.IndexBoundary; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.test.rule.ImpermanentDatabaseRule; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.neo4j.graphdb.DynamicLabel.label; @@ -123,7 +127,7 @@ public void visitsIndexes() throws Exception commitAndReOpen(); - IndexDescriptor descriptor = createSchemaIndex( labelId, pkId ); + NewIndexDescriptor descriptor = createSchemaIndex( labelId, pkId ); // WHEN accept( visitor ); @@ -142,7 +146,7 @@ public void visitsUniqueConstraintsAndIndices() throws Exception commitAndReOpen(); UniquenessConstraint constraint = createUniqueConstraint( labelId, pkId ); - IndexDescriptor descriptor = IndexDescriptorFactory.of( labelId, pkId ); + NewIndexDescriptor descriptor = NewIndexDescriptorFactory.uniqueForLabel( labelId, pkId ); // WHEN accept( visitor ); @@ -222,9 +226,9 @@ private void createRel( long startId, int relTypeId, long endId ) throws Excepti dataWrite().relationshipCreate( relTypeId, startId, endId ); } - private IndexDescriptor createSchemaIndex( int labelId, int pkId ) throws Exception + private NewIndexDescriptor createSchemaIndex( int labelId, int pkId ) throws Exception { - return schemaWrite().indexCreate( new NodePropertyDescriptor( labelId, pkId ) ); + return IndexBoundary.map( schemaWrite().indexCreate( new NodePropertyDescriptor( labelId, pkId ) ) ); } private UniquenessConstraint createUniqueConstraint( int labelId, int pkId ) throws Exception diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/QMULDbStructure.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/QMULDbStructure.java index af900c59a963..407f6d56712d 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/QMULDbStructure.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/util/dbstructure/QMULDbStructure.java @@ -21,6 +21,7 @@ import org.neo4j.helpers.collection.Visitable; import org.neo4j.kernel.api.schema.IndexDescriptorFactory; +import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory; // // GENERATED FILE. DO NOT EDIT. @@ -60,7 +61,7 @@ public void accept( DbStructureVisitor visitor ) visitor.visitPropertyKey( 16, "location_lat" ); visitor.visitRelationshipType( 0, "friends" ); visitor.visitRelationshipType( 1, "FRIEND" ); - visitor.visitIndex( IndexDescriptorFactory.of( 1, 2 ), ":Person(uid)", 1.0d, 135164L ); + visitor.visitIndex( NewIndexDescriptorFactory.forLabel( 1, 2 ), ":Person(uid)", 1.0d, 135164L ); visitor.visitAllNodesCount( 135242L ); visitor.visitNodeCount( 1, "Person", 135213L ); visitor.visitRelCount( -1, -1, -1, "MATCH ()-[]->() RETURN count(*)", 4537616L );