Java Code Examples for com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx#rollback()

The following examples show how to use com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx#rollback() . 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: 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 2
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 3
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 4
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 5
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();
    }
}