Java Code Examples for com.thinkaurelius.titan.core.schema.TitanGraphIndex.getIndexStatus()

The following are Jave code examples for showing how to use getIndexStatus() of the com.thinkaurelius.titan.core.schema.TitanGraphIndex class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: antioch   File: TitanService.java   View Source Code Vote up 5 votes
public IndexInfo(TitanGraphIndex index) {
  name = index.name();
  backingIndex = index.getBackingIndex();
  indexedElement = index.getIndexedElement();
  PropertyKey[] fieldKeys = index.getFieldKeys();
  indexStatus = index.getIndexStatus(fieldKeys[0]);
}
 
Example 2
Project: titan1withtp3.1   File: GraphIndexStatusWatcher.java   View Source Code Vote up 4 votes
@Override
public GraphIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(graphIndexName, "Index name must not be null");
    Preconditions.checkNotNull(status, "Target status must not be null");

    Map<String, SchemaStatus> notConverged = new HashMap<>();
    Map<String, SchemaStatus> converged = new HashMap<>();
    TitanGraphIndex idx;

    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        TitanManagement mgmt = null;
        try {
            mgmt = g.openManagement();
            idx = mgmt.getGraphIndex(graphIndexName);
            for (PropertyKey pk : idx.getFieldKeys()) {
                SchemaStatus s = idx.getIndexStatus(pk);
                LOGGER.debug("Key {} has status {}", pk, s);
                if (!status.equals(s))
                    notConverged.put(pk.toString(), s);
                else
                    converged.put(pk.toString(), s);
            }
        } finally {
            if (null != mgmt)
                mgmt.rollback(); // Let an exception here propagate up the stack
        }

        String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
        if (!notConverged.isEmpty()) {
            LOGGER.info("Some key(s) on index {} do not currently have status {}: {}", graphIndexName, status, waitingOn);
        } else {
            LOGGER.info("All {} key(s) on index {} have status {}", converged.size(), graphIndexName, status);
            return new GraphIndexStatusReport(true, graphIndexName, status, notConverged, converged, t.elapsed());
        }

        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);

        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} to converge on status {}",
                    timeout, graphIndexName, status);
            return new GraphIndexStatusReport(false, graphIndexName, status, notConverged, converged, t.elapsed());
        }
        notConverged.clear();
        converged.clear();

        Thread.sleep(poll.toMillis());
    }
}
 
Example 3
Project: titan1.0.1.kafka   File: GraphIndexStatusWatcher.java   View Source Code Vote up 4 votes
@Override
public GraphIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(graphIndexName, "Index name must not be null");
    Preconditions.checkNotNull(status, "Target status must not be null");

    Map<String, SchemaStatus> notConverged = new HashMap<>();
    Map<String, SchemaStatus> converged = new HashMap<>();
    TitanGraphIndex idx;

    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        TitanManagement mgmt = null;
        try {
            mgmt = g.openManagement();
            idx = mgmt.getGraphIndex(graphIndexName);
            for (PropertyKey pk : idx.getFieldKeys()) {
                SchemaStatus s = idx.getIndexStatus(pk);
                LOGGER.debug("Key {} has status {}", pk, s);
                if (!status.equals(s))
                    notConverged.put(pk.toString(), s);
                else
                    converged.put(pk.toString(), s);
            }
        } finally {
            if (null != mgmt)
                mgmt.rollback(); // Let an exception here propagate up the stack
        }

        String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
        if (!notConverged.isEmpty()) {
            LOGGER.info("Some key(s) on index {} do not currently have status {}: {}", graphIndexName, status, waitingOn);
        } else {
            LOGGER.info("All {} key(s) on index {} have status {}", converged.size(), graphIndexName, status);
            return new GraphIndexStatusReport(true, graphIndexName, status, notConverged, converged, t.elapsed());
        }

        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);

        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} to converge on status {}",
                    timeout, graphIndexName, status);
            return new GraphIndexStatusReport(false, graphIndexName, status, notConverged, converged, t.elapsed());
        }
        notConverged.clear();
        converged.clear();

        Thread.sleep(poll.toMillis());
    }
}
 
Example 4
Project: titan0.5.4-hbase1.1.1-custom   File: TitanIndexRepairMapper.java   View Source Code Vote up 4 votes
/**
 * Check that our target index is in either the ENABLED or REGISTERED state.
 */
