private void awaitOnline( IndexReference indexReference ) throws IndexNotFoundKernelException { // We do the isAdded check on the transaction state first, because indexGetState will grab a schema read-lock, which can deadlock on the write-lock // held by the index populator. Also, if we index was created in this transaction, then we will never see it come online in this transaction anyway. // Indexes don't come online until the transaction that creates them has committed. if ( !((KernelTransactionImplementation)tx).txState().indexDiffSetsBySchema( indexReference.schema() ).isAdded( (IndexDescriptor) indexReference ) ) { // If the index was not created in this transaction, then wait for it to come online before querying. Schema schema = db.schema(); IndexDefinition index = schema.getIndexByName( indexReference.name() ); schema.awaitIndexOnline( index, INDEX_ONLINE_QUERY_TIMEOUT_SECONDS, TimeUnit.SECONDS ); } // If the index was created in this transaction, then we skip this check entirely. // We will get an exception later, when we try to get an IndexReader, so this is fine. }
@Test void mustRememberNamesOfCreatedIndex() { String indexName = "Users index"; try ( Transaction tx = db.beginTx() ) { IndexDefinition index = db.schema().indexFor( USER_LABEL ).on( "name" ).withName( indexName ).create(); assertThat( index.getName(), is( indexName ) ); tx.success(); } try ( Transaction tx = db.beginTx() ) { IndexDefinition index = db.schema().getIndexByName( indexName ); assertThat( index.getName(), is( indexName ) ); tx.success(); } }
assertFalse( result.hasNext() ); result.close(); assertNotNull( db.schema().getIndexByName( "test-index" ) ); tx.success(); assertNotNull( db.schema().getIndexByName( "test-index" ) ); tx.success();
assertFalse( result.hasNext() ); result.close(); assertNotNull( db.schema().getIndexByName( "test-index" ) ); tx.success(); assertNotNull( db.schema().getIndexByName( "test-index" ) ); tx.success();