具有titanDb和DynamoDb的PartitionStrategy作为后端而不是将顶点添加到图形

时间:2016-05-03 12:35:44

标签: java amazon-dynamodb titan

我在使用PartitionStrategy和titanDb以及DynamoDb作为后端时遇到了问题。我使用dynamodb-titan-storage-backend插件将dynamoDb用作本地后端。以下是我用java编写的简单测试用例:

import com.thinkaurelius.titan.core.TitanEdge;
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.TitanGraphQuery;
import com.thinkaurelius.titan.core.TitanTransaction;
import com.thinkaurelius.titan.core.TitanVertex;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;  
import java.util.Iterator;

public class TitanTest {

    TitanGraph titanGraph;

    @Before
    public void setUp() {
        BaseConfiguration conf = new BaseConfiguration();
        conf.setProperty("storage.backend", "com.amazon.titan.diskstorage.dynamodb.DynamoDBStoreManager");
        conf.setProperty("storage.dynamodb.client.endpoint", "http://localhost:4567");
        titanGraph = TitanFactory.open(conf);
    }

   @Test
   public void testAddVertexToTitanGraph(){
       titanGraph.addVertex( "name", "Bob", "age", "4.6x10^9");
       titanGraph.traversal().V().forEachRemaining(it -> {
        System.out.println("Found " + it.value("name"));
       });
   }

    @Test
    public void addVertexViaPartitionStrategy() {
        PartitionStrategy partitionStrategy = PartitionStrategy.build().partitionKey("_partition").writePartition("a").addReadPartition("a").create();
        GraphTraversalSource graphTraversalSource = GraphTraversalSource.build().with(partitionStrategy).create(titanGraph);
        GraphTraversal<Vertex, Vertex> marko = graphTraversalSource.addV("name", "marko", "age", 29);
        graphTraversalSource.V().forEachRemaining(it -> {
        System.out.println("name:" + it.value("name").toString());
        });

    }
}

但是,当我运行addVertexViaPartitionStrategy测试用例时,我似乎没有打印出任何内容。我跟着这个例子: http://tinkerpop.apache.org/docs/3.0.1-incubating/#_partitionstrategy

我能够读取和写入数据库,请参阅test testAddVertexToTitanGraph,在使用分区stratergy时无法创建顶点。

1 个答案:

答案 0 :(得分:0)

我刚刚使用cassandra后端遇到与Titan 1.0.0相同的问题。显然你必须获取遍历的结果才能添加顶点。

这样可行:

    GraphTraversalSource gA = GraphTraversalSource.build().with(partitionStrategy).create(g);
    GraphTraversal<Vertex, Vertex> addV = gA.addV();
    Vertex v = addV.next();
    System.out.println("v: " + v);

    GraphTraversal<Vertex, Long> count = gA.V().count();
    long amt = count.next();
    System.out.println("Partition vertex count: " + amt);