zookeeper.h 108 KB

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