You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Mudit Verma <mu...@gmail.com> on 2014/09/29 17:13:28 UTC
very strange behavior - data is not written in ZK
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
Re: very strange behavior - data is not written in ZK
Posted by Mudit Verma <mu...@gmail.com>.
Success, i am also printing the return code in 2nd printf.
On 01-Oct-2014 6:54 PM, "Vitalii Tymchyshyn" <vi...@tym.im> wrote:
> Do you see "returning success" printed? If not, what is the return code?
> 29 вер. 2014 11:14, користувач "Mudit Verma" <mu...@gmail.com>
> написав:
>
> > 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
> >
>
Re: very strange behavior - data is not written in ZK
Posted by Vitalii Tymchyshyn <vi...@tym.im>.
Do you see "returning success" printed? If not, what is the return code?
29 вер. 2014 11:14, користувач "Mudit Verma" <mu...@gmail.com>
написав:
> 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
>