{"id":20564527,"url":"https://github.com/tarantool/zookeeper","last_synced_at":"2025-08-10T15:12:21.244Z","repository":{"id":26990704,"uuid":"111423624","full_name":"tarantool/zookeeper","owner":"tarantool","description":"ZooKeeper client for Tarantool","archived":false,"fork":false,"pushed_at":"2022-04-25T14:56:52.000Z","size":67,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-03-06T08:34:01.955Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tarantool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-20T14:53:37.000Z","updated_at":"2021-11-09T08:15:40.000Z","dependencies_parsed_at":"2022-07-27T09:02:45.139Z","dependency_job_id":null,"html_url":"https://github.com/tarantool/zookeeper","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tarantool/zookeeper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fzookeeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fzookeeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fzookeeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fzookeeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarantool","download_url":"https://codeload.github.com/tarantool/zookeeper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarantool%2Fzookeeper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269740412,"owners_count":24467773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T04:27:30.816Z","updated_at":"2025-08-10T15:12:21.224Z","avatar_url":"https://github.com/tarantool.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZooKeeper client for Tarantool\n--------------------------------\n\n## Support level\n\nWarning! There is no warranty for the program, to the extent permitted by applicable law\nThis repository is maintained by the community:\n- We do not check compatibility with current versions of Tarantool\n- The Tarantool team does not process requests for support, new functionality, or bug fixes\n- Feel free to take an issue and make a merge request with a solution\n\n\n## \u003ca name=\"toc\"\u003e\u003c/a\u003eTable of contents\n--------------------------------------\n\n* [Overview](#overview)\n* [Installation](#installation)\n* [API reference](#api-ref)\n  * [zookeper.init()](#zk-init)\n  * [zookeeper.zerror()](#zk-zerror)\n  * [zookeeper.deterministic_conn_order()](#zk-det-conn-order)\n  * [zookeeper.set_log_level()](#zk-set-log-level)\n  * [z:start()](#z-start)\n  * [z:close()](#z-close)\n  * [z:state()](#z-state)\n  * [z:is_connected()](#z-is-conn)\n  * [z:wait_connected()](#z-wait-conn)\n  * [z:client_id()](#z-client-id)\n  * [z:set_watcher()](#z-set-watcher)\n  * [z:create()](#z-create)\n  * [z:ensure_path()](#z-ensure-path)\n  * [z:exists()](#z-exists)\n  * [z:delete()](#z-delete)\n  * [z:get()](#z-get)\n  * [z:set()](#z-set)\n  * [z:get_children()](#z-get-children)\n  * [z:get_children2()](#z-get-children2)\n* [Appendix 1: ZooKeeper constants](#appndx-zk-constants)\n  * [watch_types](#watch-types)\n  * [errors](#errors)\n  * [api_errors](#api-errors)\n  * [states](#states)\n  * [log_level](#log-level)\n  * [create_flags](#create-flags)\n  * [permissions](#permissions)\n* [Copyright \u0026 License](#copyright-license)\n\n## \u003ca name=\"overview\"\u003e\u003c/a\u003eOverview\n----------------------------------\n\nZooKeeper is a distributed application for managing and coordinating a large number of hosts across a cluster. It helps maintain objects like configuration information and hierarchical naming space and provides various services, such as distributed synchronization and leader election.\n\n[Back to TOC](#toc)\n\n## \u003ca name=\"installation\"\u003e\u003c/a\u003eInstallation\n\nUsing a package manager (CentOS, Fedora, Debian, Ubuntu):\n\n* [Add][tarantool_repo] a tarantool repository.\n* Install tarantool-zookeeper package.\n\nUsing tarantoolctl rocks:\n\n* Install dependencies:\n  - CentOS / Fedora: tarantool-devel, zookeeper-native\n    ([full list][deps_centos]).\n  - Debian / Ubuntu: tarantool-dev, libzookeeper-st-dev, libzookeeper-st2\n    ([full list][deps_debian]).\n* tarantoolctl rocks install zookeeper\n\n[Back to TOC](#toc)\n\n[tarantool_repo]: https://tarantool.io/en/download/\n[deps_centos]: https://github.com/tarantool/zookeeper/blob/master/rpm/tarantool-zookeeper.spec#L9-L16\n[deps_debian]: https://github.com/tarantool/zookeeper/blob/master/debian/control#L5-L15\n\n## \u003ca name=\"api-ref\"\u003e\u003c/a\u003eAPI reference\n--------------------------------------\n\n#### \u003ca name=\"zk-init\"\u003e\u003c/a\u003ez = zookeeper.init(hosts, timeout, opts)\n-------------------------------------------------------------------\n\nCreate a ZooKeeper instance. No connection is established at this point.\n\n**Parameters:**\n\n* `hosts` - a string of the format: *host1:port1,host2:port2,...*. Default is **127.0.0.1:2181**.\n* `timeout` - *recv_timeout* (ZooKeeper session timeout) in seconds. Default is **30000**.\n* `opts` - a Lua table with the following **fields**:\n\n  * `clientid` - a Lua table of the format *{client_id = \\\u003cnumber\\\u003e, passwd = \\\u003cstring\\\u003e}*. Default is **nil**.\n  * `flags` - ZooKeeper init flags. Default is **0**.\n  * `reconnect_timeout` - time in seconds to wait before reconnecting. Default is **1**.\n  * `default_acl` - a default access control list (ACL) to use for all *create* requests. Must be a *zookeeper.acl.ACLList* instance. Default is **zookeeper.acl.ACLS.OPEN_ACL_UNSAFE**.\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"zk-zerror\"\u003e\u003c/a\u003eerr = zookeeper.zerror(errorcode)\n--------------------------------------------------------------\n\nGet a string description for a ZooKeeper error code.\n\n**Parameters:**\n\n* `errorcode` - a numeric ZooKeeper error code. Refer to the list of possible [API errors](#api-errors) and [client errors](#errors).\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"zk-det-conn-order\"\u003e\u003c/a\u003ezookeeper.deterministic_conn_order(\\\u003cboolean\\\u003e)\n------------------------------------------------------------------------------------\n\nInstruct ZooKeeper not to randomly choose a server from the hosts provided, but select them sequentially instead.\n\n**Parameters:**\n\n* a boolean specifying whether a deterministic connection order should be enforced\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"zk-set-log-level\"\u003e\u003c/a\u003ezookeeper.set_log_level(zookeeper.const.log_level.*)\n----------------------------------------------------------------------------------------\n\nSet a ZooKeeper logging level.\n\n**Parameters:**\n\n* `zookeeper.const.log_level.*` - a constant corresponding to a certain logging level. Refer to the [list of acceptable values](#log-level).\n\n[Back to TOC](#toc)\n\n### ZooKeeper instance methods\n------------------------------\n\n#### \u003ca name=\"z-start\"\u003e\u003c/a\u003ez:start()\n------------------------------------\n\nStart a ZooKeeper I/O loop. Connection is established at this stage.\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-close\"\u003e\u003c/a\u003ez:close()\n------------------------------------\n\nDestroy a ZooKeeper instance. After this method is called, nothing is operable and `zookeeper.init()` must be called again.\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-state\"\u003e\u003c/a\u003ez:state()\n------------------------------------\n\nReturn the current ZooKeeper state as a number. Refer to the list of [possible values](#states).\n\n\u003eTip: to convert a number to a string name, use `zookeeper.const.states_rev[\u003cnumber\u003e]`.\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-is-conn\"\u003e\u003c/a\u003ez:is_connected()\n---------------------------------------------\n\nReturn **true** when `z:state()` == *zookeeper.const.states.CONNECTED*.\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-wait-conn\"\u003e\u003c/a\u003ez:wait_connected()\n-------------------------------------------------\n\nWait until the value of `z:state()` becomes *CONNECTED*.\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-client-id\"\u003e\u003c/a\u003ez:client_id()\n--------------------------------------------\n\nReturn a Lua table of the following form:\n\n```\n{\n\tclient_id = \u003cnumber\u003e, -- current session ID\n\tpasswd = \u003cstring\u003e -- password\n}\n```\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-set-watcher\"\u003e\u003c/a\u003ez:set_watcher(watcher_func, extra_context)\n---------------------------------------------------------------------------\n\nSet a watcher function called on every change in ZooKeeper.\n\n**Parameters:**\n\n* `watcher_func` - a function with the following signature:\n  ```lua\n  local function global_watcher(z, type, state, path, context)\n      print(string.format(\n  \t\t    'Global watcher. type = %s, state = %s, path = %s',\n  \t\t    zookeeper.const.watch_types_rev[type],\n  \t\t    zookeeper.const.states_rev[state],\n  \t\t    path))\n      print('Extra context:', json.encode(context))\n  end\n  ```\n  *where:*\n\n  |Parameter|Description|\n  |---------|-----------|\n  |`z`|A ZooKeeper instance|\n  |`type`|An event type. Refer to the [list of acceptable values](#watch-types).|\n  |`state`|An event state. Refer to the [list of acceptable values](#states).|\n  |`path`|A path that specifies where an event occurred|\n  |`context`|A variable passed to `z:set_watcher()` as the second argument|\n\n* `extra_context` - a context passed to the watcher function\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-create\"\u003e\u003c/a\u003ez:create(path, value, acl, flags)\n-------------------------------------------------------------\n\nCreate a ZooKeeper node.\n\n**Parameters:**\n\n* `path` - a string of the format: `/path/to/node`. `/path/to` must exist.\n* `value` - a string value to store in a node (may be *nil*). Default is **nil**.\n* `acl` (a *zookeeper.acl.ACLList* instance) - an ACL to use. Default is **z.default_acl**.\n* `flags` - a combination of numeric [zookeeper.const.create_flags.\\* constants](#create-flags).\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-ensure-path\"\u003e\u003c/a\u003ez:ensure_path(path)\n----------------------------------------------------\n\nMake sure that a path exists.\n\n**Parameters:**\n\n* `path` - a path to check\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-exists\"\u003e\u003c/a\u003ez:exists(path, watch)\n-------------------------------------------------\n\nMake sure that a node (including all the parent nodes) exists.\n\n**Parameters:**\n\n* `path` - a path to check\n* `watch` (boolean) - specifies whether to include a path to a global watcher\n\n**Returns:**\n\n* a boolean indicating if the path exists\n* `stat` - node statistics of the following form:\n\n  ```\n  - cversion: 30\n    mtime: 1511098164443\n    pzxid: 108\n    mzxid: 4\n    ephemeralOwner: 0\n    aversion: 0\n    czxid: 4\n    dataLength: 0\n    numChildren: 2\n    ctime: 1511098164443\n    version: 0\n  ```\n\n  *where:*\n\n  |Parameter|Description|\n  |---------|-----------|\n  |`cversion`|The number of changes to the children of this node|\n  |`mtime`|The time in milliseconds from epoch when this node was last modified|\n  |`pzxid`|The zxid of the change that last modified children of this node|\n  |`mzxid`|The zxid of the change that last modified this node|\n  |`ephemeralOwner`|The session ID of the owner of this node if the node is an ephemeral node. If it is not an ephemeral node, it is zero.|\n  |`aversion`|The number of changes to the ACL of this node|\n  |`czxid`|The zxid of the change that caused this node to be created|\n  |`dataLength`|The length of the data field of this node|\n  |`numChildren`|The number of children of this node|\n  |`ctime`|The time in milliseconds from epoch when this node was created|\n  |`version`|The number of changes to the data of this node|\n\n* a ZooKeeper return code. Refer to the list of possible [API errors](#api-errors) and [client errors](#errors).\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-delete\"\u003e\u003c/a\u003ez:delete(path, version)\n---------------------------------------------------\n\nDelete a node.\n\n**Parameters:**\n\n* `path` - a path to a node to be deleted\n* `version` - a number specifying which version to delete. Default is **-1**, which is *all versions*.\n\n**Returns:**\n\n* a ZooKeeper return code. Refer to the list of possible [API errors](#api-errors) and [client errors](#errors).\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-get\"\u003e\u003c/a\u003ez:get(path, watch)\n-------------------------------------------\n\nGet the value of a node.\n\n**Parameters:**\n\n* `path` - a path to a node that holds a needed value\n* `watch` (boolean) - specifies whether to include a path to a global watcher\n\n**Returns:**\n\n* `value` - the value of a node\n* `stat` - node statistics\n* a ZooKeeper return code. Refer to the list of possible [API errors](#api-errors) and [client errors](#errors).\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-set\"\u003e\u003c/a\u003ez:set(path, version)\n---------------------------------------------\n\nSet the value of a node.\n\n**Parameters:**\n\n* `path` - a path to a node to set a value on\n* `version` - a number specifying which version to delete. Default is **-1** (create a new version).\n\n**Returns:**\n\n* a boolean indicating if the path exists\n* `stat` - node statistics\n* a ZooKeeper return code. Refer to the list of possible [API errors](#api-errors) and [client errors](#errors).\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-get-children\"\u003e\u003c/a\u003ez:get_children(path, watch)\n-------------------------------------------------------------\n\nGet a node's children.\n\n**Parameters:**\n\n* `path` - a path to a node to get the children of\n* `watch` (boolean) - specifies whether to include a path to a global watcher\n\n**Returns:**\n\n* an array of strings, each representing a node's child\n* a ZooKeeper return code. Refer to the list of possible [API errors](#api-errors) and [client errors](#errors).\n\n[Back to TOC](#toc)\n\n#### \u003ca name=\"z-get-children2\"\u003e\u003c/a\u003ez:get_children2(path, watch)\n---------------------------------------------------------------\n\nGet a node's children and statistics.\n\n**Parameters:**\n\n* `path` - a path to a node to get the children of\n* `watch` (boolean) - specifies whether to include a path to a global watcher\n\n**Returns:**\n\n* an array of strings, each representing a node's child\n* `stat` - node statistics\n* a ZooKeeper return code. Refer to the list of possible [API errors](#api-errors) and [client errors](#errors).\n\n[Back to TOC](#toc)\n\n## \u003ca name=\"appndx-zk-constants\"\u003e\u003c/a\u003eAppendix 1: ZooKeeper constants\n--------------------------------------------------------------------\n\n`zookeeper.const` also contains a *\\\u003ckey\\\u003e_rev* map for each key that holds a reverse (number-to-name) mapping. For example, *zookeeper.const.api_errors_rev* looks like this:\n\n|Code|Error|\n|----|----|\n|-118|ZSESSIONMOVED|\n|-117|ZNOTHING|\n|-116|ZCLOSING|\n|-115|ZAUTHFAILED|\n|-114|ZINVALIDACL|\n|-113|ZINVALIDCALLBACK|\n|-112|ZSESSIONEXPIRED|\n|-111|ZNOTEMPTY|\n|-110|ZNODEEXISTS|\n|-108|ZNOCHILDRENFOREPHEMERALS|\n|-103|ZBADVERSION|\n|-102|ZNOAUTH|\n|-101|ZNONODE|\n|-100|ZAPIERROR|\n\n[Back to TOC](#toc)\n\n### \u003ca name=\"watch-types\"\u003e\u003c/a\u003ewatch_types\n-----------------------------------------\n\n|Type|Code|Description|\n|----|----|-----------|\n|NOTWATCHING|-2|Watcher is not set|\n|SESSION|-1|Watching for session-related events|\n|CREATED|1|Watching for node creation events|\n|DELETED|2|Watching for node deletion events|\n|CHANGED|3|Watching for node change events|\n|CHILD|4|Watching for child-related events|\n\n[Back to TOC](#toc)\n\n### \u003ca name=\"errors\"\u003e\u003c/a\u003eerrors\n-------------------------------\n\n|Error|Code|Description|\n|----|----|-----------|\n|ZINVALIDSTATE|-9|Invalid zhandle state|\n|ZBADARGUMENTS|-8|Invalid arguments|\n|ZOPERATIONTIMEOUT|-7|Operation timeout|\n|ZUNIMPLEMENTED|-6|Operation is unimplemented|\n|ZMARSHALLINGERROR|-5|Error while marshalling or unmarshalling data|\n|ZCONNECTIONLOSS|-4|Connection to the server has been lost|\n|ZRUNTIMEINCONSISTENCY|-2|A runtime inconsistency was found|\n|ZSYSTEMERROR|-1|System error|\n|ZOK|0|Everything is OK|\n\n[Back to TOC](#toc)\n\n### \u003ca name=\"api-errors\"\u003e\u003c/a\u003eapi_errors\n---------------------------------------\n\n|Error|Code|Description|\n|----|----|----|\n|ZSESSIONMOVED|-118|Session moved to another server, so the operation is ignored|\n|ZNOTHING|-117| (not an error) no server responses to process|\n|ZCLOSING|-116| ZooKeeper is closing|\n|ZAUTHFAILED|-115|Client authentication failed|\n|ZINVALIDACL|-114|Invalid ACL specified|\n|ZINVALIDCALLBACK|-113|Invalid callback specified|\n|ZSESSIONEXPIRED|-112|The session has been expired by the server|\n|ZNOTEMPTY|-111|The node has children|\n|ZNODEEXISTS|-110|The node already exists|\n|ZNOCHILDRENFOREPHEMERALS|-108|Ephemeral nodes may not have children|\n|ZBADVERSION|-103|Version conflict|\n|ZNOAUTH|-102|Not authenticated|\n|ZNONODE|-101|Node does not exist|\n|ZAPIERROR|-100|API error|\n|ZOK|0|Everything is OK|\n\n[Back to TOC](#toc)\n\n### \u003ca name=\"states\"\u003e\u003c/a\u003estates\n-------------------------------\n\n|State|Code|Description|\n|----|----|-----------|\n|AUTH_FAILED|-113|Authentication has failed|\n|EXPIRED_SESSION|-112|Session has expired|\n|CONNECTING|1|ZooKeeper is connecting|\n|ASSOCIATING|2|Information obtained from ZooKeeper is being associated with the connection|\n|CONNECTED|3|ZooKeeper is connected|\n|READONLY|5|ZooKeeper is in read-only mode, accepting only read requests|\n|NOTCONNECTED|999|ZooKeeper is not connected|\n\n[Back to TOC](#toc)\n\n### \u003ca name=\"log-level\"\u003e\u003c/a\u003elog_level\n-------------------------------------\n\n|Name|Code|Description|\n|----|----|-----------|\n|ERROR|1|Log error events that might still allow the application to continue running|\n|WARN|2|Log potentially harmful situations|\n|INFO|3|Log informational messages that highlight the progress of the application at coarse-grained level\n|DEBUG|4|Log fine-grained informational events that are most useful to debug an application|\n\n[Back to TOC](#toc)\n\n### \u003ca name=\"create-flags\"\u003e\u003c/a\u003ecreate_flags\n-------------------------------------------\n\n|Flag|Code|Description|\n|----|----|-----------|\n|EPHEMERAL|1|Create an ephemeral node|\n|SEQUENCE|2|Create a sequence node|\n\n[Back to TOC](#toc)\n\n### \u003ca name=\"permissions\"\u003e\u003c/a\u003epermissions\n-----------------------------------------\n\n|Permission|Code|Description|\n|----------|----|-----------|\n|READ|1|Can get data from a node and list its children|\n|WRITE|2|Can set data for a node|\n|DELETE|8|Can delete a child node|\n|ADMIN|16|Can set permissions|\n|ALL|31|Can do all of the above|\n\n[Back to TOC](#toc)\n\n## \u003ca name=\"copyright-license\"\u003e\u003c/a\u003eCopyright \u0026 License\n------------------------------------------------------\n\n* [LICENSE](LICENSE.md)\n\n[Back to TOC](#toc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Fzookeeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarantool%2Fzookeeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarantool%2Fzookeeper/lists"}