5

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.

weberc2
  • 7,423
  • 4
  • 41
  • 57
Golo Roden
  • 140,679
  • 96
  • 298
  • 425

1 Answers1

7

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.

David Tanzer
  • 2,732
  • 18
  • 30
  • 1
    That's it, great :-). So it basically comes down to the question what you define as "included in the interval" ... – Golo Roden Dec 10 '12 at 19:14
  • The comparison between `this` and `successor` you mentioned is necessary nevertheless, because the finger table may be initially empty, but the successor may already be set to another node (directly after a join, e.g.). Then the `if` of `findSuccessor` may fail, and then you need that comparison to avoid an infinite loop. – Golo Roden Dec 25 '12 at 11:48
  • There is no chance of this function going into infinite loop because if there is just one node (k) in the DHT, i.e. node k is it's own successor then any arbitrary ID including it's own will fall in the "clockwise circular interval" (k, k]. –  Aug 13 '16 at 11:28