target.putLong( constraintRule.getOwnedIndex() ); break; target.putLong( constraintRule.getOwnedIndex() ); break;
@Override public void checkConstraintRule( ConstraintRule rule, DynamicRecord record, RecordAccess records, CheckerEngine<DynamicRecord,ConsistencyReport.SchemaConsistencyReport> engine ) { checkSchema( rule, record, records, engine ); if ( rule.getConstraintDescriptor().enforcesUniqueness() ) { DynamicRecord previousObligation = indexObligations.put( rule.getOwnedIndex(), record.clone() ); if ( previousObligation != null ) { engine.report().duplicateObligation( previousObligation ); } } } }
private void assertParseUniqueConstraintRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 1; int propertyKey = 3; int labelId = 55; long ownedIndexId = 2; UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertThat( deserialized.getOwnedIndex(), equalTo( ownedIndexId ) ); assertThat( deserialized.getName(), is( name ) ); }
private void assertParseNodeKeyConstraintRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 1; int propertyKey = 3; int labelId = 55; long ownedIndexId = 2; NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForLabel( labelId, propertyKey ); byte[] bytes = decodeBase64( serialized ); // WHEN ConstraintRule deserialized = assertConstraintRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized.getConstraintDescriptor(), equalTo( constraint ) ); assertThat( deserialized.schema(), equalTo( constraint.schema() ) ); assertThat( deserialized.getOwnedIndex(), equalTo( ownedIndexId ) ); assertThat( deserialized.getName(), is( name ) ); }
public void validateSchemaRule( SchemaRule schemaRule ) throws TransactionFailureException { if ( schemaRule instanceof ConstraintRule ) { ConstraintRule constraintRule = (ConstraintRule) schemaRule; if ( constraintRule.getConstraintDescriptor().enforcesUniqueness() ) { try { indexes.validateIndex( constraintRule.getOwnedIndex() ); } catch ( UniquePropertyValueValidationException e ) { throw new TransactionFailureException( Status.Transaction.TransactionValidationFailed, e, "Index validation failed" ); } catch ( IndexNotFoundKernelException | IndexPopulationFailedKernelException e ) { // We don't expect this to occur, and if they do, it is because we are in a very bad state - out of // disk or index corruption, or similar. This will kill the database such that it can be shut down // and have recovery performed. It's the safest bet to avoid loosing data. throw new TransactionFailureException( Status.Transaction.TransactionValidationFailed, e, "Index population failure" ); } } } } }
@Override public void checkConstraintRule( ConstraintRule rule, DynamicRecord record, RecordAccess records, CheckerEngine<DynamicRecord,ConsistencyReport.SchemaConsistencyReport> engine ) { if ( rule.getConstraintDescriptor().enforcesUniqueness() ) { DynamicRecord obligation = constraintObligations.get( rule.getId() ); if ( obligation == null ) { engine.report().missingObligation( SchemaRule.Kind.CONSTRAINT_INDEX_RULE ); } else { if ( obligation.getId() != rule.getOwnedIndex() ) { engine.report().uniquenessConstraintNotReferencingBack( obligation ); } } } } }
@Test public void shouldCreateUniquenessConstraintWithOwnedIndex() { // GIVEN UniquenessConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor, RULE_ID_2 ); // THEN assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertThat( constraintRule.getOwnedIndex(), equalTo( RULE_ID_2 ) ); }
@Test public void shouldCreateNodeKeyConstraintWithOwnedIndex() { // GIVEN NodeKeyConstraintDescriptor descriptor = nodeKeyForLabel( LABEL_ID, PROPERTY_ID_1 ); ConstraintRule constraintRule = ConstraintRule.constraintRule( RULE_ID, descriptor, RULE_ID_2 ); // THEN assertThat( constraintRule.getConstraintDescriptor(), equalTo( descriptor ) ); assertThat( constraintRule.getOwnedIndex(), equalTo( RULE_ID_2 ) ); }
constraintRule.getId(), indexRule.getOwningConstraint().longValue() ); assertEquals( "constraint should reference index", indexRule.getId(), constraintRule.getOwnedIndex() );
target.putLong( constraintRule.getOwnedIndex() ); break; target.putLong( constraintRule.getOwnedIndex() ); break;
public void validateSchemaRule( SchemaRule schemaRule ) throws TransactionFailureException { if ( schemaRule instanceof ConstraintRule ) { ConstraintRule constraintRule = (ConstraintRule) schemaRule; if ( constraintRule.getConstraintDescriptor().enforcesUniqueness() ) { try { indexes.validateIndex( constraintRule.getOwnedIndex() ); } catch ( UniquePropertyValueValidationException e ) { throw new TransactionFailureException( Status.Transaction.TransactionValidationFailed, e, "Index validation failed" ); } catch ( IndexNotFoundKernelException | IndexPopulationFailedKernelException e ) { // We don't expect this to occur, and if they do, it is because we are in a very bad state - out of // disk or index corruption, or similar. This will kill the database such that it can be shut down // and have recovery performed. It's the safest bet to avoid loosing data. throw new TransactionFailureException( Status.Transaction.TransactionValidationFailed, e, "Index population failure" ); } } } } }