Search in sources :

Example 46 with BackendException

use of org.janusgraph.diskstorage.BackendException 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 47 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class ElasticsearchConfigTest method testExternalMappingsViaTemplate.

@ParameterizedTest
@MethodSource("useMappingsForES7Configuration")
public void testExternalMappingsViaTemplate(Boolean useMappingsForES7) throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final ModifiableConfiguration modifiableConfiguration = esr.setConfiguration(GraphDatabaseConfiguration.buildGraphConfiguration(), INDEX_NAME).set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME);
    if (useMappingsForES7) {
        modifiableConfiguration.set(USE_MAPPING_FOR_ES7, true, INDEX_NAME);
    }
    final Configuration indexConfig = modifiableConfiguration.restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final Map<String, Object> content = new HashMap<>(2);
    content.put("template", "janusgraph_test_mapping*");
    if (isMappingUsed(idx)) {
        content.put("mappings", readTypesMapping("/strict_mapping.json").getMappings());
    } else {
        content.put("mappings", readTypelessMapping("/typeless_strict_mapping.json").getMappings());
    }
    executeRequestWithStringEntity(idx, "_template/template_1", content);
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    executeRequest(newMapping);
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    // Test that the "date" property works well.
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test that the "weight" property throws an exception.
    try {
        idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
        fail("should fail");
    } catch (final BackendException e) {
        log.debug(e.getMessage(), e);
    }
    itx.rollback();
    idx.close();
}
Also used : BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) HashMap(java.util.HashMap) IndexTransaction(org.janusgraph.diskstorage.indexing.IndexTransaction) Duration(java.time.Duration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 48 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class MapReduceIndexManagement method updateIndex.

/**
 * Updates the provided index according to the given {@link SchemaAction}.
 * Only {@link SchemaAction#REINDEX} and {@link SchemaAction#REMOVE_INDEX} are supported.
 *
 * @param index the index to process
 * @param updateAction either {@code REINDEX} or {@code REMOVE_INDEX}
 * @param hadoopConf
 * @return a future that returns immediately;
 *         this method blocks until the Hadoop MapReduce job completes
 */
// TODO make this future actually async and update javadoc @return accordingly
public ScanJobFuture updateIndex(Index index, SchemaAction updateAction, Configuration hadoopConf) throws BackendException {
    Preconditions.checkNotNull(index, "Index parameter must not be null", index);
    Preconditions.checkNotNull(updateAction, "%s parameter must not be null", SchemaAction.class.getSimpleName());
    Preconditions.checkArgument(SUPPORTED_ACTIONS.contains(updateAction), "Only these %s parameters are supported: %s (was given %s)", SchemaAction.class.getSimpleName(), SUPPORTED_ACTIONS_STRING, updateAction);
    Preconditions.checkArgument(RelationTypeIndex.class.isAssignableFrom(index.getClass()) || JanusGraphIndex.class.isAssignableFrom(index.getClass()), "Index %s has class %s: must be a %s or %s (or subtype)", index.getClass(), RelationTypeIndex.class.getSimpleName(), JanusGraphIndex.class.getSimpleName());
    ModifiableHadoopConfiguration janusGraphMapReduceConfiguration = ModifiableHadoopConfiguration.of(JanusGraphHadoopConfiguration.MAPRED_NS, hadoopConf);
    // The job we'll execute to either REINDEX or REMOVE_INDEX
    final Class<? extends IndexUpdateJob> indexJobClass;
    final Class<? extends Mapper> mapperClass;
    // The class of the IndexUpdateJob and the Mapper that will be used to run it (VertexScanJob vs ScanJob)
    if (updateAction.equals(SchemaAction.REINDEX)) {
        indexJobClass = IndexRepairJob.class;
        mapperClass = HadoopVertexScanMapper.class;
    } else {
        assert updateAction.equals(SchemaAction.REMOVE_INDEX);
        indexJobClass = IndexRemoveJob.class;
        mapperClass = HadoopScanMapper.class;
    }
    // The column family that serves as input to the IndexUpdateJob
    final String readCF;
    if (RelationTypeIndex.class.isAssignableFrom(index.getClass())) {
        readCF = Backend.EDGESTORE_NAME;
    } else {
        JanusGraphIndex graphIndex = (JanusGraphIndex) index;
        if (graphIndex.isMixedIndex() && !updateAction.equals(SchemaAction.REINDEX))
            throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
        Preconditions.checkState(JanusGraphIndex.class.isAssignableFrom(index.getClass()));
        if (updateAction.equals(SchemaAction.REMOVE_INDEX))
            readCF = Backend.INDEXSTORE_NAME;
        else
            readCF = Backend.EDGESTORE_NAME;
    }
    janusGraphMapReduceConfiguration.set(JanusGraphHadoopConfiguration.COLUMN_FAMILY_NAME, readCF);
    // The MapReduce InputFormat class based on the open graph's store manager
    HadoopStoreManager storeManager = (HadoopStoreManager) graph.getBackend().getStoreManager().getHadoopManager();
    if (storeManager == null) {
        throw new IllegalArgumentException("Store manager class " + graph.getBackend().getStoreManagerClass() + "is not supported");
    }
    final Class<? extends InputFormat> inputFormat = storeManager.getInputFormat(hadoopConf);
    // The index name and relation type name (if the latter is applicable)
    final String indexName = index.name();
    final RelationType relationType = RelationTypeIndex.class.isAssignableFrom(index.getClass()) ? ((RelationTypeIndex) index).getType() : null;
    final String relationTypeName = relationType == null ? StringUtils.EMPTY : relationType.name();
    Preconditions.checkNotNull(indexName);
    // Set the class of the IndexUpdateJob
    janusGraphMapReduceConfiguration.set(JanusGraphHadoopConfiguration.SCAN_JOB_CLASS, indexJobClass.getName());
    // Set the configuration of the IndexUpdateJob
    copyIndexJobKeys(hadoopConf, indexName, relationTypeName);
    janusGraphMapReduceConfiguration.set(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_ROOT, GraphDatabaseConfiguration.class.getName() + "#JOB_NS");
    // Copy the StandardJanusGraph configuration under JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS
    org.apache.commons.configuration2.Configuration localConfiguration = graph.getConfiguration().getConfigurationAtOpen();
    localConfiguration.clearProperty(Graph.GRAPH);
    copyInputKeys(hadoopConf, localConfiguration);
    String jobName = HadoopScanMapper.class.getSimpleName() + "[" + indexJobClass.getSimpleName() + "]";
    try {
        return new CompletedJobFuture(HadoopScanRunner.runJob(hadoopConf, inputFormat, jobName, mapperClass));
    } catch (Exception e) {
        return new FailedJobFuture(e);
    }
}
Also used : HadoopScanMapper(org.janusgraph.hadoop.scan.HadoopScanMapper) SchemaAction(org.janusgraph.core.schema.SchemaAction) FailedJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.FailedJobFuture) ModifiableHadoopConfiguration(org.janusgraph.hadoop.config.ModifiableHadoopConfiguration) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) BackendException(org.janusgraph.diskstorage.BackendException) CompletedJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.CompletedJobFuture) RelationType(org.janusgraph.core.RelationType) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex)

