Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for container and TTL nodes #255

Closed
wants to merge 12 commits into from
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _
* `init(options)`
* `connect(options, connect_cb)`
* `close()`
* `path = await create(path, data, flags)`
* `path = await create(path, data, flags, ttl)`
DavidVujic marked this conversation as resolved.
Show resolved Hide resolved
* `mkdirp(path, callback(Error))`
* `stat = await exists(path, watch)`
* `data = await get(path, watch)`
Expand Down Expand Up @@ -126,6 +126,7 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _
* `connect(options, connect_cb)`
* `close()`
* `a_create(path, data, flags, path_cb)`
* `a_createTtl(path, data, flags, path_cb)`
* `mkdirp(path, callback(Error))`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(will fix in separate branch): missing ttl parameter.

* `a_exists(path, watch, stat_cb)`
* `a_get(path, watch, data_cb)`
Expand Down Expand Up @@ -164,9 +165,17 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _
* options : object. valid keys: { connect, timeout, debug_level, host_order_deterministic, data_as_buffer}
* path : string
* data : string or Buffer
* flags : int32
* version : int32
* flags : int32. Supported:
- `ZOO_PERSISTENT`
- `ZOO_EPHEMERAL`
- `ZOO_PERSISTENT_SEQUENTIAL`
- `ZOO_EPHEMERAL_SEQUENTIAL`
- `ZOO_CONTAINER`
- `ZOO_PERSISTENT_WITH_TTL`
- `ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL`
DavidVujic marked this conversation as resolved.
Show resolved Hide resolved
* version : int32. Pass 'null' or don't pas any to skip version checking.
* watch : boolean
* ttl: int32. Must be postive if any of the TTL modes is used; not positive or unspecified otherwise.
* scheme : authorisation scheme (digest, auth)
* auth : authorisation credentials (username:password)
* acl : acls list (same as output parameter, look below) - read only
Expand Down
18 changes: 18 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,30 @@ module.exports.ZOO_LOG_LEVEL_INFO = NativeZk.ZOO_LOG_LEVEL_INFO;
/** @type {number} 4 */
module.exports.ZOO_LOG_LEVEL_DEBUG = NativeZk.ZOO_LOG_LEVEL_DEBUG;

/** @type {number} 0 */
module.exports.ZOO_PERSISTENT = NativeZk.ZOO_PERSISTENT;

/** @type {number} 1 */
module.exports.ZOO_EPHEMERAL = NativeZk.ZOO_EPHEMERAL;

/** @type {number} 2 */
module.exports.ZOO_SEQUENCE = NativeZk.ZOO_SEQUENCE;

/** @type {number} 2 */
module.exports.ZOO_PERSISTENT_SEQUENTIAL = NativeZk.ZOO_PERSISTENT_SEQUENTIAL;
DavidVujic marked this conversation as resolved.
Show resolved Hide resolved

/** @type {number} 3 */
module.exports.ZOO_EPHEMERAL_SEQUENTIAL = NativeZk.ZOO_EPHEMERAL_SEQUENTIAL;

/** @type {number} 4 */
module.exports.ZOO_CONTAINER = NativeZk.ZOO_CONTAINER;

/** @type {number} 5 */
module.exports.ZOO_PERSISTENT_WITH_TTL = NativeZk.ZOO_PERSISTENT_WITH_TTL;

/** @type {number} 6 */
module.exports.ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL = NativeZk.ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL;

/** @type {number} 0 */
module.exports.ZOK = NativeZk.ZOK;

