private void awaitIndexesOnline( int timeout, TimeUnit unit ) { try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( timeout, unit ); tx.success(); } }
@Override void doCreateIndex( DatabaseRule db ) { db.schema().indexFor( indexLabel ).on( stringProp1 ).create(); } }
@Override void doCreateIndex( DatabaseRule db ) { db.schema().indexFor( indexLabel ).on( numberProp1 ).create(); } }
private void awaitIndexes() { try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 30, SECONDS ); tx.success(); } }
private static void awaitIndexes() { try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); tx.success(); } } }
@Override void doCreateIndex( DatabaseRule db ) { db.schema().indexFor( indexLabel ).on( numberProp1 ).on( numberProp2 ).create(); } }
@Override void doCreateIndex( DatabaseRule db ) { db.schema().indexFor( indexLabel ).on( stringProp1 ).on( stringProp2 ).create(); } }
private void createIndex( String... propKeys ) { try ( Transaction tx = db.beginTx() ) { IndexCreator indexCreator = db.schema().indexFor( LABEL_ONE ); for ( String propKey : propKeys ) { indexCreator = indexCreator.on( propKey ); } indexCreator.create(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); tx.success(); } }
private void createIndex( String... keys ) { try ( Transaction tx = db.beginTx() ) { IndexCreator indexCreator = db.schema().indexFor( LABEL ); for ( String key : keys ) { indexCreator = indexCreator.on( key ); } indexCreator.create(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 10, SECONDS ); tx.success(); } } }
@BeforeClass public static void given() { // database with an index on `(:Node).prop` try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( label( "Node" ) ).on( "prop" ).create(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 10, SECONDS ); tx.success(); } }
private Runnable indexCreate( int labelIndex ) { return () -> { try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( label( labelIndex ) ).on( KEY ).create(); tx.success(); } }; }
@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() ); } }
void createIndex( DatabaseRule db ) { try ( Transaction tx = db.beginTx() ) { doCreateIndex( db ); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); tx.success(); } }
private void createIndexesButDontWaitForThemToFullyPopulate( int i ) { try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( labelA( i ) ).on( keyA( i ) ).create(); if ( random.nextBoolean() ) { db.schema().indexFor( labelB( i ) ).on( keyB( i ) ).create(); } else { db.schema().constraintFor( labelB( i ) ).assertPropertyIsUnique( keyB( i ) ).create(); } tx.success(); } }
private IndexDefinition createIndex() { try ( Transaction tx = db.beginTx() ) { for ( int i = 0; i < NODES; i++ ) { db.createNode( LABEL ).setProperty( KEY, i ); } tx.success(); } IndexDefinition indexDefinition; try ( Transaction tx = db.beginTx() ) { indexDefinition = db.schema().indexFor( LABEL ).on( KEY ).create(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 10, TimeUnit.SECONDS ); tx.success(); } return indexDefinition; }
@Test public void failedIndexShouldRepairAutomatically() throws Exception { // given try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( PERSON ).on( "name" ).create(); tx.success(); } awaitIndexesOnline( 5, SECONDS ); createNamed( PERSON, "Johan" ); // when - we restart the database in a state where the index is not operational db.restartDatabase( new SabotageNativeIndex( random.random() ) ); // then - the database should still be operational createNamed( PERSON, "Lars" ); awaitIndexesOnline( 5, SECONDS ); indexStateShouldBe( equalTo( ONLINE ) ); assertFindsNamed( PERSON, "Lars" ); }