zookeeper-3.4.6
zookeeper.h
Go to the documentation of this file.
1 
19 #ifndef ZOOKEEPER_H_
20 #define ZOOKEEPER_H_
21 
22 #include <stdlib.h>
23 #ifndef WIN32
24 #include <sys/socket.h>
25 #include <sys/time.h>
26 #else
27 #include "winconfig.h"
28 #endif
29 #include <stdio.h>
30 #include <ctype.h>
31 
32 #include "proto.h"
33 #include "zookeeper_version.h"
34 #include "recordio.h"
35 #include "zookeeper.jute.h"
36 
65 /* Support for building on various platforms */
66 
67 // on cygwin we should take care of exporting/importing symbols properly
68 #ifdef DLL_EXPORT
69 # define ZOOAPI __declspec(dllexport)
70 #else
71 # if (defined(__CYGWIN__) || defined(WIN32)) && !defined(USE_STATIC_LIB)
72 # define ZOOAPI __declspec(dllimport)
73 # else
74 # define ZOOAPI
75 # endif
76 #endif
77 
80 enum ZOO_ERRORS {
81  ZOK = 0,
103  ZAPIERROR = -100,
104  ZNONODE = -101,
105  ZNOAUTH = -102,
106  ZBADVERSION = -103,
108  ZNODEEXISTS = -110,
109  ZNOTEMPTY = -111,
112  ZINVALIDACL = -114,
113  ZAUTHFAILED = -115,
114  ZCLOSING = -116,
115  ZNOTHING = -117,
117 };
118 
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122 
126 typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel;
127 
131 extern ZOOAPI const int ZOO_PERM_READ;
132 extern ZOOAPI const int ZOO_PERM_WRITE;
133 extern ZOOAPI const int ZOO_PERM_CREATE;
134 extern ZOOAPI const int ZOO_PERM_DELETE;
135 extern ZOOAPI const int ZOO_PERM_ADMIN;
136 extern ZOOAPI const int ZOO_PERM_ALL;
137 
139 extern ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE;
143 extern ZOOAPI struct Id ZOO_AUTH_IDS;
144 
146 extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE;
148 extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE;
150 extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL;
151 
160 // @{
161 extern ZOOAPI const int ZOOKEEPER_WRITE;
162 extern ZOOAPI const int ZOOKEEPER_READ;
163 // @}
164 
171 // @{
172 extern ZOOAPI const int ZOO_EPHEMERAL;
173 extern ZOOAPI const int ZOO_SEQUENCE;
174 // @}
175 
181 // @{
182 extern ZOOAPI const int ZOO_EXPIRED_SESSION_STATE;
183 extern ZOOAPI const int ZOO_AUTH_FAILED_STATE;
184 extern ZOOAPI const int ZOO_CONNECTING_STATE;
185 extern ZOOAPI const int ZOO_ASSOCIATING_STATE;
186 extern ZOOAPI const int ZOO_CONNECTED_STATE;
187 // @}
188 
194 // @{
201 extern ZOOAPI const int ZOO_CREATED_EVENT;
208 extern ZOOAPI const int ZOO_DELETED_EVENT;
215 extern ZOOAPI const int ZOO_CHANGED_EVENT;
222 extern ZOOAPI const int ZOO_CHILD_EVENT;
228 extern ZOOAPI const int ZOO_SESSION_EVENT;
229 
236 extern ZOOAPI const int ZOO_NOTWATCHING_EVENT;
237 // @}
238 
246 typedef struct _zhandle zhandle_t;
247 
255 typedef struct {
256  int64_t client_id;
257  char passwd[16];
258 } clientid_t;
259 
269 typedef struct zoo_op {
270  int type;
271  union {
272  // CREATE
273  struct {
274  const char *path;
275  const char *data;
276  int datalen;
277  char *buf;
278  int buflen;
279  const struct ACL_vector *acl;
280  int flags;
281  } create_op;
282 
283  // DELETE
284  struct {
285  const char *path;
286  int version;
287  } delete_op;
288 
289  // SET
290  struct {
291  const char *path;
292  const char *data;
293  int datalen;
294  int version;
295  struct Stat *stat;
296  } set_op;
297 
298  // CHECK
299  struct {
300  const char *path;
301  int version;
302  } check_op;
303  };
304 } zoo_op_t;
305 
330 void zoo_create_op_init(zoo_op_t *op, const char *path, const char *value,
331  int valuelen, const struct ACL_vector *acl, int flags,
332  char *path_buffer, int path_buffer_len);
333 
346 void zoo_delete_op_init(zoo_op_t *op, const char *path, int version);
347 
363 void zoo_set_op_init(zoo_op_t *op, const char *path, const char *buffer,
364  int buflen, int version, struct Stat *stat);
365 
377 void zoo_check_op_init(zoo_op_t *op, const char *path, int version);
378 
385 typedef struct zoo_op_result {
386  int err;
387  char *value;
388  int valuelen;
389  struct Stat *stat;
390 } zoo_op_result_t;
391 
418 typedef void (*watcher_fn)(zhandle_t *zh, int type,
419  int state, const char *path,void *watcherCtx);
420 
449 ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn,
450  int recv_timeout, const clientid_t *clientid, void *context, int flags);
451 
474 ZOOAPI int zookeeper_close(zhandle_t *zh);
475 
480 ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh);
481 
487 ZOOAPI int zoo_recv_timeout(zhandle_t *zh);
488 
492 ZOOAPI const void *zoo_get_context(zhandle_t *zh);
493 
497 ZOOAPI void zoo_set_context(zhandle_t *zh, void *context);
498 
504 
510 ZOOAPI struct sockaddr* zookeeper_get_connected_host(zhandle_t *zh,
511  struct sockaddr *addr, socklen_t *addr_len);
512 
513 #ifndef THREADED
514 
533 #ifdef WIN32
534 ZOOAPI int zookeeper_interest(zhandle_t *zh, SOCKET *fd, int *interest,
535  struct timeval *tv);
536 #else
537 ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest,
538  struct timeval *tv);
539 #endif
540 
558 ZOOAPI int zookeeper_process(zhandle_t *zh, int events);
559 #endif
560 
578 typedef void (*void_completion_t)(int rc, const void *data);
579 
600 typedef void (*stat_completion_t)(int rc, const struct Stat *stat,
601  const void *data);
602 
627 typedef void (*data_completion_t)(int rc, const char *value, int value_len,
628  const struct Stat *stat, const void *data);
629 
651 typedef void (*strings_completion_t)(int rc,
652  const struct String_vector *strings, const void *data);
653 
679 typedef void (*strings_stat_completion_t)(int rc,
680  const struct String_vector *strings, const struct Stat *stat,
681  const void *data);
682 
701 typedef void
702  (*string_completion_t)(int rc, const char *value, const void *data);
703 
727 typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl,
728  struct Stat *stat, const void *data);
729 
735 ZOOAPI int zoo_state(zhandle_t *zh);
736 
769 ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value,
770  int valuelen, const struct ACL_vector *acl, int flags,
771  string_completion_t completion, const void *data);
772 
796 ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version,
797  void_completion_t completion, const void *data);
798 
820 ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch,
821  stat_completion_t completion, const void *data);
822 
852 ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path,
853  watcher_fn watcher, void* watcherCtx,
854  stat_completion_t completion, const void *data);
855 
876 ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch,
877  data_completion_t completion, const void *data);
878 
905 ZOOAPI int zoo_awget(zhandle_t *zh, const char *path,
906  watcher_fn watcher, void* watcherCtx,
907  data_completion_t completion, const void *data);
908 
935 ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen,
936  int version, stat_completion_t completion, const void *data);
937 
958 ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch,
959  strings_completion_t completion, const void *data);
960 
987 ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path,
988  watcher_fn watcher, void* watcherCtx,
989  strings_completion_t completion, const void *data);
990 
1013 ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch,
1014  strings_stat_completion_t completion, const void *data);
1015 
1044 ZOOAPI int zoo_awget_children2(zhandle_t *zh, const char *path,
1045  watcher_fn watcher, void* watcherCtx,
1046  strings_stat_completion_t completion, const void *data);
1047 
1067 ZOOAPI int zoo_async(zhandle_t *zh, const char *path,
1068  string_completion_t completion, const void *data);
1069 
1070 
1089 ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion,
1090  const void *data);
1091 
1114 ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version,
1115  struct ACL_vector *acl, void_completion_t, const void *data);
1116 
1133 ZOOAPI int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops,
1134  zoo_op_result_t *results, void_completion_t, const void *data);
1135 
1142 ZOOAPI const char* zerror(int c);
1143 
1171 ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
1172  int certLen, void_completion_t completion, const void *data);
1173 
1182 ZOOAPI int is_unrecoverable(zhandle_t *zh);
1183 
1187 ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel);
1188 
1196 ZOOAPI void zoo_set_log_stream(FILE* logStream);
1197 
1209 ZOOAPI void zoo_deterministic_conn_order(int yesOrNo);
1210 
1248 ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value,
1249  int valuelen, const struct ACL_vector *acl, int flags,
1250  char *path_buffer, int path_buffer_len);
1251 
1271 ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version);
1272 
1273 
1292 ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
1293 
1318 ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path,
1319  watcher_fn watcher, void* watcherCtx, struct Stat *stat);
1320 
1341 ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer,
1342  int* buffer_len, struct Stat *stat);
1343 
1370 ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
1371  watcher_fn watcher, void* watcherCtx,
1372  char *buffer, int* buffer_len, struct Stat *stat);
1373 
1396 ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer,
1397  int buflen, int version);
1398 
1423 ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer,
1424  int buflen, int version, struct Stat *stat);
1425 
1443 ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch,
1444  struct String_vector *strings);
1445 
1469 ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path,
1470  watcher_fn watcher, void* watcherCtx,
1471  struct String_vector *strings);
1472 
1493 ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch,
1494  struct String_vector *strings, struct Stat *stat);
1495 
1522 ZOOAPI int zoo_wget_children2(zhandle_t *zh, const char *path,
1523  watcher_fn watcher, void* watcherCtx,
1524  struct String_vector *strings, struct Stat *stat);
1525 
1542 ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl,
1543  struct Stat *stat);
1544 
1563 ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version,
1564  const struct ACL_vector *acl);
1565 
1577 ZOOAPI int zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results);
1578 
1579 #ifdef __cplusplus
1580 }
1581 #endif
1582 
1583 #endif /*ZOOKEEPER_H_*/
ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion, const void *data)
gets the acl associated with a node.
ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, strings_completion_t completion, const void *data)
lists the children of a node.
Definition: zookeeper.h:107
ZOOAPI void zoo_set_log_stream(FILE *logStream)
sets the stream to be used by the library for logging
Definition: zookeeper.h:88
Definition: zookeeper.h:115
ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version)
sets the data associated with a node. See zoo_set2 function if you require access to the stat informa...
Definition: zookeeper.h:90
ZOOAPI int zoo_awget_children2(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, strings_stat_completion_t completion, const void *data)
lists the children of a node, and get the parent stat.
ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch, strings_stat_completion_t completion, const void *data)
lists the children of a node, and get the parent stat.
Definition: zookeeper.h:89
void(* strings_completion_t)(int rc, const struct String_vector *strings, const void *data)
signature of a completion function that returns a list of strings.
Definition: zookeeper.h:651
Definition: zookeeper.h:94
ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version, struct ACL_vector *acl, void_completion_t, const void *data)
sets the acl associated with a node.
void(* stat_completion_t)(int rc, const struct Stat *stat, const void *data)
signature of a completion function that returns a Stat structure.
Definition: zookeeper.h:600
zoo_op_result structure.
Definition: zookeeper.h:385
ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch, struct String_vector *strings, struct Stat *stat)
lists the children of a node and get its stat synchronously.
ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch, data_completion_t completion, const void *data)
gets the data associated with a node.
ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, struct Stat *stat)
gets the acl associated with a node synchronously.
ZOOAPI zhandle_t * zookeeper_init(const char *host, watcher_fn fn, int recv_timeout, const clientid_t *clientid, void *context, int flags)
create a handle to used communicate with zookeeper.
ZOOAPI void zoo_set_context(zhandle_t *zh, void *context)
set the context for this handle.
ZOOAPI int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results, void_completion_t, const void *data)
atomically commits multiple zookeeper operations.
Definition: zookeeper.h:110
struct _zhandle zhandle_t
ZooKeeper handle.
Definition: zookeeper.h:246
ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat)
checks the existence of a node in zookeeper synchronously.
ZOOAPI int zoo_async(zhandle_t *zh, const char *path, string_completion_t completion, const void *data)
Flush leader channel.
Definition: zookeeper.h:111
ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel)
sets the debugging level for the library
ZOOAPI const int ZOO_NOTWATCHING_EVENT
a watch has been removed.
Definition: zookeeper.h:104
Definition: zookeeper.h:91
struct zoo_op zoo_op_t
zoo_op structure.
Definition: zookeeper.h:114
void(* strings_stat_completion_t)(int rc, const struct String_vector *strings, const struct Stat *stat, const void *data)
signature of a completion function that returns a list of strings and stat.
Definition: zookeeper.h:679
ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version)
delete a node in zookeeper synchronously.
ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version, void_completion_t completion, const void *data)
delete a node in zookeeper.
Definition: zookeeper.h:93
ZOOAPI int zoo_state(zhandle_t *zh)
get the state of the zookeeper connection.
ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh, watcher_fn newFn)
set a watcher function
ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, char *path_buffer, int path_buffer_len)
create a node synchronously.
ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch, stat_completion_t completion, const void *data)
checks the existence of a node in zookeeper.
client id structure.
Definition: zookeeper.h:255
ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, struct Stat *stat)
checks the existence of a node in zookeeper synchronously.
ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch, strings_completion_t completion, const void *data)
lists the children of a node.
Definition: zookeeper.h:106
struct zoo_op_result zoo_op_result_t
zoo_op_result structure.
Definition: zookeeper.h:109
ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version, const struct ACL_vector *acl)
sets the acl associated with a node synchronously.
Definition: zookeeper.h:112
ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, int *buffer_len, struct Stat *stat)
gets the data associated with a node synchronously.
ZOOAPI const int ZOO_CHANGED_EVENT
a node has changed.
ZOOAPI int zoo_wget_children2(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, struct String_vector *strings, struct Stat *stat)
lists the children of a node and get its stat synchronously.
ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version, struct Stat *stat)
sets the data associated with a node. This function is the same as zoo_set except that it also provid...
ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, string_completion_t completion, const void *data)
create a node.
Definition: zookeeper.h:95
void(* watcher_fn)(zhandle_t *zh, int type, int state, const char *path, void *watcherCtx)
signature of a watch function.
Definition: zookeeper.h:418
Definition: zookeeper.h:87
void(* string_completion_t)(int rc, const char *value, const void *data)
signature of a completion function that returns a list of strings.
Definition: zookeeper.h:702
void(* acl_completion_t)(int rc, struct ACL_vector *acl, struct Stat *stat, const void *data)
signature of a completion function that returns an ACL.
Definition: zookeeper.h:727
ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, stat_completion_t completion, const void *data)
checks the existence of a node in zookeeper.
Definition: zookeeper.h:116
void zoo_create_op_init(zoo_op_t *op, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, char *path_buffer, int path_buffer_len)
zoo_create_op_init.
ZOOAPI const int ZOO_CHILD_EVENT
a change as occurred in the list of children.
zoo_op structure.
Definition: zookeeper.h:269
ZOOAPI int zookeeper_close(zhandle_t *zh)
close the zookeeper handle and free up any resources.
ZOOAPI int zoo_wget(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, char *buffer, int *buffer_len, struct Stat *stat)
gets the data associated with a node synchronously.
ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest, struct timeval *tv)
Returns the events that zookeeper is interested in.
ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch, struct String_vector *strings)
lists the children of a node synchronously.
ZOOAPI const clientid_t * zoo_client_id(zhandle_t *zh)
return the client session id, only valid if the connections is currently connected (ie...
ZOO_ERRORS
Definition: zookeeper.h:80
Definition: zookeeper.h:92
Definition: zookeeper.h:105
ZOOAPI struct sockaddr * zookeeper_get_connected_host(zhandle_t *zh, struct sockaddr *addr, socklen_t *addr_len)
returns the socket address for the current connection
ZOOAPI const int ZOO_DELETED_EVENT
a node has been deleted.
ZOOAPI const int ZOO_CREATED_EVENT
a node has been created.
Definition: zookeeper.h:81
ZOOAPI int zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results)
atomically commits multiple zookeeper operations synchronously.
void zoo_check_op_init(zoo_op_t *op, const char *path, int version)
zoo_check_op_init.
ZOOAPI const char * zerror(int c)
return an error string.
ZOOAPI int zookeeper_process(zhandle_t *zh, int events)
Notifies zookeeper that an event of interest has happened.
ZOOAPI int zoo_awget(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, data_completion_t completion, const void *data)
gets the data associated with a node.
ZOOAPI const void * zoo_get_context(zhandle_t *zh)
return the context for this handle.
Definition: zookeeper.h:103
Definition: zookeeper.h:108
ZOOAPI int zoo_recv_timeout(zhandle_t *zh)
return the timeout for this session, only valid if the connections is currently connected (ie...
void(* void_completion_t)(int rc, const void *data)
signature of a completion function for a call that returns void.
Definition: zookeeper.h:578
ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version, stat_completion_t completion, const void *data)
sets the data associated with a node.
ZOOAPI int is_unrecoverable(zhandle_t *zh)
checks if the current zookeeper connection state can&#39;t be recovered.
ZOOAPI int zoo_add_auth(zhandle_t *zh, const char *scheme, const char *cert, int certLen, void_completion_t completion, const void *data)
specify application credentials.
void(* data_completion_t)(int rc, const char *value, int value_len, const struct Stat *stat, const void *data)
signature of a completion function that returns data.
Definition: zookeeper.h:627
void zoo_set_op_init(zoo_op_t *op, const char *path, const char *buffer, int buflen, int version, struct Stat *stat)
zoo_set_op_init.
ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path, watcher_fn watcher, void *watcherCtx, struct String_vector *strings)
lists the children of a node synchronously.
Definition: zookeeper.h:113
void zoo_delete_op_init(zoo_op_t *op, const char *path, int version)
zoo_delete_op_init.
ZOOAPI const int ZOO_SESSION_EVENT
a session has been lost.
ZOOAPI void zoo_deterministic_conn_order(int yesOrNo)
enable/disable quorum endpoint order randomization