Skip to content

Commit

Permalink
Add JS wrappers for C client add/remove seed functions
Browse files Browse the repository at this point in the history
as_cluster_add_seed/as_cluster_remove_seed where added in C client
v4.1.6 for dynamic seed changes after cluster has been initialized. This
just adds wrappers for these functions to the JS Client interface.
  • Loading branch information
jhecking committed May 22, 2017
1 parent f0896d9 commit ff146b9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Client.setCallbackHandler = function (callbackHandler) {
* const policy = { timeout: 1000 }
*
* Aerospike.connect((error, client) => {
* if (err) throw err
* var llist = client.LargeList(key, 'ldtBinName', policy);
* llist.add('abc', (error) => {
* client.close()
Expand All @@ -122,6 +123,36 @@ Client.prototype.LargeList = function (key, binName, policy, createModule) {
return new LargeList(this, key, binName, policy, createModule)
}

/**
* @function Client#addSeedHost
*
* @summary Adds a seed host to the cluster.
*
* @param {String} hostname - Hostname/IP address of the new seed host
* @param {Number} [port=3000] - Port number; defaults to {@link Config#port} or 3000.
*
* @since v2.6.0
*/
Client.prototype.addSeedHost = function (hostname, port) {
port = port || this.config.port
this.as_client.addSeedHost(hostname, port)
}

/**
* @function Client#removeSeedHost
*
* @summary Removes a seed host from the cluster.
*
* @param {String} hostname - Hostname/IP address of the seed host
* @param {Number} [port=3000] - Port number; defaults to {@link Config#port} or 3000.
*
* @since v2.6.0
*/
Client.prototype.removeSeedHost = function (hostname, port) {
port = port || this.config.port
this.as_client.removeSeedHost(hostname, port)
}

/**
* @function Client#batchExists
*
Expand Down
2 changes: 2 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ function Config (config) {
*/
if (typeof config.port === 'number') {
this.port = config.port
} else {
this.port = 3000
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class AerospikeClient : public ObjectWrap {
* CLIENT OPERATIONS
**********************************************************************/

static NAN_METHOD(AddSeedHost);
static NAN_METHOD(ApplyAsync);
static NAN_METHOD(BatchExists);
static NAN_METHOD(BatchGet);
Expand All @@ -107,6 +108,7 @@ class AerospikeClient : public ObjectWrap {
static NAN_METHOD(Register);
static NAN_METHOD(RegisterWait);
static NAN_METHOD(RemoveAsync);
static NAN_METHOD(RemoveSeedHost);
static NAN_METHOD(ScanBackground);
static NAN_METHOD(ScanAsync);
static NAN_METHOD(SelectAsync);
Expand Down
2 changes: 2 additions & 0 deletions src/main/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void AerospikeClient::Init()
// object using an internal field.
tpl->InstanceTemplate()->SetInternalFieldCount(1);

Nan::SetPrototypeMethod(tpl, "addSeedHost", AddSeedHost);
Nan::SetPrototypeMethod(tpl, "applyAsync", ApplyAsync);
Nan::SetPrototypeMethod(tpl, "batchExists", BatchExists);
Nan::SetPrototypeMethod(tpl, "batchGet", BatchGet);
Expand All @@ -161,6 +162,7 @@ void AerospikeClient::Init()
Nan::SetPrototypeMethod(tpl, "queryBackground", QueryBackground);
Nan::SetPrototypeMethod(tpl, "queryForeach", QueryForeach);
Nan::SetPrototypeMethod(tpl, "removeAsync", RemoveAsync);
Nan::SetPrototypeMethod(tpl, "removeSeedHost", RemoveSeedHost);
Nan::SetPrototypeMethod(tpl, "scanAsync", ScanAsync);
Nan::SetPrototypeMethod(tpl, "scanBackground", ScanBackground);
Nan::SetPrototypeMethod(tpl, "selectAsync", SelectAsync);
Expand Down
35 changes: 35 additions & 0 deletions src/main/client/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
extern "C" {
#include <aerospike/aerospike.h>
#include <aerospike/as_async_proto.h>
#include <aerospike/as_cluster.h>
}

using namespace v8;
Expand Down Expand Up @@ -95,3 +96,37 @@ NAN_METHOD(AerospikeClient::HasPendingAsyncCommands)

info.GetReturnValue().Set(Nan::New(pending));
}

/**
* Adds a seed host to the cluster.
*/
NAN_METHOD(AerospikeClient::AddSeedHost)
{
Nan::HandleScope scope;
AerospikeClient * client = ObjectWrap::Unwrap<AerospikeClient>(info.This());

TYPE_CHECK_REQ(info[0], IsString, "hostname must be a string");
TYPE_CHECK_REQ(info[1], IsNumber, "port must be a number");

String::Utf8Value hostname(info[0]->ToString());
uint16_t port = (uint16_t) info[1]->ToInteger()->Value();

as_cluster_add_seed(client->as->cluster, *hostname, NULL, port);
}

/**
* Removes a seed host from the cluster.
*/
NAN_METHOD(AerospikeClient::RemoveSeedHost)
{
Nan::HandleScope scope;
AerospikeClient * client = ObjectWrap::Unwrap<AerospikeClient>(info.This());

TYPE_CHECK_REQ(info[0], IsString, "hostname must be a string");
TYPE_CHECK_REQ(info[1], IsNumber, "port must be a number");

String::Utf8Value hostname(info[0]->ToString());
uint16_t port = (uint16_t) info[1]->ToInteger()->Value();

as_cluster_remove_seed(client->as->cluster, *hostname, port);
}

0 comments on commit ff146b9

Please sign in to comment.