zookeeper.h 118 KB

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