com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx Java Examples

The following examples show how to use com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public ManagementSystem(StandardTitanGraph graph, KCVSConfiguration config, Log sysLog,
                        ManagementLogger mgmtLogger, SchemaCache schemaCache) {
    Preconditions.checkArgument(config != null && graph != null && sysLog != null && mgmtLogger != null);
    this.graph = graph;
    this.baseConfig = config;
    this.sysLog = sysLog;
    this.mgmtLogger = mgmtLogger;
    this.schemaCache = schemaCache;
    this.transactionalConfig = new TransactionalConfiguration(baseConfig);
    this.modifyConfig = new ModifiableConfiguration(ROOT_NS,
            transactionalConfig, BasicConfiguration.Restriction.GLOBAL);
    this.userConfig = new UserModifiableConfiguration(modifyConfig, configVerifier);

    this.updatedTypes = new HashSet<TitanSchemaVertex>();
    this.updatedTypeTriggers = new HashSet<Callable<Boolean>>();
    this.graphShutdownRequired = false;

    this.transaction = (StandardTitanTx) graph.buildTransaction().disableBatchLoading().start();
    this.txStartTime = graph.getConfiguration().getTimestampProvider().getTime();
    this.isOpen = true;
}
 
Example #2
Source File: PartitionedVertexProgramExecutor.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public void run(int numThreads, ScanMetrics metrics) {
    StandardTitanTx tx=null;
    Map<Long,EntryList> pVertexAggregates = vertexMemory.retrievePartitionAggregates();
    if (pVertexAggregates.isEmpty()) return; //Nothing to do here

    try (WorkerPool workers = new WorkerPool(numThreads)) {
        tx = VertexJobConverter.startTransaction(graph);
        for (Map.Entry<Long,EntryList> pvertices : pVertexAggregates.entrySet()) {
            if (pvertices.getValue()==null) {
                metrics.incrementCustom(GHOTST_PARTITION_VERTEX);
                continue;
            }
            workers.submit(new PartitionedVertexProcessor(pvertices.getKey(),pvertices.getValue(),tx,metrics));
        }
    } catch (Throwable ex) {
        log.error("Could not post-process partitioned vertices", ex);
        metrics.incrementCustom(PARTITION_VERTEX_POSTFAIL);
    } finally {
        if (tx!=null && tx.isOpen()) tx.rollback();
    }
}
 
Example #3
Source File: IndexHelper.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public static GraphCentricQueryBuilder getQuery(CompositeIndexType index, Object[] values, StandardTitanTx tx) {
    Preconditions.checkArgument(index != null && values != null && values.length > 0 && tx != null);
    Preconditions.checkArgument(values.length==index.getFieldKeys().length);
    GraphCentricQueryBuilder gb = tx.query();
    IndexField[] fields = index.getFieldKeys();
    for (int i = 0; i <fields.length; i++) {
        IndexField f = fields[i];
        Object value = values[i];
        Preconditions.checkNotNull(value);
        PropertyKey key = f.getFieldKey();
        Preconditions.checkArgument(key.dataType().equals(value.getClass()),"Incompatible data types for: " + value);
        gb.has(key, Cmp.EQUAL,value);
    }
    if (index.hasSchemaTypeConstraint()) {
        gb.has(ImplicitKey.LABEL,Cmp.EQUAL,index.getSchemaTypeConstraint().name());
    }
    return gb;
}
 
