Search in sources :

Example 6 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class TitanHadoopSetupImpl method getTypeInspector.

@Override
public TypeInspector getTypeInspector() {
    //Pre-load schema
    for (TitanSchemaCategory sc : TitanSchemaCategory.values()) {
        for (TitanVertex k : QueryUtil.getVertices(tx, BaseKey.SchemaCategory, sc)) {
            assert k instanceof TitanSchemaVertex;
            TitanSchemaVertex s = (TitanSchemaVertex) k;
            if (sc.hasName()) {
                String name = s.name();
                Preconditions.checkNotNull(name);
            }
            TypeDefinitionMap dm = s.getDefinition();
            Preconditions.checkNotNull(dm);
            s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.OUT);
            s.getRelated(TypeDefinitionCategory.TYPE_MODIFIER, Direction.IN);
        }
    }
    return tx;
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) TitanSchemaCategory(com.thinkaurelius.titan.graphdb.internal.TitanSchemaCategory) TypeDefinitionMap(com.thinkaurelius.titan.graphdb.types.TypeDefinitionMap)

Example 7 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class IndexRemoveJob method validateIndexStatus.

@Override
protected void validateIndexStatus() {
    if (index instanceof RelationTypeIndex) {
    //Nothing specific to be done
    } else if (index instanceof TitanGraphIndex) {
        TitanGraphIndex gindex = (TitanGraphIndex) index;
        if (gindex.isMixedIndex())
            throw new UnsupportedOperationException("Cannot remove mixed indexes through Titan. This can " + "only be accomplished in the indexing system directly.");
        CompositeIndexType indexType = (CompositeIndexType) mgmt.getSchemaVertex(index).asIndexType();
        graphIndexId = indexType.getID();
    } else
        throw new UnsupportedOperationException("Unsupported index found: " + index);
    //Must be a relation type index or a composite graph index
    TitanSchemaVertex schemaVertex = mgmt.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 : TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) SchemaStatus(com.thinkaurelius.titan.core.schema.SchemaStatus)

Example 8 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class IndexRepairJob method validateIndexStatus.

/**
     * Check that our target index is in either the ENABLED or REGISTERED state.
     */
@Override
protected void validateIndexStatus() {
    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 = new HashMap<>();
        int acceptableFields = 0;
        for (PropertyKey key : gindex.getFieldKeys()) {
            SchemaStatus status = gindex.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)", Joiner.on(",").withKeyValueSeparator(" has status ").join(invalidKeyStatuses), 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
    log.debug("Index {} is valid for re-indexing");
}
Also used : TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)

Example 9 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class ManagementSystem method commit.

@Override
public synchronized void commit() {
    ensureOpen();
    //Commit config changes
    if (transactionalConfig.hasMutations()) {
        DataOutput out = graph.getDataSerializer().getDataOutput(128);
        out.writeObjectNotNull(MgmtLogType.CONFIG_MUTATION);
        transactionalConfig.logMutations(out);
        sysLog.add(out.getStaticBuffer());
    }
    transactionalConfig.commit();
    //Commit underlying transaction
    transaction.commit();
    //Communicate schema changes
    if (!updatedTypes.isEmpty()) {
        mgmtLogger.sendCacheEviction(updatedTypes, updatedTypeTriggers, getOpenInstancesInternal());
        for (TitanSchemaVertex schemaVertex : updatedTypes) {
            schemaCache.expireSchemaElement(schemaVertex.longId());
        }
    }
    if (graphShutdownRequired)
        graph.close();
    close();
}
Also used : DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)

Example 10 with TitanSchemaVertex

use of com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex in project titan by thinkaurelius.

the class StandardTransactionLogProcessor method fixSecondaryFailure.

