Search in sources :

Example 31 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class IndexUpdateJob method workerIterationStart.

public void workerIterationStart(JanusGraph graph, Configuration config, ScanMetrics metrics) {
    this.graph = (StandardJanusGraph) graph;
    Preconditions.checkArgument(config.has(GraphDatabaseConfiguration.JOB_START_TIME), "Invalid configuration for this job. Start time is required.");
    this.jobStartTime = Instant.ofEpochMilli(config.get(GraphDatabaseConfiguration.JOB_START_TIME));
    if (indexName == null) {
        Preconditions.checkArgument(config.has(INDEX_NAME), "Need to configure the name of the index to be repaired");
        indexName = config.get(INDEX_NAME);
        indexRelationTypeName = config.get(INDEX_RELATION_TYPE);
        log.info("Read index information: name={} type={}", indexName, indexRelationTypeName);
    }
    try {
        this.managementSystem = (ManagementSystem) graph.openManagement();
        if (isGlobalGraphIndex()) {
            index = managementSystem.getGraphIndex(indexName);
        } else {
            indexRelationType = managementSystem.getRelationType(indexRelationTypeName);
            Preconditions.checkArgument(indexRelationType != null, "Could not find relation type: %s", indexRelationTypeName);
            index = managementSystem.getRelationIndex(indexRelationType, indexName);
        }
        Preconditions.checkArgument(index != null, "Could not find index: %s [%s]", indexName, indexRelationTypeName);
        log.debug("Found index {}", indexName);
        validateIndexStatus();
        StandardTransactionBuilder txb = this.graph.buildTransaction();
        txb.commitTime(jobStartTime);
        writeTx = (StandardJanusGraphTx) txb.start();
    } catch (final Exception e) {
        if (null != managementSystem && managementSystem.isOpen())
            managementSystem.rollback();
        if (writeTx != null && writeTx.isOpen())
            writeTx.rollback();
        metrics.incrementCustom(FAILED_TX);
        throw new JanusGraphException(e.getMessage(), e);
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphException(org.janusgraph.core.JanusGraphException) StandardTransactionBuilder(org.janusgraph.graphdb.transaction.StandardTransactionBuilder)

Example 32 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class KCVSConfigurationBuilder method buildConfiguration.

public KCVSConfiguration buildConfiguration(final BackendOperation.TransactionalProvider txProvider, final KeyColumnValueStore store, final String identifier, final Configuration config) {
    try {
        KCVSConfiguration keyColumnValueStoreConfiguration = new KCVSConfiguration(txProvider, config, store, identifier);
        keyColumnValueStoreConfiguration.setMaxOperationWaitTime(config.get(SETUP_WAITTIME));
        return keyColumnValueStoreConfiguration;
    } catch (BackendException e) {
        throw new JanusGraphException("Could not open global configuration", e);
    }
}
Also used : KCVSConfiguration(org.janusgraph.diskstorage.configuration.backend.KCVSConfiguration) JanusGraphException(org.janusgraph.core.JanusGraphException) BackendException(org.janusgraph.diskstorage.BackendException)

Example 33 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class ManagementSystem method removeGhostVertices.

@Override
public ScanJobFuture removeGhostVertices(int numOfThreads) {
    StandardScanner.Builder builder = graph.getBackend().buildEdgeScanJob();
    builder.setJob(new GhostVertexRemover(graph));
    builder.setNumProcessingThreads(numOfThreads);
    ScanJobFuture future;
    try {
        future = builder.execute();
    } catch (BackendException e) {
        throw new JanusGraphException(e);
    }
    return future;
}
Also used : GhostVertexRemover(org.janusgraph.graphdb.olap.job.GhostVertexRemover) StandardScanner(org.janusgraph.diskstorage.keycolumnvalue.scan.StandardScanner) JanusGraphException(org.janusgraph.core.JanusGraphException) EmptyScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.EmptyScanJobFuture) ScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJobFuture) BackendException(org.janusgraph.diskstorage.BackendException)

Example 34 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class ManagementSystem method updateIndex.

