zookeeper.h 98 KB

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