Example 49 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class KCVSConfiguration method toMap.

private Map<String, Object> toMap() {
    List<Entry> result = BackendOperation.execute(new BackendOperation.Transactional<List<Entry>>() {

        @Override
        public List<Entry> call(StoreTransaction txh) throws BackendException {
            return store.getSlice(new KeySliceQuery(rowKey, BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)), txh);
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
    Map<String, Object> entries = new HashMap<>(result.size());
    for (Entry entry : result) {
        String key = staticBuffer2String(entry.getColumnAs(StaticBuffer.STATIC_FACTORY));
        Object value = staticBuffer2Object(entry.getValueAs(StaticBuffer.STATIC_FACTORY), Object.class);
        entries.put(key, value);
    }
    return entries;
}
Also used : HashMap(java.util.HashMap) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) ArrayList(java.util.ArrayList) List(java.util.List) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 50 with BackendException

use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.

the class KCVSConfiguration method close.

@Override
public void close() {
    try {
        ExceptionWrapper exceptionWrapper = new ExceptionWrapper();
        executeWithCatching(store::close, exceptionWrapper);
        executeWithCatching(txProvider::close, exceptionWrapper);
        IOUtils.closeQuietly(serializer);
        throwIfException(exceptionWrapper);
    } catch (BackendException e) {
        throw new JanusGraphException("Could not close configuration store", e);
    }
}
Also used : JanusGraphException(org.janusgraph.core.JanusGraphException) ExceptionWrapper(org.janusgraph.util.datastructures.ExceptionWrapper) BackendException(org.janusgraph.diskstorage.BackendException)

Aggregations

BackendException (org.janusgraph.diskstorage.BackendException)62 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)26 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)18 JanusGraphException (org.janusgraph.core.JanusGraphException)17 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)16 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Map (java.util.Map)12 Duration (java.time.Duration)11 HashMap (java.util.HashMap)11 Configuration (org.janusgraph.diskstorage.configuration.Configuration)11 Entry (org.janusgraph.diskstorage.Entry)10 Test (org.junit.jupiter.api.Test)10 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)9 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)9 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)9 IOException (java.io.IOException)8 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)8 Preconditions (com.google.common.base.Preconditions)6