You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Richard Sharpe <re...@gmail.com> on 2015/01/11 18:59:51 UTC

Help with what I am doing wrong with the C interface ...

Hi folks,

I am not sure if this is the correct interface, however, I am trying
to develop a config backend for Samba that connects to Zookeeper. The
intent is that parts of Samba's smb.conf would be stored in zookeeper
to make life easier in clustered environments.

I am constrained to use C both by the code I am working with and by
inclination. The examples in C are somewhat sparse.

I am trying to use the sync interface at the moment and I get zero
children back when I call zoo_get_children, however, if I use cli_mt I
can see that there is one child node under /samba in zookeeper:

    [root@localhost zookeeper-3.4.6]# ./src/c/cli_mt localhost:2181
    Watcher SESSION_EVENT state = CONNECTED_STATE
    Got a new session id: 0x14accb10de10004

    ls /
    time = 1 msec
    /: rc = 0
    samba
    zookeeper
    time = 1 msec
    ls /samba
    time = 1 msec
    /samba: rc = 0
    global
    time = 1 msec

I am pretty certain that I am asking for the children of /samba as my
logging code shows me that I am feeding that path to zoo_get_children
and when I had a bug that appended a trailing slash I got error -8
back.

Here are what I think are the relevant parts of the code I have at the moment:

-------
static void zoo_watcher(zhandle_t *zzh, int type, int state, const char *path,
                        void *context)
{
        DEBUG(10, ("%s called\n",__func__));
}

...

        zh = zookeeper_init(host_port, zoo_watcher, 30000, &myId, 0, 0);
        if (!zh) {
                DEBUG(10, ("Problem with zookeeper_init: %s\n",
strerror(errno)));
        }

...

        struct String_vector strings;
...

        rc = zoo_get_children(zh, zookeeper_key, false, &strings);
--------------

There are hints in the test code for the C client interface that
perhaps I should be doing something real in the watcher function above
but I am not sure.

Any hints would be appreciated.

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)

Re: Help with what I am doing wrong with the C interface ...

Posted by Richard Sharpe <re...@gmail.com>.
On Sun, Jan 11, 2015 at 9:59 AM, Richard Sharpe
<re...@gmail.com> wrote:
> Hi folks,
>
> I am not sure if this is the correct interface, however, I am trying
> to develop a config backend for Samba that connects to Zookeeper. The
> intent is that parts of Samba's smb.conf would be stored in zookeeper
> to make life easier in clustered environments.
>
> I am constrained to use C both by the code I am working with and by
> inclination. The examples in C are somewhat sparse.
>
> I am trying to use the sync interface at the moment and I get zero
> children back when I call zoo_get_children, however, if I use cli_mt I
> can see that there is one child node under /samba in zookeeper:
>
>     [root@localhost zookeeper-3.4.6]# ./src/c/cli_mt localhost:2181
>     Watcher SESSION_EVENT state = CONNECTED_STATE
>     Got a new session id: 0x14accb10de10004
>
>     ls /
>     time = 1 msec
>     /: rc = 0
>     samba
>     zookeeper
>     time = 1 msec
>     ls /samba
>     time = 1 msec
>     /samba: rc = 0
>     global
>     time = 1 msec
>
> I am pretty certain that I am asking for the children of /samba as my
> logging code shows me that I am feeding that path to zoo_get_children
> and when I had a bug that appended a trailing slash I got error -8
> back.
>
> Here are what I think are the relevant parts of the code I have at the moment:
>
> -------
> static void zoo_watcher(zhandle_t *zzh, int type, int state, const char *path,
>                         void *context)
> {
>         DEBUG(10, ("%s called\n",__func__));
> }
>
> ...
>
>         zh = zookeeper_init(host_port, zoo_watcher, 30000, &myId, 0, 0);
>         if (!zh) {
>                 DEBUG(10, ("Problem with zookeeper_init: %s\n",
> strerror(errno)));
>         }
>
> ...
>
>         struct String_vector strings;
> ...
>
>         rc = zoo_get_children(zh, zookeeper_key, false, &strings);
> --------------
>
> There are hints in the test code for the C client interface that
> perhaps I should be doing something real in the watcher function above
> but I am not sure.
>
> Any hints would be appreciated.

OK, it looks like the problem was my confusion between the single
threaded library and the multi-threaded library.

I was trying to use the _st library, but it seems I need more
infrastructure for that.

I wrote a small simple test program and after linking it with the _mt
library things are working.

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)