Unable to create a composite index, stuck at INSTALLED

前端 未结 2 1140
無奈伤痛
無奈伤痛 2021-02-07 08:26

I\'m unable to create an index. My Gremlin code is as follows:

usernameProperty = mgmt.getPropertyKey(\'username\')
usernameIndex = mgmt.buildIndex(\'byUsernameU         


        
相关标签:
2条回答
  • 2021-02-07 08:44

    If you're running multiple Titan instances, you should be aware that they need to coordinate before the index will become available.

    Furthermore, there are various subtleties around transaction management and under what circumstances transactions will be left open; I believe Titan 1.0.0 doesn't have the latest from TinkerPop in that regard. Have you tried creating the index immediately after boot?

    Finally, the index creation process is different depending on whether or not the property keys being indexed have been used before. Are you attempting to index new keys, or existing ones?

    0 讨论(0)
  • 2021-02-07 08:45

    You need to wait for the Titan and DynamoDB to get the index registered. You could do so by:

    ManagementSystem.awaitGraphIndexStatus(graph, propertyKeyIndexName)
                        .status(SchemaStatus.REGISTERED)
                        .timeout(10, java.time.temporal.ChronoUnit.MINUTES) // set timeout to 10 min
                        .call();
    

    The default timeout is usually not long enough, so you could increase it to 10 minutes, it usually does the trick with Dynamo backened.

    Only when the index is in REGISTERED state, you could perform a reindex. ONce the reindex is done, you need to wait until it's ENABLED. by reusing the code sample above and changing the state to ENABLED.

    For more info, see the docs.

    Edit

    Let me share the code that works with me on Berkeley and Dynamo DB backends all the time.

        graph.tx().rollback(); //Never create new indexes while a transaction is active
        TitanManagement mgmt=graph.openManagement();
        PropertyKey propertyKey=getOrCreatePropertyKeyIfNotExist(mgmt, propertyKeyName);
        String indexName = makePropertyKeyIndexName(propertyKey);
    
        if (mgmt.getGraphIndex(indexName)==null) { 
            mgmt.buildIndex(indexName, Vertex.class).addKey(propertyKey).buildCompositeIndex();
            mgmt.commit(); // you MUST commit mgmt
            graph.tx().commit(); // and commit the transaction too
            ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.REGISTERED).call();
        }else { // already defined.
            mgmt.rollback();
            graph.tx().rollback();
        }
    
    private static PropertyKey getOrCreatePropertyKeyIfNotExist(TitanManagement mgmt, String s) {
        PropertyKey key = mgmt.getPropertyKey(s);
        if (key != null)
            return key;
        else
            return mgmt.makePropertyKey(s).dataType(String.class).make();
    }
    
    private static String makePropertyKeyIndexName(PropertyKey pk) {
        return pk.name() + Tokens.INDEX_SUFFIX;
    }
    

    From the error that I saw, it seems like Titan couldn't get the index which means you're waiting for the index that is not even defined. Have a look at the line that causes the error here.

    Make sure you're passing the right index name to the awaitGraphIndexStatus.

    0 讨论(0)
提交回复
热议问题