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
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,
116 ZSESSIONMOVED = -118
118
119#ifdef __cplusplus
120extern "C" {
121#endif
122
126typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel;
127
131extern ZOOAPI const int ZOO_PERM_READ;
132extern ZOOAPI const int ZOO_PERM_WRITE;
133extern ZOOAPI const int ZOO_PERM_CREATE;
134extern ZOOAPI const int ZOO_PERM_DELETE;
135extern ZOOAPI const int ZOO_PERM_ADMIN;
136extern ZOOAPI const int ZOO_PERM_ALL;
137
139extern ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE;
143extern ZOOAPI struct Id ZOO_AUTH_IDS;
144
146extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE;
148extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE;
150extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL;
151
160// @{
161extern ZOOAPI const int ZOOKEEPER_WRITE;
162extern ZOOAPI const int ZOOKEEPER_READ;
163// @}
164
171// @{
172extern ZOOAPI const int ZOO_EPHEMERAL;
173extern ZOOAPI const int ZOO_SEQUENCE;
174// @}
175
181// @{
182extern ZOOAPI const int ZOO_EXPIRED_SESSION_STATE;
183extern ZOOAPI const int ZOO_AUTH_FAILED_STATE;
184extern ZOOAPI const int ZOO_CONNECTING_STATE;
185extern ZOOAPI const int ZOO_ASSOCIATING_STATE;
186extern ZOOAPI const int ZOO_CONNECTED_STATE;
187// @}
188
194// @{
201extern ZOOAPI const int ZOO_CREATED_EVENT;
208extern ZOOAPI const int ZOO_DELETED_EVENT;
215extern ZOOAPI const int ZOO_CHANGED_EVENT;
222extern ZOOAPI const int ZOO_CHILD_EVENT;
228extern ZOOAPI const int ZOO_SESSION_EVENT;
229
236extern ZOOAPI const int ZOO_NOTWATCHING_EVENT;
237// @}
238
246typedef struct _zhandle zhandle_t;
247
255typedef struct {
256 int64_t client_id;
257 char passwd[16];
258} clientid_t;
259
269typedef 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 };
305
330void 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
346void zoo_delete_op_init(zoo_op_t *op, const char *path, int version);
347
363void zoo_set_op_init(zoo_op_t *op, const char *path, const char *buffer,
364 int buflen, int version, struct Stat *stat);
365
377void zoo_check_op_init(zoo_op_t *op, const char *path, int version);
378
385typedef struct zoo_op_result {
386 int err;
387 char *value;
388 int valuelen;
389 struct Stat *stat;
391
418typedef void (*watcher_fn)(zhandle_t *zh, int type,
419 int state, const char *path,void *watcherCtx);
420
449ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn,
450 int recv_timeout, const clientid_t *clientid, void *context, int flags);
451
475
481
488
492ZOOAPI const void *zoo_get_context(zhandle_t *zh);
493
497ZOOAPI void zoo_set_context(zhandle_t *zh, void *context);
498
504
510ZOOAPI struct sockaddr* zookeeper_get_connected_host(zhandle_t *zh,
511 struct sockaddr *addr, socklen_t *addr_len);
512
513#ifndef THREADED
533#ifdef WIN32
534ZOOAPI int zookeeper_interest(zhandle_t *zh, SOCKET *fd, int *interest,
535 struct timeval *tv);
536#else
537ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest,
538 struct timeval *tv);
539#endif
540
558ZOOAPI int zookeeper_process(zhandle_t *zh, int events);
559#endif
560
578typedef void (*void_completion_t)(int rc, const void *data);
579
600typedef void (*stat_completion_t)(int rc, const struct Stat *stat,
601 const void *data);
602
627typedef void (*data_completion_t)(int rc, const char *value, int value_len,
628 const struct Stat *stat, const void *data);
629
651typedef void (*strings_completion_t)(int rc,
652 const struct String_vector *strings, const void *data);
653
679typedef void (*strings_stat_completion_t)(int rc,
680 const struct String_vector *strings, const struct Stat *stat,
681 const void *data);
682
701typedef void
702 (*string_completion_t)(int rc, const char *value, const void *data);
703
727typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl,
728 struct Stat *stat, const void *data);
729
735ZOOAPI int zoo_state(zhandle_t *zh);
736
769ZOOAPI 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
796ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version,
797 void_completion_t completion, const void *data);
798
820ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch,
821 stat_completion_t completion, const void *data);
822
852ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path,
853 watcher_fn watcher, void* watcherCtx,
854 stat_completion_t completion, const void *data);
855
876ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch,
877 data_completion_t completion, const void *data);
878
905ZOOAPI int zoo_awget(zhandle_t *zh, const char *path,
906 watcher_fn watcher, void* watcherCtx,
907 data_completion_t completion, const void *data);
908
935ZOOAPI 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
958ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch,
959 strings_completion_t completion, const void *data);
960
987ZOOAPI 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
1013ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch,
1014 strings_stat_completion_t completion, const void *data);
1015
1044ZOOAPI 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
1067ZOOAPI int zoo_async(zhandle_t *zh, const char *path,
1068 string_completion_t completion, const void *data);
1069
1070
1089ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion,
1090 const void *data);
1091
1114ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version,
1115 struct ACL_vector *acl, void_completion_t, const void *data);
1116
1133ZOOAPI 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
1142ZOOAPI const char* zerror(int c);
1143
1171ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
1172 int certLen, void_completion_t completion, const void *data);
1173
1183
1187ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel);
1188
1196ZOOAPI void zoo_set_log_stream(FILE* logStream);
1197
1209ZOOAPI void zoo_deterministic_conn_order(int yesOrNo);
1210
1248ZOOAPI 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
1271ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version);
1272
1273
1292ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
1293
1318ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path,
1319 watcher_fn watcher, void* watcherCtx, struct Stat *stat);
1320
1341ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer,
1342 int* buffer_len, struct Stat *stat);
1343
1370ZOOAPI 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
1396ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer,
1397 int buflen, int version);
1398
1423ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer,
1424 int buflen, int version, struct Stat *stat);
1425
1443ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch,
1444 struct String_vector *strings);
1445
1469ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path,
1470 watcher_fn watcher, void* watcherCtx,
1471 struct String_vector *strings);
1472
1493ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch,
1494 struct String_vector *strings, struct Stat *stat);
1495
1522ZOOAPI 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
1542ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl,
1543 struct Stat *stat);
1544
1563ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version,
1564 const struct ACL_vector *acl);
1565
1577ZOOAPI 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_*/
client id structure.
Definition: zookeeper.h:255
zoo_op_result structure.
Definition: zookeeper.h:385
zoo_op structure.
Definition: zookeeper.h:269
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_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.
void zoo_check_op_init(zoo_op_t *op, const char *path, int version)
zoo_check_op_init.
ZOOAPI int zookeeper_process(zhandle_t *zh, int events)
Notifies zookeeper that an event of interest has happened.
ZOOAPI struct Id ZOO_AUTH_IDS
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_recv_timeout(zhandle_t *zh)
return the timeout for this session, only valid if the connections is currently connected (ie....
ZOOAPI int is_unrecoverable(zhandle_t *zh)
checks if the current zookeeper connection state can't be recovered.
ZOOAPI const clientid_t * zoo_client_id(zhandle_t *zh)
return the client session id, only valid if the connections is currently connected (ie....
ZOOAPI const int ZOO_NOTWATCHING_EVENT
a watch has been removed.
ZOOAPI const char * zerror(int c)
return an error string.
ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE
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.
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.
ZOOAPI void zoo_set_context(zhandle_t *zh, void *context)
set the context for this handle.
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 int zoo_get_children(zhandle_t *zh, const char *path, int watch, struct String_vector *strings)
lists the children of a node synchronously.
struct zoo_op zoo_op_t
zoo_op structure.
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_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, struct Stat *stat)
gets the acl associated with a node synchronously.
ZOOAPI const int ZOO_CHANGED_EVENT
a node has changed.
ZOOAPI const int ZOO_SESSION_EVENT
a session has been lost.
ZOOAPI const int ZOO_CHILD_EVENT
a change as occurred in the list of children.
ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version, void_completion_t completion, const void *data)
delete a node in zookeeper.
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_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(* 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
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 zookeeper_interest(zhandle_t *zh, int *fd, int *interest, struct timeval *tv)
Returns the events that zookeeper is interested in.
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.
ZOOAPI const int ZOO_CREATED_EVENT
a node has been created.
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.
ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE
ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version)
delete a node in zookeeper synchronously.
ZOOAPI void zoo_deterministic_conn_order(int yesOrNo)
enable/disable quorum endpoint order randomization
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.
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_async(zhandle_t *zh, const char *path, string_completion_t completion, const void *data)
Flush leader channel.
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_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.
ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL
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 void zoo_set_log_stream(FILE *logStream)
sets the stream to be used by the library for logging
ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh, watcher_fn newFn)
set a watcher function
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.
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
ZOOAPI int zoo_state(zhandle_t *zh)
get the state of the zookeeper connection.
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 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 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_aexists(zhandle_t *zh, const char *path, int watch, stat_completion_t completion, const void *data)
checks the existence of a node in zookeeper.
void zoo_delete_op_init(zoo_op_t *op, const char *path, int version)
zoo_delete_op_init.
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.
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 const void * zoo_get_context(zhandle_t *zh)
return the context for this handle.
void(* watcher_fn)(zhandle_t *zh, int type, int state, const char *path, void *watcherCtx)
signature of a watch function.
Definition: zookeeper.h:418
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_ERRORS
Definition: zookeeper.h:80
@ ZOPERATIONTIMEOUT
Definition: zookeeper.h:93
@ ZNOTHING
Definition: zookeeper.h:115
@ ZINVALIDACL
Definition: zookeeper.h:112
@ ZNODEEXISTS
Definition: zookeeper.h:108
@ ZDATAINCONSISTENCY
Definition: zookeeper.h:89
@ ZNONODE
Definition: zookeeper.h:104
@ ZBADVERSION
Definition: zookeeper.h:106
@ ZNOAUTH
Definition: zookeeper.h:105
@ ZUNIMPLEMENTED
Definition: zookeeper.h:92
@ ZINVALIDSTATE
Definition: zookeeper.h:95
@ ZNOTEMPTY
Definition: zookeeper.h:109
@ ZMARSHALLINGERROR
Definition: zookeeper.h:91
@ ZAUTHFAILED
Definition: zookeeper.h:113
@ ZSYSTEMERROR
Definition: zookeeper.h:87
@ ZSESSIONMOVED
Definition: zookeeper.h:116
@ ZOK
Definition: zookeeper.h:81
@ ZSESSIONEXPIRED
Definition: zookeeper.h:110
@ ZRUNTIMEINCONSISTENCY
Definition: zookeeper.h:88
@ ZNOCHILDRENFOREPHEMERALS
Definition: zookeeper.h:107
@ ZAPIERROR
Definition: zookeeper.h:103
@ ZINVALIDCALLBACK
Definition: zookeeper.h:111
@ ZCLOSING
Definition: zookeeper.h:114
@ ZBADARGUMENTS
Definition: zookeeper.h:94
@ ZCONNECTIONLOSS
Definition: zookeeper.h:90
struct _zhandle zhandle_t
ZooKeeper handle.
Definition: zookeeper.h:246
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
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 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.
ZOOAPI int zookeeper_close(zhandle_t *zh)
close the zookeeper handle and free up any resources.
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.
ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel)
sets the debugging level for the library
struct zoo_op_result zoo_op_result_t
zoo_op_result structure.
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(* void_completion_t)(int rc, const void *data)
signature of a completion function for a call that returns void.
Definition: zookeeper.h:578
ZOOAPI const int ZOO_DELETED_EVENT
a node has been deleted.
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 struct ACL_vector ZOO_OPEN_ACL_UNSAFE
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...
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_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results)
atomically commits multiple zookeeper operations synchronously.