javatitantinkerpop-blueprint

Titan Cassandra - Ghost Vertices and Inconsistent Read Behavior Until Restart


Deleting vertices from Titan leads to inconsistent read behavior. I'm testing this on a single machine running Cassandra, here's my conf.properties:

storage.backend=cassandra
storage.hostname=localhost
storage.cassandra.keyspace=test

The following method deletes the appropriate vertex:

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();
}

When the following method gets called it returns two different sets of results:

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;
}

One result will be as expected - it will not contain the deleted profile. However, when I run it enough times - it sometimes will contain one extra profile - the one which was deleted.

Attempting to delete the same vertex again shows that no vertex exists with that 'uuid', the iterator's hasNext() returns false.

After the program is restarted, however, it never returns the deleted vertex. How can I fix this inconsistent behavior?


Solution

  • The problem is that on some threads, transactions had been opened for the graph already. Reading from the graph opens up a transaction, even if nothing is changed. These transactions need to be closed in order to ensure that the behavior is consistent.