org.janusgraph.graphdb.database.management.ManagementSystem Java Examples

The following examples show how to use org.janusgraph.graphdb.database.management.ManagementSystem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexingFactory.java    From egeria with Apache License 2.0 6 votes vote down vote up
private void enableIndex(JanusGraphManagement management,String indexName,boolean oldKey){
    final String methodName = "enableIndex";

    try {
        if (oldKey) {
            // If we are reusing a key created in an earlier management transaction - e.g. "guid" - we need to reindex
            // Block until the SchemaStatus transitions from INSTALLED to REGISTERED
            ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.REGISTERED).call();
            management = graph.openManagement();
            JanusGraphIndex index = management.getGraphIndex(indexName);
            management.updateIndex(index, SchemaAction.REINDEX);
            management.commit();
        }

        // Enable the index - set a relatively short timeout (10 s vs the default of 1 minute) because the property key may be shared
        // (e.g. vertex "guid" vs edge "guid" but we know the index is for vertices and there are no property key name clashes within vertices.
        log.debug("{} awaitGraphIndexStatus ENABLED for {}", methodName, indexName);
        ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).timeout(10, ChronoUnit.SECONDS).call();
    } catch (Exception e) {
        log.error("{} caught interrupted exception from awaitGraphIndexStatus ENABLED {}", methodName, e);
        management.rollback();
    }
}
 
Example #2
Source File: RepairIndex.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void restoreAll() throws Exception {
    for (String indexName : getIndexes()){
        displayCrlf("Restoring: " + indexName);
        long startTime = System.currentTimeMillis();

        ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
        JanusGraphIndex index = mgmt.getGraphIndex(indexName);
        mgmt.updateIndex(index, SchemaAction.REINDEX).get();
        mgmt.commit();

        ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).call();

        display(": Time taken: " + (System.currentTimeMillis() - startTime) + " ms");
        displayCrlf(": Done!");
    }
}
 
Example #3
Source File: RepairIndex.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static void reindexVertex(String indexName, IndexSerializer indexSerializer, Set<String> entityGUIDs) throws Exception {
    Map<String, Map<String, List<IndexEntry>>> documentsPerStore = new java.util.HashMap<>();
    ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
    StandardJanusGraphTx tx = mgmt.getWrappedTx();
    BackendTransaction mutator = tx.getTxHandle();
    JanusGraphIndex index = mgmt.getGraphIndex(indexName);
    MixedIndexType indexType = (MixedIndexType) mgmt.getSchemaVertex(index).asIndexType();

    for (String entityGuid : entityGUIDs){
        for (int attemptCount = 1; attemptCount <= MAX_TRIES_ON_FAILURE; attemptCount++) {
            AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(entityGuid);
            try {
                indexSerializer.reindexElement(vertex.getWrappedElement(), indexType, documentsPerStore);
                break;
            }catch (Exception e){
                displayCrlf("Exception: " + e.getMessage());
                displayCrlf("Pausing before retry..");
                Thread.sleep(2000 * attemptCount);
            }
        }
    }
    mutator.getIndexTransaction(indexType.getBackingIndexName()).restore(documentsPerStore);
}
 
Example #4
Source File: GraphOMRSGraphFactory.java    From egeria with Apache License 2.0 4 votes vote down vote up
private boolean createControlIndex() {

        final String methodName = "createControlIndex";


        // Prior to creating the control vertex - create an index to allow us to find it without a full scan
        JanusGraphManagement management = graph.openManagement();
        String indexName = "controlIndex";

        try {

            // Check if index exists
            JanusGraphIndex controlIndex = management.getGraphIndex(indexName);
            if (controlIndex == null) {
                log.info("{} index create {} for control vertex", methodName, indexName);
                // Property key should not already exist - but check it anyway.
                PropertyKey propertyKey = management.getPropertyKey(controlVertexIdPropertyName);

                if (propertyKey != null) {
                    // Somehow - despite this being a new graph - the property key already exists. Stop.
                    log.error("{} property key {} already exists", methodName, controlVertexIdPropertyName);
                    management.rollback();
                    return false;
                } else {
                    log.info("{} make property key {}", methodName, controlVertexIdPropertyName);
                    propertyKey = management.makePropertyKey(controlVertexIdPropertyName).dataType(String.class).make();
                }

                if (propertyKey == null) {
                    // Could not create property key. Stop.
                    log.error("{} property key {} could not be created", methodName, controlVertexIdPropertyName);
                    management.rollback();
                    return false;
                } else {
                    log.info("{} create index {}", methodName, indexName);
                    JanusGraphManagement.IndexBuilder indexBuilder = management.buildIndex(indexName, Vertex.class).addKey(propertyKey).unique();
                    JanusGraphIndex index = indexBuilder.buildCompositeIndex();
                    management.setConsistency(index, ConsistencyModifier.LOCK);
                    management.commit();
                    // Enable the index - set a relatively short timeout (10 s vs the default of 1 minute)
                    log.info("{} await ENABLED for {}", methodName, indexName);
                    ManagementSystem.awaitGraphIndexStatus(graph, indexName).status(SchemaStatus.ENABLED).timeout(10, ChronoUnit.SECONDS).call();
                    return true;
                }
            } else {
                // That really should not be possible - a new graph should not have the index. Stop.
                log.error("{} control index already exists", methodName);
                management.rollback();
                return false;
            }
        } catch (Exception e) {
            log.error("{} caught interrupted exception from awaitGraphIndexStatus ENABLED {}", methodName, e);
            management.rollback();
            return false;
        }

    }
 
Example #5
Source File: RecreateWeightIndex.java    From janusgraph_tutorial with Apache License 2.0 4 votes vote down vote up
private void waitForIndex(String label, String propertyKey) throws InterruptedException {
  String indexName = Schema.indexName(label, propertyKey);
  LOGGER.info("Awaiting index {} to become available.", indexName);
  ((ManagementSystem)mgt).awaitGraphIndexStatus(graph, indexName).call();
}
 
Example #6
Source File: ScenarioTests.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 4 votes vote down vote up
private static DynamoDbStoreTransaction getStoreTransaction(final ManagementSystem mgmt) {
    return DynamoDbStoreTransaction.getTx(((CacheTransaction) mgmt.getWrappedTx().getTxHandle().getStoreTransaction()).getWrappedTransaction());
}