|
RDFS
The Rice Comp413 2017 class' continuation on the work of the 2016 RDFS.
|
Public Member Functions | |
| ZKWrapper (const std::string &host, int &error_code, const std::string &root) | |
| std::string | prepend_zk_root (const std::string &path) const |
| std::string | removeZKRoot (const std::string &path) const |
| std::string | removeZKRootAndDir (const std::string &prefix, const std::string &path) const |
| bool | create (const std::string &path, const std::vector< std::uint8_t > &data, int &error_code, bool ephemeral, bool sync=true) const |
| bool | create_ephemeral (const std::string &path, const std::vector< std::uint8_t > &data, int &error_code, bool sync=true) const |
| bool | create_sequential (const std::string &path, const std::vector< std::uint8_t > &data, std::string &new_path, bool ephemeral, int &error_code, bool sync=true) const |
| bool | recursive_create (const std::string &path, const std::vector< std::uint8_t > &data, int &error_code, bool sync=true) const |
| bool | exists (const std::string &path, bool &exist, int &error_code) const |
| bool | wexists (const std::string &path, bool &exist, watcher_fn watch, void *watcherCtx, int &error_code) const |
| bool | delete_node (const std::string &path, int &error_code, bool sync=true) const |
| bool | recursive_delete (const std::string &path, int &error_code) const |
| bool | get_children (const std::string &path, std::vector< std::string > &children, int &error_code) const |
| bool | wget_children (const std::string &path, std::vector< std::string > &children, watcher_fn watch, void *watcherCtx, int &error_code) const |
| bool | get (const std::string &path, std::vector< std::uint8_t > &data, int &error_code, bool resize) const |
| bool | get_info (const std::string &path, struct Stat &stat, int &error_code) const |
| bool | wget (const std::string &path, std::vector< std::uint8_t > &data, watcher_fn watch, void *watcherCtx, int &error_code, bool resize) const |
| bool | set (const std::string &path, const std::vector< std::uint8_t > &data, int &error_code, bool sync=true, int version=-1) const |
| std::shared_ptr< ZooOp > | build_create_op (const std::string &path, const std::vector< std::uint8_t > &data, const int flags=0) const |
| std::shared_ptr< ZooOp > | build_delete_op (const std::string &path, int version=-1) const |
| std::shared_ptr< ZooOp > | build_set_op (const std::string &path, const std::vector< std::uint8_t > &data, int version=-1) const |
| bool | execute_multi (const std::vector< std::shared_ptr< ZooOp >> operations, std::vector< zoo_op_result > &results, int &error_code, bool sync=true) const |
| bool | flush (const std::string &full_path, bool synchronous=false) const |
| void | close () |
Static Public Member Functions | |
| static std::string | translate_error (int error_code) |
| static std::string | translate_watch_event_type (int type) |
| static std::string | translate_watch_state (int state) |
| static void | watcher_znode_data (zhandle_t *zzh, int type, int state, const char *path, void *watcherCtx) |
| static std::vector< uint8_t > | get_byte_vector (const std::string &string) |
| static void | print_error (int error) |
Static Public Attributes | |
|
static const std::vector < std::uint8_t > | EMPTY_VECTOR = std::vector<std::uint8_t>(0) |
Friends | |
| void | watcher (zhandle_t *zzh, int type, int state, const char *path, void *watcherCtx) |
| ZKWrapper::ZKWrapper | ( | const std::string & | host, |
| int & | error_code, | ||
| const std::string & | root | ||
| ) |
Initializes zookeeper. If error_code is ZOK after return, a connection to ZooKeeper would have been established, and the root would have been created.
| host | The location of where Zookeeper is running. For local development this will usually be 'localhost:2181' |
| error_code | Integer reference, set to a value in ZK_ERRORS Otherwise, an error code is returned. The meaning of an error code can be retrieved from translate_error() |
| root |
| std::shared_ptr< ZooOp > ZKWrapper::build_create_op | ( | const std::string & | path, |
| const std::vector< std::uint8_t > & | data, | ||
| const int | flags = 0 |
||
| ) | const |
| path | path of znode |
| data | data to initialize the node with. Set to the empty string to create an empty znode |
| flags | node flags: ZOO_EPHEMERAL, ZOO_SEQUENCE, ZOO_EPHEMERAL || ZOO_SEQUENCE |
| std::shared_ptr< ZooOp > ZKWrapper::build_delete_op | ( | const std::string & | path, |
| int | version = -1 |
||
| ) | const |
| path | of znode |
| version | Checks the version of the znode before deleting. Defaults to -1, which does not perform the check. |
| std::shared_ptr< ZooOp > ZKWrapper::build_set_op | ( | const std::string & | path, |
| const std::vector< std::uint8_t > & | data, | ||
| int | version = -1 |
||
| ) | const |
| path | |
| data | |
| version |
| bool ZKWrapper::create | ( | const std::string & | path, |
| const std::vector< std::uint8_t > & | data, | ||
| int & | error_code, | ||
| bool | ephemeral, | ||
| bool | sync = true |
||
| ) | const |
Create a znode in zookeeper
| path | The location of the new znode within the zookeeper structure |
| data | The data contained in this znode |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::create_sequential | ( | const std::string & | path, |
| const std::vector< std::uint8_t > & | data, | ||
| std::string & | new_path, | ||
| bool | ephemeral, | ||
| int & | error_code, | ||
| bool | sync = true |
||
| ) | const |
Creates a sequential znode
| path | The path to the new sequential znode. The last component must end in "-" like: '/foo/bar-'. When the node is created, a 10 digit sequential ID unique to the parent node will be appended to the name. |
| data | The data contained in this znode |
| new_path | Will contain the value of the newly created path |
| ephemeral | If true, the created node will ephemeral |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::delete_node | ( | const std::string & | path, |
| int & | error_code, | ||
| bool | sync = true |
||
| ) | const |
Deletes a znode from zookeeper
| path | The path to the znode that should be deleted |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::execute_multi | ( | const std::vector< std::shared_ptr< ZooOp >> | operations, |
| std::vector< zoo_op_result > & | results, | ||
| int & | error_code, | ||
| bool | sync = true |
||
| ) | const |
Runs all of the zookeeper operations within the operations vector atomically (without ordering). Atomic execution mean that either all of the operations will succeed, else they will all be rolled back.
| operations | a vector of operations to be executed |
| results | a vector that maps to the results of each of the executed operations |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::exists | ( | const std::string & | path, |
| bool & | exist, | ||
| int & | error_code | ||
| ) | const |
Checks if a znode exists or not.
| path | The path to the node |
| exist | Set to true if a znode exists at the given path, false otherwise |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::flush | ( | const std::string & | full_path, |
| bool | synchronous = false |
||
| ) | const |
Flush changes inside of ZooKeeper
| full_path | the full path of the znode directory to be flushed. Must be qualified with the ZooKeeper root |
| synchronous | Whether this operation is blocking |
| bool ZKWrapper::get | ( | const std::string & | path, |
| std::vector< std::uint8_t > & | data, | ||
| int & | error_code, | ||
| bool | resize | ||
| ) | const |
Gets the data associated with a node.
| path | The path to the node |
| data | Reference to a vector which will be filled with the znode data. The 2016 folks claimed that this field "Should be of size MAX_PAYLOAD when passed in, will be resized in this method." We (2017) are not sure why there is a MAX_PAYLOAD limit in the first place, and the 2016 folks never honored their own requirement. |
| error_code | Int reference, set to a value in ZK_ERRORS |
| resize | Should automatic resizing of the data vector be performed? If this argument is false, then the data buffer is expected to be large enough to hold everything in the node, otherwise the operation will fail. |
| bool ZKWrapper::get_children | ( | const std::string & | path, |
| std::vector< std::string > & | children, | ||
| int & | error_code | ||
| ) | const |
This function gets a list of children of the znode specified by the path
| path | The path of parent node |
| children | Reference to a vector which will be populated with the names of the children znodes of the given path TODO: How large should this vector be when passed in? |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::get_info | ( | const std::string & | path, |
| struct Stat & | stat, | ||
| int & | error_code | ||
| ) | const |
Gets the info associated with a znode
| path | The path to the node |
| stat | Reference to a stat struct to be filled with znode info |
| error_code | Int reference, set to a value in ZK_ERRORS |
| std::string ZKWrapper::prepend_zk_root | ( | const std::string & | path | ) | const |
Prepends the ZooKeeper root to all paths passed in
| path | the original path |
| bool ZKWrapper::recursive_create | ( | const std::string & | path, |
| const std::vector< std::uint8_t > & | data, | ||
| int & | error_code, | ||
| bool | sync = true |
||
| ) | const |
Recursively creates a new znode, non-existent znodes in the specified path will be created
| path | The path to create |
| data | The data to store in the new znode |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::recursive_delete | ( | const std::string & | path, |
| int & | error_code | ||
| ) | const |
Recursively deletes the znode specified in the path and any children of that path
| path | The path the znode (and its children) which will be deleted |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::set | ( | const std::string & | path, |
| const std::vector< std::uint8_t > & | data, | ||
| int & | error_code, | ||
| bool | sync = true, |
||
| int | version = -1 |
||
| ) | const |
Sets the data in a given znode
| path | The path to the znode |
| data | The data that this znode should contain |
| version | A version number indicating changes to the data at this node |
| error_code | Int reference, set to a value in ZK_ERRORS |
|
static |
Translate numerical error code to zookeeper error string
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::wexists | ( | const std::string & | path, |
| bool & | exist, | ||
| watcher_fn | watch, | ||
| void * | watcherCtx, | ||
| int & | error_code | ||
| ) | const |
This function is similar to 'exists' except it allows the caller to specify a watcher object rather than a boolean watch flag.
| path | The path to the znode that needs to be checked |
| exist | Set to true if a znode exists at the given path, false otherwise |
| watch | A watcher function |
| watcherCtx | User specific data, will be passed to the watcher callback. |
| error_code | Int reference, set to a value in ZK_ERRORS |
| bool ZKWrapper::wget | ( | const std::string & | path, |
| std::vector< std::uint8_t > & | data, | ||
| watcher_fn | watch, | ||
| void * | watcherCtx, | ||
| int & | error_code, | ||
| bool | resize | ||
| ) | const |
This function is similar to 'get' except it allows one to specify a watcher object.
| path | The path to the node |
| data | Reference to a vector which will be filled with the znode data Should be of size MAX_PAYLOAD when passed in, will be resized in this method |
| watch | A watcher function |
| watcherCtx | User specific data, will be passed to the watcher callback. |
| error_code | Int reference, set to a value in ZK_ERRORS |
| resize | Should automatic resizing of the data vector be performed? If this argument is false, then the data buffer is expected to be large enough to hold everything in the node, otherwise the operation will fail. |
| bool ZKWrapper::wget_children | ( | const std::string & | path, |
| std::vector< std::string > & | children, | ||
| watcher_fn | watch, | ||
| void * | watcherCtx, | ||
| int & | error_code | ||
| ) | const |
Similar to 'get_children', except it allows one to specify a watcher object rather than a boolean watch flag.
| path | The path to get children of and the node to place the watch on |
| children | Reference to a vector which will be populated with the names of the children znodes of the given path TODO: How large should this vector be when passed in? |
| watch | A watcher function |
| watcherCtx | User specific data, will be passed to the watcher callback. |
| error_code | Int reference, set to a value in ZK_ERRORS |
|
friend |
Currently watches the zookeeper handle and closes zookeeper on failed auths or expired sessions.
| zzh | zookeeper handle |
| type | type of event |
| state | state of the event |
| path | path to the watcher node |
| watcherCtx | the state of the watcher |
1.8.6