private void fixSecondaryFailure(final StandardTransactionId txId, final TxEntry entry) {
    logRecoveryMsg("Attempting to repair partially failed transaction [%s]", txId);
    if (entry.entry == null) {
        logRecoveryMsg("Trying to repair expired or unpersisted transaction [%s] (Ignore in startup)", txId);
        return;
    }
    boolean userLogFailure = true;
    boolean secIndexFailure = true;
    final Predicate<String> isFailedIndex;
    final TransactionLogHeader.Entry commitEntry = entry.entry;
    final TransactionLogHeader.SecondaryFailures secFail = entry.failures;
    if (secFail != null) {
        userLogFailure = secFail.userLogFailure;
        secIndexFailure = !secFail.failedIndexes.isEmpty();
        isFailedIndex = new Predicate<String>() {

            @Override
            public boolean apply(@Nullable String s) {
                return secFail.failedIndexes.contains(s);
            }
        };
    } else {
        isFailedIndex = Predicates.alwaysTrue();
    }
    // I) Restore external indexes
    if (secIndexFailure) {
        //1) Collect all elements (vertices and relations) and the indexes for which they need to be restored
        final SetMultimap<String, IndexRestore> indexRestores = HashMultimap.create();
        BackendOperation.execute(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                StandardTitanTx tx = (StandardTitanTx) graph.newTransaction();
                try {
                    for (TransactionLogHeader.Modification modification : commitEntry.getContentAsModifications(serializer)) {
                        InternalRelation rel = ModificationDeserializer.parseRelation(modification, tx);
                        //Collect affected vertex indexes
                        for (MixedIndexType index : getMixedIndexes(rel.getType())) {
                            if (index.getElement() == ElementCategory.VERTEX && isFailedIndex.apply(index.getBackingIndexName())) {
                                assert rel.isProperty();
                                indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.getVertex(0).longId(), ElementCategory.VERTEX, getIndexId(index)));
                            }
                        }
                        //See if relation itself is affected
                        for (RelationType relType : rel.getPropertyKeysDirect()) {
                            for (MixedIndexType index : getMixedIndexes(relType)) {
                                if (index.getElement().isInstance(rel) && isFailedIndex.apply(index.getBackingIndexName())) {
                                    assert rel.id() instanceof RelationIdentifier;
                                    indexRestores.put(index.getBackingIndexName(), new IndexRestore(rel.id(), ElementCategory.getByClazz(rel.getClass()), getIndexId(index)));
                                }
                            }
                        }
                    }
                } finally {
                    if (tx.isOpen())
                        tx.rollback();
                }
                return true;
            }
        }, readTime);
        //2) Restore elements per backing index
        for (final String indexName : indexRestores.keySet()) {
            final StandardTitanTx tx = (StandardTitanTx) graph.newTransaction();
            try {
                BackendTransaction btx = tx.getTxHandle();
                final IndexTransaction indexTx = btx.getIndexTransaction(indexName);
                BackendOperation.execute(new Callable<Boolean>() {

                    @Override
                    public Boolean call() throws Exception {
                        Map<String, Map<String, List<IndexEntry>>> restoredDocs = Maps.newHashMap();
                        for (IndexRestore restore : indexRestores.get(indexName)) {
                            TitanSchemaVertex indexV = (TitanSchemaVertex) tx.getVertex(restore.indexId);
                            MixedIndexType index = (MixedIndexType) indexV.asIndexType();
                            TitanElement element = restore.retrieve(tx);
                            if (element != null) {
                                graph.getIndexSerializer().reindexElement(element, index, restoredDocs);
                            } else {
                                //Element is deleted
                                graph.getIndexSerializer().removeElement(restore.elementId, index, restoredDocs);
                            }
                        }
                        indexTx.restore(restoredDocs);
                        indexTx.commit();
                        return true;
                    }

                    @Override
                    public String toString() {
                        return "IndexMutation";
                    }
                }, persistenceTime);
            } finally {
                if (tx.isOpen())
                    tx.rollback();
            }
        }
    }
    // II) Restore log messages
    final String logTxIdentifier = (String) commitEntry.getMetadata().get(LogTxMeta.LOG_ID);
    if (userLogFailure && logTxIdentifier != null) {
        TransactionLogHeader txHeader = new TransactionLogHeader(txCounter.incrementAndGet(), times.getTime(), times);
        final StaticBuffer userLogContent = txHeader.serializeUserLog(serializer, commitEntry, txId);
        BackendOperation.execute(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                final Log userLog = graph.getBackend().getUserLog(logTxIdentifier);
                Future<Message> env = userLog.add(userLogContent);
                if (env.isDone()) {
                    env.get();
                }
                return true;
            }
        }, persistenceTime);
    }
}
Also used : IndexTransaction(com.thinkaurelius.titan.diskstorage.indexing.IndexTransaction) InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) RelationType(com.thinkaurelius.titan.core.RelationType) TitanElement(com.thinkaurelius.titan.core.TitanElement) List(java.util.List) TransactionLogHeader(com.thinkaurelius.titan.graphdb.database.log.TransactionLogHeader) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) RelationIdentifier(com.thinkaurelius.titan.graphdb.relations.RelationIdentifier) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) TitanException(com.thinkaurelius.titan.core.TitanException) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future) Map(java.util.Map)

Aggregations

TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)15 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)4 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)4 MixedIndexType (com.thinkaurelius.titan.graphdb.types.MixedIndexType)4 TypeDefinitionMap (com.thinkaurelius.titan.graphdb.types.TypeDefinitionMap)4 TitanException (com.thinkaurelius.titan.core.TitanException)3 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)3 InternalRelation (com.thinkaurelius.titan.graphdb.internal.InternalRelation)3 InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)3 IndexType (com.thinkaurelius.titan.graphdb.types.IndexType)3 PropertyKeyVertex (com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex)3 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)2 RelationType (com.thinkaurelius.titan.core.RelationType)2 Parameter (com.thinkaurelius.titan.core.schema.Parameter)2 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)2 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)2 InternalVertex (com.thinkaurelius.titan.graphdb.internal.InternalVertex)2 TitanSchemaCategory (com.thinkaurelius.titan.graphdb.internal.TitanSchemaCategory)2 ParameterIndexField (com.thinkaurelius.titan.graphdb.types.ParameterIndexField)2 IndexTypeWrapper (com.thinkaurelius.titan.graphdb.types.indextype.IndexTypeWrapper)2