You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by nipun_mlist Assam <ni...@gmail.com> on 2012/12/05 18:12:02 UTC
crash with zoo_wexists
Hi,
Can anybody please let me know why simple zookeeper test program keeps
crashing. I am using zookeeper-3.3.5.
Below is the backtrace:
(gdb) bt
#0 0x000000329da751d2 in malloc_consolidate () from /lib64/libc.so.6
#1 0x000000329da77ae8 in _int_free () from /lib64/libc.so.6
#2 0x00007f100e29f296 in free_buffer (b=0x1655670) at src/zookeeper.c:873
#3 0x00007f100e29f2c8 in remove_buffer (list=<value optimized out>)
at src/zookeeper.c:900
#4 0x00007f100e29f3b4 in flush_send_queue (zh=0x16546a0, timeout=0)
at src/zookeeper.c:2863
#5 0x00007f100e2a2cf3 in send_ping (zh=0x16546a0) at src/zookeeper.c:1446
#6 0x00007f100e2a4fec in zookeeper_interest (zh=0x16546a0, fd=<value
optimized out>, interest=0x7fff52571048, tv=0x7fff52571030) at
src/zookeeper.c:1538
#7 0x00000000004011f1 in main (argc=2, argv=0x7fff52571168) at nipun1.c:136
//Below is the code:
#include <zookeeper.h>
#include <proto.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include <assert.h>
char clientIdFile[256] = "client.id";
static clientid_t myid;
zhandle_t *zh;
int connected = 0;
static const char *state2String(int state)
{
if (state == 0)
return "CLOSED_STATE";
if (state == ZOO_CONNECTING_STATE)
return "CONNECTING_STATE";
if (state == ZOO_ASSOCIATING_STATE)
return "ASSOCIATING_STATE";
if (state == ZOO_CONNECTED_STATE){
connected = 1;
return "CONNECTED_STATE";
}
if (state == ZOO_EXPIRED_SESSION_STATE)
return "EXPIRED_SESSION_STATE";
if (state == ZOO_AUTH_FAILED_STATE)
return "AUTH_FAILED_STATE";
return "INVALID_STATE";
}
void watcher(zhandle_t * zzh, int type, int state, const char *path,
void *context)
{
printf("CALLLLLEDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n");
fprintf(stderr, "Watcher %d state = %s ", type, state2String(state));
if (path && strlen(path) > 0) {
fprintf(stderr, " for path %s", path);
}
fprintf(stderr, "\n");
if (type == ZOO_SESSION_EVENT) {
if (state == ZOO_CONNECTED_STATE) {
const clientid_t *id = zoo_client_id(zzh);
if (myid.client_id == 0
|| myid.client_id != id->client_id) {
myid = *id;
if (clientIdFile) {
FILE *fh = fopen(clientIdFile, "w");
if (!fh) {
perror(clientIdFile);
} else {
int rc =
fwrite(&myid, sizeof(myid),
1, fh);
if (rc != sizeof(myid)) {
perror
("writing client id");
}
fclose(fh);
}
}
}
} else if (state == ZOO_AUTH_FAILED_STATE) {
fprintf(stderr,
"Authentication failure. Shutting down...\n");
zookeeper_close(zzh);
zh = 0;
} else if (state == ZOO_EXPIRED_SESSION_STATE) {
fprintf(stderr, "Session expired. Shutting down...\n");
zookeeper_close(zzh);
zh = 0;
}
}
}
void checkForNode()
{
int rc;
static struct Stat st;
static int called = 0;
if (called )
return ;
called = 1;
char *data = calloc(1, 256);
memcpy(data, "This is test data", strlen("This is test data") + 1);
rc = zoo_wexists(zh, "/abcd", watcher, data, &st);
if (rc == ZNONODE) {
printf("The node doesn't exist \n");
} else if (rc == ZOK) {
printf("The node exists\n");
}
}
int main(int argc, char *argv[])
{
int rc = 0;
int fd = 0;
int interest = 0;
int events = 0;
struct timeval tv;
fd_set rfds, wfds, efds;
if (argc < 2)
exit(1);
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&efds);
zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG);
zoo_deterministic_conn_order(1); // enable deterministic order
zh = zookeeper_init(argv[1], watcher, 30000, 0, 0, 0);
if (!zh) {
return errno;
}
while (1) {
if (connected) {
checkForNode(zh);
connected = 0;
}
zookeeper_interest(zh, &fd, &interest, &tv);
if (fd != -1) {
if (interest & ZOOKEEPER_READ) {
FD_SET(fd, &rfds);
} else {
FD_CLR(fd, &rfds);
}
if (interest & ZOOKEEPER_WRITE) {
FD_SET(fd, &wfds);
} else {
FD_CLR(fd, &wfds);
}
} else {
fd = 0;
}
rc = select(fd + 1, &rfds, &wfds, &efds, &tv);
events = 0;
if (FD_ISSET(fd, &rfds)) {
events |= ZOOKEEPER_READ;
}
if (FD_ISSET(fd, &wfds)) {
events |= ZOOKEEPER_WRITE;
}
zookeeper_process(zh, events);
}
return 0;
}
--
Regards,
Nipun Talukdar
Bangalore