zookeeper.h 113 KB

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