从Titan中删除顶点会导致读取行为不一致。我在一台运行Cassandra的机器上测试这个,这里是我的conf.properties:
storage.backend=cassandra
storage.hostname=localhost
storage.cassandra.keyspace=test
下面的方法删除相应的顶点:
public void deleteProfile(String uuid, String puuid) {
for(Person person : this.graph.getVertices("uuid", uuid, Person.class)) {
if (person != null) {
for (Profile profile : this.graph.getVertices("uuid", puuid, Profile.class)) {
person.removeProfile(profile);
graph.removeVertex(profile.asVertex());
}
}
}
this.graph.getBaseGraph().commit();
}
当调用以下方法时,它返回两组不同的结果:
public Iterable<ProfileImpl> getProfiles(String uuid) {
List<ProfileImpl> profiles = new ArrayList<>();
for(Person person : this.graph.getVertices("uuid", uuid, Person.class)) {
if (person != null) {
for (Profile profile : person.getProfiles()) {
profiles.add(profile.toImpl());
}
}
}
return profiles;
}
一个结果将如预期的那样-它将不包含已删除的配置文件。然而,当我运行它足够多的时候-它有时会包含一个额外的配置文件-被删除的那个。
尝试再次删除相同的顶点时,如果没有该'uuid'的顶点存在,迭代器的hasNext()返回false。
程序重新启动后,它永远不会返回删除的顶点。如何修复这种不一致的行为?
问题是在一些线程上,已经为图打开了事务。从图中读取将打开一个事务,即使没有任何更改。这些事务需要关闭,以确保行为是一致的。
根据http://s3.thinkaurelius.com/docs/titan/0.9.0-M2/tx.html#tx-config您应该设置checkInternalVertexExistence