Add vitastor_c_delete() and delete() to the node.js binding
This commit is contained in:
@@ -14,6 +14,7 @@ NAN_MODULE_INIT(InitAddon)
|
||||
|
||||
Nan::SetPrototypeMethod(tpl, "read", NodeVitastor::Read);
|
||||
Nan::SetPrototypeMethod(tpl, "write", NodeVitastor::Write);
|
||||
Nan::SetPrototypeMethod(tpl, "delete", NodeVitastor::Delete);
|
||||
Nan::SetPrototypeMethod(tpl, "sync", NodeVitastor::Sync);
|
||||
Nan::SetPrototypeMethod(tpl, "read_bitmap", NodeVitastor::ReadBitmap);
|
||||
Nan::SetPrototypeMethod(tpl, "on_ready", NodeVitastor::OnReady);
|
||||
|
||||
+84
-14
@@ -5,9 +5,10 @@
|
||||
|
||||
#define NODE_VITASTOR_READ 1
|
||||
#define NODE_VITASTOR_WRITE 2
|
||||
#define NODE_VITASTOR_SYNC 3
|
||||
#define NODE_VITASTOR_READ_BITMAP 4
|
||||
#define NODE_VITASTOR_GET_INFO 5
|
||||
#define NODE_VITASTOR_DELETE 3
|
||||
#define NODE_VITASTOR_SYNC 4
|
||||
#define NODE_VITASTOR_READ_BITMAP 5
|
||||
#define NODE_VITASTOR_GET_INFO 6
|
||||
|
||||
#ifndef INODE_POOL
|
||||
#define INODE_POOL(inode) (uint32_t)((inode) >> (64 - POOL_ID_BITS))
|
||||
@@ -133,12 +134,12 @@ NodeVitastorRequest* NodeVitastor::get_read_request(const Nan::FunctionCallbackI
|
||||
return req;
|
||||
}
|
||||
|
||||
// read(pool, inode, offset, len, callback(err, buffer, version))
|
||||
// read(pool, inode, offset, length, callback(err, buffer, version))
|
||||
NAN_METHOD(NodeVitastor::Read)
|
||||
{
|
||||
TRACE("NodeVitastor::Read");
|
||||
if (info.Length() < 5)
|
||||
Nan::ThrowError("Not enough arguments to read(pool, inode, offset, len, callback(err, buffer, version))");
|
||||
Nan::ThrowError("Not enough arguments to read(pool, inode, offset, length, callback(err, buffer, version))");
|
||||
|
||||
NodeVitastor* self = Nan::ObjectWrap::Unwrap<NodeVitastor>(info.This());
|
||||
|
||||
@@ -219,6 +220,52 @@ NAN_METHOD(NodeVitastor::Write)
|
||||
on_write_finish, req);
|
||||
}
|
||||
|
||||
NodeVitastorRequest* NodeVitastor::get_delete_request(const Nan::FunctionCallbackInfo<v8::Value> & info, int argpos)
|
||||
{
|
||||
uint64_t offset = get_ui64(info[argpos+0]);
|
||||
uint64_t len = get_ui64(info[argpos+1]);
|
||||
uint64_t version = 0;
|
||||
if (!info[argpos+2].IsEmpty() &&
|
||||
!info[argpos+2]->IsFunction() &&
|
||||
info[argpos+2]->IsObject())
|
||||
{
|
||||
auto key = Nan::New<v8::String>("version").ToLocalChecked();
|
||||
auto params = info[argpos+2].As<v8::Object>();
|
||||
auto versionObj = Nan::Get(params, key).ToLocalChecked();
|
||||
if (!versionObj.IsEmpty())
|
||||
version = get_ui64(versionObj);
|
||||
argpos++;
|
||||
}
|
||||
|
||||
v8::Local<v8::Function> callback = info[argpos+2].As<v8::Function>();
|
||||
auto req = new NodeVitastorRequest(this, callback);
|
||||
|
||||
req->offset = offset;
|
||||
req->len = len;
|
||||
req->version = version;
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
// delete(pool, inode, offset, length, { version }?, callback(err))
|
||||
NAN_METHOD(NodeVitastor::Delete)
|
||||
{
|
||||
TRACE("NodeVitastor::Delete");
|
||||
if (info.Length() < 5)
|
||||
Nan::ThrowError("Not enough arguments to delete(pool, inode, offset, length, { version }?, callback(err))");
|
||||
|
||||
NodeVitastor* self = Nan::ObjectWrap::Unwrap<NodeVitastor>(info.This());
|
||||
|
||||
uint64_t pool = get_ui64(info[0]);
|
||||
uint64_t inode = get_ui64(info[1]);
|
||||
|
||||
auto req = self->get_delete_request(info, 2);
|
||||
|
||||
self->Ref();
|
||||
vitastor_c_delete(self->c, ((pool << (64-POOL_ID_BITS)) | inode), req->offset, req->len, req->version,
|
||||
on_write_finish, req);
|
||||
}
|
||||
|
||||
// sync(callback(err))
|
||||
NAN_METHOD(NodeVitastor::Sync)
|
||||
{
|
||||
@@ -235,12 +282,12 @@ NAN_METHOD(NodeVitastor::Sync)
|
||||
vitastor_c_sync(self->c, on_write_finish, req);
|
||||
}
|
||||
|
||||
// read_bitmap(pool, inode, offset, len, with_parents, callback(err, bitmap_buffer))
|
||||
// read_bitmap(pool, inode, offset, length, with_parents, callback(err, bitmap_buffer))
|
||||
NAN_METHOD(NodeVitastor::ReadBitmap)
|
||||
{
|
||||
TRACE("NodeVitastor::ReadBitmap");
|
||||
if (info.Length() < 6)
|
||||
Nan::ThrowError("Not enough arguments to read_bitmap(pool, inode, offset, len, with_parents, callback(err, bitmap_buffer))");
|
||||
Nan::ThrowError("Not enough arguments to read_bitmap(pool, inode, offset, length, with_parents, callback(err, bitmap_buffer))");
|
||||
|
||||
NodeVitastor* self = Nan::ObjectWrap::Unwrap<NodeVitastor>(info.This());
|
||||
|
||||
@@ -436,12 +483,12 @@ NodeVitastorImage::~NodeVitastorImage()
|
||||
cli->Unref();
|
||||
}
|
||||
|
||||
// read(offset, len, callback(err, buffer, version))
|
||||
// read(offset, length, callback(err, buffer, version))
|
||||
NAN_METHOD(NodeVitastorImage::Read)
|
||||
{
|
||||
TRACE("NodeVitastorImage::Read");
|
||||
if (info.Length() < 3)
|
||||
Nan::ThrowError("Not enough arguments to read(offset, len, callback(err, buffer, version))");
|
||||
Nan::ThrowError("Not enough arguments to read(offset, length, callback(err, buffer, version))");
|
||||
|
||||
NodeVitastorImage* img = Nan::ObjectWrap::Unwrap<NodeVitastorImage>(info.This());
|
||||
|
||||
@@ -452,12 +499,12 @@ NAN_METHOD(NodeVitastorImage::Read)
|
||||
img->exec_or_wait(req);
|
||||
}
|
||||
|
||||
// write(offset, buffer, { version }?, callback(err))
|
||||
// write(offset, buf: Buffer | Buffer[], { version }?, callback(err))
|
||||
NAN_METHOD(NodeVitastorImage::Write)
|
||||
{
|
||||
TRACE("NodeVitastorImage::Write");
|
||||
if (info.Length() < 3)
|
||||
Nan::ThrowError("Not enough arguments to write(offset, buffer, { version }?, callback(err))");
|
||||
Nan::ThrowError("Not enough arguments to write(offset, buf: Buffer | Buffer[], { version }?, callback(err))");
|
||||
|
||||
NodeVitastorImage* img = Nan::ObjectWrap::Unwrap<NodeVitastorImage>(info.This());
|
||||
|
||||
@@ -468,6 +515,22 @@ NAN_METHOD(NodeVitastorImage::Write)
|
||||
img->exec_or_wait(req);
|
||||
}
|
||||
|
||||
// delete(offset, length, { version }?, callback(err))
|
||||
NAN_METHOD(NodeVitastorImage::Delete)
|
||||
{
|
||||
TRACE("NodeVitastorImage::Delete");
|
||||
if (info.Length() < 3)
|
||||
Nan::ThrowError("Not enough arguments to delete(offset, length, { version }?, callback(err))");
|
||||
|
||||
NodeVitastorImage* img = Nan::ObjectWrap::Unwrap<NodeVitastorImage>(info.This());
|
||||
|
||||
auto req = img->cli->get_delete_request(info, 0);
|
||||
req->img = img;
|
||||
req->op = NODE_VITASTOR_DELETE;
|
||||
|
||||
img->exec_or_wait(req);
|
||||
}
|
||||
|
||||
// sync(callback(err))
|
||||
NAN_METHOD(NodeVitastorImage::Sync)
|
||||
{
|
||||
@@ -485,12 +548,12 @@ NAN_METHOD(NodeVitastorImage::Sync)
|
||||
img->exec_or_wait(req);
|
||||
}
|
||||
|
||||
// read_bitmap(offset, len, with_parents, callback(err, bitmap_buffer))
|
||||
// read_bitmap(offset, length, with_parents, callback(err, bitmap_buffer))
|
||||
NAN_METHOD(NodeVitastorImage::ReadBitmap)
|
||||
{
|
||||
TRACE("NodeVitastorImage::ReadBitmap");
|
||||
if (info.Length() < 4)
|
||||
Nan::ThrowError("Not enough arguments to read_bitmap(offset, len, with_parents, callback(err, bitmap_buffer))");
|
||||
Nan::ThrowError("Not enough arguments to read_bitmap(offset, length, with_parents, callback(err, bitmap_buffer))");
|
||||
|
||||
NodeVitastorImage* img = Nan::ObjectWrap::Unwrap<NodeVitastorImage>(info.This());
|
||||
|
||||
@@ -556,6 +619,13 @@ void NodeVitastorImage::exec_request(NodeVitastorRequest *req)
|
||||
req->iov_list.size() ? req->iov_list.size() : 1,
|
||||
NodeVitastor::on_write_finish, req);
|
||||
}
|
||||
else if (req->op == NODE_VITASTOR_DELETE)
|
||||
{
|
||||
uint64_t ino = vitastor_c_inode_get_num(watch);
|
||||
cli->Ref();
|
||||
vitastor_c_delete(cli->c, ino, req->offset, req->len, req->version,
|
||||
NodeVitastor::on_write_finish, req);
|
||||
}
|
||||
else if (req->op == NODE_VITASTOR_SYNC)
|
||||
{
|
||||
uint64_t ino = vitastor_c_inode_get_num(watch);
|
||||
@@ -967,7 +1037,7 @@ NodeVitastorKVListing::~NodeVitastorKVListing()
|
||||
kv->Unref();
|
||||
}
|
||||
|
||||
// next(callback(err, value)?)
|
||||
// next(callback(err, key, value)?)
|
||||
NAN_METHOD(NodeVitastorKVListing::Next)
|
||||
{
|
||||
TRACE("NodeVitastorKVListing::Next");
|
||||
|
||||
+10
-5
@@ -15,13 +15,15 @@ class NodeVitastor: public Nan::ObjectWrap
|
||||
public:
|
||||
// constructor({ ...config })
|
||||
static NAN_METHOD(Create);
|
||||
// read(pool_id, inode, offset, len, callback(err, buffer, version))
|
||||
// read(pool_id, inode, offset, length, callback(err, buffer, version))
|
||||
static NAN_METHOD(Read);
|
||||
// write(pool_id, inode, offset, buf: Buffer | Buffer[], { version }?, callback(err))
|
||||
static NAN_METHOD(Write);
|
||||
// delete(pool_id, inode, offset, length, { version }?, callback(err))
|
||||
static NAN_METHOD(Delete);
|
||||
// sync(callback(err))
|
||||
static NAN_METHOD(Sync);
|
||||
// read_bitmap(pool_id, inode, offset, len, with_parents, callback(err, bitmap_buffer))
|
||||
// read_bitmap(pool_id, inode, offset, length, with_parents, callback(err, bitmap_buffer))
|
||||
static NAN_METHOD(ReadBitmap);
|
||||
// on_ready(callback(err))
|
||||
static NAN_METHOD(OnReady);
|
||||
@@ -51,6 +53,7 @@ private:
|
||||
|
||||
NodeVitastorRequest* get_read_request(const Nan::FunctionCallbackInfo<v8::Value> & info, int argpos);
|
||||
NodeVitastorRequest* get_write_request(const Nan::FunctionCallbackInfo<v8::Value> & info, int argpos);
|
||||
NodeVitastorRequest* get_delete_request(const Nan::FunctionCallbackInfo<v8::Value> & info, int argpos);
|
||||
|
||||
friend class NodeVitastorImage;
|
||||
friend class NodeVitastorKV;
|
||||
@@ -62,13 +65,15 @@ class NodeVitastorImage: public Nan::ObjectWrap
|
||||
public:
|
||||
// constructor(node_vitastor, name)
|
||||
static NAN_METHOD(Create);
|
||||
// read(offset, len, callback(err, buffer, version))
|
||||
// read(offset, length, callback(err, buffer, version))
|
||||
static NAN_METHOD(Read);
|
||||
// write(offset, buf: Buffer | Buffer[], { version }?, callback(err))
|
||||
static NAN_METHOD(Write);
|
||||
// delete(offset, length, { version }?, callback(err))
|
||||
static NAN_METHOD(Delete);
|
||||
// sync(callback(err))
|
||||
static NAN_METHOD(Sync);
|
||||
// read_bitmap(offset, len, with_parents, callback(err, bitmap_buffer))
|
||||
// read_bitmap(offset, length, with_parents, callback(err, bitmap_buffer))
|
||||
static NAN_METHOD(ReadBitmap);
|
||||
// get_info(callback({ num, name, size, parent_id?, readonly?, meta?, mod_revision, block_size, bitmap_granularity, immediate_commit }))
|
||||
static NAN_METHOD(GetInfo);
|
||||
@@ -129,7 +134,7 @@ class NodeVitastorKVListing: public Nan::ObjectWrap
|
||||
public:
|
||||
// constructor(node_vitastor_kv, start_key?)
|
||||
static NAN_METHOD(Create);
|
||||
// next(callback(err, value)?)
|
||||
// next(callback(err, key, value)?)
|
||||
static NAN_METHOD(Next);
|
||||
// close()
|
||||
static NAN_METHOD(Close);
|
||||
|
||||
Reference in New Issue
Block a user