zookeeper.h 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  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. #ifndef WIN32
  22. #include <sys/socket.h>
  23. #include <sys/time.h>
  24. #else
  25. #include "winconfig.h"
  26. #endif
  27. #include <stdio.h>
  28. #include <ctype.h>
  29. #include "proto.h"
  30. #include "zookeeper_version.h"
  31. #include "recordio.h"
  32. #include "zookeeper.jute.h"
  33. /**
  34. * \file zookeeper.h
  35. * \brief ZooKeeper functions and definitions.
  36. *
  37. * ZooKeeper is a network service that may be backed by a cluster of
  38. * synchronized servers. The data in the service is represented as a tree
  39. * of data nodes. Each node has data, children, an ACL, and status information.
  40. * The data for a node is read and write in its entirety.
  41. *
  42. * ZooKeeper clients can leave watches when they queries the data or children
  43. * of a node. If a watch is left, that client will be notified of the change.
  44. * The notification is a one time trigger. Subsequent chances to the node will
  45. * not trigger a notification unless the client issues a query with the watch
  46. * flag set. If the client is ever disconnected from the service, the watches do
  47. * not need to be reset. The client automatically resets the watches.
  48. *
  49. * When a node is created, it may be flagged as an ephemeral node. Ephemeral
  50. * nodes are automatically removed when a client session is closed or when
  51. * a session times out due to inactivity (the ZooKeeper runtime fills in
  52. * periods of inactivity with pings). Ephemeral nodes cannot have children.
  53. *
  54. * ZooKeeper clients are identified by a server assigned session id. For
  55. * security reasons The server
  56. * also generates a corresponding password for a session. A client may save its
  57. * id and corresponding password to persistent storage in order to use the
  58. * session across program invocation boundaries.
  59. */
  60. /* Support for building on various platforms */
  61. // on cygwin we should take care of exporting/importing symbols properly
  62. #ifdef DLL_EXPORT
  63. # define ZOOAPI __declspec(dllexport)
  64. #else
  65. # if (defined(__CYGWIN__) || defined(WIN32)) && !defined(USE_STATIC_LIB)
  66. # define ZOOAPI __declspec(dllimport)
  67. # else
  68. # define ZOOAPI
  69. # endif
  70. #endif
  71. /** zookeeper return constants **/
  72. enum ZOO_ERRORS {
  73. ZOK = 0, /*!< Everything is OK */
  74. /** System and server-side errors.
  75. * This is never thrown by the server, it shouldn't be used other than
  76. * to indicate a range. Specifically error codes greater than this
  77. * value, but lesser than {@link #ZAPIERROR}, are system errors. */
  78. ZSYSTEMERROR = -1,
  79. ZRUNTIMEINCONSISTENCY = -2, /*!< A runtime inconsistency was found */
  80. ZDATAINCONSISTENCY = -3, /*!< A data inconsistency was found */
  81. ZCONNECTIONLOSS = -4, /*!< Connection to the server has been lost */
  82. ZMARSHALLINGERROR = -5, /*!< Error while marshalling or unmarshalling data */
  83. ZUNIMPLEMENTED = -6, /*!< Operation is unimplemented */
  84. ZOPERATIONTIMEOUT = -7, /*!< Operation timeout */
  85. ZBADARGUMENTS = -8, /*!< Invalid arguments */
  86. ZINVALIDSTATE = -9, /*!< Invliad zhandle state */
  87. ZNEWCONFIGNOQUORUM = -13, /*!< No quorum of new config is connected and
  88. up-to-date with the leader of last commmitted
  89. config - try invoking reconfiguration after new
  90. servers are connected and synced */
  91. ZRECONFIGINPROGRESS = -14, /*!< Reconfiguration requested while another
  92. reconfiguration is currently in progress. This
  93. is currently not supported. Please retry. */
  94. /** API errors.
  95. * This is never thrown by the server, it shouldn't be used other than
  96. * to indicate a range. Specifically error codes greater than this
  97. * value are API errors (while values less than this indicate a
  98. * {@link #ZSYSTEMERROR}).
  99. */
  100. ZAPIERROR = -100,
  101. ZNONODE = -101, /*!< Node does not exist */
  102. ZNOAUTH = -102, /*!< Not authenticated */
  103. ZBADVERSION = -103, /*!< Version conflict */
  104. ZNOCHILDRENFOREPHEMERALS = -108, /*!< Ephemeral nodes may not have children */
  105. ZNODEEXISTS = -110, /*!< The node already exists */
  106. ZNOTEMPTY = -111, /*!< The node has children */
  107. ZSESSIONEXPIRED = -112, /*!< The session has been expired by the server */
  108. ZINVALIDCALLBACK = -113, /*!< Invalid callback specified */
  109. ZINVALIDACL = -114, /*!< Invalid ACL specified */
  110. ZAUTHFAILED = -115, /*!< Client authentication failed */
  111. ZCLOSING = -116, /*!< ZooKeeper is closing */
  112. ZNOTHING = -117, /*!< (not error) no server responses to process */
  113. ZSESSIONMOVED = -118, /*!<session moved to another server, so operation is ignored */
  114. ZNOTREADONLY = -119, /*!< state-changing request is passed to read-only server */
  115. ZEPHEMERALONLOCALSESSION = -120, /*!< Attempt to create ephemeral node on a local session */
  116. ZNOWATCHER = -121, /*!< The watcher couldn't be found */
  117. ZRWSERVERFOUND = -122, /*!< r/w server found while in r/o mode */
  118. ZRECONFIGDISABLED = -123 /*!< Attempts to perform a reconfiguration operation when reconfiguration feature is disabled */
  119. };
  120. #ifdef __cplusplus
  121. extern "C" {
  122. #endif
  123. /**
  124. * @name Debug levels
  125. */
  126. typedef enum {ZOO_LOG_LEVEL_ERROR=1,ZOO_LOG_LEVEL_WARN=2,ZOO_LOG_LEVEL_INFO=3,ZOO_LOG_LEVEL_DEBUG=4} ZooLogLevel;
  127. /**
  128. * @name ACL Consts
  129. */
  130. extern ZOOAPI const int ZOO_PERM_READ;
  131. extern ZOOAPI const int ZOO_PERM_WRITE;
  132. extern ZOOAPI const int ZOO_PERM_CREATE;
  133. extern ZOOAPI const int ZOO_PERM_DELETE;
  134. extern ZOOAPI const int ZOO_PERM_ADMIN;
  135. extern ZOOAPI const int ZOO_PERM_ALL;
  136. #define ZOO_CONFIG_NODE "/zookeeper/config"
  137. /* flags for zookeeper_init{,2} */
  138. #define ZOO_READONLY 1
  139. /** This Id represents anyone. */
  140. extern ZOOAPI struct Id ZOO_ANYONE_ID_UNSAFE;
  141. /** This Id is only usable to set ACLs. It will get substituted with the
  142. * Id's the client authenticated with.
  143. */
  144. extern ZOOAPI struct Id ZOO_AUTH_IDS;
  145. /** This is a completely open ACL*/
  146. extern ZOOAPI struct ACL_vector ZOO_OPEN_ACL_UNSAFE;
  147. /** This ACL gives the world the ability to read. */
  148. extern ZOOAPI struct ACL_vector ZOO_READ_ACL_UNSAFE;
  149. /** This ACL gives the creators authentication id's all permissions. */
  150. extern ZOOAPI struct ACL_vector ZOO_CREATOR_ALL_ACL;
  151. /**
  152. * @name Interest Consts
  153. * These constants are used to express interest in an event and to
  154. * indicate to zookeeper which events have occurred. They can
  155. * be ORed together to express multiple interests. These flags are
  156. * used in the interest and event parameters of
  157. * \ref zookeeper_interest and \ref zookeeper_process.
  158. */
  159. // @{
  160. extern ZOOAPI const int ZOOKEEPER_WRITE;
  161. extern ZOOAPI const int ZOOKEEPER_READ;
  162. // @}
  163. /**
  164. * @name Create Flags
  165. *
  166. * These flags are used by zoo_create to affect node create. They may
  167. * be ORed together to combine effects.
  168. */
  169. // @{
  170. extern ZOOAPI const int ZOO_EPHEMERAL;
  171. extern ZOOAPI const int ZOO_SEQUENCE;
  172. // @}
  173. /**
  174. * @name State Consts
  175. * These constants represent the states of a zookeeper connection. They are
  176. * possible parameters of the watcher callback.
  177. */
  178. // @{
  179. extern ZOOAPI const int ZOO_EXPIRED_SESSION_STATE;
  180. extern ZOOAPI const int ZOO_AUTH_FAILED_STATE;
  181. extern ZOOAPI const int ZOO_CONNECTING_STATE;
  182. extern ZOOAPI const int ZOO_ASSOCIATING_STATE;
  183. extern ZOOAPI const int ZOO_CONNECTED_STATE;
  184. extern ZOOAPI const int ZOO_READONLY_STATE;
  185. extern ZOOAPI const int ZOO_NOTCONNECTED_STATE;
  186. // @}
  187. /**
  188. * @name Watch Types
  189. * These constants indicate the event that caused the watch event. They are
  190. * possible values of the first parameter of the watcher callback.
  191. */
  192. // @{
  193. /**
  194. * \brief a node has been created.
  195. *
  196. * This is only generated by watches on non-existent nodes. These watches
  197. * are set using \ref zoo_exists.
  198. */
  199. extern ZOOAPI const int ZOO_CREATED_EVENT;
  200. /**
  201. * \brief a node has been deleted.
  202. *
  203. * This is only generated by watches on nodes. These watches
  204. * are set using \ref zoo_exists and \ref zoo_get.
  205. */
  206. extern ZOOAPI const int ZOO_DELETED_EVENT;
  207. /**
  208. * \brief a node has changed.
  209. *
  210. * This is only generated by watches on nodes. These watches
  211. * are set using \ref zoo_exists and \ref zoo_get.
  212. */
  213. extern ZOOAPI const int ZOO_CHANGED_EVENT;
  214. /**
  215. * \brief a change as occurred in the list of children.
  216. *
  217. * This is only generated by watches on the child list of a node. These watches
  218. * are set using \ref zoo_get_children or \ref zoo_get_children2.
  219. */
  220. extern ZOOAPI const int ZOO_CHILD_EVENT;
  221. /**
  222. * \brief a session has been lost.
  223. *
  224. * This is generated when a client loses contact or reconnects with a server.
  225. */
  226. extern ZOOAPI const int ZOO_SESSION_EVENT;
  227. /**
  228. * \brief a watch has been removed.
  229. *
  230. * This is generated when the server for some reason, probably a resource
  231. * constraint, will no longer watch a node for a client.
  232. */
  233. extern ZOOAPI const int ZOO_NOTWATCHING_EVENT;
  234. // @}
  235. /**
  236. * \brief ZooKeeper handle.
  237. *
  238. * This is the handle that represents a connection to the ZooKeeper service.
  239. * It is needed to invoke any ZooKeeper function. A handle is obtained using
  240. * \ref zookeeper_init.
  241. */
  242. typedef struct _zhandle zhandle_t;
  243. /**
  244. * \brief client id structure.
  245. *
  246. * This structure holds the id and password for the session. This structure
  247. * should be treated as opaque. It is received from the server when a session
  248. * is established and needs to be sent back as-is when reconnecting a session.
  249. */
  250. typedef struct {
  251. int64_t client_id;
  252. char passwd[16];
  253. } clientid_t;
  254. /**
  255. * \brief zoo_op structure.
  256. *
  257. * This structure holds all the arguments necessary for one op as part
  258. * of a containing multi_op via \ref zoo_multi or \ref zoo_amulti.
  259. * This structure should be treated as opaque and initialized via
  260. * \ref zoo_create_op_init, \ref zoo_delete_op_init, \ref zoo_set_op_init
  261. * and \ref zoo_check_op_init.
  262. */
  263. typedef struct zoo_op {
  264. int type;
  265. union {
  266. // CREATE
  267. struct {
  268. const char *path;
  269. const char *data;
  270. int datalen;
  271. char *buf;
  272. int buflen;
  273. const struct ACL_vector *acl;
  274. int flags;
  275. } create_op;
  276. // DELETE
  277. struct {
  278. const char *path;
  279. int version;
  280. } delete_op;
  281. // SET
  282. struct {
  283. const char *path;
  284. const char *data;
  285. int datalen;
  286. int version;
  287. struct Stat *stat;
  288. } set_op;
  289. // CHECK
  290. struct {
  291. const char *path;
  292. int version;
  293. } check_op;
  294. };
  295. } zoo_op_t;
  296. /**
  297. * \brief zoo_create_op_init.
  298. *
  299. * This function initializes a zoo_op_t with the arguments for a ZOO_CREATE_OP.
  300. *
  301. * \param op A pointer to the zoo_op_t to be initialized.
  302. * \param path The name of the node. Expressed as a file name with slashes
  303. * separating ancestors of the node.
  304. * \param value The data to be stored in the node.
  305. * \param valuelen The number of bytes in data. To set the data to be NULL use
  306. * value as NULL and valuelen as -1.
  307. * \param acl The initial ACL of the node. The ACL must not be null or empty.
  308. * \param flags this parameter can be set to 0 for normal create or an OR
  309. * of the Create Flags
  310. * \param path_buffer Buffer which will be filled with the path of the
  311. * new node (this might be different than the supplied path
  312. * because of the ZOO_SEQUENCE flag). The path string will always be
  313. * null-terminated. This parameter may be NULL if path_buffer_len = 0.
  314. * \param path_buffer_len Size of path buffer; if the path of the new
  315. * node (including space for the null terminator) exceeds the buffer size,
  316. * the path string will be truncated to fit. The actual path of the
  317. * new node in the server will not be affected by the truncation.
  318. * The path string will always be null-terminated.
  319. */
  320. void zoo_create_op_init(zoo_op_t *op, const char *path, const char *value,
  321. int valuelen, const struct ACL_vector *acl, int flags,
  322. char *path_buffer, int path_buffer_len);
  323. /**
  324. * \brief zoo_delete_op_init.
  325. *
  326. * This function initializes a zoo_op_t with the arguments for a ZOO_DELETE_OP.
  327. *
  328. * \param op A pointer to the zoo_op_t to be initialized.
  329. * \param path the name of the node. Expressed as a file name with slashes
  330. * separating ancestors of the node.
  331. * \param version the expected version of the node. The function will fail if the
  332. * actual version of the node does not match the expected version.
  333. * If -1 is used the version check will not take place.
  334. */
  335. void zoo_delete_op_init(zoo_op_t *op, const char *path, int version);
  336. /**
  337. * \brief zoo_set_op_init.
  338. *
  339. * This function initializes an zoo_op_t with the arguments for a ZOO_SETDATA_OP.
  340. *
  341. * \param op A pointer to the zoo_op_t to be initialized.
  342. * \param path the name of the node. Expressed as a file name with slashes
  343. * separating ancestors of the node.
  344. * \param buffer the buffer holding data to be written to the node.
  345. * \param buflen the number of bytes from buffer to write. To set NULL as data
  346. * use buffer as NULL and buflen as -1.
  347. * \param version the expected version of the node. The function will fail if
  348. * the actual version of the node does not match the expected version. If -1 is
  349. * used the version check will not take place.
  350. */
  351. void zoo_set_op_init(zoo_op_t *op, const char *path, const char *buffer,
  352. int buflen, int version, struct Stat *stat);
  353. /**
  354. * \brief zoo_check_op_init.
  355. *
  356. * This function initializes an zoo_op_t with the arguments for a ZOO_CHECK_OP.
  357. *
  358. * \param op A pointer to the zoo_op_t to be initialized.
  359. * \param path The name of the node. Expressed as a file name with slashes
  360. * separating ancestors of the node.
  361. * \param version the expected version of the node. The function will fail if the
  362. * actual version of the node does not match the expected version.
  363. */
  364. void zoo_check_op_init(zoo_op_t *op, const char *path, int version);
  365. /**
  366. * \brief zoo_op_result structure.
  367. *
  368. * This structure holds the result for an op submitted as part of a multi_op
  369. * via \ref zoo_multi or \ref zoo_amulti.
  370. */
  371. typedef struct zoo_op_result {
  372. int err;
  373. char *value;
  374. int valuelen;
  375. struct Stat *stat;
  376. } zoo_op_result_t;
  377. /**
  378. * \brief signature of a watch function.
  379. *
  380. * There are two ways to receive watch notifications: legacy and watcher object.
  381. * <p>
  382. * The legacy style, an application wishing to receive events from ZooKeeper must
  383. * first implement a function with this signature and pass a pointer to the function
  384. * to \ref zookeeper_init. Next, the application sets a watch by calling one of
  385. * the getter API that accept the watch integer flag (for example, \ref zoo_aexists,
  386. * \ref zoo_get, etc).
  387. * <p>
  388. * The watcher object style uses an instance of a "watcher object" which in
  389. * the C world is represented by a pair: a pointer to a function implementing this
  390. * signature and a pointer to watcher context -- handback user-specific data.
  391. * When a watch is triggered this function will be called along with
  392. * the watcher context. An application wishing to use this style must use
  393. * the getter API functions with the "w" prefix in their names (for example, \ref
  394. * zoo_awexists, \ref zoo_wget, etc).
  395. *
  396. * \param zh zookeeper handle
  397. * \param type event type. This is one of the *_EVENT constants.
  398. * \param state connection state. The state value will be one of the *_STATE constants.
  399. * \param path znode path for which the watcher is triggered. NULL if the event
  400. * type is ZOO_SESSION_EVENT
  401. * \param watcherCtx watcher context.
  402. */
  403. typedef void (*watcher_fn)(zhandle_t *zh, int type,
  404. int state, const char *path,void *watcherCtx);
  405. /**
  406. * \brief typedef for setting the log callback. It's a function pointer which
  407. * returns void and accepts a const char* as its only argument.
  408. *
  409. * \param message message to be passed to the callback function.
  410. */
  411. typedef void (*log_callback_fn)(const char *message);
  412. /**
  413. * \brief create a handle to used communicate with zookeeper.
  414. *
  415. * This method creates a new handle and a zookeeper session that corresponds
  416. * to that handle. Session establishment is asynchronous, meaning that the
  417. * session should not be considered established until (and unless) an
  418. * event of state ZOO_CONNECTED_STATE is received.
  419. * \param host comma separated host:port pairs, each corresponding to a zk
  420. * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
  421. * \param fn the global watcher callback function. When notifications are
  422. * triggered this function will be invoked.
  423. * \param clientid the id of a previously established session that this
  424. * client will be reconnecting to. Pass 0 if not reconnecting to a previous
  425. * session. Clients can access the session id of an established, valid,
  426. * connection by calling \ref zoo_client_id. If the session corresponding to
  427. * the specified clientid has expired, or if the clientid is invalid for
  428. * any reason, the returned zhandle_t will be invalid -- the zhandle_t
  429. * state will indicate the reason for failure (typically
  430. * ZOO_EXPIRED_SESSION_STATE).
  431. * \param context the handback object that will be associated with this instance
  432. * of zhandle_t. Application can access it (for example, in the watcher
  433. * callback) using \ref zoo_get_context. The object is not used by zookeeper
  434. * internally and can be null.
  435. * \param flags reserved for future use. Should be set to zero.
  436. * \return a pointer to the opaque zhandle structure. If it fails to create
  437. * a new zhandle the function returns NULL and the errno variable
  438. * indicates the reason.
  439. */
  440. ZOOAPI zhandle_t *zookeeper_init(const char *host, watcher_fn fn,
  441. int recv_timeout, const clientid_t *clientid, void *context, int flags);
  442. /**
  443. * \brief create a handle to communicate with zookeeper.
  444. *
  445. * This function is identical to \ref zookeeper_init except it allows one
  446. * to specify an additional callback to be used for all logging for that
  447. * specific connection. For more details on the logging callback see
  448. * \ref zoo_get_log_callback and \ref zoo_set_log_callback.
  449. *
  450. * This method creates a new handle and a zookeeper session that corresponds
  451. * to that handle. Session establishment is asynchronous, meaning that the
  452. * session should not be considered established until (and unless) an
  453. * event of state ZOO_CONNECTED_STATE is received.
  454. * \param host comma separated host:port pairs, each corresponding to a zk
  455. * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
  456. * \param fn the global watcher callback function. When notifications are
  457. * triggered this function will be invoked.
  458. * \param clientid the id of a previously established session that this
  459. * client will be reconnecting to. Pass 0 if not reconnecting to a previous
  460. * session. Clients can access the session id of an established, valid,
  461. * connection by calling \ref zoo_client_id. If the session corresponding to
  462. * the specified clientid has expired, or if the clientid is invalid for
  463. * any reason, the returned zhandle_t will be invalid -- the zhandle_t
  464. * state will indicate the reason for failure (typically
  465. * ZOO_EXPIRED_SESSION_STATE).
  466. * \param context the handback object that will be associated with this instance
  467. * of zhandle_t. Application can access it (for example, in the watcher
  468. * callback) using \ref zoo_get_context. The object is not used by zookeeper
  469. * internally and can be null.
  470. * \param flags reserved for future use. Should be set to zero.
  471. * \param log_callback All log messages will be passed to this callback function.
  472. * For more details see \ref zoo_get_log_callback and \ref zoo_set_log_callback.
  473. * \return a pointer to the opaque zhandle structure. If it fails to create
  474. * a new zhandle the function returns NULL and the errno variable
  475. * indicates the reason.
  476. */
  477. ZOOAPI zhandle_t *zookeeper_init2(const char *host, watcher_fn fn,
  478. int recv_timeout, const clientid_t *clientid, void *context, int flags,
  479. log_callback_fn log_callback);
  480. /**
  481. * \brief update the list of servers this client will connect to.
  482. *
  483. * This method allows a client to update the connection string by providing
  484. * a new comma separated list of host:port pairs, each corresponding to a
  485. * ZooKeeper server.
  486. *
  487. * This function invokes a probabilistic load-balancing algorithm which may cause
  488. * the client to disconnect from its current host to achieve expected uniform
  489. * connections per server in the new list. In case the current host to which the
  490. * client is connected is not in the new list this call will always cause the
  491. * connection to be dropped. Otherwise, the decision is based on whether the
  492. * number of servers has increased or decreased and by how much.
  493. *
  494. * If the connection is dropped, the client moves to a special "reconfig" mode
  495. * where he chooses a new server to connect to using the probabilistic algorithm.
  496. * After finding a server or exhaustively trying all the servers in the new list,
  497. * the client moves back to the normal mode of operation where it will pick an
  498. * arbitrary server from the 'host' string.
  499. *
  500. * See {@link https://issues.apache.org/jira/browse/ZOOKEEPER-1355} for the
  501. * protocol and its evaluation,
  502. *
  503. * \param host comma separated host:port pairs, each corresponding to a zk
  504. * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
  505. * \return ZOK on success or one of the following errcodes on failure:
  506. * ZBADARGUMENTS - invalid input parameters
  507. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  508. * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details
  509. */
  510. ZOOAPI int zoo_set_servers(zhandle_t *zh, const char *hosts);
  511. /**
  512. * \brief cycle to the next server on the next connection attempt.
  513. *
  514. * Note: typically this method should NOT be used outside of testing.
  515. *
  516. * This method allows a client to cycle through the list of servers in it's
  517. * connection pool to be used on the next connection attempt. This function does
  518. * not actually trigger a connection or state change in any way. Its purpose is
  519. * to allow testing changing servers on the fly and the probabilistic load
  520. * balancing algorithm.
  521. */
  522. ZOOAPI void zoo_cycle_next_server(zhandle_t *zh);
  523. /**
  524. * \brief get current host:port this client is connecting/connected to.
  525. *
  526. * Note: typically this method should NOT be used outside of testing.
  527. *
  528. * This method allows a client to get the current host:port that this client
  529. * is either in the process of connecting to or is currently connected to. This
  530. * is mainly used for testing purposes but might also come in handy as a general
  531. * purpose tool to be used by other clients.
  532. */
  533. ZOOAPI const char* zoo_get_current_server(zhandle_t* zh);
  534. /**
  535. * \brief close the zookeeper handle and free up any resources.
  536. *
  537. * After this call, the client session will no longer be valid. The function
  538. * will flush any outstanding send requests before return. As a result it may
  539. * block.
  540. *
  541. * This method should only be called only once on a zookeeper handle. Calling
  542. * twice will cause undefined (and probably undesirable behavior). Calling any other
  543. * zookeeper method after calling close is undefined behaviour and should be avoided.
  544. *
  545. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  546. * \return a result code. Regardless of the error code returned, the zhandle
  547. * will be destroyed and all resources freed.
  548. *
  549. * ZOK - success
  550. * ZBADARGUMENTS - invalid input parameters
  551. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  552. * ZOPERATIONTIMEOUT - failed to flush the buffers within the specified timeout.
  553. * ZCONNECTIONLOSS - a network error occured while attempting to send request to server
  554. * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details
  555. */
  556. ZOOAPI int zookeeper_close(zhandle_t *zh);
  557. /**
  558. * \brief return the client session id, only valid if the connections
  559. * is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE)
  560. */
  561. ZOOAPI const clientid_t *zoo_client_id(zhandle_t *zh);
  562. /**
  563. * \brief return the timeout for this session, only valid if the connections
  564. * is currently connected (ie. last watcher state is ZOO_CONNECTED_STATE). This
  565. * value may change after a server re-connect.
  566. */
  567. ZOOAPI int zoo_recv_timeout(zhandle_t *zh);
  568. /**
  569. * \brief return the context for this handle.
  570. */
  571. ZOOAPI const void *zoo_get_context(zhandle_t *zh);
  572. /**
  573. * \brief set the context for this handle.
  574. */
  575. ZOOAPI void zoo_set_context(zhandle_t *zh, void *context);
  576. /**
  577. * \brief set a watcher function
  578. * \return previous watcher function
  579. */
  580. ZOOAPI watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn);
  581. /**
  582. * \brief returns the socket address for the current connection
  583. * \return socket address of the connected host or NULL on failure, only valid if the
  584. * connection is current connected
  585. */
  586. ZOOAPI struct sockaddr* zookeeper_get_connected_host(zhandle_t *zh,
  587. struct sockaddr *addr, socklen_t *addr_len);
  588. #ifndef THREADED
  589. /**
  590. * \brief Returns the events that zookeeper is interested in.
  591. *
  592. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  593. * \param fd is the file descriptor of interest
  594. * \param interest is an or of the ZOOKEEPER_WRITE and ZOOKEEPER_READ flags to
  595. * indicate the I/O of interest on fd.
  596. * \param tv a timeout value to be used with select/poll system call
  597. * \return a result code.
  598. * ZOK - success
  599. * ZBADARGUMENTS - invalid input parameters
  600. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  601. * ZCONNECTIONLOSS - a network error occured while attempting to establish
  602. * a connection to the server
  603. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  604. * ZOPERATIONTIMEOUT - hasn't received anything from the server for 2/3 of the
  605. * timeout value specified in zookeeper_init()
  606. * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details
  607. */
  608. #ifdef WIN32
  609. ZOOAPI int zookeeper_interest(zhandle_t *zh, SOCKET *fd, int *interest,
  610. struct timeval *tv);
  611. #else
  612. ZOOAPI int zookeeper_interest(zhandle_t *zh, int *fd, int *interest,
  613. struct timeval *tv);
  614. #endif
  615. /**
  616. * \brief Notifies zookeeper that an event of interest has happened.
  617. *
  618. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  619. * \param events will be an OR of the ZOOKEEPER_WRITE and ZOOKEEPER_READ flags.
  620. * \return a result code.
  621. * ZOK - success
  622. * ZBADARGUMENTS - invalid input parameters
  623. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  624. * ZCONNECTIONLOSS - a network error occured while attempting to send request to server
  625. * ZSESSIONEXPIRED - connection attempt failed -- the session's expired
  626. * ZAUTHFAILED - authentication request failed, e.i. invalid credentials
  627. * ZRUNTIMEINCONSISTENCY - a server response came out of order
  628. * ZSYSTEMERROR -- a system (OS) error occured; it's worth checking errno to get details
  629. * ZNOTHING -- not an error; simply indicates that there no more data from the server
  630. * to be processed (when called with ZOOKEEPER_READ flag).
  631. */
  632. ZOOAPI int zookeeper_process(zhandle_t *zh, int events);
  633. #endif
  634. /**
  635. * \brief signature of a completion function for a call that returns void.
  636. *
  637. * This method will be invoked at the end of a asynchronous call and also as
  638. * a result of connection loss or timeout.
  639. * \param rc the error code of the call. Connection loss/timeout triggers
  640. * the completion with one of the following error codes:
  641. * ZCONNECTIONLOSS -- lost connection to the server
  642. * ZOPERATIONTIMEOUT -- connection timed out
  643. * Data related events trigger the completion with error codes listed the
  644. * Exceptions section of the documentation of the function that initiated the
  645. * call. (Zero indicates call was successful.)
  646. * \param data the pointer that was passed by the caller when the function
  647. * that this completion corresponds to was invoked. The programmer
  648. * is responsible for any memory freeing associated with the data
  649. * pointer.
  650. */
  651. typedef void (*void_completion_t)(int rc, const void *data);
  652. /**
  653. * \brief signature of a completion function that returns a Stat structure.
  654. *
  655. * This method will be invoked at the end of a asynchronous call and also as
  656. * a result of connection loss or timeout.
  657. * \param rc the error code of the call. Connection loss/timeout triggers
  658. * the completion with one of the following error codes:
  659. * ZCONNECTIONLOSS -- lost connection to the server
  660. * ZOPERATIONTIMEOUT -- connection timed out
  661. * Data related events trigger the completion with error codes listed the
  662. * Exceptions section of the documentation of the function that initiated the
  663. * call. (Zero indicates call was successful.)
  664. * \param stat a pointer to the stat information for the node involved in
  665. * this function. If a non zero error code is returned, the content of
  666. * stat is undefined. The programmer is NOT responsible for freeing stat.
  667. * \param data the pointer that was passed by the caller when the function
  668. * that this completion corresponds to was invoked. The programmer
  669. * is responsible for any memory freeing associated with the data
  670. * pointer.
  671. */
  672. typedef void (*stat_completion_t)(int rc, const struct Stat *stat,
  673. const void *data);
  674. /**
  675. * \brief signature of a completion function that returns data.
  676. *
  677. * This method will be invoked at the end of a asynchronous call and also as
  678. * a result of connection loss or timeout.
  679. * \param rc the error code of the call. Connection loss/timeout triggers
  680. * the completion with one of the following error codes:
  681. * ZCONNECTIONLOSS -- lost connection to the server
  682. * ZOPERATIONTIMEOUT -- connection timed out
  683. * Data related events trigger the completion with error codes listed the
  684. * Exceptions section of the documentation of the function that initiated the
  685. * call. (Zero indicates call was successful.)
  686. * \param value the value of the information returned by the asynchronous call.
  687. * If a non zero error code is returned, the content of value is undefined.
  688. * The programmer is NOT responsible for freeing value.
  689. * \param value_len the number of bytes in value.
  690. * \param stat a pointer to the stat information for the node involved in
  691. * this function. If a non zero error code is returned, the content of
  692. * stat is undefined. The programmer is NOT responsible for freeing stat.
  693. * \param data the pointer that was passed by the caller when the function
  694. * that this completion corresponds to was invoked. The programmer
  695. * is responsible for any memory freeing associated with the data
  696. * pointer.
  697. */
  698. typedef void (*data_completion_t)(int rc, const char *value, int value_len,
  699. const struct Stat *stat, const void *data);
  700. /**
  701. * \brief signature of a completion function that returns a list of strings.
  702. *
  703. * This method will be invoked at the end of a asynchronous call and also as
  704. * a result of connection loss or timeout.
  705. * \param rc the error code of the call. Connection loss/timeout triggers
  706. * the completion with one of the following error codes:
  707. * ZCONNECTIONLOSS -- lost connection to the server
  708. * ZOPERATIONTIMEOUT -- connection timed out
  709. * Data related events trigger the completion with error codes listed the
  710. * Exceptions section of the documentation of the function that initiated the
  711. * call. (Zero indicates call was successful.)
  712. * \param strings a pointer to the structure containng the list of strings of the
  713. * names of the children of a node. If a non zero error code is returned,
  714. * the content of strings is undefined. The programmer is NOT responsible
  715. * for freeing strings.
  716. * \param data the pointer that was passed by the caller when the function
  717. * that this completion corresponds to was invoked. The programmer
  718. * is responsible for any memory freeing associated with the data
  719. * pointer.
  720. */
  721. typedef void (*strings_completion_t)(int rc,
  722. const struct String_vector *strings, const void *data);
  723. /**
  724. * \brief signature of a completion function that returns a string and stat.
  725. * .
  726. *
  727. * This method will be invoked at the end of a asynchronous call and also as
  728. * a result of connection loss or timeout.
  729. * \param rc the error code of the call. Connection loss/timeout triggers
  730. * the completion with one of the following error codes:
  731. * ZCONNECTIONLOSS -- lost connection to the server
  732. * ZOPERATIONTIMEOUT -- connection timed out
  733. * Data related events trigger the completion with error codes listed the
  734. * Exceptions section of the documentation of the function that initiated the
  735. * call. (Zero indicates call was successful.)
  736. * \param value the value of the string returned.
  737. * \param stat a pointer to the stat information for the node involved in
  738. * this function. If a non zero error code is returned, the content of
  739. * stat is undefined. The programmer is NOT responsible for freeing stat.
  740. * \param data the pointer that was passed by the caller when the function
  741. * that this completion corresponds to was invoked. The programmer
  742. * is responsible for any memory freeing associated with the data
  743. * pointer.
  744. */
  745. typedef void (*string_stat_completion_t)(int rc,
  746. const char *string, const struct Stat *stat, const void *data);
  747. /**
  748. * \brief signature of a completion function that returns a list of strings and stat.
  749. * .
  750. *
  751. * This method will be invoked at the end of a asynchronous call and also as
  752. * a result of connection loss or timeout.
  753. * \param rc the error code of the call. Connection loss/timeout triggers
  754. * the completion with one of the following error codes:
  755. * ZCONNECTIONLOSS -- lost connection to the server
  756. * ZOPERATIONTIMEOUT -- connection timed out
  757. * Data related events trigger the completion with error codes listed the
  758. * Exceptions section of the documentation of the function that initiated the
  759. * call. (Zero indicates call was successful.)
  760. * \param strings a pointer to the structure containng the list of strings of the
  761. * names of the children of a node. If a non zero error code is returned,
  762. * the content of strings is undefined. The programmer is NOT responsible
  763. * for freeing strings.
  764. * \param stat a pointer to the stat information for the node involved in
  765. * this function. If a non zero error code is returned, the content of
  766. * stat is undefined. The programmer is NOT responsible for freeing stat.
  767. * \param data the pointer that was passed by the caller when the function
  768. * that this completion corresponds to was invoked. The programmer
  769. * is responsible for any memory freeing associated with the data
  770. * pointer.
  771. */
  772. typedef void (*strings_stat_completion_t)(int rc,
  773. const struct String_vector *strings, const struct Stat *stat,
  774. const void *data);
  775. /**
  776. * \brief signature of a completion function that returns a list of strings.
  777. *
  778. * This method will be invoked at the end of a asynchronous call and also as
  779. * a result of connection loss or timeout.
  780. * \param rc the error code of the call. Connection loss/timeout triggers
  781. * the completion with one of the following error codes:
  782. * ZCONNECTIONLOSS -- lost connection to the server
  783. * ZOPERATIONTIMEOUT -- connection timed out
  784. * Data related events trigger the completion with error codes listed the
  785. * Exceptions section of the documentation of the function that initiated the
  786. * call. (Zero indicates call was successful.)
  787. * \param value the value of the string returned.
  788. * \param data the pointer that was passed by the caller when the function
  789. * that this completion corresponds to was invoked. The programmer
  790. * is responsible for any memory freeing associated with the data
  791. * pointer.
  792. */
  793. typedef void
  794. (*string_completion_t)(int rc, const char *value, const void *data);
  795. /**
  796. * \brief signature of a completion function that returns an ACL.
  797. *
  798. * This method will be invoked at the end of a asynchronous call and also as
  799. * a result of connection loss or timeout.
  800. * \param rc the error code of the call. Connection loss/timeout triggers
  801. * the completion with one of the following error codes:
  802. * ZCONNECTIONLOSS -- lost connection to the server
  803. * ZOPERATIONTIMEOUT -- connection timed out
  804. * Data related events trigger the completion with error codes listed the
  805. * Exceptions section of the documentation of the function that initiated the
  806. * call. (Zero indicates call was successful.)
  807. * \param acl a pointer to the structure containng the ACL of a node. If a non
  808. * zero error code is returned, the content of strings is undefined. The
  809. * programmer is NOT responsible for freeing acl.
  810. * \param stat a pointer to the stat information for the node involved in
  811. * this function. If a non zero error code is returned, the content of
  812. * stat is undefined. The programmer is NOT responsible for freeing stat.
  813. * \param data the pointer that was passed by the caller when the function
  814. * that this completion corresponds to was invoked. The programmer
  815. * is responsible for any memory freeing associated with the data
  816. * pointer.
  817. */
  818. typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl,
  819. struct Stat *stat, const void *data);
  820. /**
  821. * \brief get the state of the zookeeper connection.
  822. *
  823. * The return value will be one of the \ref State Consts.
  824. */
  825. ZOOAPI int zoo_state(zhandle_t *zh);
  826. /**
  827. * \brief create a node.
  828. *
  829. * This method will create a node in ZooKeeper. A node can only be created if
  830. * it does not already exists. The Create Flags affect the creation of nodes.
  831. * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the
  832. * client session goes away. If the ZOO_SEQUENCE flag is set, a unique
  833. * monotonically increasing sequence number is appended to the path name. The
  834. * sequence number is always fixed length of 10 digits, 0 padded.
  835. *
  836. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  837. * \param path The name of the node. Expressed as a file name with slashes
  838. * separating ancestors of the node.
  839. * \param value The data to be stored in the node.
  840. * \param valuelen The number of bytes in data.
  841. * \param acl The initial ACL of the node. The ACL must not be null or empty.
  842. * \param flags this parameter can be set to 0 for normal create or an OR
  843. * of the Create Flags
  844. * \param completion the routine to invoke when the request completes. The completion
  845. * will be triggered with one of the following codes passed in as the rc argument:
  846. * ZOK operation completed successfully
  847. * ZNONODE the parent node does not exist.
  848. * ZNODEEXISTS the node already exists
  849. * ZNOAUTH the client does not have permission.
  850. * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.
  851. * \param data The data that will be passed to the completion routine when the
  852. * function completes.
  853. * \return ZOK on success or one of the following errcodes on failure:
  854. * ZBADARGUMENTS - invalid input parameters
  855. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  856. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  857. */
  858. ZOOAPI int zoo_acreate(zhandle_t *zh, const char *path, const char *value,
  859. int valuelen, const struct ACL_vector *acl, int flags,
  860. string_completion_t completion, const void *data);
  861. /**
  862. * \brief create a node asynchronously and returns stat details.
  863. *
  864. * This method will create a node in ZooKeeper. A node can only be created if
  865. * it does not already exists. The Create Flags affect the creation of nodes.
  866. * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the
  867. * client session goes away. If the ZOO_SEQUENCE flag is set, a unique
  868. * monotonically increasing sequence number is appended to the path name. The
  869. * sequence number is always fixed length of 10 digits, 0 padded.
  870. *
  871. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  872. * \param path The name of the node. Expressed as a file name with slashes
  873. * separating ancestors of the node.
  874. * \param value The data to be stored in the node.
  875. * \param valuelen The number of bytes in data.
  876. * \param acl The initial ACL of the node. The ACL must not be null or empty.
  877. * \param flags this parameter can be set to 0 for normal create or an OR
  878. * of the Create Flags
  879. * \param completion the routine to invoke when the request completes. The completion
  880. * will be triggered with one of the following codes passed in as the rc argument:
  881. * ZOK operation completed successfully
  882. * ZNONODE the parent node does not exist.
  883. * ZNODEEXISTS the node already exists
  884. * ZNOAUTH the client does not have permission.
  885. * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.
  886. * \param data The data that will be passed to the completion routine when the
  887. * function completes.
  888. * \return ZOK on success or one of the following errcodes on failure:
  889. * ZBADARGUMENTS - invalid input parameters
  890. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  891. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  892. */
  893. ZOOAPI int zoo_acreate2(zhandle_t *zh, const char *path, const char *value,
  894. int valuelen, const struct ACL_vector *acl, int flags,
  895. string_stat_completion_t completion, const void *data);
  896. /**
  897. * \brief delete a node in zookeeper.
  898. *
  899. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  900. * \param path the name of the node. Expressed as a file name with slashes
  901. * separating ancestors of the node.
  902. * \param version the expected version of the node. The function will fail if the
  903. * actual version of the node does not match the expected version.
  904. * If -1 is used the version check will not take place.
  905. * \param completion the routine to invoke when the request completes. The completion
  906. * will be triggered with one of the following codes passed in as the rc argument:
  907. * ZOK operation completed successfully
  908. * ZNONODE the node does not exist.
  909. * ZNOAUTH the client does not have permission.
  910. * ZBADVERSION expected version does not match actual version.
  911. * ZNOTEMPTY children are present; node cannot be deleted.
  912. * \param data the data that will be passed to the completion routine when
  913. * the function completes.
  914. * \return ZOK on success or one of the following errcodes on failure:
  915. * ZBADARGUMENTS - invalid input parameters
  916. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  917. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  918. */
  919. ZOOAPI int zoo_adelete(zhandle_t *zh, const char *path, int version,
  920. void_completion_t completion, const void *data);
  921. /**
  922. * \brief checks the existence of a node in zookeeper.
  923. *
  924. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  925. * \param path the name of the node. Expressed as a file name with slashes
  926. * separating ancestors of the node.
  927. * \param watch if nonzero, a watch will be set at the server to notify the
  928. * client if the node changes. The watch will be set even if the node does not
  929. * exist. This allows clients to watch for nodes to appear.
  930. * \param completion the routine to invoke when the request completes. The completion
  931. * will be triggered with one of the following codes passed in as the rc argument:
  932. * ZOK operation completed successfully
  933. * ZNONODE the node does not exist.
  934. * ZNOAUTH the client does not have permission.
  935. * \param data the data that will be passed to the completion routine when the
  936. * function completes.
  937. * \return ZOK on success or one of the following errcodes on failure:
  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_aexists(zhandle_t *zh, const char *path, int watch,
  943. stat_completion_t completion, const void *data);
  944. /**
  945. * \brief checks the existence of a node in zookeeper.
  946. *
  947. * This function is similar to \ref zoo_axists except it allows one specify
  948. * a watcher object - a function pointer and associated context. The function
  949. * will be called once the watch has fired. The associated context data will be
  950. * passed to the function as the watcher context parameter.
  951. *
  952. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  953. * \param path the name of the node. Expressed as a file name with slashes
  954. * separating ancestors of the node.
  955. * \param watcher if non-null a watch will set on the specified znode on the server.
  956. * The watch will be set even if the node does not exist. This allows clients
  957. * to watch for nodes to appear.
  958. * \param watcherCtx user specific data, will be passed to the watcher callback.
  959. * Unlike the global context set by \ref zookeeper_init, this watcher context
  960. * is associated with the given instance of the watcher only.
  961. * \param completion the routine to invoke when the request completes. The completion
  962. * will be triggered with one of the following codes passed in as the rc argument:
  963. * ZOK operation completed successfully
  964. * ZNONODE the node does not exist.
  965. * ZNOAUTH the client does not have permission.
  966. * \param data the data that will be passed to the completion routine when the
  967. * function completes.
  968. * \return ZOK on success or one of the following errcodes on failure:
  969. * ZBADARGUMENTS - invalid input parameters
  970. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  971. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  972. */
  973. ZOOAPI int zoo_awexists(zhandle_t *zh, const char *path,
  974. watcher_fn watcher, void* watcherCtx,
  975. stat_completion_t completion, const void *data);
  976. /**
  977. * \brief gets the data associated with a node.
  978. *
  979. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  980. * \param path the name of the node. Expressed as a file name with slashes
  981. * separating ancestors of the node.
  982. * \param watch if nonzero, a watch will be set at the server to notify
  983. * the client if the node changes.
  984. * \param completion the routine to invoke when the request completes. The completion
  985. * will be triggered with one of the following codes passed in as the rc argument:
  986. * ZOK operation completed successfully
  987. * ZNONODE the node does not exist.
  988. * ZNOAUTH the client does not have permission.
  989. * \param data the data that will be passed to the completion routine when
  990. * the function completes.
  991. * \return ZOK on success or one of the following errcodes on failure:
  992. * ZBADARGUMENTS - invalid input parameters
  993. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  994. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  995. */
  996. ZOOAPI int zoo_aget(zhandle_t *zh, const char *path, int watch,
  997. data_completion_t completion, const void *data);
  998. /**
  999. * \brief gets the data associated with a node.
  1000. *
  1001. * This function is similar to \ref zoo_aget except it allows one specify
  1002. * a watcher object rather than a boolean watch flag.
  1003. *
  1004. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1005. * \param path the name of the node. Expressed as a file name with slashes
  1006. * separating ancestors of the node.
  1007. * \param watcher if non-null, a watch will be set at the server to notify
  1008. * the client if the node changes.
  1009. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1010. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1011. * is associated with the given instance of the watcher only.
  1012. * \param completion the routine to invoke when the request completes. The completion
  1013. * will be triggered with one of the following codes passed in as the rc argument:
  1014. * ZOK operation completed successfully
  1015. * ZNONODE the node does not exist.
  1016. * ZNOAUTH the client does not have permission.
  1017. * \param data the data that will be passed to the completion routine when
  1018. * the function completes.
  1019. * \return ZOK on success or one of the following errcodes on failure:
  1020. * ZBADARGUMENTS - invalid input parameters
  1021. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1022. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1023. */
  1024. ZOOAPI int zoo_awget(zhandle_t *zh, const char *path,
  1025. watcher_fn watcher, void* watcherCtx,
  1026. data_completion_t completion, const void *data);
  1027. /**
  1028. * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to
  1029. * the server to which the client is connected.
  1030. *
  1031. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1032. * \param watch if nonzero, a watch will be set at the server to notify
  1033. * the client if the configuration changes.
  1034. * \param completion the routine to invoke when the request completes. The completion
  1035. * will be triggered with one of the following codes passed in as the rc argument:
  1036. * ZOK operation completed successfully
  1037. * ZNONODE the configuration node (/zookeeper/config) does not exist.
  1038. * ZNOAUTH the client does not have permission to access the configuration node.
  1039. * \param data the configuration data that will be passed to the completion routine when
  1040. * the function completes.
  1041. * \return ZOK on success or one of the following errcodes on failure:
  1042. * ZBADARGUMENTS - invalid input parameters
  1043. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1044. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1045. */
  1046. ZOOAPI int zoo_agetconfig(zhandle_t *zh, int watch,
  1047. data_completion_t completion, const void *data);
  1048. /**
  1049. * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to
  1050. * the server to which the client is connected.
  1051. *
  1052. * This function is similar to \ref zoo_agetconfig except it allows one specify
  1053. * a watcher object rather than a boolean watch flag.
  1054. *
  1055. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1056. * \param watcher if non-null, a watch will be set at the server to notify
  1057. * the client if the node changes.
  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 completion the routine to invoke when the request completes. The completion
  1062. * will be triggered with one of the following codes passed in as the rc argument:
  1063. * ZOK operation completed successfully
  1064. * ZNONODE the configuration node (/zookeeper/config) does not exist.
  1065. * ZNOAUTH the client does not have permission to access the configuration node.
  1066. * \param data the configuration data that will be passed to the completion routine when
  1067. * the function completes.
  1068. * \return ZOK on success or one of the following errcodes on failure:
  1069. * ZBADARGUMENTS - invalid input parameters
  1070. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1071. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1072. */
  1073. ZOOAPI int zoo_awgetconfig(zhandle_t *zh, watcher_fn watcher, void* watcherCtx,
  1074. data_completion_t completion, const void *data);
  1075. /**
  1076. * \brief asynchronous reconfiguration interface - allows changing ZK cluster
  1077. * ensemble membership and roles of ensemble peers.
  1078. *
  1079. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1080. * \param joining - comma separated list of servers to be added to the ensemble.
  1081. * Each has a configuration line for a server to be added (as would appear in a
  1082. * configuration file), only for maj. quorums. NULL for non-incremental reconfiguration.
  1083. * \param leaving - comma separated list of server IDs to be removed from the ensemble.
  1084. * Each has an id of a server to be removed, only for maj. quorums. NULL for
  1085. * non-incremental reconfiguration.
  1086. * \param members - comma separated list of new membership (e.g., contents of a
  1087. * membership configuration file) - for use only with a non-incremental
  1088. * reconfiguration. NULL for incremental reconfiguration.
  1089. * \param version - version of config from which we want to reconfigure - if
  1090. * current config is different reconfiguration will fail. Should be -1 to disable
  1091. * this option.
  1092. * \param completion - the routine to invoke when the request completes. The
  1093. * completion will be triggered with one of the following codes passed in as the
  1094. * rc argument:
  1095. * ZOK operation completed successfully
  1096. * \param data the configuration data that will be passed to the completion routine
  1097. * when the function completes.
  1098. * \return return value of the function call.
  1099. * ZOK operation completed successfully
  1100. * ZBADARGUMENTS - invalid input parameters (one case when this is returned is
  1101. * when the new config has less than 2 servers)
  1102. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1103. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1104. * ZNEWCONFIGNOQUORUM - no quorum of new config is connected and up-to-date with
  1105. * the leader of last committed config - try invoking reconfiguration after new servers are connected and synced
  1106. * ZRECONFIGINPROGRESS - another reconfig is currently in progress
  1107. */
  1108. ZOOAPI int zoo_areconfig(zhandle_t *zh, const char *joining, const char *leaving,
  1109. const char *members, int64_t version, data_completion_t dc, const void *data);
  1110. /**
  1111. * \brief sets the data associated with a node.
  1112. *
  1113. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1114. * \param path the name of the node. Expressed as a file name with slashes
  1115. * separating ancestors of the node.
  1116. * \param buffer the buffer holding data to be written to the node.
  1117. * \param buflen the number of bytes from buffer to write.
  1118. * \param version the expected version of the node. The function will fail if
  1119. * the actual version of the node does not match the expected version. If -1 is
  1120. * used the version check will not take place. * completion: If null,
  1121. * the function will execute synchronously. Otherwise, the function will return
  1122. * immediately and invoke the completion routine when the request completes.
  1123. * \param completion the routine to invoke when the request completes. The completion
  1124. * will be triggered with one of the following codes passed in as the rc argument:
  1125. * ZOK operation completed successfully
  1126. * ZNONODE the node does not exist.
  1127. * ZNOAUTH the client does not have permission.
  1128. * ZBADVERSION expected version does not match actual version.
  1129. * \param data the data that will be passed to the completion routine when
  1130. * the function completes.
  1131. * \return ZOK on success or one of the following errcodes on failure:
  1132. * ZBADARGUMENTS - invalid input parameters
  1133. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1134. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1135. */
  1136. ZOOAPI int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen,
  1137. int version, stat_completion_t completion, const void *data);
  1138. /**
  1139. * \brief lists the children of a node.
  1140. *
  1141. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1142. * \param path the name of the node. Expressed as a file name with slashes
  1143. * separating ancestors of the node.
  1144. * \param watch if nonzero, a watch will be set at the server to notify
  1145. * the client if the node changes.
  1146. * \param completion the routine to invoke when the request completes. The completion
  1147. * will be triggered with one of the following codes passed in as the rc argument:
  1148. * ZOK operation completed successfully
  1149. * ZNONODE the node does not exist.
  1150. * ZNOAUTH the client does not have permission.
  1151. * \param data the data that will be passed to the completion routine when
  1152. * the function completes.
  1153. * \return ZOK on success or one of the following errcodes on failure:
  1154. * ZBADARGUMENTS - invalid input parameters
  1155. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1156. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1157. */
  1158. ZOOAPI int zoo_aget_children(zhandle_t *zh, const char *path, int watch,
  1159. strings_completion_t completion, const void *data);
  1160. /**
  1161. * \brief lists the children of a node.
  1162. *
  1163. * This function is similar to \ref zoo_aget_children except it allows one specify
  1164. * a watcher object rather than a boolean watch flag.
  1165. *
  1166. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1167. * \param path the name of the node. Expressed as a file name with slashes
  1168. * separating ancestors of the node.
  1169. * \param watcher if non-null, a watch will be set at the server to notify
  1170. * the client if the node changes.
  1171. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1172. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1173. * is associated with the given instance of the watcher only.
  1174. * \param completion the routine to invoke when the request completes. The completion
  1175. * will be triggered with one of the following codes passed in as the rc argument:
  1176. * ZOK operation completed successfully
  1177. * ZNONODE the node does not exist.
  1178. * ZNOAUTH the client does not have permission.
  1179. * \param data the data that will be passed to the completion routine when
  1180. * the function completes.
  1181. * \return ZOK on success or one of the following errcodes on failure:
  1182. * ZBADARGUMENTS - invalid input parameters
  1183. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1184. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1185. */
  1186. ZOOAPI int zoo_awget_children(zhandle_t *zh, const char *path,
  1187. watcher_fn watcher, void* watcherCtx,
  1188. strings_completion_t completion, const void *data);
  1189. /**
  1190. * \brief lists the children of a node, and get the parent stat.
  1191. *
  1192. * This function is new in version 3.3.0
  1193. *
  1194. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1195. * \param path the name of the node. Expressed as a file name with slashes
  1196. * separating ancestors of the node.
  1197. * \param watch if nonzero, a watch will be set at the server to notify
  1198. * the client if the node changes.
  1199. * \param completion the routine to invoke when the request completes. The completion
  1200. * will be triggered with one of the following codes passed in as the rc argument:
  1201. * ZOK operation completed successfully
  1202. * ZNONODE the node does not exist.
  1203. * ZNOAUTH the client does not have permission.
  1204. * \param data the data that will be passed to the completion routine when
  1205. * the function completes.
  1206. * \return ZOK on success or one of the following errcodes on failure:
  1207. * ZBADARGUMENTS - invalid input parameters
  1208. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1209. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1210. */
  1211. ZOOAPI int zoo_aget_children2(zhandle_t *zh, const char *path, int watch,
  1212. strings_stat_completion_t completion, const void *data);
  1213. /**
  1214. * \brief lists the children of a node, and get the parent stat.
  1215. *
  1216. * This function is similar to \ref zoo_aget_children2 except it allows one specify
  1217. * a watcher object rather than a boolean watch flag.
  1218. *
  1219. * This function is new in version 3.3.0
  1220. *
  1221. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1222. * \param path the name of the node. Expressed as a file name with slashes
  1223. * separating ancestors of the node.
  1224. * \param watcher if non-null, a watch will be set at the server to notify
  1225. * the client if the node changes.
  1226. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1227. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1228. * is associated with the given instance of the watcher only.
  1229. * \param completion the routine to invoke when the request completes. The completion
  1230. * will be triggered with one of the following codes passed in as the rc argument:
  1231. * ZOK operation completed successfully
  1232. * ZNONODE the node does not exist.
  1233. * ZNOAUTH the client does not have permission.
  1234. * \param data the data that will be passed to the completion routine when
  1235. * the function completes.
  1236. * \return ZOK on success or one of the following errcodes on failure:
  1237. * ZBADARGUMENTS - invalid input parameters
  1238. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1239. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1240. */
  1241. ZOOAPI int zoo_awget_children2(zhandle_t *zh, const char *path,
  1242. watcher_fn watcher, void* watcherCtx,
  1243. strings_stat_completion_t completion, const void *data);
  1244. /**
  1245. * \brief Flush leader channel.
  1246. *
  1247. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1248. * \param path the name of the node. Expressed as a file name with slashes
  1249. * separating ancestors of the node.
  1250. * \param completion the routine to invoke when the request completes. The completion
  1251. * will be triggered with one of the following codes passed in as the rc argument:
  1252. * ZOK operation completed successfully
  1253. * ZNONODE the node does not exist.
  1254. * ZNOAUTH the client does not have permission.
  1255. * \param data the data that will be passed to the completion routine when
  1256. * the function completes.
  1257. * \return ZOK on success or one of the following errcodes on failure:
  1258. * ZBADARGUMENTS - invalid input parameters
  1259. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1260. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1261. */
  1262. ZOOAPI int zoo_async(zhandle_t *zh, const char *path,
  1263. string_completion_t completion, const void *data);
  1264. /**
  1265. * \brief gets the acl associated with a node.
  1266. *
  1267. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1268. * \param path the name of the node. Expressed as a file name with slashes
  1269. * separating ancestors of the node.
  1270. * \param completion the routine to invoke when the request completes. The completion
  1271. * will be triggered with one of the following codes passed in as the rc argument:
  1272. * ZOK operation completed successfully
  1273. * ZNONODE the node does not exist.
  1274. * ZNOAUTH the client does not have permission.
  1275. * \param data the data that will be passed to the completion routine when
  1276. * the function completes.
  1277. * \return ZOK on success or one of the following errcodes on failure:
  1278. * ZBADARGUMENTS - invalid input parameters
  1279. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1280. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1281. */
  1282. ZOOAPI int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion,
  1283. const void *data);
  1284. /**
  1285. * \brief sets the acl associated with a node.
  1286. *
  1287. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1288. * \param path the name of the node. Expressed as a file name with slashes
  1289. * separating ancestors of the node.
  1290. * \param buffer the buffer holding the acls to be written to the node.
  1291. * \param buflen the number of bytes from buffer to write.
  1292. * \param completion the routine to invoke when the request completes. The completion
  1293. * will be triggered with one of the following codes passed in as the rc argument:
  1294. * ZOK operation completed successfully
  1295. * ZNONODE the node does not exist.
  1296. * ZNOAUTH the client does not have permission.
  1297. * ZINVALIDACL invalid ACL specified
  1298. * ZBADVERSION expected version does not match actual version.
  1299. * \param data the data that will be passed to the completion routine when
  1300. * the function completes.
  1301. * \return ZOK on success or one of the following errcodes on failure:
  1302. * ZBADARGUMENTS - invalid input parameters
  1303. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1304. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1305. */
  1306. ZOOAPI int zoo_aset_acl(zhandle_t *zh, const char *path, int version,
  1307. struct ACL_vector *acl, void_completion_t, const void *data);
  1308. /**
  1309. * \brief atomically commits multiple zookeeper operations.
  1310. *
  1311. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1312. * \param count the number of operations
  1313. * \param ops an array of operations to commit
  1314. * \param results an array to hold the results of the operations
  1315. * \param completion the routine to invoke when the request completes. The completion
  1316. * will be triggered with any of the error codes that can that can be returned by the
  1317. * ops supported by a multi op (see \ref zoo_acreate, \ref zoo_adelete, \ref zoo_aset).
  1318. * \param data the data that will be passed to the completion routine when
  1319. * the function completes.
  1320. * \return the return code for the function call. This can be any of the
  1321. * values that can be returned by the ops supported by a multi op (see
  1322. * \ref zoo_acreate, \ref zoo_adelete, \ref zoo_aset).
  1323. */
  1324. ZOOAPI int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops,
  1325. zoo_op_result_t *results, void_completion_t, const void *data);
  1326. /**
  1327. * \brief return an error string.
  1328. *
  1329. * \param return code
  1330. * \return string corresponding to the return code
  1331. */
  1332. ZOOAPI const char* zerror(int c);
  1333. /**
  1334. * \brief specify application credentials.
  1335. *
  1336. * The application calls this function to specify its credentials for purposes
  1337. * of authentication. The server will use the security provider specified by
  1338. * the scheme parameter to authenticate the client connection. If the
  1339. * authentication request has failed:
  1340. * - the server connection is dropped
  1341. * - the watcher is called with the ZOO_AUTH_FAILED_STATE value as the state
  1342. * parameter.
  1343. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1344. * \param scheme the id of authentication scheme. Natively supported:
  1345. * "digest" password-based authentication
  1346. * \param cert application credentials. The actual value depends on the scheme.
  1347. * \param certLen the length of the data parameter
  1348. * \param completion the routine to invoke when the request completes. One of
  1349. * the following result codes may be passed into the completion callback:
  1350. * ZOK operation completed successfully
  1351. * ZAUTHFAILED authentication failed
  1352. * \param data the data that will be passed to the completion routine when the
  1353. * function completes.
  1354. * \return ZOK on success or one of the following errcodes on failure:
  1355. * ZBADARGUMENTS - invalid input parameters
  1356. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1357. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1358. * ZSYSTEMERROR - a system error occured
  1359. */
  1360. ZOOAPI int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
  1361. int certLen, void_completion_t completion, const void *data);
  1362. /**
  1363. * \brief checks if the current zookeeper connection state can't be recovered.
  1364. *
  1365. * The application must close the zhandle and try to reconnect.
  1366. *
  1367. * \param zh the zookeeper handle (see \ref zookeeper_init)
  1368. * \return ZINVALIDSTATE if connection is unrecoverable
  1369. */
  1370. ZOOAPI int is_unrecoverable(zhandle_t *zh);
  1371. /**
  1372. * \brief sets the debugging level for the library
  1373. */
  1374. ZOOAPI void zoo_set_debug_level(ZooLogLevel logLevel);
  1375. /**
  1376. * \brief sets the stream to be used by the library for logging
  1377. *
  1378. * The zookeeper library uses stderr as its default log stream. Application
  1379. * must make sure the stream is writable. Passing in NULL resets the stream
  1380. * to its default value (stderr).
  1381. */
  1382. ZOOAPI void zoo_set_log_stream(FILE* logStream);
  1383. /**
  1384. * \brief gets the callback to be used by this connection for logging.
  1385. *
  1386. * This is a per-connection logging mechanism that will take priority over
  1387. * the library-wide default log stream. That is, zookeeper library will first
  1388. * try to use a per-connection callback if available and if not, will fallback
  1389. * to using the logging stream. Passing in NULL resets the callback and will
  1390. * cause it to then fallback to using the logging stream as described in \ref
  1391. * zoo_set_log_stream.
  1392. */
  1393. ZOOAPI log_callback_fn zoo_get_log_callback(const zhandle_t *zh);
  1394. /**
  1395. * \brief sets the callback to be used by the library for logging
  1396. *
  1397. * Setting this callback has the effect of overriding the default log stream.
  1398. * Zookeeper will first try to use a per-connection callback if available
  1399. * and if not, will fallback to using the logging stream. Passing in NULL
  1400. * resets the callback and will cause it to then fallback to using the logging
  1401. * stream as described in \ref zoo_set_log_stream.
  1402. *
  1403. * Note: The provided callback will be invoked by multiple threads and therefore
  1404. * it needs to be thread-safe.
  1405. */
  1406. ZOOAPI void zoo_set_log_callback(zhandle_t *zh, log_callback_fn callback);
  1407. /**
  1408. * \brief enable/disable quorum endpoint order randomization
  1409. *
  1410. * Note: typically this method should NOT be used outside of testing.
  1411. *
  1412. * If passed a non-zero value, will make the client connect to quorum peers
  1413. * in the order as specified in the zookeeper_init() call.
  1414. * A zero value causes zookeeper_init() to permute the peer endpoints
  1415. * which is good for more even client connection distribution among the
  1416. * quorum peers.
  1417. */
  1418. ZOOAPI void zoo_deterministic_conn_order(int yesOrNo);
  1419. /**
  1420. * \brief create a node synchronously.
  1421. *
  1422. * This method will create a node in ZooKeeper. A node can only be created if
  1423. * it does not already exists. The Create Flags affect the creation of nodes.
  1424. * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the
  1425. * client session goes away. If the ZOO_SEQUENCE flag is set, a unique
  1426. * monotonically increasing sequence number is appended to the path name.
  1427. *
  1428. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1429. * \param path The name of the node. Expressed as a file name with slashes
  1430. * separating ancestors of the node.
  1431. * \param value The data to be stored in the node.
  1432. * \param valuelen The number of bytes in data. To set the data to be NULL use
  1433. * value as NULL and valuelen as -1.
  1434. * \param acl The initial ACL of the node. The ACL must not be null or empty.
  1435. * \param flags this parameter can be set to 0 for normal create or an OR
  1436. * of the Create Flags
  1437. * \param path_buffer Buffer which will be filled with the path of the
  1438. * new node (this might be different than the supplied path
  1439. * because of the ZOO_SEQUENCE flag). The path string will always be
  1440. * null-terminated. This parameter may be NULL if path_buffer_len = 0.
  1441. * \param path_buffer_len Size of path buffer; if the path of the new
  1442. * node (including space for the null terminator) exceeds the buffer size,
  1443. * the path string will be truncated to fit. The actual path of the
  1444. * new node in the server will not be affected by the truncation.
  1445. * The path string will always be null-terminated.
  1446. * \return one of the following codes are returned:
  1447. * ZOK operation completed successfully
  1448. * ZNONODE the parent node does not exist.
  1449. * ZNODEEXISTS the node already exists
  1450. * ZNOAUTH the client does not have permission.
  1451. * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.
  1452. * ZBADARGUMENTS - invalid input parameters
  1453. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1454. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1455. */
  1456. ZOOAPI int zoo_create(zhandle_t *zh, const char *path, const char *value,
  1457. int valuelen, const struct ACL_vector *acl, int flags,
  1458. char *path_buffer, int path_buffer_len);
  1459. /**
  1460. * \brief create a node synchronously and collect stat details.
  1461. *
  1462. * This method will create a node in ZooKeeper. A node can only be created if
  1463. * it does not already exists. The Create Flags affect the creation of nodes.
  1464. * If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the
  1465. * client session goes away. If the ZOO_SEQUENCE flag is set, a unique
  1466. * monotonically increasing sequence number is appended to the path name.
  1467. *
  1468. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1469. * \param path The name of the node. Expressed as a file name with slashes
  1470. * separating ancestors of the node.
  1471. * \param value The data to be stored in the node.
  1472. * \param valuelen The number of bytes in data. To set the data to be NULL use
  1473. * value as NULL and valuelen as -1.
  1474. * \param acl The initial ACL of the node. The ACL must not be null or empty.
  1475. * \param flags this parameter can be set to 0 for normal create or an OR
  1476. * of the Create Flags
  1477. * \param path_buffer Buffer which will be filled with the path of the
  1478. * new node (this might be different than the supplied path
  1479. * because of the ZOO_SEQUENCE flag). The path string will always be
  1480. * null-terminated. This parameter may be NULL if path_buffer_len = 0.
  1481. * \param path_buffer_len Size of path buffer; if the path of the new
  1482. * node (including space for the null terminator) exceeds the buffer size,
  1483. * the path string will be truncated to fit. The actual path of the
  1484. * new node in the server will not be affected by the truncation.
  1485. * The path string will always be null-terminated.
  1486. * \param stat The Stat struct to store Stat info into.
  1487. * \return one of the following codes are returned:
  1488. * ZOK operation completed successfully
  1489. * ZNONODE the parent node does not exist.
  1490. * ZNODEEXISTS the node already exists
  1491. * ZNOAUTH the client does not have permission.
  1492. * ZNOCHILDRENFOREPHEMERALS cannot create children of ephemeral nodes.
  1493. * ZBADARGUMENTS - invalid input parameters
  1494. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1495. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1496. */
  1497. ZOOAPI int zoo_create2(zhandle_t *zh, const char *path, const char *value,
  1498. int valuelen, const struct ACL_vector *acl, int flags,
  1499. char *path_buffer, int path_buffer_len, struct Stat *stat);
  1500. /**
  1501. * \brief delete a node in zookeeper synchronously.
  1502. *
  1503. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1504. * \param path the name of the node. Expressed as a file name with slashes
  1505. * separating ancestors of the node.
  1506. * \param version the expected version of the node. The function will fail if the
  1507. * actual version of the node does not match the expected version.
  1508. * If -1 is used the version check will not take place.
  1509. * \return one of the following values is returned.
  1510. * ZOK operation completed successfully
  1511. * ZNONODE the node does not exist.
  1512. * ZNOAUTH the client does not have permission.
  1513. * ZBADVERSION expected version does not match actual version.
  1514. * ZNOTEMPTY children are present; node cannot be deleted.
  1515. * ZBADARGUMENTS - invalid input parameters
  1516. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1517. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1518. */
  1519. ZOOAPI int zoo_delete(zhandle_t *zh, const char *path, int version);
  1520. /**
  1521. * \brief checks the existence of a node in zookeeper synchronously.
  1522. *
  1523. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1524. * \param path the name of the node. Expressed as a file name with slashes
  1525. * separating ancestors of the node.
  1526. * \param watch if nonzero, a watch will be set at the server to notify the
  1527. * client if the node changes. The watch will be set even if the node does not
  1528. * exist. This allows clients to watch for nodes to appear.
  1529. * \param the return stat value of the node.
  1530. * \return return code of the function call.
  1531. * ZOK operation completed successfully
  1532. * ZNONODE the node does not exist.
  1533. * ZNOAUTH the client does not have permission.
  1534. * ZBADARGUMENTS - invalid input parameters
  1535. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1536. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1537. */
  1538. ZOOAPI int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
  1539. /**
  1540. * \brief checks the existence of a node in zookeeper synchronously.
  1541. *
  1542. * This function is similar to \ref zoo_exists except it allows one specify
  1543. * a watcher object rather than a boolean watch flag.
  1544. *
  1545. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1546. * \param path the name of the node. Expressed as a file name with slashes
  1547. * separating ancestors of the node.
  1548. * \param watcher if non-null a watch will set on the specified znode on the server.
  1549. * The watch will be set even if the node does not exist. This allows clients
  1550. * to watch for nodes to appear.
  1551. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1552. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1553. * is associated with the given instance of the watcher only.
  1554. * \param the return stat value of the node.
  1555. * \return return code of the function call.
  1556. * ZOK operation completed successfully
  1557. * ZNONODE the node does not exist.
  1558. * ZNOAUTH the client does not have permission.
  1559. * ZBADARGUMENTS - invalid input parameters
  1560. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1561. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1562. */
  1563. ZOOAPI int zoo_wexists(zhandle_t *zh, const char *path,
  1564. watcher_fn watcher, void* watcherCtx, struct Stat *stat);
  1565. /**
  1566. * \brief gets the data associated with a node synchronously.
  1567. *
  1568. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1569. * \param path the name of the node. Expressed as a file name with slashes
  1570. * separating ancestors of the node.
  1571. * \param watch if nonzero, a watch will be set at the server to notify
  1572. * the client if the node changes.
  1573. * \param buffer the buffer holding the node data returned by the server
  1574. * \param buffer_len is the size of the buffer pointed to by the buffer parameter.
  1575. * It'll be set to the actual data length upon return. If the data is NULL, length is -1.
  1576. * \param stat if not NULL, will hold the value of stat for the path on return.
  1577. * \return return value of the function call.
  1578. * ZOK operation completed successfully
  1579. * ZNONODE the node does not exist.
  1580. * ZNOAUTH the client does not have permission.
  1581. * ZBADARGUMENTS - invalid input parameters
  1582. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1583. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1584. */
  1585. ZOOAPI int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer,
  1586. int* buffer_len, struct Stat *stat);
  1587. /**
  1588. * \brief gets the data associated with a node synchronously.
  1589. *
  1590. * This function is similar to \ref zoo_get except it allows one specify
  1591. * a watcher object rather than a boolean watch flag.
  1592. *
  1593. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1594. * \param path the name of the node. Expressed as a file name with slashes
  1595. * separating ancestors of the node.
  1596. * \param watcher if non-null, a watch will be set at the server to notify
  1597. * the client if the node changes.
  1598. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1599. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1600. * is associated with the given instance of the watcher only.
  1601. * \param buffer the buffer holding the node data returned by the server
  1602. * \param buffer_len is the size of the buffer pointed to by the buffer parameter.
  1603. * It'll be set to the actual data length upon return. If the data is NULL, length is -1.
  1604. * \param stat if not NULL, will hold the value of stat for the path on return.
  1605. * \return return value of the function call.
  1606. * ZOK operation completed successfully
  1607. * ZNONODE the node does not exist.
  1608. * ZNOAUTH the client does not have permission.
  1609. * ZBADARGUMENTS - invalid input parameters
  1610. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1611. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1612. */
  1613. ZOOAPI int zoo_wget(zhandle_t *zh, const char *path,
  1614. watcher_fn watcher, void* watcherCtx,
  1615. char *buffer, int* buffer_len, struct Stat *stat);
  1616. /**
  1617. * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to
  1618. * the server to which the client is connected, synchronously.
  1619. *
  1620. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1621. * \param watch if nonzero, a watch will be set at the server to notify
  1622. * the client if the node changes.
  1623. * \param buffer the buffer holding the configuration data returned by the server
  1624. * \param buffer_len is the size of the buffer pointed to by the buffer parameter.
  1625. * It'll be set to the actual data length upon return. If the data is NULL, length is -1.
  1626. * \param stat if not NULL, will hold the value of stat for the path on return.
  1627. * \return return value of the function call.
  1628. * ZOK operation completed successfully
  1629. * ZNONODE the configuration node (/zookeeper/config) does not exist.
  1630. * ZNOAUTH the client does not have permission to access the configuration node.
  1631. * ZBADARGUMENTS - invalid input parameters
  1632. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1633. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1634. */
  1635. ZOOAPI int zoo_getconfig(zhandle_t *zh, int watch, char *buffer,
  1636. int* buffer_len, struct Stat *stat);
  1637. /**
  1638. * \brief gets the last committed configuration of the ZooKeeper cluster as it is known to
  1639. * the server to which the client is connected, synchronously.
  1640. *
  1641. * This function is similar to \ref zoo_getconfig except it allows one specify
  1642. * a watcher object rather than a boolean watch flag.
  1643. *
  1644. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1645. * \param watcher if non-null, a watch will be set at the server to notify
  1646. * the client if the node changes.
  1647. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1648. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1649. * is associated with the given instance of the watcher only.
  1650. * \param buffer the buffer holding the configuration data returned by the server
  1651. * \param buffer_len is the size of the buffer pointed to by the buffer parameter.
  1652. * It'll be set to the actual data length upon return. If the data is NULL, length is -1.
  1653. * \param stat if not NULL, will hold the value of stat for the path on return.
  1654. * \return return value of the function call.
  1655. * ZOK operation completed successfully
  1656. * ZNONODE the configuration node (/zookeeper/config) does not exist.
  1657. * ZNOAUTH the client does not have permission to access the configuration node.
  1658. * ZBADARGUMENTS - invalid input parameters
  1659. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1660. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1661. */
  1662. ZOOAPI int zoo_wgetconfig(zhandle_t *zh, watcher_fn watcher, void* watcherCtx,
  1663. char *buffer, int* buffer_len, struct Stat *stat);
  1664. /**
  1665. * \brief synchronous reconfiguration interface - allows changing ZK cluster
  1666. * ensemble membership and roles of ensemble peers.
  1667. *
  1668. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1669. * \param joining - comma separated list of servers to be added to the ensemble.
  1670. * Each has a configuration line for a server to be added (as would appear in a
  1671. * configuration file), only for maj. quorums. NULL for non-incremental reconfiguration.
  1672. * \param leaving - comma separated list of server IDs to be removed from the ensemble.
  1673. * Each has an id of a server to be removed, only for maj. quorums. NULL for
  1674. * non-incremental reconfiguration.
  1675. * \param members - comma separated list of new membership (e.g., contents of a
  1676. * membership configuration file) - for use only with a non-incremental
  1677. * reconfiguration. NULL for incremental reconfiguration.
  1678. * \param version - zxid of config from which we want to reconfigure - if
  1679. * current config is different reconfiguration will fail. Should be -1 to
  1680. * disable this option.
  1681. * \param buffer the buffer holding the configuration data returned by the server
  1682. * \param buffer_len is the size of the buffer pointed to by the buffer parameter.
  1683. * It'll be set to the actual data length upon return. If the data is NULL, length
  1684. * is -1.
  1685. * \param stat if not NULL, will hold the value of stat for the path on return.
  1686. * \return return value of the function call.
  1687. * ZOK operation completed successfully
  1688. * ZBADARGUMENTS - invalid input parameters (one case when this is returned is
  1689. * when the new config has less than 2 servers)
  1690. * ZINVALIDSTATE - zhandle state is either in ZOO_SESSION_EXPIRED_STATE or
  1691. * ZOO_AUTH_FAILED_STATE
  1692. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1693. * ZNEWCONFIGNOQUORUM - no quorum of new config is connected and up-to-date with
  1694. * the leader of last committed config - try invoking reconfiguration after new
  1695. * servers are connected and synced
  1696. * ZRECONFIGINPROGRESS - another reconfig is currently in progress
  1697. */
  1698. ZOOAPI int zoo_reconfig(zhandle_t *zh, const char *joining, const char *leaving,
  1699. const char *members, int64_t version, char *buffer, int* buffer_len,
  1700. struct Stat *stat);
  1701. /**
  1702. * \brief sets the data associated with a node. See zoo_set2 function if
  1703. * you require access to the stat information associated with the znode.
  1704. *
  1705. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1706. * \param path the name of the node. Expressed as a file name with slashes
  1707. * separating ancestors of the node.
  1708. * \param buffer the buffer holding data to be written to the node.
  1709. * \param buflen the number of bytes from buffer to write. To set NULL as data
  1710. * use buffer as NULL and buflen as -1.
  1711. * \param version the expected version of the node. The function will fail if
  1712. * the actual version of the node does not match the expected version. If -1 is
  1713. * used the version check will not take place.
  1714. * \return the return code for the function call.
  1715. * ZOK operation completed successfully
  1716. * ZNONODE the node does not exist.
  1717. * ZNOAUTH the client does not have permission.
  1718. * ZBADVERSION expected version does not match actual version.
  1719. * ZBADARGUMENTS - invalid input parameters
  1720. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1721. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1722. */
  1723. ZOOAPI int zoo_set(zhandle_t *zh, const char *path, const char *buffer,
  1724. int buflen, int version);
  1725. /**
  1726. * \brief sets the data associated with a node. This function is the same
  1727. * as zoo_set except that it also provides access to stat information
  1728. * associated with the znode.
  1729. *
  1730. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1731. * \param path the name of the node. Expressed as a file name with slashes
  1732. * separating ancestors of the node.
  1733. * \param buffer the buffer holding data to be written to the node.
  1734. * \param buflen the number of bytes from buffer to write. To set NULL as data
  1735. * use buffer as NULL and buflen as -1.
  1736. * \param version the expected version of the node. The function will fail if
  1737. * the actual version of the node does not match the expected version. If -1 is
  1738. * used the version check will not take place.
  1739. * \param stat if not NULL, will hold the value of stat for the path on return.
  1740. * \return the return code for the function call.
  1741. * ZOK operation completed successfully
  1742. * ZNONODE the node does not exist.
  1743. * ZNOAUTH the client does not have permission.
  1744. * ZBADVERSION expected version does not match actual version.
  1745. * ZBADARGUMENTS - invalid input parameters
  1746. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1747. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1748. */
  1749. ZOOAPI int zoo_set2(zhandle_t *zh, const char *path, const char *buffer,
  1750. int buflen, int version, struct Stat *stat);
  1751. /**
  1752. * \brief lists the children of a node synchronously.
  1753. *
  1754. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1755. * \param path the name of the node. Expressed as a file name with slashes
  1756. * separating ancestors of the node.
  1757. * \param watch if nonzero, a watch will be set at the server to notify
  1758. * the client if the node changes.
  1759. * \param strings return value of children paths.
  1760. * \return the return code of the function.
  1761. * ZOK operation completed successfully
  1762. * ZNONODE the node does not exist.
  1763. * ZNOAUTH the client does not have permission.
  1764. * ZBADARGUMENTS - invalid input parameters
  1765. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1766. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1767. */
  1768. ZOOAPI int zoo_get_children(zhandle_t *zh, const char *path, int watch,
  1769. struct String_vector *strings);
  1770. /**
  1771. * \brief lists the children of a node synchronously.
  1772. *
  1773. * This function is similar to \ref zoo_get_children except it allows one specify
  1774. * a watcher object rather than a boolean watch flag.
  1775. *
  1776. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1777. * \param path the name of the node. Expressed as a file name with slashes
  1778. * separating ancestors of the node.
  1779. * \param watcher if non-null, a watch will be set at the server to notify
  1780. * the client if the node changes.
  1781. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1782. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1783. * is associated with the given instance of the watcher only.
  1784. * \param strings return value of children paths.
  1785. * \return the return code of the function.
  1786. * ZOK operation completed successfully
  1787. * ZNONODE the node does not exist.
  1788. * ZNOAUTH the client does not have permission.
  1789. * ZBADARGUMENTS - invalid input parameters
  1790. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1791. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1792. */
  1793. ZOOAPI int zoo_wget_children(zhandle_t *zh, const char *path,
  1794. watcher_fn watcher, void* watcherCtx,
  1795. struct String_vector *strings);
  1796. /**
  1797. * \brief lists the children of a node and get its stat synchronously.
  1798. *
  1799. * This function is new in version 3.3.0
  1800. *
  1801. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1802. * \param path the name of the node. Expressed as a file name with slashes
  1803. * separating ancestors of the node.
  1804. * \param watch if nonzero, a watch will be set at the server to notify
  1805. * the client if the node changes.
  1806. * \param strings return value of children paths.
  1807. * \param stat return value of node stat.
  1808. * \return the return code of the function.
  1809. * ZOK operation completed successfully
  1810. * ZNONODE the node does not exist.
  1811. * ZNOAUTH the client does not have permission.
  1812. * ZBADARGUMENTS - invalid input parameters
  1813. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1814. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1815. */
  1816. ZOOAPI int zoo_get_children2(zhandle_t *zh, const char *path, int watch,
  1817. struct String_vector *strings, struct Stat *stat);
  1818. /**
  1819. * \brief lists the children of a node and get its stat synchronously.
  1820. *
  1821. * This function is similar to \ref zoo_get_children except it allows one specify
  1822. * a watcher object rather than a boolean watch flag.
  1823. *
  1824. * This function is new in version 3.3.0
  1825. *
  1826. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1827. * \param path the name of the node. Expressed as a file name with slashes
  1828. * separating ancestors of the node.
  1829. * \param watcher if non-null, a watch will be set at the server to notify
  1830. * the client if the node changes.
  1831. * \param watcherCtx user specific data, will be passed to the watcher callback.
  1832. * Unlike the global context set by \ref zookeeper_init, this watcher context
  1833. * is associated with the given instance of the watcher only.
  1834. * \param strings return value of children paths.
  1835. * \param stat return value of node stat.
  1836. * \return the return code of the function.
  1837. * ZOK operation completed successfully
  1838. * ZNONODE the node does not exist.
  1839. * ZNOAUTH the client does not have permission.
  1840. * ZBADARGUMENTS - invalid input parameters
  1841. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1842. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1843. */
  1844. ZOOAPI int zoo_wget_children2(zhandle_t *zh, const char *path,
  1845. watcher_fn watcher, void* watcherCtx,
  1846. struct String_vector *strings, struct Stat *stat);
  1847. /**
  1848. * \brief gets the acl associated with a node synchronously.
  1849. *
  1850. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1851. * \param path the name of the node. Expressed as a file name with slashes
  1852. * separating ancestors of the node.
  1853. * \param acl the return value of acls on the path.
  1854. * \param stat returns the stat of the path specified.
  1855. * \return the return code for the function call.
  1856. * ZOK operation completed successfully
  1857. * ZNONODE the node does not exist.
  1858. * ZNOAUTH the client does not have permission.
  1859. * ZBADARGUMENTS - invalid input parameters
  1860. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1861. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1862. */
  1863. ZOOAPI int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl,
  1864. struct Stat *stat);
  1865. /**
  1866. * \brief sets the acl associated with a node synchronously.
  1867. *
  1868. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1869. * \param path the name of the node. Expressed as a file name with slashes
  1870. * separating ancestors of the node.
  1871. * \param version the expected version of the path.
  1872. * \param acl the acl to be set on the path.
  1873. * \return the return code for the function call.
  1874. * ZOK operation completed successfully
  1875. * ZNONODE the node does not exist.
  1876. * ZNOAUTH the client does not have permission.
  1877. * ZINVALIDACL invalid ACL specified
  1878. * ZBADVERSION expected version does not match actual version.
  1879. * ZBADARGUMENTS - invalid input parameters
  1880. * ZINVALIDSTATE - zhandle state is either ZOO_SESSION_EXPIRED_STATE or ZOO_AUTH_FAILED_STATE
  1881. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1882. */
  1883. ZOOAPI int zoo_set_acl(zhandle_t *zh, const char *path, int version,
  1884. const struct ACL_vector *acl);
  1885. /**
  1886. * \brief atomically commits multiple zookeeper operations synchronously.
  1887. *
  1888. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1889. * \param count the number of operations
  1890. * \param ops an array of operations to commit
  1891. * \param results an array to hold the results of the operations
  1892. * \return the return code for the function call. This can be any of the
  1893. * values that can be returned by the ops supported by a multi op (see
  1894. * \ref zoo_acreate, \ref zoo_adelete, \ref zoo_aset).
  1895. */
  1896. ZOOAPI int zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results);
  1897. /**
  1898. * Type of watchers: used to select which type of watchers should be removed
  1899. */
  1900. typedef enum {
  1901. ZWATCHERTYPE_CHILDREN = 1,
  1902. ZWATCHERTYPE_DATA = 2,
  1903. ZWATCHERTYPE_ANY = 3
  1904. } ZooWatcherType;
  1905. /**
  1906. * \brief removes the watchers for the given path and watcher type.
  1907. *
  1908. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1909. * \param path the path for which watchers will be removed
  1910. * \param wtype the watcher type to be removed
  1911. * \param watcher the watcher to be removed, if null all watchers for that
  1912. * path (and watcher type) will be removed
  1913. * \param watcherCtx the contex associated with the watcher to be removed
  1914. * \param local whether the watchers will be removed locally even if there is
  1915. * no server connection
  1916. * \return the return code for the function call.
  1917. * ZOK - operation completed successfully
  1918. * ZNOWATCHER - the watcher couldn't be found.
  1919. * ZINVALIDSTATE - if !local, zhandle state is either ZOO_SESSION_EXPIRED_STATE
  1920. * or ZOO_AUTH_FAILED_STATE
  1921. * ZBADARGUMENTS - invalid input parameters
  1922. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1923. * ZSYSTEMERROR - a system error occured
  1924. */
  1925. ZOOAPI int zoo_remove_watchers(zhandle_t *zh, const char *path,
  1926. ZooWatcherType wtype, watcher_fn watcher, void *watcherCtx, int local);
  1927. /**
  1928. * \brief removes the watchers for the given path and watcher type.
  1929. *
  1930. * \param zh the zookeeper handle obtained by a call to \ref zookeeper_init
  1931. * \param path the path for which watchers will be removed
  1932. * \param wtype the watcher type to be removed
  1933. * \param watcher the watcher to be removed, if null all watchers for that
  1934. * path (and watcher type) will be removed
  1935. * \param watcherCtx the contex associated with the watcher to be removed
  1936. * \param local whether the watchers will be removed locally even if there is
  1937. * no server connection
  1938. * \return the return code for the function call.
  1939. * ZOK - operation completed successfully
  1940. * ZNOWATCHER - the watcher couldn't be found.
  1941. * ZINVALIDSTATE - if !local, zhandle state is either ZOO_SESSION_EXPIRED_STATE
  1942. * or ZOO_AUTH_FAILED_STATE
  1943. * ZBADARGUMENTS - invalid input parameters
  1944. * ZMARSHALLINGERROR - failed to marshall a request; possibly, out of memory
  1945. * ZSYSTEMERROR - a system error occured
  1946. */
  1947. ZOOAPI int zoo_aremove_watchers(zhandle_t *zh, const char *path,
  1948. ZooWatcherType wtype, watcher_fn watcher, void *watcherCtx, int local,
  1949. void_completion_t *completion, const void *data);
  1950. #ifdef __cplusplus
  1951. }
  1952. #endif
  1953. #endif /*ZOOKEEPER_H_*/