Example #4
Source File: TitanTraversalUtil.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public static TitanTransaction getTx(Traversal.Admin<?, ?> traversal) {
    TitanTransaction tx = null;
    Optional<Graph> optGraph = TraversalHelper.getRootTraversal(traversal.asAdmin()).getGraph();

    if (traversal instanceof FulgoraElementTraversal) {
        tx = (TitanTransaction) optGraph.get();
    } else {
        if (!optGraph.isPresent())
            throw new IllegalArgumentException("Traversal is not bound to a graph: " + traversal);
        Graph graph = optGraph.get();
        if (graph instanceof TitanTransaction) tx = (TitanTransaction) graph;
        else if (graph instanceof TitanBlueprintsGraph) tx = ((TitanBlueprintsGraph) graph).getCurrentThreadTx();
        else throw new IllegalArgumentException("Traversal is not bound to a Titan Graph, but: " + graph);
    }
    if (tx == null)
        throw new IllegalArgumentException("Not a valid start step for a Titan traversal: " + traversal);
    if (tx.isOpen()) return tx;
    else return ((StandardTitanTx) tx).getNextTx();
}
 
Example #5
Source File: BasicVertexCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the extended sort key of the given type. The extended sort key extends the type's primary sort key
 * by ADJACENT_ID and ID depending on the multiplicity of the type in the given direction.
 * It also converts the type ids to actual types.
 *
 * @param type
 * @param dir
 * @param tx
 * @return
 */
private static PropertyKey[] getExtendedSortKey(InternalRelationType type, Direction dir, StandardTitanTx tx) {
    int additional = 0;
    if (!type.multiplicity().isUnique(dir)) {
        if (!type.multiplicity().isConstrained()) additional++;
        if (type.isEdgeLabel()) additional++;
    }
    PropertyKey[] entireKey = new PropertyKey[type.getSortKey().length+additional];
    int i;
    for (i=0;i<type.getSortKey().length;i++) {
        entireKey[i]=tx.getExistingPropertyKey(type.getSortKey()[i]);
    }
    if (type.isEdgeLabel() && !type.multiplicity().isUnique(dir)) entireKey[i++]=ImplicitKey.ADJACENT_ID;
    if (!type.multiplicity().isConstrained()) entireKey[i++]=ImplicitKey.TITANID;
    return entireKey;
}
 
Example #6
Source File: MizoRDD.java    From mizo with Apache License 2.0 6 votes vote down vote up
/**
 * Given a path for Titan config file, connects and gets the internal Titan types,
 * converting them to MizoTitanRelationTypes mapped by type-ids
 * @param titanConfigPath Path to Titan's config path
 * @return Mapping between relation type-ids to InternalRelationType instances
 */
protected static HashMap<Long, MizoTitanRelationType> loadRelationTypes(String titanConfigPath) {
    TitanGraph g = TitanFactory.open(titanConfigPath);
    StandardTitanTx tx = (StandardTitanTx)g.buildTransaction().readOnly().start();

    HashMap<Long, MizoTitanRelationType> relations = Maps.newHashMap();

    tx.query()
            .has(BaseKey.SchemaCategory, Contain.IN, Lists.newArrayList(TitanSchemaCategory.values()))
            .vertices()
            .forEach(v -> {
                if (v instanceof InternalRelationType)
                    relations.put(v.longId(), new MizoTitanRelationType((InternalRelationType)v));
            });

    tx.close();

    try {
        ((StandardTitanGraph)g).getBackend().close();
    } catch (BackendException e) {
        e.printStackTrace();
    }

    return relations;
}
 
Example #7
Source File: StandardLogProcessorFramework.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
private void readRelations(TransactionLogHeader.Entry txentry,
                           StandardTitanTx tx, StandardChangeState changes) {
    for (TransactionLogHeader.Modification modification : txentry.getContentAsModifications(serializer)) {
        InternalRelation rel = ModificationDeserializer.parseRelation(modification,tx);

        //Special case for vertex addition/removal
        Change state = modification.state;
        if (rel.getType().equals(BaseKey.VertexExists) && !(rel.getVertex(0) instanceof TitanSchemaElement)) {
            if (state==Change.REMOVED) { //Mark as removed
                ((StandardVertex)rel.getVertex(0)).updateLifeCycle(ElementLifeCycle.Event.REMOVED);
            }
            changes.addVertex(rel.getVertex(0), state);
        } else if (!rel.isInvisible()) {
            changes.addRelation(rel,state);
        }
    }
}
 
