Do you see "returning success" printed? If not, what is the return code?
29 вер. 2014 11:14, користувач "Mudit Verma" <[email protected]>
написав:
> Hi,
>
> I have following function which sets a value to a znode as 1 or 0. However,
> the value is not getting set in Zookeeper ( data version is being changed
> though). This piece of code used to work, until I upgraded the cluster to
> latest zookeeper version.
>
> Any idea what is going wrong? Your help is much appreciated !!
>
> zk_map_status
>
> *zk_map_lock(zk_map *zkm) { *
>
> struct Stat *stats = (struct Stat *)xcalloc(1,sizeof(struct Stat));
>
> int lock, size;
>
> *int rc,zrc = zoo_get(zkm->zk, zkm->path, 0, (char *)&lock,
> &size,stats); * /*/getting the lock value from ZK*
>
> if(zrc ==ZOK) {
>
> //here we need to grab the lock
>
> if(lock == 0) {
>
> printf("\n zk_map_lock %s lock:%d version:%d"
> ,zkm->path,lock,stats->version);fflush(stdout);
>
> lock=1;
>
> int zrc2 = *zoo_set(zkm->zk, zkm->path,(char *)&lock,
> sizeof(int),stats->version); //if zero setting to 1*
>
> if(zrc2 == ZOK){
>
> printf("\n Returning Success");fflush(stdout);
>
> rc = ZK_MAP_SUCCESS;
>
> } else
>
> rc = ZK_MAP_FAILURE;
>
> }
>
> else
>
> rc = ZK_MAP_FAILURE;
>
>
> }
>
> else if(zrc == ZNONODE)
>
> rc = ZK_MAP_ENOENT;
>
> else
>
> rc = ZK_MAP_FAILURE;
>
>
> //testing need to be removed later on
>
> lock=0;
>
> *zrc = zoo_get(zkm->zk, zkm->path, 0, (char *)&lock, &size,stats);
> //retrieving the value and it is still 0 -->very strange*
>
> printf("\n zrc:%d zk_map_lock %s lock:%d version:%d"
> ,zrc,zkm->path,lock,stats->version);fflush(stdout);
>
>
> free(stats);
>
> return rc;
>
>
> }
>
> =======
>
> output
>
> *Printf1: zk_map_lock /dir/6549211657075368907 lock:0 version:0*
>
> *Printf2: zrc:0 zk_map_lock /dir/6549211657075368907 lock:0 version:1*
>
>
>
> Thanks, Mudit
>