[chord] Possible bug in join.c

Michael Walfish mwalfish at lcs.mit.edu
Wed Feb 25 09:17:04 EST 2004


| void join(Node *n, int *nodeId)
| 
| the first if statement
| 
| if ((!(n1 = getNode(*nodeId))) || (n1 && n->status == ABSENT))
|     // probably nodeId has been deleted in the meantime
|     n1 = getNode(getRandomActiveNodeId());
| 
| checks whether node n is ABSENT. You probably wanted to check whether node
| n1 is ABSENT, since node n is the node that wants to join via node n1. 

Ion, please correct me if I'm wrong about the following.

Andy, I think you are right that this is a coding error. However, the
correctness of the simulator is unaffected, the reason being that
n->status will be ABSENT (the status field is indeed initialized; see
below). Hence, what happens is that if sim makes it to the second part of
the or condition (as it will every time, after the first node joins), the
condition will evaluate to true, and sim will pick a new active Id at
random, whether or not n1 was active. And since the event generator had
picked nodeId at random, before the simulator began running, you shouldn't
care that the decision about "which node first hears the join" is made
online, since the choice is again random. The fact that this decision is
made on every join slows sim down but only very slightly, since the number
of join events is usually few compared to the number of events that sim
processes in total.

| In 
| 
| Node *newNode(int id)
| 
| n->status should probably be initialized as well.

The memory pointed to by n is allocated by calloc(); calloc zeroes out the
memory it allocates. Since the status code for ABSENT is 0, the
initialization you mention does occur, albeit implicitly.

Please let me know if you have further questions.

-Mike



More information about the chord mailing list