zookeeper.h 115 KB

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