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

MAJOR: Update to leveldown v6.1.1 #17

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/level-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,6 @@ class IteratorOptions {
this.values = options.values;
}

if (options.start != null)
this.start = options.start;

if (options.end != null)
this.end = options.end;

if (options.gte != null)
this.start = options.gte;

Expand All @@ -633,13 +627,13 @@ class IteratorOptions {
if (this.start != null) {
if (typeof this.start === 'string')
this.start = Buffer.from(this.start, 'utf8');
assert(Buffer.isBuffer(this.start), '`start` must be a Buffer.');
assert(Buffer.isBuffer(this.start), '`gt(e)` must be a Buffer.');
}

if (this.end != null) {
if (typeof this.end === 'string')
this.end = Buffer.from(this.end, 'utf8');
assert(Buffer.isBuffer(this.end), '`end` must be a Buffer.');
assert(Buffer.isBuffer(this.end), '`lt(e)` must be a Buffer.');
}

if (options.keyAsBuffer != null) {
Expand Down
10 changes: 2 additions & 8 deletions lib/memdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,6 @@ class IteratorOptions {
this.values = options.values;
}

if (options.start != null)
this.start = options.start;

if (options.end != null)
this.end = options.end;

if (options.gte != null)
this.start = options.gte;

Expand All @@ -641,13 +635,13 @@ class IteratorOptions {
if (this.start != null) {
if (typeof this.start === 'string')
this.start = Buffer.from(this.start, 'utf8');
assert(Buffer.isBuffer(this.start), '`start` must be a Buffer.');
assert(Buffer.isBuffer(this.start), '`gt(e)` must be a Buffer.');
}

if (this.end != null) {
if (typeof this.end === 'string')
this.end = Buffer.from(this.end, 'utf8');
assert(Buffer.isBuffer(this.end), '`end` must be a Buffer.');
assert(Buffer.isBuffer(this.end), '`lt(e)` must be a Buffer.');
}

if (options.keyAsBuffer != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/src/binding.cc b/src/binding.cc
index b42e570..26c8fed 100644
index c30ac76..e933861 100644
--- a/src/binding.cc
+++ b/src/binding.cc
@@ -1677,7 +1677,8 @@ struct Batch {
@@ -1874,7 +1874,8 @@ struct Batch {
Batch (Database* database)
: database_(database),
batch_(new leveldb::WriteBatch()),
Expand All @@ -12,7 +12,7 @@ index b42e570..26c8fed 100644

~Batch () {
delete batch_;
@@ -1704,9 +1705,22 @@ struct Batch {
@@ -1901,9 +1902,22 @@ struct Batch {
return database_->WriteBatch(options, batch_);
}

Expand All @@ -35,7 +35,7 @@ index b42e570..26c8fed 100644
};

/**
@@ -1741,11 +1755,15 @@ NAPI_METHOD(batch_put) {
@@ -1938,11 +1952,15 @@ NAPI_METHOD(batch_put) {
NAPI_ARGV(3);
NAPI_BATCH_CONTEXT();

Expand All @@ -56,7 +56,7 @@ index b42e570..26c8fed 100644

NAPI_RETURN_UNDEFINED();
}
@@ -1757,9 +1775,13 @@ NAPI_METHOD(batch_del) {
@@ -1954,9 +1972,13 @@ NAPI_METHOD(batch_del) {
NAPI_ARGV(2);
NAPI_BATCH_CONTEXT();

Expand All @@ -73,7 +73,7 @@ index b42e570..26c8fed 100644

NAPI_RETURN_UNDEFINED();
}
@@ -1771,7 +1793,11 @@ NAPI_METHOD(batch_clear) {
@@ -1968,7 +1990,11 @@ NAPI_METHOD(batch_clear) {
NAPI_ARGV(1);
NAPI_BATCH_CONTEXT();

Expand All @@ -86,48 +86,34 @@ index b42e570..26c8fed 100644

NAPI_RETURN_UNDEFINED();
}
@@ -1788,6 +1814,9 @@ struct BatchWriteWorker final : public PriorityWorker {
@@ -1985,6 +2011,9 @@ struct BatchWriteWorker final : public PriorityWorker {
: PriorityWorker(env, batch->database_, callback, "leveldown.batch.write"),
batch_(batch),
sync_(sync) {
+ // For thread saftey, consider BatchWrite as shared.
+ // For thread safety, consider BatchWrite as shared.
+ batch->Share();
+
// Prevent GC of batch object before we execute
NAPI_STATUS_THROWS_VOID(napi_create_reference(env_, context, 1, &contextRef_));
NAPI_STATUS_THROWS_VOID(napi_create_reference(env, context, 1, &contextRef_));
}
@@ -1802,6 +1831,11 @@ struct BatchWriteWorker final : public PriorityWorker {
}
}
@@ -1999,6 +2028,7 @@ struct BatchWriteWorker final : public PriorityWorker {

+ void DoFinally () override {
+ database_->DecrementPriorityWork();
void DoFinally (napi_env env) override {
napi_delete_reference(env, contextRef_);
+ batch_->Unshare();
+ }
+
Batch* batch_;
bool sync_;

@@ -1816,12 +1850,18 @@ NAPI_METHOD(batch_write) {
NAPI_ARGV(3);
NAPI_BATCH_CONTEXT();
PriorityWorker::DoFinally(env);
}

- napi_value options = argv[1];
- bool sync = BooleanProperty(env, options, "sync", false);
@@ -2019,6 +2049,12 @@ NAPI_METHOD(batch_write) {
const bool sync = BooleanProperty(env, options, "sync", false);
napi_value callback = argv[2];

- BatchWriteWorker* worker = new BatchWriteWorker(env, argv[0], batch, callback, sync);
- worker->Queue();
+ if (!batch->IsShared()) {
+ napi_value options = argv[1];
+ bool sync = BooleanProperty(env, options, "sync", false);
+
+ BatchWriteWorker* worker = new BatchWriteWorker(env, argv[0], batch, callback, sync);
+ worker->Queue();
+ } else {
+ if (batch->IsShared()) {
+ napi_value argv = CreateError(env, "Unsafe batch write.");
+ CallFunction(env, callback, 1, &argv);
+ NAPI_RETURN_UNDEFINED();
+ }
+
BatchWriteWorker* worker = new BatchWriteWorker(env, argv[0], batch, callback, sync);
worker->Queue(env);

NAPI_RETURN_UNDEFINED();
}
Loading