Example #8
Source File: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example #9
Source File: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example #10
Source File: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example #11
Source File: StandardRelationTypeMaker.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public StandardRelationTypeMaker(final StandardTitanTx tx, String name,
                                 final IndexSerializer indexSerializer,
                                 final AttributeHandler attributeHandler) {
    Preconditions.checkNotNull(tx);
    Preconditions.checkNotNull(indexSerializer);
    Preconditions.checkNotNull(attributeHandler);
    this.tx = tx;
    this.indexSerializer = indexSerializer;
    this.attributeHandler = attributeHandler;
    name(name);

    //Default assignments
    isInvisible = false;
    sortKey = new ArrayList<>(4);
    sortOrder = Order.ASC;
    signature = new ArrayList<>(4);
    multiplicity = Multiplicity.MULTI;
}
 
Example #12
Source File: SimpleVertexQueryProcessor.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public SimpleVertexQueryProcessor(VertexCentricQuery query, StandardTitanTx tx) {
    Preconditions.checkArgument(query.isSimple());
    this.query=query;
    this.tx=tx;
    BackendQueryHolder<SliceQuery> bqh = query.getSubQuery(0);
    this.sliceQuery=bqh.getBackendQuery();
    this.profiler=bqh.getProfiler();
    this.vertex=query.getVertex();
    this.edgeSerializer=tx.getEdgeSerializer();
}
 
Example #13
Source File: GraphCentricQueryBuilder.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public GraphCentricQueryBuilder(StandardTitanTx tx, IndexSerializer serializer) {
    log.debug("Loaded shaded version of class GraphCentricQueryBuilder");
    Preconditions.checkNotNull(tx);
    Preconditions.checkNotNull(serializer);
    this.tx = tx;
    this.serializer = serializer;
    this.constraints = new ArrayList<>(5);
}
 
Example #14
Source File: TitanFeatures.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public VertexProperty.Cardinality getCardinality(final String key) {
    StandardTitanTx tx = (StandardTitanTx)TitanFeatures.this.graph.newTransaction();
    try {
        if (!tx.containsPropertyKey(key)) return tx.getConfiguration().getAutoSchemaMaker().defaultPropertyCardinality(key).convert();
        return tx.getPropertyKey(key).cardinality().convert();
    } finally {
        tx.rollback();
    }
}
 
Example #15
Source File: QueryUtil.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static InternalRelationType getType(StandardTitanTx tx, String typeName) {
    RelationType t = tx.getRelationType(typeName);
    if (t == null && !tx.getConfiguration().getAutoSchemaMaker().ignoreUndefinedQueryTypes()) {
        throw new IllegalArgumentException("Undefined type used in query: " + typeName);
    }
    return (InternalRelationType) t;
}
 
Example #16
Source File: IndexQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public IndexQueryBuilder(StandardTitanTx tx, IndexSerializer serializer) {
    Preconditions.checkNotNull(tx);
    Preconditions.checkNotNull(serializer);
    this.tx = tx;
    this.serializer = serializer;

    parameters = Lists.newArrayList();
    unkownKeyName = tx.getGraph().getConfiguration().getUnknownIndexKeyName();
    this.offset=0;
}
 
