Skip to content

Commit

Permalink
Removed old IndexDescriptor around TxState
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and chrisvest committed Feb 14, 2017
1 parent 8fbaa3b commit 7384215
Show file tree
Hide file tree
Showing 31 changed files with 281 additions and 322 deletions.
Expand Up @@ -222,7 +222,7 @@ public void checkConstraintRule( ConstraintRule rule, DynamicRecord record,
private void checkSchema( SchemaRule rule, DynamicRecord record, private void checkSchema( SchemaRule rule, DynamicRecord record,
RecordAccess records, CheckerEngine<DynamicRecord,ConsistencyReport.SchemaConsistencyReport> engine ) RecordAccess records, CheckerEngine<DynamicRecord,ConsistencyReport.SchemaConsistencyReport> engine )
{ {
new CheckSchema( engine, records ).process( rule.getSchemaDescriptor() ); new CheckSchema( engine, records ).process( rule.schema() );
checkForDuplicates( rule, record, engine ); checkForDuplicates( rule, record, engine );
} }


Expand Down
Expand Up @@ -38,7 +38,7 @@ public IndexCheck( IndexRule indexRule )
@Override @Override
public void check( IndexEntry record, CheckerEngine<IndexEntry, ConsistencyReport.IndexConsistencyReport> engine, RecordAccess records ) public void check( IndexEntry record, CheckerEngine<IndexEntry, ConsistencyReport.IndexConsistencyReport> engine, RecordAccess records )
{ {
int labelId = indexRule.getSchemaDescriptor().getLabelId(); int labelId = indexRule.schema().getLabelId();
engine.comparativeCheck( records.node( record.getId() ), engine.comparativeCheck( records.node( record.getId() ),
new NodeInUseWithCorrectLabelsCheck<>( new long[]{labelId}, false ) ); new NodeInUseWithCorrectLabelsCheck<>( new long[]{labelId}, false ) );
} }
Expand Down
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.consistency.checking.full; package org.neo4j.consistency.checking.full;


import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.function.Function; import java.util.function.Function;


import org.neo4j.collection.primitive.Primitive; import org.neo4j.collection.primitive.Primitive;
Expand All @@ -30,7 +29,6 @@
import org.neo4j.consistency.RecordType; import org.neo4j.consistency.RecordType;
import org.neo4j.consistency.report.ConsistencyReport; import org.neo4j.consistency.report.ConsistencyReport;
import org.neo4j.consistency.report.ConsistencyReporter; import org.neo4j.consistency.report.ConsistencyReporter;
import org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor; import org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.SchemaProcessor; import org.neo4j.kernel.api.schema_new.SchemaProcessor;
Expand Down Expand Up @@ -58,7 +56,7 @@ public MandatoryProperties( StoreAccess storeAccess )
{ {
if ( rule.getConstraintDescriptor().type() == EXISTS ) if ( rule.getConstraintDescriptor().type() == EXISTS )
{ {
constraintRecorder.process( rule.getSchemaDescriptor() ); constraintRecorder.process( rule.schema() );
} }
} }
} }
Expand Down
Expand Up @@ -81,7 +81,7 @@ private void checkIndexToLabels( NodeRecord record,
List<PropertyBlock> properties = null; List<PropertyBlock> properties = null;
for ( IndexRule indexRule : indexes.rules() ) for ( IndexRule indexRule : indexes.rules() )
{ {
long labelId = indexRule.getSchemaDescriptor().getLabelId(); long labelId = indexRule.schema().getLabelId();
if ( !labels.contains( labelId ) ) if ( !labels.contains( labelId ) )
{ {
continue; continue;
Expand All @@ -91,7 +91,7 @@ private void checkIndexToLabels( NodeRecord record,
{ {
properties = propertyReader.propertyBlocks( propertyRecs ); properties = propertyReader.propertyBlocks( propertyRecs );
} }
int propertyId = indexRule.getSchemaDescriptor().getPropertyIds()[0]; // assuming 1 property always int propertyId = indexRule.schema().getPropertyIds()[0]; // assuming 1 property always
PropertyBlock property = propertyWithKey( properties, propertyId ); PropertyBlock property = propertyWithKey( properties, propertyId );


if ( property == null ) if ( property == null )
Expand Down
Expand Up @@ -66,11 +66,11 @@ public interface SchemaDescriptor
*/ */
default boolean isSame( SchemaDescriptor.Supplier supplier ) default boolean isSame( SchemaDescriptor.Supplier supplier )
{ {
return this.equals( supplier.getSchemaDescriptor() ); return this.equals( supplier.schema() );
} }


interface Supplier interface Supplier
{ {
SchemaDescriptor getSchemaDescriptor(); SchemaDescriptor schema();
} }
} }
Expand Up @@ -27,19 +27,19 @@ public class SchemaDescriptorPredicates
{ {
public static boolean hasLabel( SchemaDescriptor.Supplier supplier, int labelId ) public static boolean hasLabel( SchemaDescriptor.Supplier supplier, int labelId )
{ {
Optional<Integer> labelOpt = getLabel.compute( supplier.getSchemaDescriptor() ); Optional<Integer> labelOpt = getLabel.compute( supplier.schema() );
return labelOpt.isPresent() && labelOpt.get() == labelId; return labelOpt.isPresent() && labelOpt.get() == labelId;
} }


public static boolean hasRelType( SchemaDescriptor.Supplier supplier, int relTypeId ) public static boolean hasRelType( SchemaDescriptor.Supplier supplier, int relTypeId )
{ {
Optional<Integer> relTypeOpt = getRelType.compute( supplier.getSchemaDescriptor() ); Optional<Integer> relTypeOpt = getRelType.compute( supplier.schema() );
return relTypeOpt.isPresent() && relTypeOpt.get() == relTypeId; return relTypeOpt.isPresent() && relTypeOpt.get() == relTypeId;
} }


public static boolean hasProperty( SchemaDescriptor.Supplier supplier, int propertyId ) public static boolean hasProperty( SchemaDescriptor.Supplier supplier, int propertyId )
{ {
List<Integer> properties = getProperties.compute( supplier.getSchemaDescriptor() ); List<Integer> properties = getProperties.compute( supplier.schema() );
return properties.contains( propertyId ); return properties.contains( propertyId );
} }


Expand Down
Expand Up @@ -28,7 +28,7 @@
* Internal representation of a graph constraint, including the schema unit it targets (eg. label-property combination) * Internal representation of a graph constraint, including the schema unit it targets (eg. label-property combination)
* and the how that schema unit is constrained (eg. "has to exist", or "must be unique"). * and the how that schema unit is constrained (eg. "has to exist", or "must be unique").
*/ */
public class ConstraintDescriptor public class ConstraintDescriptor implements SchemaDescriptor.Supplier
{ {
public enum Type { UNIQUE, EXISTS } public enum Type { UNIQUE, EXISTS }


Expand All @@ -48,6 +48,7 @@ public interface Supplier


// METHODS // METHODS


@Override
public SchemaDescriptor schema() public SchemaDescriptor schema()
{ {
return schema; return schema;
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.helpers.collection.Iterators; import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema.IndexDescriptor;
import org.neo4j.kernel.api.schema.IndexDescriptorFactory; import org.neo4j.kernel.api.schema.IndexDescriptorFactory;
import org.neo4j.kernel.api.schema.NodePropertyDescriptor;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;


/** /**
Expand Down Expand Up @@ -59,6 +60,24 @@ public static NewIndexDescriptor map( IndexDescriptor descriptor )
return NewIndexDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() ); return NewIndexDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() );
} }


public static NewIndexDescriptor map( NodePropertyDescriptor descriptor )
{
if ( descriptor == null )
{
return null;
}
return NewIndexDescriptorFactory.forLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() );
}

public static NewIndexDescriptor mapUnique( IndexDescriptor descriptor )
{
if ( descriptor == null )
{
return null;
}
return NewIndexDescriptorFactory.uniqueForLabel( descriptor.getLabelId(), descriptor.getPropertyKeyId() );
}

public static Iterator<IndexDescriptor> map( Iterator<NewIndexDescriptor> iterator ) public static Iterator<IndexDescriptor> map( Iterator<NewIndexDescriptor> iterator )
{ {
return Iterators.map( IndexBoundary::map, iterator ); return Iterators.map( IndexBoundary::map, iterator );
Expand Down
Expand Up @@ -19,8 +19,11 @@
*/ */
package org.neo4j.kernel.api.schema_new.index; package org.neo4j.kernel.api.schema_new.index;


import java.util.function.Predicate;

import org.neo4j.kernel.api.TokenNameLookup; import org.neo4j.kernel.api.TokenNameLookup;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor; import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.SchemaDescriptor;


import static java.lang.String.format; import static java.lang.String.format;


Expand All @@ -31,10 +34,38 @@
* This will be renamed to IndexDescriptor, once the old org.neo4j.kernel.api.schema.IndexDescriptor is completely * This will be renamed to IndexDescriptor, once the old org.neo4j.kernel.api.schema.IndexDescriptor is completely
* removed. * removed.
*/ */
public class NewIndexDescriptor public class NewIndexDescriptor implements SchemaDescriptor.Supplier
{ {
public enum Type { GENERAL, UNIQUE } public enum Type { GENERAL, UNIQUE }


public enum Filter implements Predicate<NewIndexDescriptor>
{
GENERAL
{
@Override
public boolean test( NewIndexDescriptor rule )
{
return rule.type == Type.GENERAL;
}
},
UNIQUE
{
@Override
public boolean test( NewIndexDescriptor rule )
{
return rule.type == Type.UNIQUE;
}
},
ANY
{
@Override
public boolean test( NewIndexDescriptor rule )
{
return true;
}
}
}

public interface Supplier public interface Supplier
{ {
NewIndexDescriptor getIndexDescriptor(); NewIndexDescriptor getIndexDescriptor();
Expand All @@ -60,6 +91,7 @@ public Type type()
* This method currently returns the specific LabelSchemaDescriptor, as we do not support indexes on relations. * This method currently returns the specific LabelSchemaDescriptor, as we do not support indexes on relations.
* When we do, consider down-typing this to a SchemaDescriptor. * When we do, consider down-typing this to a SchemaDescriptor.
*/ */
@Override
public LabelSchemaDescriptor schema() public LabelSchemaDescriptor schema()
{ {
return schema; return schema;
Expand Down
Expand Up @@ -24,9 +24,10 @@
import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint; import org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint;
import org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint; import org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint;
import org.neo4j.kernel.api.constraints.UniquenessConstraint; import org.neo4j.kernel.api.constraints.UniquenessConstraint;
import org.neo4j.kernel.api.schema.IndexDescriptor;
import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.api.properties.Property; import org.neo4j.kernel.api.properties.Property;
import org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor;
import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;


/** /**
Expand Down Expand Up @@ -78,13 +79,9 @@ void relationshipDoReplaceProperty( long relationshipId,


// SCHEMA RELATED // SCHEMA RELATED


void indexRuleDoAdd( IndexDescriptor descriptor ); void indexRuleDoAdd( NewIndexDescriptor descriptor );


void constraintIndexRuleDoAdd( IndexDescriptor descriptor ); void indexDoDrop( NewIndexDescriptor descriptor );

void indexDoDrop( IndexDescriptor descriptor );

void constraintIndexDoDrop( IndexDescriptor descriptor );


void constraintDoAdd( UniquenessConstraint constraint, long indexId ); void constraintDoAdd( UniquenessConstraint constraint, long indexId );


Expand All @@ -100,5 +97,5 @@ void relationshipDoReplaceProperty( long relationshipId,


boolean constraintIndexDoUnRemove( UniquenessConstraint constraint ); boolean constraintIndexDoUnRemove( UniquenessConstraint constraint );


void indexDoUpdateProperty( IndexDescriptor descriptor, long nodeId, DefinedProperty before, DefinedProperty after ); void indexDoUpdateProperty( LabelSchemaDescriptor descriptor, long nodeId, DefinedProperty before, DefinedProperty after );
} }
Expand Up @@ -43,7 +43,7 @@
import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationKernelException; import org.neo4j.kernel.api.exceptions.schema.ConstraintValidationKernelException;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException; import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException; import org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException;
import org.neo4j.kernel.api.schema.IndexDescriptor; import org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor;
import org.neo4j.kernel.api.security.SecurityContext; import org.neo4j.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.txstate.LegacyIndexTransactionState; import org.neo4j.kernel.api.txstate.LegacyIndexTransactionState;
import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.api.txstate.TransactionState;
Expand Down Expand Up @@ -349,7 +349,7 @@ private void dropCreatedConstraintIndexes() throws TransactionFailureException
{ {
if ( hasTxStateWithChanges() ) if ( hasTxStateWithChanges() )
{ {
for ( IndexDescriptor createdConstraintIndex : txState().constraintIndexesCreatedInTx() ) for ( NewIndexDescriptor createdConstraintIndex : txState().constraintIndexesCreatedInTx() )
{ {
try try
{ {
Expand Down

0 comments on commit 7384215

Please sign in to comment.