private void validateIndexStatus() {
    if (indexType==null || StringUtils.isBlank(indexType)) {
        index = mgmt.getGraphIndex(indexName);
    } else {
        indexRelationType = mgmt.getRelationType(indexType);
        Preconditions.checkArgument(indexRelationType!=null,"Could not find relation type: %s",indexType);
        index = mgmt.getRelationIndex(indexRelationType,indexName);
    }
    Preconditions.checkArgument(index!=null,"Could not find index: %s",indexName);
    log.info("Found index {}", indexName);
    TitanSchemaVertex schemaVertex = mgmt.getSchemaVertex(index);
    Set<SchemaStatus> acceptableStatuses = SchemaAction.REINDEX.getApplicableStatus();
    boolean isValidIndex = true;
    String invalidIndexHint;
    if (index instanceof RelationTypeIndex ||
            (index instanceof TitanGraphIndex && ((TitanGraphIndex)index).isCompositeIndex()) ) {
        SchemaStatus actualStatus = schemaVertex.getStatus();
        isValidIndex = acceptableStatuses.contains(actualStatus);
        invalidIndexHint = String.format(
                "The index has status %s, but one of %s is required",
                actualStatus, acceptableStatuses);
    } else {
        Preconditions.checkArgument(index instanceof TitanGraphIndex,"Unexpected index: %s",index);
        TitanGraphIndex gindex = (TitanGraphIndex)index;
        Preconditions.checkArgument(gindex.isMixedIndex());
        Map<String, SchemaStatus> invalidKeyStatuses = Maps.newHashMap();
        for (PropertyKey key : gindex.getFieldKeys()) {
            SchemaStatus status = gindex.getIndexStatus(key);
            if (status!=SchemaStatus.DISABLED && !acceptableStatuses.contains(status)) {
                isValidIndex=false;
                invalidKeyStatuses.put(key.getName(), status);
                log.warn("Index {} has key {} in an invalid status {}",index,key,status);
            }
        }
        invalidIndexHint = String.format(
                "The following index keys have invalid status: %s (status must be one of %s)",
                Joiner.on(",").withKeyValueSeparator(" has status ").join(invalidKeyStatuses), acceptableStatuses);
    }
    Preconditions.checkArgument(isValidIndex, "The index %s is in an invalid state and cannot be indexed. %s", indexName, invalidIndexHint);
    // TODO consider retrieving the current Job object and calling killJob() if !isValidIndex -- would be more efficient than throwing an exception on the first pair processed by each mapper
    log.debug("Index {} is valid for re-indexing");
}
 
Example 5
Project: titan0.5.4-hbase1.1.1-custom   File: ManagementSystem.java   View Source Code Vote up 4 votes
/**
 * Do not use this method.  This may be removed or refactored in future Titan versions.
 *
 * Final API pending resolution of https://github.com/thinkaurelius/titan/issues/709.
 *
 */
public static boolean awaitGraphIndexStatus(TitanGraph g, String indexName, SchemaStatus status, long timeout, TimeUnit timeoutUnit) {
    Preconditions.checkNotNull(g);
    Preconditions.checkNotNull(indexName);
    Preconditions.checkNotNull(status);
    Preconditions.checkArgument(0L <= timeout);
    Preconditions.checkNotNull(timeoutUnit);

    Map<PropertyKey, SchemaStatus> notConverged = new HashMap<PropertyKey, SchemaStatus>();
    Map<PropertyKey, SchemaStatus> converged = new HashMap<PropertyKey, SchemaStatus>();
    TitanGraphIndex idx;

    Timer t = new Timer(Timestamps.MILLI).start();
    boolean timedOut;
    while (true) {
        TitanManagement mgmt = g.getManagementSystem();
        idx  = mgmt.getGraphIndex(indexName);
        for (PropertyKey pk : idx.getFieldKeys()) {
            SchemaStatus s = idx.getIndexStatus(pk);
            LOGGER.debug("Key {} has status {}", pk, s);
            if (!status.equals(s))
                notConverged.put(pk, s);
            else
                converged.put(pk, s);
        }
        /* Rollback must follow the Joiner...(notConverged).  The Joiner calls toString on
         * PropertyKeys, and the current implementation calls the getName method on the key,
         * and this expects the attached transaction to be open and usable to read the name.
         * Rolling back or committing the managementsystem before calling getName results
         * in an IllegalStateException in the guts of Joiner calling toString on a key.
         */
        String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
        mgmt.rollback();
        if (!notConverged.isEmpty()) {
            LOGGER.info("Some key(s) on index {} do not currently have status {}: ", indexName, status, waitingOn);
        } else {
            LOGGER.info("All {} key(s) on index {} have status {}", converged.size(), indexName, status);
            return true;
        }
        timedOut = timeout <= t.elapsed().getLength(timeoutUnit);
        if (timedOut) {
            LOGGER.info("Timed out ({} {}) while waiting for index {} to converge on status {}",
                    timeout, timeoutUnit, indexName, status);
            return false;
        }
        notConverged.clear();
        converged.clear();
    }
}