zookeeper.h 115 KB

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