@Override
public ScanJobFuture updateIndex(Index index, SchemaAction updateAction, int numOfThreads) {
    Preconditions.checkArgument(index != null, "Need to provide an index");
    Preconditions.checkArgument(updateAction != null, "Need to provide update action");
    JanusGraphSchemaVertex schemaVertex = getSchemaVertex(index);
    Set<JanusGraphSchemaVertex> dependentTypes;
    Set<PropertyKeyVertex> keySubset = Collections.emptySet();
    if (index instanceof RelationTypeIndex) {
        dependentTypes = Collections.singleton((JanusGraphSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
        if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
            return null;
    } else if (index instanceof JanusGraphIndex) {
        IndexType indexType = schemaVertex.asIndexType();
        dependentTypes = new HashSet<>();
        if (indexType.isCompositeIndex()) {
            if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
                return null;
            for (PropertyKey key : ((JanusGraphIndex) index).getFieldKeys()) {
                dependentTypes.add((PropertyKeyVertex) key);
            }
        } else {
            keySubset = new HashSet<>();
            MixedIndexType mixedIndexType = (MixedIndexType) indexType;
            Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
            for (ParameterIndexField field : mixedIndexType.getFieldKeys()) {
                if (applicableStatus.contains(field.getStatus()))
                    keySubset.add((PropertyKeyVertex) field.getFieldKey());
            }
            if (keySubset.isEmpty())
                return null;
            dependentTypes.addAll(keySubset);
        }
    } else
        throw new UnsupportedOperationException("Updates not supported for index: " + index);
    IndexIdentifier indexId = new IndexIdentifier(index);
    StandardScanner.Builder builder;
    ScanJobFuture future;
    switch(updateAction) {
        case REGISTER_INDEX:
            setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
            updatedTypes.add(schemaVertex);
            updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
            future = new EmptyScanJobFuture();
            break;
        case REINDEX:
            builder = graph.getBackend().buildEdgeScanJob();
            builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
            builder.setJobId(indexId);
            builder.setNumProcessingThreads(numOfThreads);
            builder.setJob(VertexJobConverter.convert(graph, new IndexRepairJob(indexId.indexName, indexId.relationTypeName)));
            try {
                future = builder.execute();
            } catch (BackendException e) {
                throw new JanusGraphException(e);
            }
            break;
        case ENABLE_INDEX:
            setStatus(schemaVertex, SchemaStatus.ENABLED, keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty())
                updatedTypes.addAll(dependentTypes);
            future = new EmptyScanJobFuture();
            break;
        case DISABLE_INDEX:
            setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty())
                updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
            future = new EmptyScanJobFuture();
            break;
        case REMOVE_INDEX:
            if (index instanceof RelationTypeIndex) {
                builder = graph.getBackend().buildEdgeScanJob();
            } else {
                JanusGraphIndex graphIndex = (JanusGraphIndex) index;
                if (graphIndex.isMixedIndex())
                    throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
                builder = graph.getBackend().buildGraphIndexScanJob();
            }
            builder.setFinishJob(indexId.getIndexJobFinisher());
            builder.setJobId(indexId);
            builder.setNumProcessingThreads(numOfThreads);
            builder.setJob(new IndexRemoveJob(graph, indexId.indexName, indexId.relationTypeName));
            try {
                future = builder.execute();
            } catch (BackendException e) {
                throw new JanusGraphException(e);
            }
            break;
        default:
            throw new UnsupportedOperationException("Update action not supported: " + updateAction);
    }
    return future;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) JanusGraphException(org.janusgraph.core.JanusGraphException) IndexRepairJob(org.janusgraph.graphdb.olap.job.IndexRepairJob) ParameterIndexField(org.janusgraph.graphdb.types.ParameterIndexField) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) EmptyScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.EmptyScanJobFuture) ScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJobFuture) BackendException(org.janusgraph.diskstorage.BackendException) StandardScanner(org.janusgraph.diskstorage.keycolumnvalue.scan.StandardScanner) EmptyScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.EmptyScanJobFuture) JanusGraphSchemaVertex(org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex) PropertyKeyVertex(org.janusgraph.graphdb.types.vertices.PropertyKeyVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) IndexType(org.janusgraph.graphdb.types.IndexType) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) PropertyKey(org.janusgraph.core.PropertyKey) HashSet(java.util.HashSet) IndexRemoveJob(org.janusgraph.graphdb.olap.job.IndexRemoveJob)

Example 35 with JanusGraphException

use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.

the class StandardIDPool method close.

@Override
public synchronized void close() {
    closed = true;
    try {
        waitForIDBlockGetter();
    } catch (InterruptedException e) {
        throw new JanusGraphException("Interrupted while waiting for id renewer thread to finish", e);
    }
    for (Future<?> closeBlocker : closeBlockers) {
        try {
            closeBlocker.get();
        } catch (InterruptedException e) {
            throw new JanusGraphException("Interrupted while waiting for runaway ID renewer task " + closeBlocker, e);
        } catch (ExecutionException e) {
            log.debug("Runaway ID renewer task completed with exception", e);
        }
    }
    exec.shutdownNow();
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

JanusGraphException (org.janusgraph.core.JanusGraphException)46 BackendException (org.janusgraph.diskstorage.BackendException)18 PropertyKey (org.janusgraph.core.PropertyKey)9 Test (org.junit.jupiter.api.Test)7 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)6 StandardScanner (org.janusgraph.diskstorage.keycolumnvalue.scan.StandardScanner)6 Set (java.util.Set)5 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)5 CompositeIndexType (org.janusgraph.graphdb.types.CompositeIndexType)5 IndexType (org.janusgraph.graphdb.types.IndexType)5 MixedIndexType (org.janusgraph.graphdb.types.MixedIndexType)5 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ExecutionException (java.util.concurrent.ExecutionException)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)4 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)4 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)4