Search in sources :

Example 1 with SchemaStatus

use of org.janusgraph.core.schema.SchemaStatus in project janusgraph by JanusGraph.

the class IndexRemoveJob method validateIndexStatus.

@Override
protected void validateIndexStatus() {
    if (!(index instanceof RelationTypeIndex || index instanceof JanusGraphIndex)) {
        throw new UnsupportedOperationException("Unsupported index found: " + index);
    }
    if (index instanceof JanusGraphIndex) {
        JanusGraphIndex graphIndex = (JanusGraphIndex) index;
        if (graphIndex.isMixedIndex())
            throw new UnsupportedOperationException("Cannot remove mixed indexes through JanusGraph. This can " + "only be accomplished in the indexing system directly.");
        CompositeIndexType indexType = (CompositeIndexType) managementSystem.getSchemaVertex(index).asIndexType();
        graphIndexId = indexType.getID();
    }
    // Must be a relation type index or a composite graph index
    JanusGraphSchemaVertex schemaVertex = managementSystem.getSchemaVertex(index);
    SchemaStatus actualStatus = schemaVertex.getStatus();
    Preconditions.checkArgument(actualStatus == SchemaStatus.DISABLED, "The index [%s] must be disabled before it can be removed", indexName);
}
Also used : CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) SchemaStatus(org.janusgraph.core.schema.SchemaStatus)

Example 2 with SchemaStatus

use of org.janusgraph.core.schema.SchemaStatus in project janusgraph by JanusGraph.

the class ParameterIndexField method getStatus.

public SchemaStatus getStatus() {
    SchemaStatus status = ParameterType.STATUS.findParameter(parameters, null);
    Preconditions.checkState(status != null, "Field [%s] did not have a status", this);
    return status;
}
Also used : SchemaStatus(org.janusgraph.core.schema.SchemaStatus)

Example 3 with SchemaStatus

use of org.janusgraph.core.schema.SchemaStatus in project janusgraph by JanusGraph.

the class GraphIndexStatusWatcher method call.

@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(statuses, "Target statuses must not be null");
    Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
    Map<String, SchemaStatus> notConverged = new HashMap<>();
    Map<String, SchemaStatus> converged = new HashMap<>();
    JanusGraphIndex idx;
    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        JanusGraphManagement management = null;
        try {
            management = g.openManagement();
            idx = management.getGraphIndex(graphIndexName);
            for (PropertyKey pk : idx.getFieldKeys()) {
                SchemaStatus s = idx.getIndexStatus(pk);
                LOGGER.debug("Key {} has status {}", pk, s);
                if (!statuses.contains(s))
                    notConverged.put(pk.toString(), s);
                else
                    converged.put(pk.toString(), s);
            }
        } finally {
            if (null != management)
                // Let an exception here propagate up the stack
                management.rollback();
        }
        if (!notConverged.isEmpty()) {
            String waitingOn = StringUtils.join(notConverged, "=", ",");
            LOGGER.info("Some key(s) on index {} do not currently have status(es) {}: {}", graphIndexName, statuses, waitingOn);
        } else {
            LOGGER.info("All {} key(s) on index {} have status(es) {}", converged.size(), graphIndexName, statuses);
            return new GraphIndexStatusReport(true, graphIndexName, statuses, 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(es) {}", timeout, graphIndexName, statuses);
            return new GraphIndexStatusReport(false, graphIndexName, statuses, notConverged, converged, t.elapsed());
        }
        notConverged.clear();
        converged.clear();
        Thread.sleep(poll.toMillis());
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Timer(org.janusgraph.diskstorage.util.time.Timer) HashMap(java.util.HashMap) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) PropertyKey(org.janusgraph.core.PropertyKey)

Example 4 with SchemaStatus

use of org.janusgraph.core.schema.SchemaStatus in project janusgraph by JanusGraph.

the class IndexRepairJob method validateIndexStatus.

/**
 * Check that our target index is in either the ENABLED or REGISTERED state.
 */
@Override
protected void validateIndexStatus() {
    JanusGraphSchemaVertex schemaVertex = managementSystem.getSchemaVertex(index);
    Set<SchemaStatus> acceptableStatuses = SchemaAction.REINDEX.getApplicableStatus();
    boolean isValidIndex = true;
    String invalidIndexHint;
    if (index instanceof RelationTypeIndex || (index instanceof JanusGraphIndex && ((JanusGraphIndex) 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 JanusGraphIndex, "Unexpected index: %s", index);
        JanusGraphIndex graphIndex = (JanusGraphIndex) index;
        Preconditions.checkArgument(graphIndex.isMixedIndex());
        Map<String, SchemaStatus> invalidKeyStatuses = new HashMap<>();
        int acceptableFields = 0;
        for (PropertyKey key : graphIndex.getFieldKeys()) {
            SchemaStatus status = graphIndex.getIndexStatus(key);
            if (status != SchemaStatus.DISABLED && !acceptableStatuses.contains(status)) {
                isValidIndex = false;
                invalidKeyStatuses.put(key.name(), status);
                log.warn("Index {} has key {} in an invalid status {}", index, key, status);
            }
            if (acceptableStatuses.contains(status))
                acceptableFields++;
        }
        invalidIndexHint = String.format("The following index keys have invalid status: %s (status must be one of %s)", StringUtils.join(invalidKeyStatuses, " has status ", ","), acceptableStatuses);
        if (isValidIndex && acceptableFields == 0) {
            isValidIndex = false;
            invalidIndexHint = "The index does not contain any valid keys";
        }
    }
    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
    if (log.isDebugEnabled()) {
        log.debug("Index " + index.name() + " is valid for re-indexing");
    }
}
Also used : HashMap(java.util.HashMap) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) PropertyKey(org.janusgraph.core.PropertyKey)

Example 5 with SchemaStatus

use of org.janusgraph.core.schema.SchemaStatus in project janusgraph by JanusGraph.

the class RelationIndexStatusWatcher method call.

/**
 * Poll a relation index until it has a certain {@link SchemaStatus},
 * or until a configurable timeout is exceeded.
 *
 * @return a report with information about schema state, execution duration, and the index
 */
@Override
public RelationIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(relationIndexName, "Index name must not be null");
    Preconditions.checkNotNull(statuses, "Target statuses must not be null");
    Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
    RelationTypeIndex idx;
    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        final SchemaStatus actualStatus;
        JanusGraphManagement management = null;
        try {
            management = g.openManagement();
            idx = management.getRelationIndex(management.getRelationType(relationTypeName), relationIndexName);
            actualStatus = idx.getIndexStatus();
            LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
            if (statuses.contains(actualStatus)) {
                return new RelationIndexStatusReport(true, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
            }
        } finally {
            if (null != management)
                // Let an exception here propagate up the stack
                management.rollback();
        }
        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} (relation type {}) to reach status(es) {}", timeout, relationIndexName, relationTypeName, statuses);
            return new RelationIndexStatusReport(false, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
        }
        Thread.sleep(poll.toMillis());
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Timer(org.janusgraph.diskstorage.util.time.Timer) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) SchemaStatus(org.janusgraph.core.schema.SchemaStatus)

Aggregations

SchemaStatus (org.janusgraph.core.schema.SchemaStatus)5 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)3 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)3 HashMap (java.util.HashMap)2 PropertyKey (org.janusgraph.core.PropertyKey)2 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)2 Timer (org.janusgraph.diskstorage.util.time.Timer)2 JanusGraphSchemaVertex (org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex)2 CompositeIndexType (org.janusgraph.graphdb.types.CompositeIndexType)1