【问题标题】:PartitionStrategy with titanDb and DynamoDb as a backend not adding vertex to graph以titanDb 和DynamoDb 作为后端的PartitionStrategy 不向图形添加顶点
【发布时间】:2016-08-28 12:15:27
【问题描述】:

我在使用 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

我能够读取和写入数据库,请参阅测试 testAddVertexToTitanGraph,只是在使用分区策略时无法创建顶点。

【问题讨论】:

    标签: java amazon-dynamodb titan


    【解决方案1】:

    我刚刚在带有 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多