org.neo4j.graphdb.schema.Schema.awaitIndexOnline()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中org.neo4j.graphdb.schema.Schema.awaitIndexOnline()方法的一些代码示例,展示了Schema.awaitIndexOnline()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Schema.awaitIndexOnline()方法的具体详情如下:
包路径:org.neo4j.graphdb.schema.Schema
类名称:Schema
方法名:awaitIndexOnline

Schema.awaitIndexOnline介绍

[英]Wait until an index comes online
[中]等待索引上线

代码示例

代码示例来源:origin: neo4j/neo4j

public static void waitForIndex( GraphDatabaseService beansAPI, IndexDefinition indexDef )
{
  try ( Transaction ignored = beansAPI.beginTx() )
  {
    beansAPI.schema().awaitIndexOnline( indexDef, 30, SECONDS );
  }
}

代码示例来源:origin: neo4j/neo4j

private void awaitIndexOnline( IndexDefinition definition )
{
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().awaitIndexOnline( definition, 10, TimeUnit.SECONDS );
    tx.success();
  }
}

代码示例来源:origin: neo4j/neo4j

private void waitForIndex( IndexDefinition definition )
{
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().awaitIndexOnline( definition, 10, TimeUnit.SECONDS );
    tx.success();
  }
}

代码示例来源:origin: neo4j/neo4j

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.
}

代码示例来源:origin: neo4j/neo4j

private void createIndexAndAwaitPopulation( Label label )
{
  IndexDefinition index = createIndex( label );
  try ( Transaction tx = db.beginTx() )
  {
    db.schema().awaitIndexOnline( index, 10, SECONDS );
    tx.success();
  }
}

代码示例来源:origin: neo4j/neo4j

@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 ) );
  }
}

代码示例来源:origin: neo4j/neo4j

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();
  }
}

代码示例来源:origin: neo4j/neo4j

@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();
  }
}

代码示例来源:origin: neo4j/neo4j

db.schema().awaitIndexOnline( indexDefinition, 10, TimeUnit.SECONDS );
tx.success();

代码示例来源:origin: org.neo4j/neo4j-shell

@Override
public void awaitIndexOnline( IndexDefinition index, long duration, TimeUnit unit )
{
  actual.awaitIndexOnline( index, duration, unit );
}

代码示例来源:origin: org.neo4j/neo4j-shell

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 );
    }
  }
}

代码示例来源:origin: SciGraph/SciGraph

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();
   }
  }
 }
}

代码示例来源:origin: org.neo4j.examples/neo4j-examples

schema.awaitIndexOnline( indexDefinition, 10, TimeUnit.SECONDS );

相关文章