Details
Description
1. start zookeeper cluster with multi servers
2. multi clients connect to different zookeeper server at the same time
3. clients use lock from zookeeper recipes lock's C implement.
for example:
Client A create a node like x-025373e3a9960050-0000000067
and Client B create a node like x-015373e3a9960050-0000000068;
A is a lock owner now, then kill A, as expect, B should become owner, but in fact B not.
Because in zoo_lock.c, function zkr_lock_operation call child_floor to monitoring a pre node, but child_floor has bug, it caused B not check its prenode A.
B function child_floor just simply strcmp "x-025373e3a9960050-0000000067" with own node "x-015373e3a9960050-0000000068",
it should only strcmp "0000000067" with "0000000068", not include session info.
besides, it is better that using binary search than travelling every node for looking for a pre node when there exists many nodes.
fix:
static char* child_floor(char **sorted_data, int len, char *element) {
char* ret = NULL;
int begin = 0;
int end = len-1;
int index = 0;
while (begin <= end) {
index = (begin+end)/2;
int iCmpRet = strcmp(strrchr(sorted_data[index], '')+1, strrchr(element, '')+1);
if (iCmpRet < 0)
else {
if (iCmpRet == 0) {
if (index - 1 >= 0)
break;
}
else
}
}
return ret;
}