@nxtedition/rocksdb 15.2.4 → 15.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.cc +0 -1
- package/chained-batch.js +40 -10
- package/package.json +1 -1
- package/prebuilds/linux-x64/@nxtedition+rocksdb.node +0 -0
- package/util.h +74 -4
package/binding.cc
CHANGED
|
@@ -1960,7 +1960,6 @@ NAPI_METHOD(batch_write) {
|
|
|
1960
1960
|
|
|
1961
1961
|
rocksdb::WriteBatch* batch;
|
|
1962
1962
|
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[1], reinterpret_cast<void**>(&batch)));
|
|
1963
|
-
|
|
1964
1963
|
bool sync = false;
|
|
1965
1964
|
NAPI_STATUS_THROWS(GetProperty(env, argv[2], "sync", sync));
|
|
1966
1965
|
|
package/chained-batch.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { fromCallback } = require('catering')
|
|
3
4
|
const { AbstractChainedBatch } = require('abstract-level')
|
|
4
|
-
const binding = require('./binding')
|
|
5
5
|
const ModuleError = require('module-error')
|
|
6
6
|
const assert = require('node:assert')
|
|
7
7
|
|
|
8
|
+
const binding = require('./binding')
|
|
9
|
+
|
|
10
|
+
const kPromise = Symbol('promise')
|
|
8
11
|
const kBatchContext = Symbol('batchContext')
|
|
9
12
|
const kDbContext = Symbol('dbContext')
|
|
13
|
+
const kBusy = Symbol('busy')
|
|
14
|
+
|
|
10
15
|
const EMPTY = {}
|
|
11
16
|
|
|
12
17
|
class ChainedBatch extends AbstractChainedBatch {
|
|
@@ -15,10 +20,18 @@ class ChainedBatch extends AbstractChainedBatch {
|
|
|
15
20
|
|
|
16
21
|
this[kDbContext] = context
|
|
17
22
|
this[kBatchContext] = binding.batch_init()
|
|
23
|
+
this[kBusy] = false
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get length () {
|
|
27
|
+
assert(this[kBatchContext])
|
|
28
|
+
|
|
29
|
+
return binding.batch_count(this[kBatchContext])
|
|
18
30
|
}
|
|
19
31
|
|
|
20
32
|
_put (key, value, options) {
|
|
21
33
|
assert(this[kBatchContext])
|
|
34
|
+
assert(!this[kBusy])
|
|
22
35
|
|
|
23
36
|
if (key === null || key === undefined) {
|
|
24
37
|
throw new ModuleError('Key cannot be null or undefined', {
|
|
@@ -40,6 +53,7 @@ class ChainedBatch extends AbstractChainedBatch {
|
|
|
40
53
|
|
|
41
54
|
_putLogData (blob) {
|
|
42
55
|
assert(this[kBatchContext])
|
|
56
|
+
assert(!this[kBusy])
|
|
43
57
|
|
|
44
58
|
if (blob === null || blob === undefined) {
|
|
45
59
|
throw new ModuleError('Blob cannot be null or undefined', {
|
|
@@ -54,6 +68,7 @@ class ChainedBatch extends AbstractChainedBatch {
|
|
|
54
68
|
|
|
55
69
|
_del (key, options) {
|
|
56
70
|
assert(this[kBatchContext])
|
|
71
|
+
assert(!this[kBusy])
|
|
57
72
|
|
|
58
73
|
if (key === null || key === undefined) {
|
|
59
74
|
throw new ModuleError('Key cannot be null or undefined', {
|
|
@@ -68,24 +83,43 @@ class ChainedBatch extends AbstractChainedBatch {
|
|
|
68
83
|
|
|
69
84
|
_clear () {
|
|
70
85
|
assert(this[kBatchContext])
|
|
86
|
+
assert(!this[kBusy])
|
|
71
87
|
|
|
72
88
|
binding.batch_clear(this[kBatchContext])
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
_write (options, callback) {
|
|
76
92
|
assert(this[kBatchContext])
|
|
93
|
+
assert(!this[kBusy])
|
|
77
94
|
|
|
78
|
-
|
|
95
|
+
return this._writeAsync(options, callback)
|
|
79
96
|
}
|
|
80
97
|
|
|
81
98
|
_writeSync (options) {
|
|
82
99
|
assert(this[kBatchContext])
|
|
100
|
+
assert(!this[kBusy])
|
|
83
101
|
|
|
84
102
|
binding.batch_write_sync(this[kDbContext], this[kBatchContext], options ?? EMPTY)
|
|
85
103
|
}
|
|
86
104
|
|
|
105
|
+
_writeAsync (options, callback) {
|
|
106
|
+
assert(this[kBatchContext])
|
|
107
|
+
assert(!this[kBusy])
|
|
108
|
+
|
|
109
|
+
callback = fromCallback(callback, kPromise)
|
|
110
|
+
|
|
111
|
+
this[kBusy] = true
|
|
112
|
+
binding.batch_write(this[kDbContext], this[kBatchContext], options ?? EMPTY, (err) => {
|
|
113
|
+
this[kBusy] = false
|
|
114
|
+
callback(err)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
return callback[kPromise]
|
|
118
|
+
}
|
|
119
|
+
|
|
87
120
|
_close (callback) {
|
|
88
121
|
assert(this[kBatchContext])
|
|
122
|
+
assert(!this[kBusy])
|
|
89
123
|
|
|
90
124
|
try {
|
|
91
125
|
this._closeSync()
|
|
@@ -96,20 +130,16 @@ class ChainedBatch extends AbstractChainedBatch {
|
|
|
96
130
|
}
|
|
97
131
|
|
|
98
132
|
_closeSync () {
|
|
99
|
-
if (this[kBatchContext]) {
|
|
100
|
-
binding.batch_clear(this[kBatchContext])
|
|
101
|
-
this[kBatchContext] = null
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
get length () {
|
|
106
133
|
assert(this[kBatchContext])
|
|
134
|
+
assert(!this[kBusy])
|
|
107
135
|
|
|
108
|
-
|
|
136
|
+
binding.batch_clear(this[kBatchContext])
|
|
137
|
+
this[kBatchContext] = null
|
|
109
138
|
}
|
|
110
139
|
|
|
111
140
|
_merge (key, value, options) {
|
|
112
141
|
assert(this[kBatchContext])
|
|
142
|
+
assert(!this[kBusy])
|
|
113
143
|
|
|
114
144
|
if (key === null || key === undefined) {
|
|
115
145
|
throw new ModuleError('Key cannot be null or undefined', {
|
package/package.json
CHANGED
|
Binary file
|
package/util.h
CHANGED
|
@@ -452,21 +452,90 @@ napi_status Convert(napi_env env,
|
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
454
|
|
|
455
|
+
class Reference {
|
|
456
|
+
Reference(napi_env env, napi_ref ref) : env_(env), ref_(ref) {}
|
|
457
|
+
|
|
458
|
+
public:
|
|
459
|
+
static napi_status Create(napi_env env, napi_value value, Reference& handle) {
|
|
460
|
+
napi_ref ref;
|
|
461
|
+
NAPI_STATUS_RETURN(napi_create_reference(env, value, 1, &ref));
|
|
462
|
+
handle = Reference(env, ref);
|
|
463
|
+
return napi_ok;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
Reference() = default;
|
|
467
|
+
|
|
468
|
+
~Reference() {
|
|
469
|
+
if (ref_) {
|
|
470
|
+
napi_delete_reference(env_, ref_);
|
|
471
|
+
ref_ = nullptr;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
Reference(Reference&& other) noexcept : env_(other.env_), ref_(other.ref_) {
|
|
475
|
+
other.env_ = nullptr;
|
|
476
|
+
other.ref_ = nullptr;
|
|
477
|
+
}
|
|
478
|
+
Reference& operator=(Reference&& other) noexcept {
|
|
479
|
+
if (this != &other) {
|
|
480
|
+
if (ref_) {
|
|
481
|
+
napi_delete_reference(env_, ref_);
|
|
482
|
+
}
|
|
483
|
+
env_ = other.env_;
|
|
484
|
+
ref_ = other.ref_;
|
|
485
|
+
other.env_ = nullptr;
|
|
486
|
+
other.ref_ = nullptr;
|
|
487
|
+
}
|
|
488
|
+
return *this;
|
|
489
|
+
}
|
|
490
|
+
Reference(const Reference&) = delete;
|
|
491
|
+
Reference& operator=(const Reference&) = delete;
|
|
492
|
+
|
|
493
|
+
private:
|
|
494
|
+
napi_env env_ = nullptr;
|
|
495
|
+
napi_ref ref_ = nullptr;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
|
|
455
499
|
class HandleScope {
|
|
500
|
+
HandleScope(napi_env env, napi_handle_scope scope) : env_(env), scope_(scope) {}
|
|
501
|
+
|
|
456
502
|
public:
|
|
457
|
-
|
|
503
|
+
static napi_status Create(napi_env env, HandleScope& handleScope) {
|
|
504
|
+
napi_handle_scope scope;
|
|
505
|
+
NAPI_STATUS_RETURN(napi_open_handle_scope(env, &scope));
|
|
506
|
+
handleScope = HandleScope(env, scope);
|
|
507
|
+
return napi_ok;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
HandleScope() = default;
|
|
511
|
+
|
|
458
512
|
~HandleScope() {
|
|
459
|
-
if (
|
|
513
|
+
if (scope_) {
|
|
460
514
|
napi_close_handle_scope(env_, scope_);
|
|
461
515
|
}
|
|
462
516
|
}
|
|
517
|
+
HandleScope(HandleScope&& other) noexcept : env_(other.env_), scope_(other.scope_) {
|
|
518
|
+
other.env_ = nullptr;
|
|
519
|
+
other.scope_ = nullptr;
|
|
520
|
+
}
|
|
521
|
+
HandleScope& operator=(HandleScope&& other) noexcept {
|
|
522
|
+
if (this != &other) {
|
|
523
|
+
if (scope_) {
|
|
524
|
+
napi_close_handle_scope(env_, scope_);
|
|
525
|
+
}
|
|
526
|
+
env_ = other.env_;
|
|
527
|
+
scope_ = other.scope_;
|
|
528
|
+
other.env_ = nullptr;
|
|
529
|
+
other.scope_ = nullptr;
|
|
530
|
+
}
|
|
531
|
+
return *this;
|
|
532
|
+
}
|
|
463
533
|
HandleScope(const HandleScope&) = delete;
|
|
464
534
|
HandleScope& operator=(const HandleScope&) = delete;
|
|
465
535
|
|
|
466
536
|
private:
|
|
467
537
|
napi_env env_ = nullptr;
|
|
468
538
|
napi_handle_scope scope_ = nullptr;
|
|
469
|
-
napi_status status_ = napi_generic_failure;
|
|
470
539
|
};
|
|
471
540
|
|
|
472
541
|
template <typename State, typename T1, typename T2>
|
|
@@ -490,7 +559,8 @@ napi_status runAsync(napi_value asyncResourceName, napi_env env, napi_value call
|
|
|
490
559
|
return; // env is tearing down, just clean up
|
|
491
560
|
}
|
|
492
561
|
|
|
493
|
-
HandleScope scope
|
|
562
|
+
HandleScope scope;
|
|
563
|
+
NAPI_STATUS_THROWS_VOID(HandleScope::Create(env, scope));
|
|
494
564
|
|
|
495
565
|
napi_value callback;
|
|
496
566
|
NAPI_STATUS_THROWS_VOID(napi_get_reference_value(env, worker->ref, &callback));
|