zookeeper.h 118 KB

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