Example #17
Source File: RelationIdentifier.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
TitanRelation findRelation(TitanTransaction tx) {
    TitanVertex v = ((StandardTitanTx)tx).getInternalVertex(outVertexId);
    if (v == null || v.isRemoved()) return null;
    TitanVertex typeVertex = tx.getVertex(typeId);
    if (typeVertex == null) return null;
    if (!(typeVertex instanceof RelationType))
        throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type");

    RelationType type = (RelationType) typeVertex;
    Iterable<? extends TitanRelation> rels;
    if (((RelationType) typeVertex).isEdgeLabel()) {
        Direction dir = Direction.OUT;
        TitanVertex other = ((StandardTitanTx)tx).getInternalVertex(inVertexId);
        if (other==null || other.isRemoved()) return null;
        if (((StandardTitanTx) tx).isPartitionedVertex(v) && !((StandardTitanTx) tx).isPartitionedVertex(other)) { //Swap for likely better performance
            TitanVertex tmp = other;
            other = v;
            v = tmp;
            dir = Direction.IN;
        }
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges();
    } else {
        rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties();
    }

    for (TitanRelation r : rels) {
        //Find current or previous relation
        if (r.longId() == relationId ||
                ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId)) return r;
    }
    return null;
}
 
Example #18
Source File: QueryUtil.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private static <E extends TitanElement> void addConstraint(RelationType type, TitanPredicate predicate,
                                                           Object value, MultiCondition<E> conditions, StandardTitanTx tx) {
    if (type.isPropertyKey()) {
        if (value != null)
            value = tx.verifyAttribute((PropertyKey) type, value);
    } else { //t.isEdgeLabel()
        Preconditions.checkArgument(value instanceof TitanVertex);
    }
    PredicateCondition<RelationType, E> pc = new PredicateCondition<RelationType, E>(type, predicate, value);
    if (!conditions.contains(pc)) conditions.add(pc);
}
 
Example #19
Source File: GraphCentricQueryBuilder.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public GraphCentricQueryBuilder(StandardTitanTx tx, IndexSerializer serializer) {
    Preconditions.checkNotNull(tx);
    Preconditions.checkNotNull(serializer);
    this.tx = tx;
    this.serializer = serializer;
    this.constraints = new ArrayList<PredicateCondition<String, TitanElement>>(5);
}
 
Example #20
Source File: StandardTitanGraph.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public StandardTitanGraph(GraphDatabaseConfiguration configuration) {

        this.config = configuration;
        this.backend = configuration.getBackend();

        this.idAssigner = config.getIDAssigner(backend);
        this.idManager = idAssigner.getIDManager();

        this.serializer = config.getSerializer();
        StoreFeatures storeFeatures = backend.getStoreFeatures();
        this.indexSerializer = new IndexSerializer(configuration.getConfiguration(), this.serializer,
                this.backend.getIndexInformation(), storeFeatures.isDistributed() && storeFeatures.isKeyOrdered());
        this.edgeSerializer = new EdgeSerializer(this.serializer);
        this.vertexExistenceQuery = edgeSerializer.getQuery(BaseKey.VertexExists, Direction.OUT, new EdgeSerializer.TypedInterval[0]).setLimit(1);
        this.queryCache = new RelationQueryCache(this.edgeSerializer);
        this.schemaCache = configuration.getTypeCache(typeCacheRetrieval);
        this.times = configuration.getTimestampProvider();

        isOpen = true;
        txCounter = new AtomicLong(0);
        openTransactions = Collections.newSetFromMap(new ConcurrentHashMap<StandardTitanTx, Boolean>(100, 0.75f, 1));

        //Register instance and ensure uniqueness
        String uniqueInstanceId = configuration.getUniqueGraphId();
        ModifiableConfiguration globalConfig = GraphDatabaseConfiguration.getGlobalSystemConfig(backend);
        if (globalConfig.has(REGISTRATION_TIME, uniqueInstanceId)) {
            throw new TitanException(String.format("A Titan graph with the same instance id [%s] is already open. Might required forced shutdown.", uniqueInstanceId));
        }
        globalConfig.set(REGISTRATION_TIME, times.getTime(), uniqueInstanceId);

        Log mgmtLog = backend.getSystemMgmtLog();
        mgmtLogger = new ManagementLogger(this, mgmtLog, schemaCache, this.times);
        mgmtLog.registerReader(ReadMarker.fromNow(), mgmtLogger);

        shutdownHook = new ShutdownThread(this);
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        log.debug("Installed shutdown hook {}", shutdownHook, new Throwable("Hook creation trace"));
    }
 
