Cassandra Can';无法从图形实例中看到顶点和边,但可以从其他图形实例中看到
如果我在应用程序中使用Graph实例添加顶点和边,然后查询这些顶点和边,有时查询结果会向我发送顶点和边,有时则不会,但是如果我创建一个指向服务器的JUnit测试,我可以看到顶点和边被持久化。如果我删除顶点或边,也会发生同样的情况Cassandra Can';无法从图形实例中看到顶点和边,但可以从其他图形实例中看到,cassandra,graph-theory,tinkerpop3,janusgraph,Cassandra,Graph Theory,Tinkerpop3,Janusgraph,如果我在应用程序中使用Graph实例添加顶点和边,然后查询这些顶点和边,有时查询结果会向我发送顶点和边,有时则不会,但是如果我创建一个指向服务器的JUnit测试,我可以看到顶点和边被持久化。如果我删除顶点或边,也会发生同样的情况 What I'm missing? ============= Class to work with Vertex and Edge ================= public class JanusGraphRepository implements Gra
What I'm missing?
============= Class to work with Vertex and Edge =================
public class JanusGraphRepository implements GraphRepository {
private Graph graph;
private GraphTraversalSource g;
public JanusGraphRepository(Graph janusGraph) {
this.graph = janusGraph;
this.g = graph.traversal();
}
@Override
public void dropE(Object id) {
g.E(id).drop().iterate();
g.tx().commit();
}
@Override
public void dropV(Object id) {
g.V(id).drop().iterate();
g.tx().commit();
}
@Override
public Vertex addV(final Object... keyValues) {
Vertex v = graph.addVertex(keyValues);
graph.tx().commit();
return v;
}
@Override
public Edge addE(String edgeLabel, Object fromVertex, Object toVertex,
Object... keyValues) {
Edge e = graph.vertices(fromVertex).next().addEdge(edgeLabel,
graph.vertices(toVertex).next(), keyValues);
graph.tx().commit();
return e;
}
}
======================== Code to get vertices and edges ======================
JanusGraphFactory.Builder config = JanusGraphFactory.build();
config.set("storage.backend", "cql");
config.set("storage.hostname", "10.2.1.134");
config.set("storage.cql.keyspace", "janusgraph");
config.set("index.search.backend", "elasticsearch");
config.set("index.search.hostname", "10.2.1.134");
// config.set("index.search.elasticsearch.client-only", "true");
// ip address where cassandra is installed
// config.set("storage.username", "cassandra");
// config.set("storage.password", "cassandra");
// config.set("storage.port", "8182");
// Get the instance of graph
JanusGraph graph = config.open();
graph.vertices().forEachRemaining(x -> {
System.out.println(x.id());
});
System.out.println("------ Edges -------");
graph.edges().forEachRemaining(x -> {
System.out.println(x.toString());
});
Thanks
不能保证卡桑德拉突变立即可见。 我看到您正在为Janus使用CQL存储后端,这告诉我您正在使用Cassandra节点/集群。在Cassandra中,写入需要传播到每个节点,并且可能不会立即发生。听起来你可能正在经历这种情况 特别是在需要将特定写入传递给拥有其索引范围的节点的情况下,后续读取最终从该节点读取,可能会出现写入后紧接着立即读取的情况,即写入后不显示刚刚写入的数据 写入显示所需的时间取决于中的各种因素 卡桑德拉集群;一般来说,即使在非常高的规模下,也不应该超过几分钟,但这并不能保证。卡桑德拉将可用性置于突变一致性之上。只要集群保持在线且可操作,突变最终将使其访问集群内的所有副本,但不一定是在写入调用返回时。这种行为称为“最终一致性” 为了避免这种情况,你必须调整你的期望;您不能期望刚刚写入集群的数据(因此在使用Cassandra作为后端时JanusGraph)立即可用 如果您的用例不能与Cassandra的一致性模型一起工作,我建议您查看HBase或列表中列出的其他后端之一