public static void waitForIndex( GraphDatabaseService beansAPI, IndexDefinition indexDef ) { try ( Transaction ignored = beansAPI.beginTx() ) { beansAPI.schema().awaitIndexOnline( indexDef, 30, SECONDS ); } }
private void awaitIndexOnline( IndexDefinition definition ) { try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexOnline( definition, 10, TimeUnit.SECONDS ); tx.success(); } }
private void waitForIndex( IndexDefinition definition ) { try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexOnline( definition, 10, TimeUnit.SECONDS ); tx.success(); } }
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. }
private void createIndexAndAwaitPopulation( Label label ) { IndexDefinition index = createIndex( label ); try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexOnline( index, 10, SECONDS ); tx.success(); } }
@Test public void awaitingIndexComingOnlineWorks() { // GIVEN // WHEN IndexDefinition index = createIndex( db, label, propertyKey ); // PASS try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexOnline( index, 1L, TimeUnit.MINUTES ); // THEN assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) ); } }
private static void createIndex( GraphDatabaseService gds, Label label, String propKey ) { IndexDefinition indexDefinition; try ( Transaction tx = gds.beginTx() ) { indexDefinition = gds.schema().indexFor( label ).on( propKey ).create(); tx.success(); } try ( Transaction tx = gds.beginTx() ) { gds.schema().awaitIndexOnline( indexDefinition, 1, TimeUnit.MINUTES ); tx.success(); } }
@Test public void shouldTimeoutWaitingForIndexToComeOnline() { // given GraphDatabaseService db = rule.getGraphDatabaseAPI(); DoubleLatch latch = provider.installPopulationJobCompletionLatch(); IndexDefinition index; try ( Transaction tx = db.beginTx() ) { index = db.schema().indexFor( Label.label( "Person" ) ).on( "name" ).create(); tx.success(); } latch.waitForAllToStart(); // when try ( Transaction tx = db.beginTx() ) { // then db.schema().awaitIndexOnline( index, 1, TimeUnit.MILLISECONDS ); fail( "Expected IllegalStateException to be thrown" ); } catch ( IllegalStateException e ) { // good assertThat( e.getMessage(), containsString( "come online" ) ); } finally { latch.finish(); } }
db.schema().awaitIndexOnline( indexDefinition, 10, TimeUnit.SECONDS ); tx.success();
@Override public void awaitIndexOnline( IndexDefinition index, long duration, TimeUnit unit ) { actual.awaitIndexOnline( index, duration, unit ); }
private void awaitIndexes( Output out, org.neo4j.graphdb.schema.Schema schema, Label[] labels, String property ) throws RemoteException { for ( IndexDefinition index : indexesByLabelAndProperty( schema, labels, property ) ) { if ( schema.getIndexState( index ) != IndexState.ONLINE ) { out.println( String.format( "Awaiting :%s ON %s %s", index.getLabel().name(), asList( index.getPropertyKeys() ), IndexState.ONLINE ) ); schema.awaitIndexOnline( index, 10000, TimeUnit.DAYS ); } } }
public static void setupSchemaIndexes(GraphDatabaseService graphDb, Neo4jConfiguration config) { Map<String, Set<String>> schemaIndexes = config.getSchemaIndexes(); for (Map.Entry<String, Set<String>> entry : schemaIndexes.entrySet()) { Label label = Label.label(entry.getKey()); for (String property : entry.getValue()) { try (Transaction tx = graphDb.beginTx()) { Schema schema = graphDb.schema(); IndexDefinition indexDefinition = schema.indexFor(label).on(property).create(); tx.success(); tx.close(); Transaction tx2 = graphDb.beginTx(); schema.awaitIndexOnline(indexDefinition, 2, TimeUnit.MINUTES); tx2.success(); tx2.close(); } } } }
schema.awaitIndexOnline( indexDefinition, 10, TimeUnit.SECONDS );