Example #21
Source File: StandardTitanGraph.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public StandardTitanTx newTransaction(final TransactionConfiguration configuration) {
    if (!isOpen) ExceptionFactory.graphShutdown();
    try {
        StandardTitanTx tx = new StandardTitanTx(this, configuration);
        tx.setBackendTransaction(openBackendTransaction(tx));
        openTransactions.add(tx);
        return tx;
    } catch (BackendException e) {
        throw new TitanException("Could not start new transaction", e);
    }
}
 
Example #22
Source File: IndexUpdateJob.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public void workerIterationStart(TitanGraph graph, Configuration config, ScanMetrics metrics) {
    this.graph = (StandardTitanGraph)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.mgmt = (ManagementSystem)graph.openManagement();

        if (isGlobalGraphIndex()) {
            index = mgmt.getGraphIndex(indexName);
        } else {
            indexRelationType = mgmt.getRelationType(indexRelationTypeName);
            Preconditions.checkArgument(indexRelationType!=null,"Could not find relation type: %s", indexRelationTypeName);
            index = mgmt.getRelationIndex(indexRelationType,indexName);
        }
        Preconditions.checkArgument(index!=null,"Could not find index: %s [%s]",indexName,indexRelationTypeName);
        log.info("Found index {}", indexName);
        validateIndexStatus();

        StandardTransactionBuilder txb = this.graph.buildTransaction();
        txb.commitTime(jobStartTime);
        writeTx = (StandardTitanTx)txb.start();
    } catch (final Exception e) {
        if (null != mgmt && mgmt.isOpen())
            mgmt.rollback();
        if (writeTx!=null && writeTx.isOpen())
            writeTx.rollback();
        metrics.incrementCustom(FAILED_TX);
        throw new TitanException(e.getMessage(), e);
    }
}
 
Example #23
Source File: VertexJobConverter.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static StandardTitanTx startTransaction(StandardTitanGraph graph) {
    StandardTransactionBuilder txb = graph.buildTransaction().readOnly();
    txb.setPreloadedData(true);
    txb.checkInternalVertexExistence(false);
    txb.dirtyVertexSize(0);
    txb.vertexCacheSize(0);
    return (StandardTitanTx)txb.start();
}
 
Example #24
Source File: StandardTitanGraph.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public Long retrieveSchemaByName(String typeName) {
    // Get a consistent tx
    Configuration customTxOptions = backend.getStoreFeatures().getKeyConsistentTxConfig();
    StandardTitanTx consistentTx = null;
    try {
        consistentTx = StandardTitanGraph.this.newTransaction(new StandardTransactionBuilder(getConfiguration(),
                StandardTitanGraph.this, customTxOptions).groupName(GraphDatabaseConfiguration.METRICS_SCHEMA_PREFIX_DEFAULT));
        consistentTx.getTxHandle().disableCache();
        TitanVertex v = Iterables.getOnlyElement(QueryUtil.getVertices(consistentTx, BaseKey.SchemaName, typeName), null);
        return v!=null?v.longId():null;
    } finally {
        TXUtils.rollbackQuietly(consistentTx);
    }
}
 
Example #25
Source File: StandardTitanGraph.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public EntryList retrieveSchemaRelations(final long schemaId, final BaseRelationType type, final Direction dir) {
    SliceQuery query = queryCache.getQuery(type,dir);
    Configuration customTxOptions = backend.getStoreFeatures().getKeyConsistentTxConfig();
    StandardTitanTx consistentTx = null;
    try {
        consistentTx = StandardTitanGraph.this.newTransaction(new StandardTransactionBuilder(getConfiguration(),
                StandardTitanGraph.this, customTxOptions).groupName(GraphDatabaseConfiguration.METRICS_SCHEMA_PREFIX_DEFAULT));
        consistentTx.getTxHandle().disableCache();
        EntryList result = edgeQuery(schemaId, query, consistentTx.getTxHandle());
        return result;
    } finally {
        TXUtils.rollbackQuietly(consistentTx);
    }
}
 
