[Pkg-javascript-commits] [node-leveldown] 246/492: build full WriteBatch in v8 thread
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:05 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit 4815aacc50bea56265b966315d165db55d62aac3
Author: Rod Vagg <rod at vagg.org>
Date: Sat Mar 9 18:09:05 2013 +1100
build full WriteBatch in v8 thread
---
binding.gyp | 1 -
src/async.cc | 1 -
src/batch.cc | 31 --------------------------
src/batch.h | 62 ---------------------------------------------------
src/database.cc | 28 ++++++++++++-----------
src/database_async.cc | 23 +++++++++----------
src/database_async.h | 7 +++---
7 files changed, 30 insertions(+), 123 deletions(-)
diff --git a/binding.gyp b/binding.gyp
index 8f16109..bedc1bb 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -6,7 +6,6 @@
]
, "sources": [
"src/async.cc"
- , "src/batch.cc"
, "src/database.cc"
, "src/database_async.cc"
, "src/iterator.cc"
diff --git a/src/async.cc b/src/async.cc
index 5edf818..6b58c4e 100644
--- a/src/async.cc
+++ b/src/async.cc
@@ -8,7 +8,6 @@
#include "database.h"
#include "leveldown.h"
#include "async.h"
-#include "batch.h"
namespace leveldown {
diff --git a/src/batch.cc b/src/batch.cc
deleted file mode 100644
index af71621..0000000
--- a/src/batch.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Copyright (c) 2012-2013 LevelDOWN contributors
- * See list at <https://github.com/rvagg/node-leveldown#contributing>
- * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
- */
-
-#include "leveldb/write_batch.h"
-
-#include "batch.h"
-
-namespace leveldown {
-
-BatchOp::~BatchOp () {}
-
-BatchDelete::~BatchDelete () {
- keyPtr.Dispose();
-}
-
-void BatchDelete::Execute (leveldb::WriteBatch* batch) {
- batch->Delete(key);
-}
-
-BatchWrite::~BatchWrite () {
- keyPtr.Dispose();
- valuePtr.Dispose();
-}
-
-void BatchWrite::Execute (leveldb::WriteBatch* batch) {
- batch->Put(key, value);
-}
-
-} // namespace leveldown
diff --git a/src/batch.h b/src/batch.h
deleted file mode 100644
index 90aa2d9..0000000
--- a/src/batch.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Copyright (c) 2012-2013 LevelDOWN contributors
- * See list at <https://github.com/rvagg/node-leveldown#contributing>
- * MIT +no-false-attribs License <https://github.com/rvagg/node-leveldown/blob/master/LICENSE>
- */
-
-#ifndef LD_BATCH_H
-#define LD_BATCH_H
-
-#include "leveldb/write_batch.h"
-
-#include "database.h"
-
-namespace leveldown {
-
-class BatchOp {
-public:
- BatchOp () {};
- virtual ~BatchOp ();
- virtual void Execute (leveldb::WriteBatch* batch) =0;
-};
-
-class BatchDelete : public BatchOp {
-public:
- BatchDelete (
- leveldb::Slice key
- , v8::Persistent<v8::Value> keyPtr
- ) : key(key)
- , keyPtr(keyPtr)
- {};
- ~BatchDelete ();
- void Execute (leveldb::WriteBatch* batch);
-
-private:
- leveldb::Slice key;
- v8::Persistent<v8::Value> keyPtr;
-};
-
-class BatchWrite : public BatchOp {
-public:
- BatchWrite (
- leveldb::Slice key
- , leveldb::Slice value
- , v8::Persistent<v8::Value> keyPtr
- , v8::Persistent<v8::Value> valuePtr
- ) : key(key)
- , keyPtr(keyPtr)
- , value(value)
- , valuePtr(valuePtr)
- {};
- ~BatchWrite ();
- void Execute (leveldb::WriteBatch* batch);
-
-private:
- leveldb::Slice key;
- v8::Persistent<v8::Value> keyPtr;
- leveldb::Slice value;
- v8::Persistent<v8::Value> valuePtr;
-};
-
-} // namespace leveldown
-
-#endif
diff --git a/src/database.cc b/src/database.cc
index 673592a..4b943aa 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -8,12 +8,12 @@
#include <node_buffer.h>
#include "leveldb/db.h"
+#include "leveldb/write_batch.h"
#include "leveldown.h"
#include "database.h"
#include "async.h"
#include "database_async.h"
-#include "batch.h"
#include "iterator.h"
namespace leveldown {
@@ -314,7 +314,10 @@ v8::Handle<v8::Value> Database::Batch (const v8::Arguments& args) {
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[0]);
- std::vector<BatchOp*>* operations = new std::vector<BatchOp*>;
+ std::vector< v8::Persistent<v8::Value> >* references =
+ new std::vector< v8::Persistent<v8::Value> >;
+ leveldb::WriteBatch* batch = new leveldb::WriteBatch();
+
for (unsigned int i = 0; i < array->Length(); i++) {
if (!array->Get(i)->IsObject())
continue;
@@ -329,10 +332,9 @@ v8::Handle<v8::Value> Database::Batch (const v8::Arguments& args) {
if (obj->Get(str_type)->StrictEquals(str_del)) {
LD_STRING_OR_BUFFER_TO_SLICE(key, keyBuffer, Key)
- operations->push_back(new BatchDelete(
- key
- , v8::Persistent<v8::Value>::New(keyBuffer)
- ));
+ batch->Delete(key);
+ if (node::Buffer::HasInstance(keyBuffer->ToObject()))
+ references->push_back(v8::Persistent<v8::Value>::New(keyBuffer));
} else if (obj->Get(str_type)->StrictEquals(str_put)) {
v8::Local<v8::Value> valueBuffer = obj->Get(str_value);
LD_CB_ERR_IF_NULL_OR_UNDEFINED(valueBuffer, value)
@@ -340,19 +342,19 @@ v8::Handle<v8::Value> Database::Batch (const v8::Arguments& args) {
LD_STRING_OR_BUFFER_TO_SLICE(key, keyBuffer, Key)
LD_STRING_OR_BUFFER_TO_SLICE(value, valueBuffer, Value)
- operations->push_back(new BatchWrite(
- key
- , value
- , v8::Persistent<v8::Value>::New(keyBuffer)
- , v8::Persistent<v8::Value>::New(valueBuffer)
- ));
+ batch->Put(key, value);
+ if (node::Buffer::HasInstance(keyBuffer->ToObject()))
+ references->push_back(v8::Persistent<v8::Value>::New(keyBuffer));
+ if (node::Buffer::HasInstance(valueBuffer->ToObject()))
+ references->push_back(v8::Persistent<v8::Value>::New(valueBuffer));
}
}
AsyncQueueWorker(new BatchWorker(
database
, callback
- , operations
+ , batch
+ , references
, sync
));
diff --git a/src/database_async.cc b/src/database_async.cc
index 4345a05..0422e0b 100644
--- a/src/database_async.cc
+++ b/src/database_async.cc
@@ -10,7 +10,6 @@
#include "leveldown.h"
#include "async.h"
#include "database_async.h"
-#include "batch.h"
namespace leveldown {
@@ -173,30 +172,30 @@ void WriteWorker::WorkComplete () {
BatchWorker::BatchWorker (
Database* database
, v8::Persistent<v8::Function> callback
- , std::vector<BatchOp*>* operations
+ , leveldb::WriteBatch* batch
+ , std::vector< v8::Persistent<v8::Value> >* references
, bool sync
) : AsyncWorker(database, callback)
- , operations(operations)
+ , batch(batch)
+ , references(references)
{
options = new leveldb::WriteOptions();
options->sync = sync;
};
BatchWorker::~BatchWorker () {
- for (std::vector<BatchOp*>::iterator it = operations->begin(); it != operations->end();) {
- delete *it;
- it = operations->erase(it);
+ for (std::vector< v8::Persistent<v8::Value> >::iterator it = references->begin()
+ ; it != references->end()
+ ; ) {
+ it->Dispose();
+ it = references->erase(it);
}
- delete operations;
+ delete references;
delete options;
}
void BatchWorker::Execute () {
- leveldb::WriteBatch batch;
- for (std::vector<BatchOp*>::iterator it = operations->begin(); it != operations->end();) {
- (*it++)->Execute(&batch);
- }
- status = database->WriteBatchToDatabase(options, &batch);
+ status = database->WriteBatchToDatabase(options, batch);
}
/** APPROXIMATE SIZE WORKER **/
diff --git a/src/database_async.h b/src/database_async.h
index 2f66dee..25df5d9 100644
--- a/src/database_async.h
+++ b/src/database_async.h
@@ -12,7 +12,6 @@
#include "leveldb/cache.h"
#include "async.h"
-#include "batch.h"
namespace leveldown {
@@ -127,7 +126,8 @@ public:
BatchWorker (
Database* database
, v8::Persistent<v8::Function> callback
- , std::vector<BatchOp*>* operations
+ , leveldb::WriteBatch* batch
+ , std::vector< v8::Persistent<v8::Value> >* references
, bool sync
);
@@ -136,7 +136,8 @@ public:
private:
leveldb::WriteOptions* options;
- std::vector<BatchOp*>* operations;
+ leveldb::WriteBatch* batch;
+ std::vector< v8::Persistent<v8::Value> >* references;
};
class ApproximateSizeWorker : public AsyncWorker {
--
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