[Pkg-javascript-commits] [node-leveldown] 13/23: made liveBackup() async

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:21:53 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to tag hyper-0.10.2
in repository node-leveldown.

commit 0d37078c6c16d2b118447fba13320e569607ac0b
Author: Rod Vagg <rod at vagg.org>
Date:   Fri Aug 30 13:05:40 2013 +1000

    made liveBackup() async
---
 src/database.cc       | 35 ++++++++++++++++++++++++++++++-----
 src/database.h        |  2 +-
 src/database_async.cc | 22 ++++++++++++++++++++++
 src/database_async.h  | 17 +++++++++++++++++
 4 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/src/database.cc b/src/database.cc
index d3df8c4..fa7b0cb 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -89,11 +89,8 @@ void Database::GetPropertyFromDatabase (
   db->GetProperty(property, value);
 }
 
-void Database::LiveBackup (
-      const leveldb::Slice& name
-    ) {
-
-  db->LiveBackup(name);
+leveldb::Status Database::LiveBackup (const leveldb::Slice& name) {
+  return db->LiveBackup(name);
 }
 
 leveldb::Iterator* Database::NewIterator (leveldb::ReadOptions* options) {
@@ -619,5 +616,33 @@ NAN_METHOD(Database::Iterator) {
   NanReturnValue(iteratorHandle);
 }
 
+NAN_METHOD(Database::LiveBackup) {
+  NanScope();
+
+  v8::Local<v8::Object> nameHandle = args[0].As<v8::Object>();
+
+  if (nameHandle->IsNull()
+      || nameHandle->IsUndefined()
+      || nameHandle->IsFunction()) {
+    return NanThrowError("liveBackup() requires a valid `name` argument");
+  }
+
+  LD_METHOD_SETUP_COMMON(liveBackup, -1, 1)
+
+  LD_CB_ERR_IF_NULL_OR_UNDEFINED(args[0], name)
+
+  LD_STRING_OR_BUFFER_TO_SLICE(name, nameHandle, name)
+
+  LiveBackupWorker* worker  = new LiveBackupWorker(
+      database
+    , new NanCallback(callback)
+    , name
+    , nameHandle
+  );
+  NanAsyncQueueWorker(worker);
+
+  NanReturnUndefined();
+}
+
 } // namespace leveldown
 
diff --git a/src/database.h b/src/database.h
index a55631e..0e4212f 100644
--- a/src/database.h
+++ b/src/database.h
@@ -70,7 +70,7 @@ public:
   );
   uint64_t ApproximateSizeFromDatabase (const leveldb::Range* range);
   void GetPropertyFromDatabase (const leveldb::Slice& property, std::string* value);
-  void LiveBackup (const leveldb::Slice& name);
+  leveldb::Status LiveBackup (const leveldb::Slice& name);
   leveldb::Iterator* NewIterator (leveldb::ReadOptions* options);
   const leveldb::Snapshot* NewSnapshot ();
   void ReleaseSnapshot (const leveldb::Snapshot* snapshot);
diff --git a/src/database_async.cc b/src/database_async.cc
index 3f520b1..414f7f4 100644
--- a/src/database_async.cc
+++ b/src/database_async.cc
@@ -266,4 +266,26 @@ void ApproximateSizeWorker::HandleOKCallback () {
   callback->Call(2, argv);
 }
 
+LiveBackupWorker::LiveBackupWorker (
+    Database *database
+  , NanCallback *callback
+  , leveldb::Slice name
+  , v8::Local<v8::Object> &nameHandle
+) : AsyncWorker(database, callback)
+  , name(name)
+{
+  SavePersistent("name", nameHandle);
+};
+
+LiveBackupWorker::~LiveBackupWorker () {}
+
+void LiveBackupWorker::Execute () {
+  SetStatus(database->LiveBackup(name));
+}
+
+void LiveBackupWorker::WorkComplete () {
+  DisposeStringOrBufferFromSlice(GetFromPersistent("name"), name);
+  AsyncWorker::WorkComplete();
+}
+
 } // namespace leveldown
diff --git a/src/database_async.h b/src/database_async.h
index 5401d70..23b2b94 100644
--- a/src/database_async.h
+++ b/src/database_async.h
@@ -162,6 +162,23 @@ public:
     uint64_t size;
 };
 
+class LiveBackupWorker : public AsyncWorker {
+public:
+  LiveBackupWorker (
+      Database *database
+    , NanCallback *callback
+    , leveldb::Slice name
+    , v8::Local<v8::Object> &nameHandle
+  );
+
+  virtual ~LiveBackupWorker ();
+  virtual void Execute ();
+  virtual void WorkComplete ();
+
+private:
+  leveldb::Slice name;
+};
+
 } // namespace leveldown
 
 #endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git



More information about the Pkg-javascript-commits mailing list