Example #26
Source File: TransactionLogHeader.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public StaticBuffer serializeModifications(Serializer serializer, LogTxStatus status, StandardTitanTx tx,
                                           final Collection<InternalRelation> addedRelations,
                                           final Collection<InternalRelation> deletedRelations) {
    Preconditions.checkArgument(status==LogTxStatus.PRECOMMIT || status==LogTxStatus.USER_LOG);
    DataOutput out = serializeHeader(serializer, 256 + (addedRelations.size() + deletedRelations.size()) * 40, status, status == LogTxStatus.PRECOMMIT ? tx.getConfiguration() : null);
    logRelations(out, addedRelations, tx);
    logRelations(out, deletedRelations,tx);
    return out.getStaticBuffer();
}
 
Example #27
Source File: TransactionLogHeader.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private static void logRelations(DataOutput out, final Collection<InternalRelation> relations, StandardTitanTx tx) {
    VariableLong.writePositive(out,relations.size());
    for (InternalRelation rel : relations) {
        VariableLong.writePositive(out,rel.getVertex(0).longId());
        com.thinkaurelius.titan.diskstorage.Entry entry = tx.getEdgeSerializer().writeRelation(rel, 0, tx);
        BufferUtil.writeEntry(out,entry);
    }
}
 
Example #28
Source File: QueryContainer.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public QueryContainer(StandardTitanTx tx) {
    Preconditions.checkArgument(tx != null);
    this.tx = tx;
    queries = new HashSet<>(6);
    inverseQueries = HashMultimap.create();
    hardQueryLimit = DEFAULT_HARD_QUERY_LIMIT;
    requiresName = true;
}
 
Example #29
Source File: RelationTypeIndexWrapper.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public RelationType[] getSortKey() {
    StandardTitanTx tx = type.tx();
    long[] ids = type.getSortKey();
    RelationType[] keys = new RelationType[ids.length];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = tx.getExistingRelationType(ids[i]);
    }
    return keys;
}
 
Example #30
Source File: ModificationDeserializer.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardTitanTx tx) {
    Change state = modification.state;
    assert state.isProper();
    long outVertexId = modification.outVertexId;
    Entry relEntry = modification.relationEntry;
    InternalVertex outVertex = tx.getInternalVertex(outVertexId);
    //Special relation parsing, compare to {@link RelationConstructor}
    RelationCache relCache = tx.getEdgeSerializer().readRelation(relEntry, false, tx);
    assert relCache.direction == Direction.OUT;
    InternalRelationType type = (InternalRelationType)tx.getExistingRelationType(relCache.typeId);
    assert type.getBaseType()==null;
    InternalRelation rel;
    if (type.isPropertyKey()) {
        if (state==Change.REMOVED) {
            rel = new StandardVertexProperty(relCache.relationId,(PropertyKey)type,outVertex,relCache.getValue(), ElementLifeCycle.Removed);
        } else {
            rel = new CacheVertexProperty(relCache.relationId,(PropertyKey)type,outVertex,relCache.getValue(),relEntry);
        }
    } else {
        assert type.isEdgeLabel();
        InternalVertex otherVertex = tx.getInternalVertex(relCache.getOtherVertexId());
        if (state==Change.REMOVED) {
            rel = new StandardEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex,ElementLifeCycle.Removed);
        } else {
            rel = new CacheEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex,relEntry);
        }
    }
    if (state==Change.REMOVED && relCache.hasProperties()) { //copy over properties
        for (LongObjectCursor<Object> entry : relCache) {
            rel.setPropertyDirect(tx.getExistingPropertyKey(entry.key),entry.value);
        }
    }
    return rel;
}