@Override public void start() throws Throwable { neoStores.makeStoreOk(); tokenHolders.propertyKeyTokens().setInitialTokens( neoStores.getPropertyKeyTokenStore().getTokens() ); tokenHolders.relationshipTypeTokens().setInitialTokens( neoStores.getRelationshipTypeTokenStore().getTokens() ); tokenHolders.labelTokens().setInitialTokens( neoStores.getLabelTokenStore().getTokens() ); neoStores.startCountStore(); // TODO: move this to counts store lifecycle loadSchemaCache(); indexingService.start(); labelScanStore.start(); idController.start(); }
@Test public void shouldDropUniquenessConstraintWhereConstraintRecordIsMissing() throws Exception { // given try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create(); tx.success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore(); SchemaRule indexRule = single( filter( rule -> rule instanceof ConstraintRule, schemaStore.loadAllSchemaRules() ) ); setSchemaRecordNotInUse( schemaStore, indexRule.getId() ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() ) { // We don't use single() here, because it is okay for the schema cache reload to clean up after us. db.schema().getConstraints( label ).forEach( ConstraintDefinition::drop ); db.schema().getIndexes( label ).forEach( IndexDefinition::drop ); tx.success(); } // then try ( Transaction ignore = db.beginTx() ) { assertFalse( db.schema().getConstraints().iterator().hasNext() ); assertFalse( db.schema().getIndexes().iterator().hasNext() ); } }
@Test public void shouldDropUniquenessConstraintWithBackingIndexNotInUse() { // given try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create(); tx.success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore(); SchemaRule indexRule = single( filter( rule -> rule instanceof StoreIndexDescriptor, schemaStore.loadAllSchemaRules() ) ); setSchemaRecordNotInUse( schemaStore, indexRule.getId() ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() ) { single( db.schema().getConstraints( label ).iterator() ).drop(); tx.success(); } // then try ( Transaction ignore = db.beginTx() ) { assertFalse( db.schema().getConstraints().iterator().hasNext() ); assertFalse( db.schema().getIndexes().iterator().hasNext() ); } }
@Test public void shouldDropUniquenessConstraintWithBackingIndexHavingNoOwner() throws Exception { // given try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create(); tx.success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore(); SchemaRule indexRule = single( filter( rule -> rule instanceof StoreIndexDescriptor, schemaStore.loadAllSchemaRules() ) ); setOwnerNull( schemaStore, (StoreIndexDescriptor) indexRule ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() ) { single( db.schema().getConstraints( label ).iterator() ).drop(); tx.success(); } // then try ( Transaction ignore = db.beginTx() ) { assertFalse( db.schema().getConstraints().iterator().hasNext() ); assertFalse( db.schema().getIndexes().iterator().hasNext() ); } }
setOwnerNull( schemaStore, (StoreIndexDescriptor) indexRule ); storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() )
@Override public void start() throws Throwable { neoStores.makeStoreOk(); tokenHolders.propertyKeyTokens().setInitialTokens( neoStores.getPropertyKeyTokenStore().getTokens() ); tokenHolders.relationshipTypeTokens().setInitialTokens( neoStores.getRelationshipTypeTokenStore().getTokens() ); tokenHolders.labelTokens().setInitialTokens( neoStores.getLabelTokenStore().getTokens() ); neoStores.startCountStore(); // TODO: move this to counts store lifecycle loadSchemaCache(); indexingService.start(); labelScanStore.start(); idController.start(); }