zookeeper.h 114 KB

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