zookeeper.h 57 KB

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