Search in sources :

Example 41 with JanusGraphException

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

the class KCVSLog method add.

/**
 * Adds the given message (content) to the timeslice for the partition identified by the provided partitionId.
 * If a persistor is specified, this persistor is used to add the message otherwise the internal delivery systems are used.
 *
 * @param content
 * @param partitionId
 * @param persistor
 * @return
 */
private Future<Message> add(StaticBuffer content, int partitionId, ExternalPersistor persistor) {
    ResourceUnavailableException.verifyOpen(isOpen, "Log", name);
    Preconditions.checkArgument(content != null && content.length() > 0, "Content is empty");
    Preconditions.checkArgument(partitionId >= 0 && partitionId < (1 << manager.partitionBitWidth), "Invalid partition id: %s", partitionId);
    final Instant timestamp = times.getTime();
    KCVSMessage msg = new KCVSMessage(content, timestamp, manager.senderId);
    FutureMessage futureMessage = new FutureMessage(msg);
    StaticBuffer key = getLogKey(partitionId, (int) (numBucketCounter.incrementAndGet() % numBuckets), getTimeSlice(timestamp));
    MessageEnvelope envelope = new MessageEnvelope(futureMessage, key, writeMessage(msg));
    if (persistor != null) {
        try {
            persistor.add(envelope.key, envelope.entry);
            envelope.message.delivered();
        } catch (JanusGraphException e) {
            envelope.message.failed(e);
            throw e;
        }
    } else if (outgoingMsg == null) {
        sendMessages(Collections.singletonList(envelope));
    } else {
        try {
            // Produces back pressure when full
            outgoingMsg.put(envelope);
            log.debug("Enqueued {} for partition {}", envelope, partitionId);
        } catch (InterruptedException e) {
            throw new JanusGraphException("Got interrupted waiting to send message", e);
        }
    }
    return futureMessage;
}
Also used : Instant(java.time.Instant) JanusGraphException(org.janusgraph.core.JanusGraphException) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) FutureMessage(org.janusgraph.diskstorage.log.util.FutureMessage)

Example 42 with JanusGraphException

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

the class StandardJanusGraphTx method commit.

/*
     * ------------------------------------ Transaction State ------------------------------------
     */
@Override
public synchronized void commit() {
    Preconditions.checkArgument(isOpen(), "The transaction has already been closed");
    boolean success = false;
    if (null != config.getGroupName()) {
        MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit").inc();
    }
    try {
        if (hasModifications()) {
            graph.commit(addedRelations.getAll(), deletedRelations.values(), this);
        } else {
            txHandle.commit();
        }
        success = true;
    } catch (Exception e) {
        try {
            txHandle.rollback();
        } catch (BackendException e1) {
            throw new JanusGraphException("Could not rollback after a failed commit", e);
        }
        throw new JanusGraphException("Could not commit transaction due to exception during persistence", e);
    } finally {
        releaseTransaction();
        if (null != config.getGroupName() && !success) {
            MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "commit.exceptions").inc();
        }
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphException(org.janusgraph.core.JanusGraphException) SchemaViolationException(org.janusgraph.core.SchemaViolationException) NoSuchElementException(java.util.NoSuchElementException) BackendException(org.janusgraph.diskstorage.BackendException) ReadOnlyTransactionException(org.janusgraph.core.ReadOnlyTransactionException) BackendException(org.janusgraph.diskstorage.BackendException)

Example 43 with JanusGraphException

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

the class StandardJanusGraphTx method rollback.

@Override
public synchronized void rollback() {
    Preconditions.checkArgument(isOpen(), "The transaction has already been closed");
    boolean success = false;
    if (null != config.getGroupName()) {
        MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "rollback").inc();
    }
    try {
        txHandle.rollback();
        success = true;
    } catch (Exception e) {
        throw new JanusGraphException("Could not rollback transaction due to exception", e);
    } finally {
        releaseTransaction();
        if (null != config.getGroupName() && !success) {
            MetricManager.INSTANCE.getCounter(config.getGroupName(), "tx", "rollback.exceptions").inc();
        }
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphException(org.janusgraph.core.JanusGraphException) SchemaViolationException(org.janusgraph.core.SchemaViolationException) NoSuchElementException(java.util.NoSuchElementException) BackendException(org.janusgraph.diskstorage.BackendException) ReadOnlyTransactionException(org.janusgraph.core.ReadOnlyTransactionException)

Example 44 with JanusGraphException

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

the class ReadConfigurationBuilderTest method shouldThrowExceptionOnDisallowedUpgradeAndNonEqualStorageVersions.

@Test
public void shouldThrowExceptionOnDisallowedUpgradeAndNonEqualStorageVersions() {
    frozenGlobalWriteWithAllowUpgradeMock(false);
    JanusGraphException exception = assertThrows(JanusGraphException.class, this::buildConfiguration);
    String storageVersion = (globalWrite.has(INITIAL_STORAGE_VERSION)) ? globalWrite.get(INITIAL_STORAGE_VERSION) : "1";
    assertEquals(String.format(ReadConfigurationBuilder.INCOMPATIBLE_STORAGE_VERSION_EXCEPTION, storageVersion, JanusGraphConstants.STORAGE_VERSION, null), exception.getMessage());
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with JanusGraphException

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

the class ManagementSystem method updateIndex.

/* --------------
    Schema Update
     --------------- */
@Override
public IndexJobFuture updateIndex(Index index, SchemaAction updateAction) {
    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 = ImmutableSet.of();
    if (index instanceof RelationTypeIndex) {
        dependentTypes = ImmutableSet.of((JanusGraphSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
        if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
            return null;
    } else if (index instanceof JanusGraphIndex) {
        IndexType indexType = schemaVertex.asIndexType();
        dependentTypes = Sets.newHashSet();
        if (indexType.isCompositeIndex()) {
            if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
                return null;
            for (PropertyKey key : ((JanusGraphIndex) index).getFieldKeys()) {
                dependentTypes.add((PropertyKeyVertex) key);
            }
        } else {
            keySubset = Sets.newHashSet();
            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;
    IndexJobFuture 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 EmptyIndexJobFuture();
            break;
        case REINDEX:
            builder = graph.getBackend().buildEdgeScanJob();
            builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
            builder.setJobId(indexId);
            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 EmptyIndexJobFuture();
            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 EmptyIndexJobFuture();
            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.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) ImmutableSet(com.google.common.collect.ImmutableSet) 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) BackendException(org.janusgraph.diskstorage.BackendException) StandardScanner(org.janusgraph.diskstorage.keycolumnvalue.scan.StandardScanner) 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) IndexRemoveJob(org.janusgraph.graphdb.olap.job.IndexRemoveJob)

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