zookeeper.h 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef ZOOKEEPER_H_
  19. #define ZOOKEEPER_H_
  20. #include <stdlib.h>
  21. #include <sys/time.h>
  22. #include <stdio.h>
  23. #include "zookeeper_version.h"
  24. #include "recordio.h"
  25. #include "zookeeper.jute.h"
  26. /**
  27. * \file zookeeper.h
  28. * \brief ZooKeeper functions and definitions.
  29. *
  30. * ZooKeeper is a network service that may be backed by a cluster of
  31. * synchronized servers. The data in the service is represented as a tree
  32. * of data nodes. Each node has data, children, an ACL, and status information.
  33. * The data for a node is read and write in its entirety.
  34. *
  35. * ZooKeeper clients can leave watches when they queries the data or children
  36. * of a node. If a watch is left, that client will be notified of the change.
  37. * The notification is a one time trigger. Subsequent chances to the node will
  38. * not trigger a notification unless the client issues a querity with the watch
  39. * flag set. If the client is ever disconnected from the service, even if the
  40. * disconnection is temporary, the watches of the client will be removed from
  41. * the service, so a client must treat a disconnect notification as an implicit
  42. * trigger of all outstanding watches.
  43. *
  44. * When a node is created, it may be flagged as an ephemeral node. Ephemeral
  45. * nodes are automatically removed when a client session is closed or when
  46. * a session times out due to inactivity (the ZooKeeper runtime fills in
  47. * periods of inactivity with pings). Ephemeral nodes cannot have children.
  48. *
  49. * ZooKeeper clients are identified by a server assigned session id. For
  50. * security reasons The server
  51. * also generates a corresponding password for a session. A client may save its
  52. * id and corresponding password to persistent storage in order to use the
  53. * session across program invocation boundaries.
  54. */
  55. /* Support for building on various platforms */
  56. // on cygwin we should take care of exporting/importing symbols properly
  57. #ifdef DLL_EXPORT
  58. # define ZOOAPI __declspec(dllexport)
  59. #else
  60. # if defined(__CYGWIN__) && !defined(USE_STATIC_LIB)
  61. # define ZOOAPI __declspec(dllimport)
  62. # else
  63. # define ZOOAPI
  64. # endif
  65. #endif
  66. /** zookeeper return constants **/
  67. enum ZOO_ERRORS {
  68. ZOK = 0, /*!< Everything is OK */
  69. /** System and server-side errors.
  70. * This is never thrown by the server, it shouldn't be used other than
  71. * to indicate a range. Specifically error codes greater than this
  72. * value, but lesser than {@link #ZAPIERROR}, are system errors. */
  73. ZSYSTEMERROR = -1,
  74. ZRUNTIMEINCONSISTENCY = -2, /*!< A runtime inconsistency was found */
  75. ZDATAINCONSISTENCY = -3, /*!< A data inconsistency was found */
  76. ZCONNECTIONLOSS = -4, /*!< Connection to the server has been lost */
  77. ZMARSHALLINGERROR = -5, /*!< Error while marshalling or unmarshalling data */
  78. ZUNIMPLEMENTED = -6, /*!< Operation is unimplemented */
  79. ZOPERATIONTIMEOUT = -7, /*!< Operation timeout */
  80. ZBADARGUMENTS = -8, /*!< Invalid arguments */
  81. ZINVALIDSTATE = -9, /*!< Invliad zhandle state */
  82. /** API errors.
  83. * This is never thrown by the server, it shouldn't be used other than
  84. * to indicate a range. Specifically error codes greater than this
  85. * value are API errors (while values less than this indicate a
  86. * {@link #ZSYSTEMERROR}).
  87. */
  88. ZAPIERROR = -100,
  89. ZNONODE = -101, /*!< Node does not exist */
  90. ZNOAUTH = -102, /*!< Not authenticated */
  91. ZBADVERSION = -103, /*!< Version conflict */
  92. ZNOCHILDRENFOREPHEMERALS = -108, /*!< Ephemeral nodes may not have children */
  93. ZNODEEXISTS = -110, /*!< The node already exists */
  94. ZNOTEMPTY = -111, /*!< The node has children */
  95. ZSESSIONEXPIRED = -112, /*!< The session has been expired by the server */
  96. ZINVALIDCALLBACK = -113, /*!< Invalid callback specified */
  97. ZINVALIDACL = -114, /*!< Invalid ACL specified */
  98. ZAUTHFAILED = -115, /*!< Client authentication failed */
  99. ZCLOSING = -116, /*!< ZooKeeper is closing */
  100. ZNOTHING = -117, /*!< (not error) no server responses to process */
  101. ZSESSIONMOVED = -118 /*!<session moved to another server, so operation is ignored */
  102. };
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. /**
  107. * @name Debug levels
  108. */
  109. typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel;
  110. /**
  111. * @name ACL Consts
  112. */
  113. extern ZOOAPI const int ZOO_PERM_READ;
  114. extern ZOOAPI const int ZOO_PERM_WRITE;
  115. extern ZOOAPI const int ZOO_PERM_CREATE;
  116. extern ZOOAPI const int ZOO_PERM_DELETE;
  117. extern ZOOAPI const int ZOO_PERM_ADMIN;
  118. extern ZOOAPI const int ZOO_PERM_ALL;
  119. /** This Id represents anyone. */
  120. extern ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE;
  121. /** This Id is only usable to set ACLs. It will get substituted with the
  122. * Id's the client authenticated with.
  123. */
  124. extern ZOOAPI struct Id ZOO_AUTH_IDS;
  125. /** This is a completely open ACL*/
  126. extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE;
  127. /** This ACL gives the world the ability to read. */
  128. extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE;
  129. /** This ACL gives the creators authentication id's all permissions. */
  130. extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL;
  131. /**
  132. * @name Interest Consts
  133. * These constants are used to express interest in an event and to
  134. * indicate to zookeeper which events have occurred. They can
  135. * be ORed together to express multiple interests. These flags are
  136. * used in the interest and event parameters of
  137. * \ref zookeeper_interest and \ref zookeeper_process.
  138. */
  139. // @{
  140. extern ZOOAPI const int ZOOKEEPER_WRITE;
  141. extern ZOOAPI const int ZOOKEEPER_READ;
  142. // @}
  143. /**
  144. * @name Create Flags
  145. *
  146. * These flags are used by zoo_create to affect node create. They may
  147. * be ORed together to combine effects.
  148. */
  149. // @{
  150. extern ZOOAPI const int ZOO_EPHEMERAL;
  151. extern ZOOAPI const int ZOO_SEQUENCE;
  152. // @}
  153. /**
  154. * @name State Consts
  155. * These constants represent the states of a zookeeper connection. They are
  156. * possible parameters of the watcher callback.
  157. */
  158. // @{
  159. extern ZOOAPI const int ZOO_EXPIRED_SESSION_STATE;
  160. extern ZOOAPI const int ZOO_AUTH_FAILED_STATE;
  161. extern ZOOAPI const int ZOO_CONNECTING_STATE;
  162. extern ZOOAPI const int ZOO_ASSOCIATING_STATE;
  163. extern ZOOAPI const int ZOO_CONNECTED_STATE;
  164. // @}
  165. /**
  166. * @name Watch Types
  167. * These constants indicate the event that caused the watch event. They are
  168. * possible values of the first parameter of the watcher callback.
  169. */
  170. // @{
  171. /**
  172. * \brief a node has been created.
  173. *
  174. * This is only generated by watches on non-existent nodes. These watches
  175. * are set using \ref zoo_exists.
  176. */
  177. extern ZOOAPI const int ZOO_CREATED_EVENT;
  178. /**
  179. * \brief a node has been deleted.
  180. *
  181. * This is only generated by watches on nodes. These watches
  182. * are set using \ref zoo_exists and \ref zoo_get.
  183. */
  184. extern ZOOAPI const int ZOO_DELETED_EVENT;
  185. /**
  186. * \brief a node has changed.
  187. *
  188. * This is only generated by watches on nodes. These watches
  189. * are set using \ref zoo_exists and \ref zoo_get.
  190. */
  191. extern ZOOAPI const int ZOO_CHANGED_EVENT;
  192. /**
  193. * \brief a change as occurred in the list of children.
  194. *
  195. * This is only generated by watches on the child list of a node. These watches
  196. * are set using \ref zoo_get_children or \ref zoo_get_children2.
  197. */
  198. extern ZOOAPI const int ZOO_CHILD_EVENT;
  199. /**
  200. * \brief a session has been lost.
  201. *
  202. * This is generated when a client loses contact or reconnects with a server.
  203. */
  204. extern ZOOAPI const int ZOO_SESSION_EVENT;
  205. /**
  206. * \brief a watch has been removed.
  207. *
  208. * This is generated when the server for some reason, probably a resource
  209. * constraint, will no longer watch a node for a client.
  210. */
  211. extern ZOOAPI const int ZOO_NOTWATCHING_EVENT;
  212. // @}
  213. /**
  214. * \brief ZooKeeper handle.
  215. *
  216. * This is the handle that represents a connection to the ZooKeeper service.
  217. * It is needed to invoke any ZooKeeper function. A handle is obtained using
  218. * \ref zookeeper_init.
  219. */
  220. typedef struct _zhandle zhandle_t;
  221. /**
  222. * \brief client id structure.
  223. *
  224. * This structure holds the id and password for the session. This structure
  225. * should be treated as opaque. It is received from the server when a session
  226. * is established and needs to be sent back as-is when reconnecting a session.
  227. */
  228. typedef struct {
  229. int64_t client_id;
  230. char passwd[16];
  231. } clientid_t;
  232. /**
  233. * \brief signature of a watch function.
  234. *
  235. * There are two ways to receive watch notifications: legacy and watcher object.
  236. * <p>
  237. * The legacy style, an application wishing to receive events from ZooKeeper must
  238. * first implement a function with this signature and pass a pointer to the function
  239. * to \ref zookeeper_init. Next, the application sets a watch by calling one of
  240. * the getter API that accept the watch integer flag (for example, \ref zoo_aexists,
  241. * \ref zoo_get, etc).
  242. * <p>
  243. * The watcher object style uses an instance of a "watcher object" which in
  244. * the C world is represented by a pair: a pointer to a function implementing this
  245. * signature and a pointer to watcher context -- handback user-specific data.
  246. * When a watch is triggered this function will be called along with
  247. * the watcher context. An application wishing to use this style must use
  248. * the getter API functions with the "w" prefix in their names (for example, \ref
  249. * zoo_awexists, \ref zoo_wget, etc).
  250. *
  251. * \param zh zookeeper handle
  252. * \param type event type. This is one of the *_EVENT constants.
  253. * \param state connection state. The state value will be one of the *_STATE constants.
  254. * \param path znode path for which the watcher is triggered. NULL if the event
  255. * type is ZOO_SESSION_EVENT
  256. * \param watcherCtx watcher context.
  257. */
  258. typedef void (*watcher_fn)(zhandle_t *zh, int type,
  259. int state, const char *path,void *watcherCtx);
  260. /**
  261. * \brief create a handle to used communicate with zookeeper.
  262. *
  263. * This method creates a new handle and a zookeeper session that corresponds
  264. * to that handle. Session establishment is asynchronous, meaning that the
  265. * session should not be considered established until (and unless) an
  266. * event of state ZOO_CONNECTED_STATE is received.
  267. * \param host comma separated host:port pairs, each corresponding to a zk
  268. * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
  269. * \param fn the global watcher callback function. When notifications are
  270. * triggered this function will be invoked.
  271. * \param clientid the id of a previously established session that this
  272. * client will be reconnecting to. Pass 0 if not reconnecting to a previous
  273. * session. Clients can access the session id of an established, valid,
  274. * connection by calling \ref zoo_client_id. If the session corresponding to
  275. * the specified clientid has expired, or if the clientid is invalid for
  276. * any reason, the returned zhandle_t will be invalid -- the zhandle_t
  277. * state will indicate the reason for failure (typically
  278. * ZOO_EXPIRED_SESSION_STATE).
  279. * \param context the handback object that will be associated with this instance
  280. * of zhandle_t. Application can access it (for example, in the watcher
  281. * callback) using \ref zoo_get_context. The object is not used by zookeeper
  282. * internally and can be null.
  283. * \param flags reserved for future use. Should be set to zero.
  284. * \return a pointer to the opaque zhandle structure. If it fails to create
  285. * a new zhandle the function returns NULL and the errno variable
  286. * indicates the reason.
  287. */
  288. ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn,
  289. int recv_timeout, const clientid_t *clientid, void *context, int flags);
  290. /**
  291. * \brief close the zookeeper handle and free up any resources.
  292. *
  293. * After this call, the client session will no longer be valid. The function
  294. * will flush any outstanding send requests before return. As a result it may
  295. * block.
  296. *
  297. * This method should only be called only once on a zookeeper handle. Calling
  298. * twice will cause undefined (and probably undesirable behavior). Calling any other
  299. * zookeeper method after calling close is undefined behaviour and should be avoided.
  300. *
  301. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  302. * \return a result code. Regardless of the error code returned, the zhandle
  303. * will be destroyed and all resources freed.
  304. *
  305. * ZOK - success
  306. * ZBADARGUMENTS - invalid input parameters
  307. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  308. * ZOPERATIONTIMEOUT - failed to flush the buffers within the specified timeout.
  309. * ZCONNECTIONLOSS - a network error occured while attempting to send request to server
  310. * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details
  311. */
  312. ZOOAPI int zookeeper_close(zhandle_t *zh);
  313. /**
  314. * \brief return the client session id, only valid if the connections
  315. * is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE)
  316. */
  317. ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh);
  318. ZOOAPI int zoo_recv_timeout(zhandle_t *zh);
  319. ZOOAPI const void *zoo_get_context(zhandle_t *zh);
  320. ZOOAPI void zoo_set_context(zhandle_t *zh, void *context);
  321. /**
  322. * \brief set a watcher function
  323. * \return previous watcher function
  324. */
  325. ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn);
  326. #ifndef THREADED
  327. /**
  328. * \brief Returns the events that zookeeper is interested in.
  329. *
  330. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  331. * \param fd is the file descriptor of interest
  332. * \param interest is an or of the ZOOKEEPER_WRITE and ZOOKEEPER_READ flags to
  333. * indicate the I/O of interest on fd.
  334. * \param tv a timeout value to be used with select/poll system call
  335. * \return a result code.
  336. * ZOK - success
  337. * ZBADARGUMENTS - invalid input parameters
  338. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  339. * ZCONNECTIONLOSS - a network error occured while attempting to establish
  340. * a connection to the server
  341. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  342. * ZOPERATIONTIMEOUT - hasn't received anything from the server for 2/3 of the
  343. * timeout value specified in zookeeper_init()
  344. * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details
  345. */
  346. ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest,
  347. struct timeval *tv);
  348. /**
  349. * \brief Notifies zookeeper that an event of interest has happened.
  350. *
  351. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  352. * \param events will be an OR of the ZOOKEEPER_WRITE and ZOOKEEPER_READ flags.
  353. * \return a result code.
  354. * ZOK - success
  355. * ZBADARGUMENTS - invalid input parameters
  356. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  357. * ZCONNECTIONLOSS - a network error occured while attempting to send request to server
  358. * ZSESSIONEXPIRED - connection attempt failed -- the session's expired
  359. * ZAUTHFAILED - authentication request failed, e.i. invalid credentials
  360. * ZRUNTIMEINCONSISTENCY - a server response came out of order
  361. * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details
  362. * ZNOTHING -- not an error; simply indicates that there no more data from the server
  363. * to be processed (when called with ZOOKEEPER_READ flag).
  364. */
  365. ZOOAPI int zookeeper_process(zhandle_t *zh, int events);
  366. #endif
  367. /**
  368. * \brief signature of a completion function for a call that returns void.
  369. *
  370. * This method will be invoked at the end of a asynchronous call and also as
  371. * a result of connection loss or timeout.
  372. * \param rc the error code of the call. Connection loss/timeout triggers
  373. * the completion with one of the following error codes:
  374. * ZCONNECTIONLOSS -- lost connection to the server
  375. * ZOPERATIONTIMEOUT -- connection timed out
  376. * Data related events trigger the completion with error codes listed the
  377. * Exceptions section of the documentation of the function that initiated the
  378. * call. (Zero indicates call was successful.)
  379. * \param data the pointer that was passed by the caller when the function
  380. * that this completion corresponds to was invoked. The programmer
  381. * is responsible for any memory freeing associated with the data
  382. * pointer.
  383. */
  384. typedef void (*void_completion_t)(int rc, const void *data);
  385. /**
  386. * \brief signature of a completion function that returns a Stat structure.
  387. *
  388. * This method will be invoked at the end of a asynchronous call and also as
  389. * a result of connection loss or timeout.
  390. * \param rc the error code of the call. Connection loss/timeout triggers
  391. * the completion with one of the following error codes:
  392. * ZCONNECTIONLOSS -- lost connection to the server
  393. * ZOPERATIONTIMEOUT -- connection timed out
  394. * Data related events trigger the completion with error codes listed the
  395. * Exceptions section of the documentation of the function that initiated the
  396. * call. (Zero indicates call was successful.)
  397. * \param stat a pointer to the stat information for the node involved in
  398. * this function. If a non zero error code is returned, the content of
  399. * stat is undefined. The programmer is NOT responsible for freeing stat.
  400. * \param data the pointer that was passed by the caller when the function
  401. * that this completion corresponds to was invoked. The programmer
  402. * is responsible for any memory freeing associated with the data
  403. * pointer.
  404. */
  405. typedef void (*stat_completion_t)(int rc, const struct Stat *stat,
  406. const void *data);
  407. /**
  408. * \brief signature of a completion function that returns data.
  409. *
  410. * This method will be invoked at the end of a asynchronous call and also as
  411. * a result of connection loss or timeout.
  412. * \param rc the error code of the call. Connection loss/timeout triggers
  413. * the completion with one of the following error codes:
  414. * ZCONNECTIONLOSS -- lost connection to the server
  415. * ZOPERATIONTIMEOUT -- connection timed out
  416. * Data related events trigger the completion with error codes listed the
  417. * Exceptions section of the documentation of the function that initiated the
  418. * call. (Zero indicates call was successful.)
  419. * \param value the value of the information returned by the asynchronous call.
  420. * If a non zero error code is returned, the content of value is undefined.
  421. * The programmer is NOT responsible for freeing value.
  422. * \param value_len the number of bytes in value.
  423. * \param stat a pointer to the stat information for the node involved in
  424. * this function. If a non zero error code is returned, the content of
  425. * stat is undefined. The programmer is NOT responsible for freeing stat.
  426. * \param data the pointer that was passed by the caller when the function
  427. * that this completion corresponds to was invoked. The programmer
  428. * is responsible for any memory freeing associated with the data
  429. * pointer.
  430. */
  431. typedef void (*data_completion_t)(int rc, const char *value, int value_len,
  432. const struct Stat *stat, const void *data);
  433. /**
  434. * \brief signature of a completion function that returns a list of strings.
  435. *
  436. * This method will be invoked at the end of a asynchronous call and also as
  437. * a result of connection loss or timeout.
  438. * \param rc the error code of the call. Connection loss/timeout triggers
  439. * the completion with one of the following error codes:
  440. * ZCONNECTIONLOSS -- lost connection to the server
  441. * ZOPERATIONTIMEOUT -- connection timed out
  442. * Data related events trigger the completion with error codes listed the
  443. * Exceptions section of the documentation of the function that initiated the
  444. * call. (Zero indicates call was successful.)
  445. * \param strings a pointer to the structure containng the list of strings of the
  446. * names of the children of a node. If a non zero error code is returned,
  447. * the content of strings is undefined. The programmer is NOT responsible
  448. * for freeing strings.
  449. * \param data the pointer that was passed by the caller when the function
  450. * that this completion corresponds to was invoked. The programmer
  451. * is responsible for any memory freeing associated with the data
  452. * pointer.
  453. */
  454. typedef void (*strings_completion_t)(int rc,
  455. const struct String_vector *strings, const void *data);
  456. /**
  457. * \brief signature of a completion function that returns a list of strings and stat.
  458. * .
  459. *
  460. * This method will be invoked at the end of a asynchronous call and also as
  461. * a result of connection loss or timeout.
  462. * \param rc the error code of the call. Connection loss/timeout triggers
  463. * the completion with one of the following error codes:
  464. * ZCONNECTIONLOSS -- lost connection to the server
  465. * ZOPERATIONTIMEOUT -- connection timed out
  466. * Data related events trigger the completion with error codes listed the
  467. * Exceptions section of the documentation of the function that initiated the
  468. * call. (Zero indicates call was successful.)
  469. * \param strings a pointer to the structure containng the list of strings of the
  470. * names of the children of a node. If a non zero error code is returned,
  471. * the content of strings is undefined. The programmer is NOT responsible
  472. * for freeing strings.
  473. * \param stat a pointer to the stat information for the node involved in
  474. * this function. If a non zero error code is returned, the content of
  475. * stat is undefined. The programmer is NOT responsible for freeing stat.
  476. * \param data the pointer that was passed by the caller when the function
  477. * that this completion corresponds to was invoked. The programmer
  478. * is responsible for any memory freeing associated with the data
  479. * pointer.
  480. */
  481. typedef void (*strings_stat_completion_t)(int rc,
  482. const struct String_vector *strings, const struct Stat *stat,
  483. const void *data);
  484. /**
  485. * \brief signature of a completion function that returns a list of strings.
  486. *
  487. * This method will be invoked at the end of a asynchronous call and also as
  488. * a result of connection loss or timeout.
  489. * \param rc the error code of the call. Connection loss/timeout triggers
  490. * the completion with one of the following error codes:
  491. * ZCONNECTIONLOSS -- lost connection to the server
  492. * ZOPERATIONTIMEOUT -- connection timed out
  493. * Data related events trigger the completion with error codes listed the
  494. * Exceptions section of the documentation of the function that initiated the
  495. * call. (Zero indicates call was successful.)
  496. * \param value the value of the string returned.
  497. * \param data the pointer that was passed by the caller when the function
  498. * that this completion corresponds to was invoked. The programmer
  499. * is responsible for any memory freeing associated with the data
  500. * pointer.
  501. */
  502. typedef void
  503. (*string_completion_t)(int rc, const char *value, const void *data);
  504. /**
  505. * \brief signature of a completion function that returns an ACL.
  506. *
  507. * This method will be invoked at the end of a asynchronous call and also as
  508. * a result of connection loss or timeout.
  509. * \param rc the error code of the call. Connection loss/timeout triggers
  510. * the completion with one of the following error codes:
  511. * ZCONNECTIONLOSS -- lost connection to the server
  512. * ZOPERATIONTIMEOUT -- connection timed out
  513. * Data related events trigger the completion with error codes listed the
  514. * Exceptions section of the documentation of the function that initiated the
  515. * call. (Zero indicates call was successful.)
  516. * \param acl a pointer to the structure containng the ACL of a node. If a non
  517. * zero error code is returned, the content of strings is undefined. The
  518. * programmer is NOT responsible for freeing acl.
  519. * \param stat a pointer to the stat information for the node involved in
  520. * this function. If a non zero error code is returned, the content of
  521. * stat is undefined. The programmer is NOT responsible for freeing stat.
  522. * \param data the pointer that was passed by the caller when the function
  523. * that this completion corresponds to was invoked. The programmer
  524. * is responsible for any memory freeing associated with the data
  525. * pointer.
  526. */
  527. typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl,
  528. struct Stat *stat, const void *data);
  529. /**
  530. * \brief get the state of the zookeeper connection.
  531. *
  532. * The return value will be one of the \ref State Consts.
  533. */
  534. ZOOAPI int zoo_state(zhandle_t *zh);
  535. /**
  536. * \brief create a node.
  537. *
  538. * This method will create a node in ZooKeeper. A node can only be created if
  539. * it does not already exists. The Create Flags affect the creation of nodes.
  540. * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the
  541. * client session goes away. If the ZOO_SEQUENCE flag is set, a unique
  542. * monotonically increasing sequence number is appended to the path name.
  543. *
  544. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  545. * \param path The name of the node. Expressed as a file name with slashes
  546. * separating ancestors of the node.
  547. * \param value The data to be stored in the node.
  548. * \param valuelen The number of bytes in data.
  549. * \param acl The initial ACL of the node. If null, the ACL of the parent will be
  550. * used.
  551. * \param flags this parameter can be set to 0 for normal create or an OR
  552. * of the Create Flags
  553. * \param completion the routine to invoke when the request completes. The completion
  554. * will be triggered with one of the following codes passed in as the rc argument:
  555. * ZOK operation completed succesfully
  556. * ZNONODE the parent node does not exist.
  557. * ZNODEEXISTS the node already exists
  558. * ZNOAUTH the client does not have permission.
  559. * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.
  560. * \param data The data that will be passed to the completion routine when the
  561. * function completes.
  562. * \return ZOK on success or one of the following errcodes on failure:
  563. * ZBADARGUMENTS - invalid input parameters
  564. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  565. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  566. */
  567. ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value,
  568. int valuelen, const struct ACL_vector *acl, int flags,
  569. string_completion_t completion, const void *data);
  570. /**
  571. * \brief delete a node in zookeeper.
  572. *
  573. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  574. * \param path the name of the node. Expressed as a file name with slashes
  575. * separating ancestors of the node.
  576. * \param version the expected version of the node. The function will fail if the
  577. * actual version of the node does not match the expected version.
  578. * If -1 is used the version check will not take place.
  579. * \param completion the routine to invoke when the request completes. The completion
  580. * will be triggered with one of the following codes passed in as the rc argument:
  581. * ZOK operation completed succesfully
  582. * ZNONODE the node does not exist.
  583. * ZNOAUTH the client does not have permission.
  584. * ZBADVERSION expected version does not match actual version.
  585. * ZNOTEMPTY children are present; node cannot be deleted.
  586. * \param data the data that will be passed to the completion routine when
  587. * the function completes.
  588. * \return ZOK on success or one of the following errcodes on failure:
  589. * ZBADARGUMENTS - invalid input parameters
  590. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  591. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  592. */
  593. ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version,
  594. void_completion_t completion, const void *data);
  595. /**
  596. * \brief checks the existence of a node in zookeeper.
  597. *
  598. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  599. * \param path the name of the node. Expressed as a file name with slashes
  600. * separating ancestors of the node.
  601. * \param watch if nonzero, a watch will be set at the server to notify the
  602. * client if the node changes. The watch will be set even if the node does not
  603. * exist. This allows clients to watch for nodes to appear.
  604. * \param completion the routine to invoke when the request completes. The completion
  605. * will be triggered with one of the following codes passed in as the rc argument:
  606. * ZOK operation completed succesfully
  607. * ZNONODE the node does not exist.
  608. * ZNOAUTH the client does not have permission.
  609. * \param data the data that will be passed to the completion routine when the
  610. * function completes.
  611. * \return ZOK on success or one of the following errcodes on failure:
  612. * ZBADARGUMENTS - invalid input parameters
  613. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  614. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  615. */
  616. ZOOAPI int zoo_aexists(zhandle_t *zh, const char *path, int watch,
  617. stat_completion_t completion, const void *data);
  618. /**
  619. * \brief checks the existence of a node in zookeeper.
  620. *
  621. * This function is similar to \ref zoo_axists except it allows one specify
  622. * a watcher object - a function pointer and associated context. The function
  623. * will be called once the watch has fired. The associated context data will be
  624. * passed to the function as the watcher context parameter.
  625. *
  626. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  627. * \param path the name of the node. Expressed as a file name with slashes
  628. * separating ancestors of the node.
  629. * \param watcher if non-null a watch will set on the specified znode on the server.
  630. * The watch will be set even if the node does not exist. This allows clients
  631. * to watch for nodes to appear.
  632. * \param watcherCtx user specific data, will be passed to the watcher callback.
  633. * Unlike the global context set by \ref zookeeper_init, this watcher context
  634. * is associated with the given instance of the watcher only.
  635. * \param completion the routine to invoke when the request completes. The completion
  636. * will be triggered with one of the following codes passed in as the rc argument:
  637. * ZOK operation completed succesfully
  638. * ZNONODE the node does not exist.
  639. * ZNOAUTH the client does not have permission.
  640. * \param data the data that will be passed to the completion routine when the
  641. * function completes.
  642. * \return ZOK on success or one of the following errcodes on failure:
  643. * ZBADARGUMENTS - invalid input parameters
  644. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  645. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  646. */
  647. ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path,
  648. watcher_fn watcher, void* watcherCtx,
  649. stat_completion_t completion, const void *data);
  650. /**
  651. * \brief gets the data associated with a node.
  652. *
  653. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  654. * \param path the name of the node. Expressed as a file name with slashes
  655. * separating ancestors of the node.
  656. * \param watch if nonzero, a watch will be set at the server to notify
  657. * the client if the node changes.
  658. * \param completion the routine to invoke when the request completes. The completion
  659. * will be triggered with one of the following codes passed in as the rc argument:
  660. * ZOK operation completed succesfully
  661. * ZNONODE the node does not exist.
  662. * ZNOAUTH the client does not have permission.
  663. * \param data the data that will be passed to the completion routine when
  664. * the function completes.
  665. * \return ZOK on success or one of the following errcodes on failure:
  666. * ZBADARGUMENTS - invalid input parameters
  667. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  668. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  669. */
  670. ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch,
  671. data_completion_t completion, const void *data);
  672. /**
  673. * \brief gets the data associated with a node.
  674. *
  675. * This function is similar to \ref zoo_aget except it allows one specify
  676. * a watcher object rather than a boolean watch flag.
  677. *
  678. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  679. * \param path the name of the node. Expressed as a file name with slashes
  680. * separating ancestors of the node.
  681. * \param watcher if non-null, a watch will be set at the server to notify
  682. * the client if the node changes.
  683. * \param watcherCtx user specific data, will be passed to the watcher callback.
  684. * Unlike the global context set by \ref zookeeper_init, this watcher context
  685. * is associated with the given instance of the watcher only.
  686. * \param completion the routine to invoke when the request completes. The completion
  687. * will be triggered with one of the following codes passed in as the rc argument:
  688. * ZOK operation completed succesfully
  689. * ZNONODE the node does not exist.
  690. * ZNOAUTH the client does not have permission.
  691. * \param data the data that will be passed to the completion routine when
  692. * the function completes.
  693. * \return ZOK on success or one of the following errcodes on failure:
  694. * ZBADARGUMENTS - invalid input parameters
  695. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  696. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  697. */
  698. ZOOAPI int zoo_awget(zhandle_t *zh, const char *path,
  699. watcher_fn watcher, void* watcherCtx,
  700. data_completion_t completion, const void *data);
  701. /**
  702. * \brief sets the data associated with a node.
  703. *
  704. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  705. * \param path the name of the node. Expressed as a file name with slashes
  706. * separating ancestors of the node.
  707. * \param buffer the buffer holding data to be written to the node.
  708. * \param buflen the number of bytes from buffer to write.
  709. * \param version the expected version of the node. The function will fail if
  710. * the actual version of the node does not match the expected version. If -1 is
  711. * used the version check will not take place. * completion: If null,
  712. * the function will execute synchronously. Otherwise, the function will return
  713. * immediately and invoke the completion routine when the request completes.
  714. * \param completion the routine to invoke when the request completes. The completion
  715. * will be triggered with one of the following codes passed in as the rc argument:
  716. * ZOK operation completed succesfully
  717. * ZNONODE the node does not exist.
  718. * ZNOAUTH the client does not have permission.
  719. * ZBADVERSION expected version does not match actual version.
  720. * \param data the data that will be passed to the completion routine when
  721. * the function completes.
  722. * \return ZOK on success or one of the following errcodes on failure:
  723. * ZBADARGUMENTS - invalid input parameters
  724. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  725. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  726. */
  727. ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen,
  728. int version, stat_completion_t completion, const void *data);
  729. /**
  730. * \brief lists the children of a node.
  731. *
  732. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  733. * \param path the name of the node. Expressed as a file name with slashes
  734. * separating ancestors of the node.
  735. * \param watch if nonzero, a watch will be set at the server to notify
  736. * the client if the node changes.
  737. * \param completion the routine to invoke when the request completes. The completion
  738. * will be triggered with one of the following codes passed in as the rc argument:
  739. * ZOK operation completed succesfully
  740. * ZNONODE the node does not exist.
  741. * ZNOAUTH the client does not have permission.
  742. * \param data the data that will be passed to the completion routine when
  743. * the function completes.
  744. * \return ZOK on success or one of the following errcodes on failure:
  745. * ZBADARGUMENTS - invalid input parameters
  746. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  747. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  748. */
  749. ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch,
  750. strings_completion_t completion, const void *data);
  751. /**
  752. * \brief lists the children of a node.
  753. *
  754. * This function is similar to \ref zoo_aget_children except it allows one specify
  755. * a watcher object rather than a boolean watch flag.
  756. *
  757. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  758. * \param path the name of the node. Expressed as a file name with slashes
  759. * separating ancestors of the node.
  760. * \param watcher if non-null, a watch will be set at the server to notify
  761. * the client if the node changes.
  762. * \param watcherCtx user specific data, will be passed to the watcher callback.
  763. * Unlike the global context set by \ref zookeeper_init, this watcher context
  764. * is associated with the given instance of the watcher only.
  765. * \param completion the routine to invoke when the request completes. The completion
  766. * will be triggered with one of the following codes passed in as the rc argument:
  767. * ZOK operation completed succesfully
  768. * ZNONODE the node does not exist.
  769. * ZNOAUTH the client does not have permission.
  770. * \param data the data that will be passed to the completion routine when
  771. * the function completes.
  772. * \return ZOK on success or one of the following errcodes on failure:
  773. * ZBADARGUMENTS - invalid input parameters
  774. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  775. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  776. */
  777. ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path,
  778. watcher_fn watcher, void* watcherCtx,
  779. strings_completion_t completion, const void *data);
  780. /**
  781. * \brief lists the children of a node, and get the parent stat.
  782. *
  783. * This function is new in version 3.3.0
  784. *
  785. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  786. * \param path the name of the node. Expressed as a file name with slashes
  787. * separating ancestors of the node.
  788. * \param watch if nonzero, a watch will be set at the server to notify
  789. * the client if the node changes.
  790. * \param completion the routine to invoke when the request completes. The completion
  791. * will be triggered with one of the following codes passed in as the rc argument:
  792. * ZOK operation completed succesfully
  793. * ZNONODE the node does not exist.
  794. * ZNOAUTH the client does not have permission.
  795. * \param data the data that will be passed to the completion routine when
  796. * the function completes.
  797. * \return ZOK on success or one of the following errcodes on failure:
  798. * ZBADARGUMENTS - invalid input parameters
  799. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  800. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  801. */
  802. ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch,
  803. strings_stat_completion_t completion, const void *data);
  804. /**
  805. * \brief lists the children of a node, and get the parent stat.
  806. *
  807. * This function is similar to \ref zoo_aget_children2 except it allows one specify
  808. * a watcher object rather than a boolean watch flag.
  809. *
  810. * This function is new in version 3.3.0
  811. *
  812. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  813. * \param path the name of the node. Expressed as a file name with slashes
  814. * separating ancestors of the node.
  815. * \param watcher if non-null, a watch will be set at the server to notify
  816. * the client if the node changes.
  817. * \param watcherCtx user specific data, will be passed to the watcher callback.
  818. * Unlike the global context set by \ref zookeeper_init, this watcher context
  819. * is associated with the given instance of the watcher only.
  820. * \param completion the routine to invoke when the request completes. The completion
  821. * will be triggered with one of the following codes passed in as the rc argument:
  822. * ZOK operation completed succesfully
  823. * ZNONODE the node does not exist.
  824. * ZNOAUTH the client does not have permission.
  825. * \param data the data that will be passed to the completion routine when
  826. * the function completes.
  827. * \return ZOK on success or one of the following errcodes on failure:
  828. * ZBADARGUMENTS - invalid input parameters
  829. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  830. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  831. */
  832. ZOOAPI int zoo_awget_children2(zhandle_t *zh, const char *path,
  833. watcher_fn watcher, void* watcherCtx,
  834. strings_stat_completion_t completion, const void *data);
  835. /**
  836. * \brief Flush leader channel.
  837. *
  838. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  839. * \param path the name of the node. Expressed as a file name with slashes
  840. * separating ancestors of the node.
  841. * \param completion the routine to invoke when the request completes. The completion
  842. * will be triggered with one of the following codes passed in as the rc argument:
  843. * ZOK operation completed succesfully
  844. * ZNONODE the node does not exist.
  845. * ZNOAUTH the client does not have permission.
  846. * \param data the data that will be passed to the completion routine when
  847. * the function completes.
  848. * \return ZOK on success or one of the following errcodes on failure:
  849. * ZBADARGUMENTS - invalid input parameters
  850. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  851. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  852. */
  853. ZOOAPI int zoo_async(zhandle_t *zh, const char *path,
  854. string_completion_t completion, const void *data);
  855. /**
  856. * \brief gets the acl associated with a node.
  857. *
  858. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  859. * \param path the name of the node. Expressed as a file name with slashes
  860. * separating ancestors of the node.
  861. * \param completion the routine to invoke when the request completes. The completion
  862. * will be triggered with one of the following codes passed in as the rc argument:
  863. * ZOK operation completed succesfully
  864. * ZNONODE the node does not exist.
  865. * ZNOAUTH the client does not have permission.
  866. * \param data the data that will be passed to the completion routine when
  867. * the function completes.
  868. * \return ZOK on success or one of the following errcodes on failure:
  869. * ZBADARGUMENTS - invalid input parameters
  870. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  871. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  872. */
  873. ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion,
  874. const void *data);
  875. /**
  876. * \brief sets the acl associated with a node.
  877. *
  878. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  879. * \param path the name of the node. Expressed as a file name with slashes
  880. * separating ancestors of the node.
  881. * \param buffer the buffer holding the acls to be written to the node.
  882. * \param buflen the number of bytes from buffer to write.
  883. * \param completion the routine to invoke when the request completes. The completion
  884. * will be triggered with one of the following codes passed in as the rc argument:
  885. * ZOK operation completed succesfully
  886. * ZNONODE the node does not exist.
  887. * ZNOAUTH the client does not have permission.
  888. * ZINVALIDACL invalid ACL specified
  889. * ZBADVERSION expected version does not match actual version.
  890. * \param data the data that will be passed to the completion routine when
  891. * the function completes.
  892. * \return ZOK on success or one of the following errcodes on failure:
  893. * ZBADARGUMENTS - invalid input parameters
  894. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  895. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  896. */
  897. ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version,
  898. struct ACL_vector *acl, void_completion_t, const void *data);
  899. /**
  900. * \brief return an error string.
  901. *
  902. * \param return code
  903. * \return string corresponding to the return code
  904. */
  905. ZOOAPI const char* zerror(int c);
  906. /**
  907. * \brief specify application credentials.
  908. *
  909. * The application calls this function to specify its credentials for purposes
  910. * of authentication. The server will use the security provider specified by
  911. * the scheme parameter to authenticate the client connection. If the
  912. * authentication request has failed:
  913. * - the server connection is dropped
  914. * - the watcher is called with the ZOO_AUTH_FAILED_STATE value as the state
  915. * parameter.
  916. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  917. * \param scheme the id of authentication scheme. Natively supported:
  918. * "digest" password-based authentication
  919. * \param cert application credentials. The actual value depends on the scheme.
  920. * \param certLen the length of the data parameter
  921. * \param completion the routine to invoke when the request completes. One of
  922. * the following result codes may be passed into the completion callback:
  923. * ZOK operation completed successfully
  924. * ZAUTHFAILED authentication failed
  925. * \param data the data that will be passed to the completion routine when the
  926. * function completes.
  927. * \return ZOK on success or one of the following errcodes on failure:
  928. * ZBADARGUMENTS - invalid input parameters
  929. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  930. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  931. * ZSYSTEMERROR - a system error occured
  932. */
  933. ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
  934. int certLen, void_completion_t completion, const void *data);
  935. /**
  936. * \brief checks if the current zookeeper connection state can't be recovered.
  937. *
  938. * The application must close the zhandle and try to reconnect.
  939. *
  940. * \param zh the zookeeper handle (see \ref zookeeper_init)
  941. * \return ZINVALIDSTATE if connection is unrecoverable
  942. */
  943. ZOOAPI int is_unrecoverable(zhandle_t *zh);
  944. /**
  945. * \brief sets the debugging level for the library
  946. */
  947. ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel);
  948. /**
  949. * \brief sets the stream to be used by the library for logging
  950. *
  951. * The zookeeper library uses stderr as its default log stream. Application
  952. * must make sure the stream is writable. Passing in NULL resets the stream
  953. * to its default value (stderr).
  954. */
  955. ZOOAPI void zoo_set_log_stream(FILE* logStream);
  956. /**
  957. * \brief enable/disable quorum endpoint order randomization
  958. *
  959. * If passed a non-zero value, will make the client connect to quorum peers
  960. * in the order as specified in the zookeeper_init() call.
  961. * A zero value causes zookeeper_init() to permute the peer endpoints
  962. * which is good for more even client connection distribution among the
  963. * quorum peers.
  964. */
  965. ZOOAPI void zoo_deterministic_conn_order(int yesOrNo);
  966. /**
  967. * \brief create a node synchronously.
  968. *
  969. * This method will create a node in ZooKeeper. A node can only be created if
  970. * it does not already exists. The Create Flags affect the creation of nodes.
  971. * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the
  972. * client session goes away. If the ZOO_SEQUENCE flag is set, a unique
  973. * monotonically increasing sequence number is appended to the path name.
  974. *
  975. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  976. * \param path The name of the node. Expressed as a file name with slashes
  977. * separating ancestors of the node.
  978. * \param value The data to be stored in the node.
  979. * \param valuelen The number of bytes in data. To set the data to be NULL use
  980. * value as NULL and valuelen as -1.
  981. * \param acl The initial ACL of the node. If null, the ACL of the parent will be
  982. * used.
  983. * \param flags this parameter can be set to 0 for normal create or an OR
  984. * of the Create Flags
  985. * \param path_buffer Buffer which will be filled with the path of the
  986. * new node (this might be different than the supplied path
  987. * because of the ZOO_SEQUENCE flag). The path string will always be
  988. * null-terminated.
  989. * \param path_buffer_len Size of path buffer; if the path of the new
  990. * node (including space for the null terminator) exceeds the buffer size,
  991. * the path string will be truncated to fit. The actual path of the
  992. * new node in the server will not be affected by the truncation.
  993. * The path string will always be null-terminated.
  994. * \return one of the following codes are returned:
  995. * ZOK operation completed succesfully
  996. * ZNONODE the parent node does not exist.
  997. * ZNODEEXISTS the node already exists
  998. * ZNOAUTH the client does not have permission.
  999. * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.
  1000. * ZBADARGUMENTS - invalid input parameters
  1001. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1002. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1003. */
  1004. ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value,
  1005. int valuelen, const struct ACL_vector *acl, int flags,
  1006. char *path_buffer, int path_buffer_len);
  1007. /**
  1008. * \brief delete a node in zookeeper synchronously.
  1009. *
  1010. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1011. * \param path the name of the node. Expressed as a file name with slashes
  1012. * separating ancestors of the node.
  1013. * \param version the expected version of the node. The function will fail if the
  1014. * actual version of the node does not match the expected version.
  1015. * If -1 is used the version check will not take place.
  1016. * \return one of the following values is returned.
  1017. * ZOK operation completed succesfully
  1018. * ZNONODE the node does not exist.
  1019. * ZNOAUTH the client does not have permission.
  1020. * ZBADVERSION expected version does not match actual version.
  1021. * ZNOTEMPTY children are present; node cannot be deleted.
  1022. * ZBADARGUMENTS - invalid input parameters
  1023. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1024. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1025. */
  1026. ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version);
  1027. /**
  1028. * \brief checks the existence of a node in zookeeper synchronously.
  1029. *
  1030. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1031. * \param path the name of the node. Expressed as a file name with slashes
  1032. * separating ancestors of the node.
  1033. * \param watch if nonzero, a watch will be set at the server to notify the
  1034. * client if the node changes. The watch will be set even if the node does not
  1035. * exist. This allows clients to watch for nodes to appear.
  1036. * \param the return stat value of the node.
  1037. * \return return code of the function call.
  1038. * ZOK operation completed succesfully
  1039. * ZNONODE the node does not exist.
  1040. * ZNOAUTH the client does not have permission.
  1041. * ZBADARGUMENTS - invalid input parameters
  1042. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1043. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1044. */
  1045. ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
  1046. /**
  1047. * \brief checks the existence of a node in zookeeper synchronously.
  1048. *
  1049. * This function is similar to \ref zoo_exists except it allows one specify
  1050. * a watcher object rather than a boolean watch flag.
  1051. *
  1052. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1053. * \param path the name of the node. Expressed as a file name with slashes
  1054. * separating ancestors of the node.
  1055. * \param watcher if non-null a watch will set on the specified znode on the server.
  1056. * The watch will be set even if the node does not exist. This allows clients
  1057. * to watch for nodes to appear.
  1058. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1059. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1060. * is associated with the given instance of the watcher only.
  1061. * \param the return stat value of the node.
  1062. * \return return code of the function call.
  1063. * ZOK operation completed succesfully
  1064. * ZNONODE the node does not exist.
  1065. * ZNOAUTH the client does not have permission.
  1066. * ZBADARGUMENTS - invalid input parameters
  1067. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1068. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1069. */
  1070. ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path,
  1071. watcher_fn watcher, void* watcherCtx, struct Stat *stat);
  1072. /**
  1073. * \brief gets the data associated with a node synchronously.
  1074. *
  1075. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1076. * \param path the name of the node. Expressed as a file name with slashes
  1077. * separating ancestors of the node.
  1078. * \param watch if nonzero, a watch will be set at the server to notify
  1079. * the client if the node changes.
  1080. * \param buffer the buffer holding the node data returned by the server
  1081. * \param buffer_len is the size of the buffer pointed to by the buffer parameter.
  1082. * It'll be set to the actual data length upon return. If the data is NULL, length is -1.
  1083. * \param stat if not NULL, will hold the value of stat for the path on return.
  1084. * \return return value of the function call.
  1085. * ZOK operation completed succesfully
  1086. * ZNONODE the node does not exist.
  1087. * ZNOAUTH the client does not have permission.
  1088. * ZBADARGUMENTS - invalid input parameters
  1089. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1090. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1091. */
  1092. ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer,
  1093. int* buffer_len, struct Stat *stat);
  1094. /**
  1095. * \brief gets the data associated with a node synchronously.
  1096. *
  1097. * This function is similar to \ref zoo_get except it allows one specify
  1098. * a watcher object rather than a boolean watch flag.
  1099. *
  1100. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1101. * \param path the name of the node. Expressed as a file name with slashes
  1102. * separating ancestors of the node.
  1103. * \param watcher if non-null, a watch will be set at the server to notify
  1104. * the client if the node changes.
  1105. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1106. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1107. * is associated with the given instance of the watcher only.
  1108. * \param buffer the buffer holding the node data returned by the server
  1109. * \param buffer_len is the size of the buffer pointed to by the buffer parameter.
  1110. * It'll be set to the actual data length upon return. If the data is NULL, length is -1.
  1111. * \param stat if not NULL, will hold the value of stat for the path on return.
  1112. * \return return value of the function call.
  1113. * ZOK operation completed succesfully
  1114. * ZNONODE the node does not exist.
  1115. * ZNOAUTH the client does not have permission.
  1116. * ZBADARGUMENTS - invalid input parameters
  1117. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1118. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1119. */
  1120. ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
  1121. watcher_fn watcher, void* watcherCtx,
  1122. char *buffer, int* buffer_len, struct Stat *stat);
  1123. /**
  1124. * \brief sets the data associated with a node. See zoo_set2 function if
  1125. * you require access to the stat information associated with the znode.
  1126. *
  1127. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1128. * \param path the name of the node. Expressed as a file name with slashes
  1129. * separating ancestors of the node.
  1130. * \param buffer the buffer holding data to be written to the node.
  1131. * \param buflen the number of bytes from buffer to write. To set NULL as data
  1132. * use buffer as NULL and buflen as -1.
  1133. * \param version the expected version of the node. The function will fail if
  1134. * the actual version of the node does not match the expected version. If -1 is
  1135. * used the version check will not take place.
  1136. * \return the return code for the function call.
  1137. * ZOK operation completed succesfully
  1138. * ZNONODE the node does not exist.
  1139. * ZNOAUTH the client does not have permission.
  1140. * ZBADVERSION expected version does not match actual version.
  1141. * ZBADARGUMENTS - invalid input parameters
  1142. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1143. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1144. */
  1145. ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer,
  1146. int buflen, int version);
  1147. /**
  1148. * \brief sets the data associated with a node. This function is the same
  1149. * as zoo_set except that it also provides access to stat information
  1150. * associated with the znode.
  1151. *
  1152. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1153. * \param path the name of the node. Expressed as a file name with slashes
  1154. * separating ancestors of the node.
  1155. * \param buffer the buffer holding data to be written to the node.
  1156. * \param buflen the number of bytes from buffer to write. To set NULL as data
  1157. * use buffer as NULL and buflen as -1.
  1158. * \param version the expected version of the node. The function will fail if
  1159. * the actual version of the node does not match the expected version. If -1 is
  1160. * used the version check will not take place.
  1161. * \param stat if not NULL, will hold the value of stat for the path on return.
  1162. * \return the return code for the function call.
  1163. * ZOK operation completed succesfully
  1164. * ZNONODE the node does not exist.
  1165. * ZNOAUTH the client does not have permission.
  1166. * ZBADVERSION expected version does not match actual version.
  1167. * ZBADARGUMENTS - invalid input parameters
  1168. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1169. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1170. */
  1171. ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer,
  1172. int buflen, int version, struct Stat *stat);
  1173. /**
  1174. * \brief lists the children of a node synchronously.
  1175. *
  1176. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1177. * \param path the name of the node. Expressed as a file name with slashes
  1178. * separating ancestors of the node.
  1179. * \param watch if nonzero, a watch will be set at the server to notify
  1180. * the client if the node changes.
  1181. * \param strings return value of children paths.
  1182. * \return the return code of the function.
  1183. * ZOK operation completed succesfully
  1184. * ZNONODE the node does not exist.
  1185. * ZNOAUTH the client does not have permission.
  1186. * ZBADARGUMENTS - invalid input parameters
  1187. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1188. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1189. */
  1190. ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch,
  1191. struct String_vector *strings);
  1192. /**
  1193. * \brief lists the children of a node synchronously.
  1194. *
  1195. * This function is similar to \ref zoo_get_children except it allows one specify
  1196. * a watcher object rather than a boolean watch flag.
  1197. *
  1198. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1199. * \param path the name of the node. Expressed as a file name with slashes
  1200. * separating ancestors of the node.
  1201. * \param watcher if non-null, a watch will be set at the server to notify
  1202. * the client if the node changes.
  1203. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1204. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1205. * is associated with the given instance of the watcher only.
  1206. * \param strings return value of children paths.
  1207. * \return the return code of the function.
  1208. * ZOK operation completed succesfully
  1209. * ZNONODE the node does not exist.
  1210. * ZNOAUTH the client does not have permission.
  1211. * ZBADARGUMENTS - invalid input parameters
  1212. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1213. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1214. */
  1215. ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path,
  1216. watcher_fn watcher, void* watcherCtx,
  1217. struct String_vector *strings);
  1218. /**
  1219. * \brief lists the children of a node and get its stat synchronously.
  1220. *
  1221. * This function is new in version 3.3.0
  1222. *
  1223. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1224. * \param path the name of the node. Expressed as a file name with slashes
  1225. * separating ancestors of the node.
  1226. * \param watch if nonzero, a watch will be set at the server to notify
  1227. * the client if the node changes.
  1228. * \param strings return value of children paths.
  1229. * \param stat return value of node stat.
  1230. * \return the return code of the function.
  1231. * ZOK operation completed succesfully
  1232. * ZNONODE the node does not exist.
  1233. * ZNOAUTH the client does not have permission.
  1234. * ZBADARGUMENTS - invalid input parameters
  1235. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1236. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1237. */
  1238. ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch,
  1239. struct String_vector *strings, struct Stat *stat);
  1240. /**
  1241. * \brief lists the children of a node and get its stat synchronously.
  1242. *
  1243. * This function is similar to \ref zoo_get_children except it allows one specify
  1244. * a watcher object rather than a boolean watch flag.
  1245. *
  1246. * This function is new in version 3.3.0
  1247. *
  1248. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1249. * \param path the name of the node. Expressed as a file name with slashes
  1250. * separating ancestors of the node.
  1251. * \param watcher if non-null, a watch will be set at the server to notify
  1252. * the client if the node changes.
  1253. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1254. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1255. * is associated with the given instance of the watcher only.
  1256. * \param strings return value of children paths.
  1257. * \param stat return value of node stat.
  1258. * \return the return code of the function.
  1259. * ZOK operation completed succesfully
  1260. * ZNONODE the node does not exist.
  1261. * ZNOAUTH the client does not have permission.
  1262. * ZBADARGUMENTS - invalid input parameters
  1263. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1264. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1265. */
  1266. ZOOAPI int zoo_wget_children2(zhandle_t *zh, const char *path,
  1267. watcher_fn watcher, void* watcherCtx,
  1268. struct String_vector *strings, struct Stat *stat);
  1269. /**
  1270. * \brief gets the acl associated with a node synchronously.
  1271. *
  1272. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1273. * \param path the name of the node. Expressed as a file name with slashes
  1274. * separating ancestors of the node.
  1275. * \param acl the return value of acls on the path.
  1276. * \param stat returns the stat of the path specified.
  1277. * \return the return code for the function call.
  1278. * ZOK operation completed succesfully
  1279. * ZNONODE the node does not exist.
  1280. * ZNOAUTH the client does not have permission.
  1281. * ZBADARGUMENTS - invalid input parameters
  1282. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1283. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1284. */
  1285. ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl,
  1286. struct Stat *stat);
  1287. /**
  1288. * \brief sets the acl associated with a node synchronously.
  1289. *
  1290. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1291. * \param path the name of the node. Expressed as a file name with slashes
  1292. * separating ancestors of the node.
  1293. * \param version the expected version of the path.
  1294. * \param acl the acl to be set on the path.
  1295. * \return the return code for the function call.
  1296. * ZOK operation completed succesfully
  1297. * ZNONODE the node does not exist.
  1298. * ZNOAUTH the client does not have permission.
  1299. * ZINVALIDACL invalid ACL specified
  1300. * ZBADVERSION expected version does not match actual version.
  1301. * ZBADARGUMENTS - invalid input parameters
  1302. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1303. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1304. */
  1305. ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version,
  1306. const struct ACL_vector *acl);
  1307. #ifdef __cplusplus
  1308. }
  1309. #endif
  1310. #endif /*ZOOKEEPER_H_*/