Expand Down
6 changes: 6 additions & 0 deletions lib/typedeclarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,14 @@ declare module "zookeeperConstants" {
export var ZOO_LOG_LEVEL_WARN: number;
export var ZOO_LOG_LEVEL_INFO: number;
export var ZOO_LOG_LEVEL_DEBUG: number;
export var ZOO_PERSISTENT: number;
export var ZOO_EPHEMERAL: number;
export var ZOO_PERSISTENT_SEQUENTIAL: number;
export var ZOO_EPHEMERAL_SEQUENTIAL: number;
export var ZOO_SEQUENCE: number;
export var ZOO_CONTAINER: number;
export var ZOO_PERSISTENT_WITH_TTL: number;
export var ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL: number;
export var ZOK: number;
export var ZSYSTEMERROR: number;
export var ZRUNTIMEINCONSISTENCY: number;
Expand Down
7 changes: 5 additions & 2 deletions lib/zk_promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ class ZooKeeperPromise extends ZooKeeper {
* @param {string} path
* @param {(string|Buffer)} data
* @param {number} flags
* @param {number} ttl,
* Must be positive integer if using any TTL mode;
DavidVujic marked this conversation as resolved.
Show resolved Hide resolved
* not-positive integer or null/undefined otherwise
* @fulfill {string}
* @returns {Promise.<string>}
*/
create(path, data, flags) {
return this.promisify(super.a_create, [path, data, flags]);
create(path, data, flags, ttl) {
return this.promisify(super.a_createTtl, [path, data, flags, ttl]);
}

/**
Expand Down
23 changes: 21 additions & 2 deletions lib/zookeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,27 @@ class ZooKeeper extends EventEmitter {
* @returns {*}
*/
a_create(path, data, flags, pathCb) {
this.log(`Calling a_create with ${util.inspect([path, data, flags, pathCb])}`);
return this.native.a_create(path, data, flags, pathCb);
this.log(`Calling a_create with ${util.inspect([path, data, flags, -1, pathCb])}`);
return this.native.a_create(path, data, flags, -1, pathCb);
}

/**
* @param {string} path
* @param {string|Buffer} data
* @param {number} flags - an int32 value
* @param {number} ttl
* Must be positive integer if using any TTL mode;
* not-positive integer or null/undefined otherwise
* @param {pathCb} pathCb
* @returns {*}
*/
a_createTtl(path, data, flags, ttl, pathCb) {
if (flags < 0) {
DavidVujic marked this conversation as resolved.
Show resolved Hide resolved
pathCb(new Error('Unsupported flags used. Are you on Windows? Then you\'re stuck to client version 3.4 and can\'t use container/ttl nodes.'));
}
const realTtl = ttl || -1;
this.log(`Calling a_create with ${util.inspect([path, data, flags, realTtl, pathCb])}`);
return this.native.a_create(path, data, flags, realTtl, pathCb);
}

/**
Expand Down
Binary file removed prebuilds/darwin-x64/node.abi72.node
Binary file not shown.
Binary file removed prebuilds/darwin-x64/node.abi83.node
Binary file not shown.
Binary file removed prebuilds/win32-x64/node.abi72.node
Binary file not shown.
Binary file removed prebuilds/win32-x64/node.abi83.node
Binary file not shown.
14 changes: 10 additions & 4 deletions src/node-zk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class ZooKeeper: public Nan::ObjectWrap {
Nan::DefineOwnProperty(acl_creator, LOCAL_STRING("auth"), LOCAL_STRING(""), static_cast<PropertyAttribute>(ReadOnly | DontDelete));
Nan::DefineOwnProperty(constructor, LOCAL_STRING("ZOO_CREATOR_ALL_ACL"), acl_creator, static_cast<PropertyAttribute>(ReadOnly | DontDelete));


NODE_DEFINE_CONSTANT(constructor, ZOO_CREATED_EVENT);
NODE_DEFINE_CONSTANT(constructor, ZOO_DELETED_EVENT);
NODE_DEFINE_CONSTANT(constructor, ZOO_CHANGED_EVENT);
Expand All @@ -190,8 +189,14 @@ class ZooKeeper: public Nan::ObjectWrap {
NODE_DEFINE_CONSTANT(constructor, ZOOKEEPER_WRITE);
NODE_DEFINE_CONSTANT(constructor, ZOOKEEPER_READ);

NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT);
NODE_DEFINE_CONSTANT(constructor, ZOO_EPHEMERAL);
NODE_DEFINE_CONSTANT(constructor, ZOO_SEQUENCE);
NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT_SEQUENTIAL);
NODE_DEFINE_CONSTANT(constructor, ZOO_EPHEMERAL_SEQUENTIAL);
NODE_DEFINE_CONSTANT(constructor, ZOO_CONTAINER);
NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT_WITH_TTL);
NODE_DEFINE_CONSTANT(constructor, ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL);

NODE_DEFINE_CONSTANT(constructor, ZOO_CREATED_EVENT);
NODE_DEFINE_CONSTANT(constructor, ZOO_DELETED_EVENT);
Expand Down Expand Up @@ -637,17 +642,18 @@ class ZooKeeper: public Nan::ObjectWrap {
}

static void ACreate(const Nan::FunctionCallbackInfo<Value>& info) {
A_METHOD_PROLOG(4);
A_METHOD_PROLOG(5);

Nan::Utf8String _path (toString(info[0]));
uint32_t flags = toUint(info[2]);

int32_t ttl = toInt(info[3]);
DavidVujic marked this conversation as resolved.
Show resolved Hide resolved
if (Buffer::HasInstance(info[1])) { // buffer
Local<Object> _data = toLocalObj(info[1]);
METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb));
METHOD_EPILOG(zoo_acreate_ttl(zk->zhandle, *_path, BufferData(_data), BufferLength(_data), &ZOO_OPEN_ACL_UNSAFE, flags, ttl, string_completion, cb));
} else { // other
Nan::Utf8String _data (toString(info[1]));
METHOD_EPILOG(zoo_acreate(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, string_completion, cb));
METHOD_EPILOG(zoo_acreate_ttl(zk->zhandle, *_path, *_data, _data.length(), &ZOO_OPEN_ACL_UNSAFE, flags, ttl, string_completion, cb));
}
}

Expand Down