private void assertSerializeAndDeserializeIndexRule( StoreIndexDescriptor indexRule ) throws MalformedSchemaRuleException { StoreIndexDescriptor deserialized = assertIndexRule( serialiseAndDeserialise( indexRule ) ); assertThat( deserialized.getId(), equalTo( indexRule.getId() ) ); assertThat( deserialized, equalTo( indexRule ) ); assertThat( deserialized.schema(), equalTo( indexRule.schema() ) ); assertThat( deserialized.providerDescriptor(), equalTo( indexRule.providerDescriptor() ) ); }
@Test public void shouldCreateUniqueIndex() { // GIVEN IndexDescriptor descriptor = uniqueForLabel( LABEL_ID, PROPERTY_ID_1 ); StoreIndexDescriptor indexRule = descriptor.withId( RULE_ID ); // THEN assertThat( indexRule.getId(), equalTo( RULE_ID ) ); assertTrue( indexRule.canSupportUniqueConstraint() ); assertThat( indexRule.schema(), equalTo( descriptor.schema() ) ); assertThat( indexRule, equalTo( descriptor ) ); assertThat( indexRule.providerDescriptor(), equalTo( PROVIDER_DESCRIPTOR ) ); assertThat( indexRule.getOwningConstraint(), equalTo( null ) ); StoreIndexDescriptor withConstraint = indexRule.withOwningConstraint( RULE_ID_2 ); assertThat( withConstraint.getOwningConstraint(), equalTo( RULE_ID_2 ) ); assertThat( indexRule.getOwningConstraint(), equalTo( null ) ); // this is unchanged }
/** * Compute the byte size needed to serialize the provided IndexRule using serialize. * @param indexDescriptor the StoreIndexDescriptor * @return the byte size of StoreIndexDescriptor */ static int lengthOf( StoreIndexDescriptor indexDescriptor ) { int length = 4; // legacy label or relType id length += 1; // schema rule type IndexProviderDescriptor providerDescriptor = indexDescriptor.providerDescriptor(); length += UTF8.computeRequiredByteBufferSize( providerDescriptor.getKey() ); length += UTF8.computeRequiredByteBufferSize( providerDescriptor.getVersion() ); length += 1; // index type if ( indexDescriptor.type() == IndexDescriptor.Type.UNIQUE ) { length += 8; // owning constraint id } length += indexDescriptor.schema().computeWith( schemaSizeComputer ); length += UTF8.computeRequiredByteBufferSize( indexDescriptor.getName() ); return length; }
public boolean isIndexWithoutOwningConstraint() { return canSupportUniqueConstraint() && getOwningConstraint() == null; }
/** * WARNING: This toString is currently used in the inconsistency report, and cannot be changed due to backwards * compatibility. If you are also annoyed by this, maybe now is the time to fix the inconsistency checker. * * see InconsistencyReportReader.propagate( String, long ) */ @Override public String toString() { String ownerString = ""; if ( canSupportUniqueConstraint() ) { ownerString = ", owner=" + owningConstraintId; } return "IndexRule[id=" + id + ", descriptor=" + this.userDescription( idTokenNameLookup ) + ", provider=" + this.providerDescriptor() + ownerString + "]"; }
/** * Create a {@link StoreIndexDescriptor} with the given owning constraint id. * * @param constraintId an id >= 0, or null if no owning constraint exists. * @return a new StoreIndexDescriptor with modified owning constraint. */ public StoreIndexDescriptor withOwningConstraint( Long constraintId ) { if ( !canSupportUniqueConstraint() ) { throw new IllegalStateException( this + " is not a constraint index" ); } return new StoreIndexDescriptor( this, id, constraintId ); }
private void assertParseUniqueIndexRule( String serialized, String name ) throws MalformedSchemaRuleException { // GIVEN long ruleId = 33; long constraintId = 11; IndexDescriptor index = TestIndexDescriptorFactory.uniqueForLabel( 61, 988 ); IndexProviderDescriptor indexProvider = new IndexProviderDescriptor( "index-provider", "25.0" ); byte[] bytes = decodeBase64( serialized ); // WHEN StoreIndexDescriptor deserialized = assertIndexRule( SchemaRuleSerialization.deserialize( ruleId, ByteBuffer.wrap( bytes ) ) ); // THEN assertThat( deserialized.getId(), equalTo( ruleId ) ); assertThat( deserialized, equalTo( index ) ); assertThat( deserialized.schema(), equalTo( index.schema() ) ); assertThat( deserialized.providerDescriptor(), equalTo( indexProvider ) ); assertThat( deserialized.getOwningConstraint(), equalTo( constraintId ) ); assertThat( deserialized.getName(), is( name ) ); }
private StoreIndexDescriptor findRuleForLabel( LabelSchemaDescriptor schemaDescriptor ) { for ( StoreIndexDescriptor rule : rules ) { if ( rule.schema().equals( schemaDescriptor ) ) { return rule; } } return null; } }
indexesToDropAfterCompletedRecovery.remove( descriptor.getId() ); IndexProxy index = indexMap.getIndexProxy( descriptor.getId() ); if ( index != null && state == State.NOT_STARTED ) continue; boolean flipToTentative = descriptor.canSupportUniqueConstraint(); if ( state == State.RUNNING ) if ( descriptor.schema().entityType() == EntityType.NODE )
@Override public String getPopulationFailure( StoreIndexDescriptor descriptor ) throws IllegalStateException { String failure = getIndexStorage( descriptor.getId() ).getStoredIndexFailure(); if ( failure == null ) { throw new IllegalStateException( "Index " + descriptor.getId() + " isn't failed" ); } return failure; }
@Override public void checkIndexRule( StoreIndexDescriptor rule, DynamicRecord record, RecordAccess records, CheckerEngine<DynamicRecord,ConsistencyReport.SchemaConsistencyReport> engine ) { if ( rule.canSupportUniqueConstraint() ) { DynamicRecord obligation = indexObligations.get( rule.getId() ); if ( obligation == null ) // no pointer to here { if ( rule.getOwningConstraint() != null ) // we only expect a pointer if we have an owner { engine.report().missingObligation( SchemaRule.Kind.UNIQUENESS_CONSTRAINT ); } } else { // if someone points to here, it must be our owner if ( obligation.getId() != rule.getOwningConstraint() ) { engine.report().constraintIndexRuleNotReferencingBack( obligation ); } } } if ( indexAccessors.notOnlineRules().contains( rule ) ) { engine.report().schemaRuleNotOnline( rule ); } }
private String indexUserDescription( final StoreIndexDescriptor descriptor ) { return format( "%s [provider: %s]", descriptor.schema().userDescription( tokenNameLookup ), descriptor.providerDescriptor().toString() ); }
public boolean canSupportUniqueConstraint() { return type() == IndexDescriptor.Type.UNIQUE; }
for ( StoreIndexDescriptor indexRule : indexes.onlineRules() ) SchemaDescriptor schema = indexRule.schema(); if ( schema.entityType() == EntityType.NODE && schema.isAffected( labels ) ) if ( indexRule.canSupportUniqueConstraint() )
@Before public void setup() throws IOException { valueCreatorUtil = createValueCreatorUtil(); indexDescriptor = valueCreatorUtil.indexDescriptor(); layout = createLayout(); indexDirectoryStructure = directoriesByProvider( directory.directory( "root" ) ).forProvider( indexDescriptor.providerDescriptor() ); indexFile = indexDirectoryStructure.directoryForIndex( indexDescriptor.getId() ); fs.mkdirs( indexFile.getParentFile() ); pageCache = pageCacheRule.getPageCache( fs ); }
@Override public IndexPopulator getPopulator( StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig ) { SchemaIndex luceneIndex = LuceneSchemaIndexBuilder.create( descriptor, config ) .withFileSystem( fileSystem ) .withOperationalMode( operationalMode ) .withSamplingConfig( samplingConfig ) .withIndexStorage( getIndexStorage( descriptor.getId() ) ) .withWriterConfig( IndexWriterConfigs::population ) .build(); if ( luceneIndex.isReadOnly() ) { throw new UnsupportedOperationException( "Can't create populator for read only index" ); } if ( descriptor.type() == UNIQUE ) { return new UniqueLuceneIndexPopulator( luceneIndex, descriptor ); } else { return new NonUniqueLuceneIndexPopulator( luceneIndex, samplingConfig ); } }
constraintRule.getId(), indexRule.getOwningConstraint().longValue() ); assertEquals( "constraint should reference index", indexRule.getId(), constraintRule.getOwnedIndex() );
private IndexProvider provider( IndexProviderMap providers, StoreIndexDescriptor indexRule ) { return providers.lookup( indexRule.providerDescriptor() ); }
IndexProviderDescriptor providerDescriptor = descriptor.providerDescriptor(); IndexLogRecord indexLogRecord = new IndexLogRecord( descriptor ); indexStates.computeIfAbsent( state, internalIndexState -> new ArrayList<>() ) if ( descriptor.type() != IndexDescriptor.Type.UNIQUE )