Question

I am currently dealing with the Chord protocol.

For each node there are two functions, findSuccessor and closestPrecedingNode which are given as pseudo-code.

findSuccessor is:

n.findSuccessor(id)
  if(id is.in (n, successor])
    return successor;
  else
    n' = closestPrecedingNode(id);
    return n'.findSuccessor(id);

closestPrecedingNode is:

n.closestPrecedingNode(id)
  for i = m downto 1
    if(finger[i] is.in (n, id))
      return finger[i];
  return n;

When a node is created, its successor is initially set to the node itself, and its finger table is empty.

Now my question is what happens when there is only one single node, and it is asked for any id except its own id. Then findSuccessor runs the else block and calls closestPrecedingNode. Since the finger table is empty, the node itself is returned to findSuccessor. Hence n' is then equal to n.

Afterwards, findSuccessor is called on n', which is a recursive call to itself.

And then we have an infinite loop ... or am I missing something?

NOTE: Pseudo-code is taken from Chord: A Scalable Peer-to-peer Lookup Protocol for Internet Applications, page 5.

Was it helpful?

Solution

The implementer of "jchord" seems to agree with you, since he adds the following code to findSuccessor:

if (this == successor) {
    return this;
}

But there seems to be a more elegant solution with is closer to the pseudo code. When checking if an ID is in the interval (n, successor] (left excluded, right included), make that check cyclic. jDHTUQ seems to do it like this (Starting at line 75. Warning: Really ugly code):

http://jdhtuq.svn.sourceforge.net/viewvc/jdhtuq/source_code/distributed_lookup_service/LookupService/src/co/edu/uniquindio/utils/hashing/Key.java?revision=63&view=markup

IMHO performing the interval check in a cyclic way seems to be the right thing to do. The paper you linked says (on page 4):

The notation (a; b] denotes the segment of the Chord ring obtained by moving clockwise from (but not including) a until reaching (and including) b.

In case of a single node, you would check if

id is.in (n, n]

which should yield true since the id is within the ring that starts right after n and ends with n.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top