palwe-prafulla
palwe-prafulla

Reputation: 141

Titan graph API removing the wrong edge

I am using java Titan API to remove edge between 2 vertices as below:

public void deleteEdge(Vertex vFrom, Vertex vTo, String edgeName) {

  Iterator<Edge> iter = getEdges(vFrom, Direction.OUT, edgeName);
            TitanEdge te = null;
            while (iter.hasNext()) {
                te = (TitanEdge) iter.next();
                TitanVertex tvTo = te.otherVertex(vFrom);
                if (vTo == tvTo) {
                    break;
                }
            }

            if (te != null) { ***----> this is the issue when edge is not present this is set to the last edge present on vFrom and it gets deleted because of this condition. Fixed it to set boolean if edge found and use it with this condition.***
                te.remove();
            }
}

getEdges() method used in delete method above is :

public Iterator<Edge> getEdges(Vertex v, Direction dir, String... labels) {
        if (v == null)
            return null;
        TitanVertex tv = (TitanVertex) v;
        Iterator<Edge> iter = (labels == null) ? tv.edges(dir) : tv.edges(dir,
                labels);
        return iter;
    }

I have graph vertices and edges as below:

  1. NodeA ------X----> Node1:TX
  2. Node1:RX -----X----> NodeA

  3. NodeA ------X----> Node2:TX

  4. Node2:RX -----X----> NodeA

  5. NodeA ------X----> Node3:TX

  6. Node3:RX -----X----> NodeA

For some mysterious reasons, when 3 to 6 is executed sometimes, I see 1 getting deleted.

This is very strange behavior and its inconsistent and doesnt happen all the time.

I am using cassndara backed with Titan graph.


I have no clue how the edge goes missing with TX node.

The only difference between TX/RX nodes are that NodeA is fromNode with TX and toNode with RX.

So based on getEdges method that i shared, it will retrieve all the other edges where NodeA is fromNode of the edge and will only retrieve particular edge when NodeA is toNode.

But the code still compares the vTo with input To node to verify the edge has same from and To before removing the edge.

Its a mystery how this code can remove the edge from same from Node but to different toNode than the input toNode.

Also i was worried about the code using == for comparing toNode but its working fine so far and the delete never fails for the input edge, its just that sometimes its removing other edge also.

This doesnt make sense because code is breaking when it matches the toNode with input so it shouldnt even try to remove any other edges.

Even if by some mysterious reasons, it successfully compare toNode with some other toNode and deletes that wrong edge then the right edge shoould never be deleted as it break from the loop.


I was wondering if its clustering issue but the same issue happens on single node cassanda without any clustering.


Few things to note:

There is application code which calls deleteEdge on the same edge twice. the deleteEdge method doesnt commit anything after edge removal. The application code commits once everything is done for the use case.

Once I corrected the application issue of sending duplicate deletes, the issue seem to be resolved.

So 1st delete removes the edge, 2nd delete comes in and 1st was not commited yet so it can get the same edge and removes it again.

However, I am very very curious how this is causing wrong edge to be deleted somewhere sometimes.


I am still curious about using == for comparison of toVertex.

It uses getVertex first to get from and to vertices.

Then it used frm.getEdges to get edges whihc has toVertex. Not sure how the toVertex on edge can be same object as returned by calling getVertex to get toVertex.

But I dont know internal implemnetation of titan api, so as i said it never fails to delete input edge.


This problem has made me very curious but I am not abel to find any related information or issues reported anywhere.

Any help/pointers will be really really appreciated as I want to know how this can happen. (I already fixed application code to not send duplicate deletes but curious about how duplicate deleted is causing titan api to delete wrong edge)

I am using Titan api 1.0.0

Upvotes: 1

Views: 71

Answers (1)

palwe-prafulla
palwe-prafulla

Reputation: 141

The root cause is found and no issue with Titan API. Application code to deleteEdge has issue if you noticed that its checking for te != null after while loop. When there are more than one edge of same label then on 2nd duplicate delete te is not null and its the last edge from the vFrom vertex and it gets deleted. This happens when you are trying to delete edge which is not present. I feel so annoyed that I didnt realise this bug earlier. :) :) Thanks to all who viewed the question .. All good now :) :)

Upvotes: 0

Related Questions