@nxtedition/rocksdb 5.2.13 → 5.2.21
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/CHANGELOG.md +6 -0
- package/binding.cc +100 -161
- package/binding.gyp +3 -0
- package/deps/rocksdb/rocksdb.gyp +41 -47
- package/deps/snappy/snappy.gyp +4 -1
- package/package.json +1 -1
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
package/CHANGELOG.md
CHANGED
package/binding.cc
CHANGED
|
@@ -41,7 +41,7 @@ static void iterator_do_close (napi_env env, Iterator* iterator, napi_value cb);
|
|
|
41
41
|
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], (void**)&iterator));
|
|
42
42
|
|
|
43
43
|
#define NAPI_BATCH_CONTEXT() \
|
|
44
|
-
|
|
44
|
+
rocksdb::WriteBatch* batch = nullptr; \
|
|
45
45
|
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], (void**)&batch));
|
|
46
46
|
|
|
47
47
|
static bool IsString (napi_env env, napi_value value) {
|
|
@@ -158,7 +158,7 @@ static std::string ToString (napi_env env, napi_value from, const std::string& d
|
|
|
158
158
|
return defaultValue;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
static std::string StringProperty (napi_env env, napi_value obj, const std::string& key) {
|
|
161
|
+
static std::string StringProperty (napi_env env, napi_value obj, const std::string& key, const std::string& defaultValue = "") {
|
|
162
162
|
if (HasProperty(env, obj, key)) {
|
|
163
163
|
napi_value value = GetProperty(env, obj, key);
|
|
164
164
|
if (IsString(env, value)) {
|
|
@@ -166,7 +166,7 @@ static std::string StringProperty (napi_env env, napi_value obj, const std::stri
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
return
|
|
169
|
+
return defaultValue;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
static size_t StringOrBufferLength (napi_env env, napi_value value) {
|
|
@@ -267,7 +267,7 @@ struct BaseWorker {
|
|
|
267
267
|
self->DoExecute();
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
bool SetStatus (const
|
|
270
|
+
bool SetStatus (const rocksdb::Status& status) {
|
|
271
271
|
status_ = status;
|
|
272
272
|
return status.ok();
|
|
273
273
|
}
|
|
@@ -340,7 +340,7 @@ struct BaseWorker {
|
|
|
340
340
|
private:
|
|
341
341
|
napi_ref callbackRef_;
|
|
342
342
|
napi_async_work asyncWork_;
|
|
343
|
-
|
|
343
|
+
rocksdb::Status status_;
|
|
344
344
|
};
|
|
345
345
|
|
|
346
346
|
/**
|
|
@@ -352,17 +352,17 @@ struct Database {
|
|
|
352
352
|
ref_(nullptr),
|
|
353
353
|
priorityWork_(0) {}
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
rocksdb::Status Open (const rocksdb::Options& options,
|
|
356
356
|
const bool readOnly,
|
|
357
357
|
const char* location) {
|
|
358
358
|
if (readOnly) {
|
|
359
|
-
|
|
359
|
+
rocksdb::DB* db = nullptr;
|
|
360
360
|
const auto status = rocksdb::DB::OpenForReadOnly(options, location, &db);
|
|
361
361
|
db_.reset(db);
|
|
362
362
|
return status;
|
|
363
363
|
} else {
|
|
364
|
-
|
|
365
|
-
const auto status =
|
|
364
|
+
rocksdb::DB* db = nullptr;
|
|
365
|
+
const auto status = rocksdb::DB::Open(options, location, &db);
|
|
366
366
|
db_.reset(db);
|
|
367
367
|
return status;
|
|
368
368
|
}
|
|
@@ -372,36 +372,36 @@ struct Database {
|
|
|
372
372
|
db_.reset();
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
|
|
375
|
+
rocksdb::Status Put (const rocksdb::WriteOptions& options,
|
|
376
376
|
const std::string& key,
|
|
377
377
|
const std::string& value) {
|
|
378
378
|
return db_->Put(options, db_->DefaultColumnFamily(), key, value);
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
|
|
381
|
+
rocksdb::Status Get (const rocksdb::ReadOptions& options,
|
|
382
382
|
const std::string& key,
|
|
383
383
|
rocksdb::PinnableSlice& value) {
|
|
384
384
|
return db_->Get(options, db_->DefaultColumnFamily(), key, &value);
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
|
|
387
|
+
rocksdb::Status Del (const rocksdb::WriteOptions& options,
|
|
388
388
|
const std::string& key) {
|
|
389
389
|
return db_->Delete(options, db_->DefaultColumnFamily(), key);
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
rocksdb::Status WriteBatch (const rocksdb::WriteOptions& options,
|
|
393
|
+
rocksdb::WriteBatch* batch) {
|
|
394
394
|
return db_->Write(options, batch);
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
uint64_t ApproximateSize (const
|
|
397
|
+
uint64_t ApproximateSize (const rocksdb::Range* range) {
|
|
398
398
|
uint64_t size = 0;
|
|
399
399
|
db_->GetApproximateSizes(range, 1, &size);
|
|
400
400
|
return size;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
void CompactRange (const
|
|
404
|
-
const
|
|
403
|
+
void CompactRange (const rocksdb::Slice* start,
|
|
404
|
+
const rocksdb::Slice* end) {
|
|
405
405
|
rocksdb::CompactRangeOptions options;
|
|
406
406
|
db_->CompactRange(options, start, end);
|
|
407
407
|
}
|
|
@@ -410,15 +410,15 @@ struct Database {
|
|
|
410
410
|
db_->GetProperty(property, &value);
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
const
|
|
413
|
+
const rocksdb::Snapshot* NewSnapshot () {
|
|
414
414
|
return db_->GetSnapshot();
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
-
|
|
417
|
+
rocksdb::Iterator* NewIterator (const rocksdb::ReadOptions& options) {
|
|
418
418
|
return db_->NewIterator(options);
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
-
void ReleaseSnapshot (const
|
|
421
|
+
void ReleaseSnapshot (const rocksdb::Snapshot* snapshot) {
|
|
422
422
|
return db_->ReleaseSnapshot(snapshot);
|
|
423
423
|
}
|
|
424
424
|
|
|
@@ -449,7 +449,7 @@ struct Database {
|
|
|
449
449
|
return priorityWork_ > 0;
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
-
std::unique_ptr<
|
|
452
|
+
std::unique_ptr<rocksdb::DB> db_;
|
|
453
453
|
BaseWorker* pendingCloseWorker_;
|
|
454
454
|
std::set<Iterator*> iterators_;
|
|
455
455
|
napi_ref ref_;
|
|
@@ -487,7 +487,7 @@ struct BaseIterator {
|
|
|
487
487
|
: database_(database),
|
|
488
488
|
snapshot_(database->NewSnapshot()),
|
|
489
489
|
dbIterator_(database->NewIterator([&]{
|
|
490
|
-
|
|
490
|
+
rocksdb::ReadOptions options;
|
|
491
491
|
options.fill_cache = fillCache;
|
|
492
492
|
options.verify_checksums = false;
|
|
493
493
|
options.snapshot = snapshot_;
|
|
@@ -617,19 +617,19 @@ struct BaseIterator {
|
|
|
617
617
|
Next();
|
|
618
618
|
}
|
|
619
619
|
|
|
620
|
-
|
|
620
|
+
rocksdb::Slice CurrentKey () const {
|
|
621
621
|
return dbIterator_->key();
|
|
622
622
|
}
|
|
623
623
|
|
|
624
|
-
|
|
624
|
+
rocksdb::Slice CurrentValue () const {
|
|
625
625
|
return dbIterator_->value();
|
|
626
626
|
}
|
|
627
627
|
|
|
628
|
-
|
|
628
|
+
rocksdb::Status Status () const {
|
|
629
629
|
return dbIterator_->status();
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
-
bool OutOfRange (const
|
|
632
|
+
bool OutOfRange (const rocksdb::Slice& target) const {
|
|
633
633
|
if (lte_) {
|
|
634
634
|
if (target.compare(*lte_) > 0) return true;
|
|
635
635
|
} else if (lt_) {
|
|
@@ -648,8 +648,8 @@ struct BaseIterator {
|
|
|
648
648
|
Database* database_;
|
|
649
649
|
|
|
650
650
|
private:
|
|
651
|
-
const
|
|
652
|
-
|
|
651
|
+
const rocksdb::Snapshot* snapshot_;
|
|
652
|
+
rocksdb::Iterator* dbIterator_;
|
|
653
653
|
bool didSeek_;
|
|
654
654
|
const bool reverse_;
|
|
655
655
|
const std::string* lt_;
|
|
@@ -681,9 +681,6 @@ struct Iterator final : public BaseIterator {
|
|
|
681
681
|
valueAsBuffer_(valueAsBuffer),
|
|
682
682
|
highWaterMarkBytes_(highWaterMarkBytes),
|
|
683
683
|
first_(true),
|
|
684
|
-
nexting_(false),
|
|
685
|
-
isClosing_(false),
|
|
686
|
-
closeWorker_(nullptr),
|
|
687
684
|
ref_(nullptr) {
|
|
688
685
|
}
|
|
689
686
|
|
|
@@ -740,9 +737,6 @@ struct Iterator final : public BaseIterator {
|
|
|
740
737
|
const bool valueAsBuffer_;
|
|
741
738
|
const uint32_t highWaterMarkBytes_;
|
|
742
739
|
bool first_;
|
|
743
|
-
bool nexting_;
|
|
744
|
-
bool isClosing_;
|
|
745
|
-
BaseWorker* closeWorker_;
|
|
746
740
|
std::vector<std::string> cache_;
|
|
747
741
|
|
|
748
742
|
private:
|
|
@@ -755,7 +749,7 @@ private:
|
|
|
755
749
|
* the guarantee that no db operations will be in-flight at this time.
|
|
756
750
|
*/
|
|
757
751
|
static void env_cleanup_hook (void* arg) {
|
|
758
|
-
|
|
752
|
+
auto database = reinterpret_cast<Database*>(arg);
|
|
759
753
|
|
|
760
754
|
// Do everything that db_close() does but synchronously. We're expecting that GC
|
|
761
755
|
// did not (yet) collect the database because that would be a user mistake (not
|
|
@@ -776,7 +770,7 @@ static void env_cleanup_hook (void* arg) {
|
|
|
776
770
|
|
|
777
771
|
static void FinalizeDatabase (napi_env env, void* data, void* hint) {
|
|
778
772
|
if (data) {
|
|
779
|
-
|
|
773
|
+
auto database = reinterpret_cast<Database*>(data);
|
|
780
774
|
napi_remove_env_cleanup_hook(env, env_cleanup_hook, database);
|
|
781
775
|
if (database->ref_) napi_delete_reference(env, database->ref_);
|
|
782
776
|
delete database;
|
|
@@ -784,7 +778,7 @@ static void FinalizeDatabase (napi_env env, void* data, void* hint) {
|
|
|
784
778
|
}
|
|
785
779
|
|
|
786
780
|
NAPI_METHOD(db_init) {
|
|
787
|
-
|
|
781
|
+
auto database = new Database();
|
|
788
782
|
napi_add_env_cleanup_hook(env, env_cleanup_hook, database);
|
|
789
783
|
|
|
790
784
|
napi_value result;
|
|
@@ -798,11 +792,7 @@ NAPI_METHOD(db_init) {
|
|
|
798
792
|
return result;
|
|
799
793
|
}
|
|
800
794
|
|
|
801
|
-
|
|
802
|
-
* Worker class for opening a database.
|
|
803
|
-
* TODO: shouldn't this be a PriorityWorker?
|
|
804
|
-
*/
|
|
805
|
-
struct OpenWorker final : public BaseWorker {
|
|
795
|
+
struct OpenWorker final : public PriorityWorker {
|
|
806
796
|
OpenWorker (napi_env env,
|
|
807
797
|
Database* database,
|
|
808
798
|
napi_value callback,
|
|
@@ -818,14 +808,14 @@ struct OpenWorker final : public BaseWorker {
|
|
|
818
808
|
const uint32_t cacheSize,
|
|
819
809
|
const std::string& infoLogLevel,
|
|
820
810
|
const bool readOnly)
|
|
821
|
-
:
|
|
811
|
+
: PriorityWorker(env, database, callback, "leveldown.db.open"),
|
|
822
812
|
readOnly_(readOnly),
|
|
823
813
|
location_(location) {
|
|
824
814
|
options_.create_if_missing = createIfMissing;
|
|
825
815
|
options_.error_if_exists = errorIfExists;
|
|
826
816
|
options_.compression = compression
|
|
827
|
-
?
|
|
828
|
-
:
|
|
817
|
+
? rocksdb::kSnappyCompression
|
|
818
|
+
: rocksdb::kNoCompression;
|
|
829
819
|
options_.write_buffer_size = writeBufferSize;
|
|
830
820
|
options_.max_open_files = maxOpenFiles;
|
|
831
821
|
options_.max_log_file_size = maxFileSize;
|
|
@@ -861,6 +851,8 @@ struct OpenWorker final : public BaseWorker {
|
|
|
861
851
|
tableOptions.block_size = blockSize;
|
|
862
852
|
tableOptions.block_restart_interval = blockRestartInterval;
|
|
863
853
|
tableOptions.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10));
|
|
854
|
+
tableOptions.format_version = 5;
|
|
855
|
+
tableOptions.checksum = rocksdb::kxxHash64;
|
|
864
856
|
|
|
865
857
|
options_.table_factory.reset(
|
|
866
858
|
rocksdb::NewBlockBasedTableFactory(tableOptions)
|
|
@@ -871,7 +863,7 @@ struct OpenWorker final : public BaseWorker {
|
|
|
871
863
|
SetStatus(database_->Open(options_, readOnly_, location_.c_str()));
|
|
872
864
|
}
|
|
873
865
|
|
|
874
|
-
|
|
866
|
+
rocksdb::Options options_;
|
|
875
867
|
const bool readOnly_;
|
|
876
868
|
const std::string location_;
|
|
877
869
|
};
|
|
@@ -931,13 +923,6 @@ NAPI_METHOD(db_close) {
|
|
|
931
923
|
|
|
932
924
|
const auto callback = argv[1];
|
|
933
925
|
|
|
934
|
-
napi_value noop;
|
|
935
|
-
napi_create_function(env, nullptr, 0, noop_callback, nullptr, &noop);
|
|
936
|
-
|
|
937
|
-
for (auto it : database->iterators_) {
|
|
938
|
-
iterator_do_close(env, it, noop);
|
|
939
|
-
}
|
|
940
|
-
|
|
941
926
|
auto worker = new CloseWorker(env, database, callback);
|
|
942
927
|
|
|
943
928
|
if (!database->HasPriorityWork()) {
|
|
@@ -961,7 +946,7 @@ struct PutWorker final : public PriorityWorker {
|
|
|
961
946
|
}
|
|
962
947
|
|
|
963
948
|
void DoExecute () override {
|
|
964
|
-
|
|
949
|
+
rocksdb::WriteOptions options;
|
|
965
950
|
options.sync = sync_;
|
|
966
951
|
SetStatus(database_->Put(options, key_, value_));
|
|
967
952
|
}
|
|
@@ -998,7 +983,7 @@ struct GetWorker final : public PriorityWorker {
|
|
|
998
983
|
}
|
|
999
984
|
|
|
1000
985
|
void DoExecute () override {
|
|
1001
|
-
|
|
986
|
+
rocksdb::ReadOptions options;
|
|
1002
987
|
options.fill_cache = fillCache_;
|
|
1003
988
|
SetStatus(database_->Get(options, key_, value_));
|
|
1004
989
|
}
|
|
@@ -1055,7 +1040,7 @@ struct GetManyWorker final : public PriorityWorker {
|
|
|
1055
1040
|
void DoExecute () override {
|
|
1056
1041
|
cache_.reserve(keys_.size());
|
|
1057
1042
|
|
|
1058
|
-
|
|
1043
|
+
rocksdb::ReadOptions options;
|
|
1059
1044
|
options.snapshot = snapshot_;
|
|
1060
1045
|
options.fill_cache = fillCache_;
|
|
1061
1046
|
|
|
@@ -1107,7 +1092,7 @@ private:
|
|
|
1107
1092
|
const bool valueAsBuffer_;
|
|
1108
1093
|
std::vector<rocksdb::PinnableSlice> cache_;
|
|
1109
1094
|
const bool fillCache_;
|
|
1110
|
-
const
|
|
1095
|
+
const rocksdb::Snapshot* snapshot_;
|
|
1111
1096
|
};
|
|
1112
1097
|
|
|
1113
1098
|
NAPI_METHOD(db_get_many) {
|
|
@@ -1137,7 +1122,7 @@ struct DelWorker final : public PriorityWorker {
|
|
|
1137
1122
|
}
|
|
1138
1123
|
|
|
1139
1124
|
void DoExecute () override {
|
|
1140
|
-
|
|
1125
|
+
rocksdb::WriteOptions options;
|
|
1141
1126
|
options.sync = sync_;
|
|
1142
1127
|
SetStatus(database_->Del(options, key_));
|
|
1143
1128
|
}
|
|
@@ -1179,10 +1164,9 @@ struct ClearWorker final : public PriorityWorker {
|
|
|
1179
1164
|
|
|
1180
1165
|
// TODO: add option
|
|
1181
1166
|
const uint32_t hwm = 16 * 1024;
|
|
1182
|
-
leveldb::WriteBatch batch;
|
|
1183
1167
|
|
|
1184
|
-
|
|
1185
|
-
options
|
|
1168
|
+
rocksdb::WriteBatch batch;
|
|
1169
|
+
rocksdb::WriteOptions options;
|
|
1186
1170
|
|
|
1187
1171
|
while (true) {
|
|
1188
1172
|
size_t bytesRead = 0;
|
|
@@ -1243,7 +1227,7 @@ struct ApproximateSizeWorker final : public PriorityWorker {
|
|
|
1243
1227
|
start_(start), end_(end) {}
|
|
1244
1228
|
|
|
1245
1229
|
void DoExecute () override {
|
|
1246
|
-
|
|
1230
|
+
rocksdb::Range range(start_, end_);
|
|
1247
1231
|
size_ = database_->ApproximateSize(&range);
|
|
1248
1232
|
}
|
|
1249
1233
|
|
|
@@ -1283,8 +1267,8 @@ struct CompactRangeWorker final : public PriorityWorker {
|
|
|
1283
1267
|
start_(start), end_(end) {}
|
|
1284
1268
|
|
|
1285
1269
|
void DoExecute () override {
|
|
1286
|
-
|
|
1287
|
-
|
|
1270
|
+
rocksdb::Slice start = start_;
|
|
1271
|
+
rocksdb::Slice end = end_;
|
|
1288
1272
|
database_->CompactRange(&start, &end);
|
|
1289
1273
|
}
|
|
1290
1274
|
|
|
@@ -1331,8 +1315,8 @@ struct DestroyWorker final : public BaseWorker {
|
|
|
1331
1315
|
~DestroyWorker () {}
|
|
1332
1316
|
|
|
1333
1317
|
void DoExecute () override {
|
|
1334
|
-
|
|
1335
|
-
SetStatus(
|
|
1318
|
+
rocksdb::Options options;
|
|
1319
|
+
SetStatus(rocksdb::DestroyDB(location_, options));
|
|
1336
1320
|
}
|
|
1337
1321
|
|
|
1338
1322
|
const std::string location_;
|
|
@@ -1358,8 +1342,8 @@ struct RepairWorker final : public BaseWorker {
|
|
|
1358
1342
|
location_(location) {}
|
|
1359
1343
|
|
|
1360
1344
|
void DoExecute () override {
|
|
1361
|
-
|
|
1362
|
-
SetStatus(
|
|
1345
|
+
rocksdb::Options options;
|
|
1346
|
+
SetStatus(rocksdb::RepairDB(location_, options));
|
|
1363
1347
|
}
|
|
1364
1348
|
|
|
1365
1349
|
const std::string location_;
|
|
@@ -1422,10 +1406,6 @@ NAPI_METHOD(iterator_seek) {
|
|
|
1422
1406
|
NAPI_ARGV(2);
|
|
1423
1407
|
NAPI_ITERATOR_CONTEXT();
|
|
1424
1408
|
|
|
1425
|
-
if (iterator->isClosing_) {
|
|
1426
|
-
napi_throw_error(env, nullptr, "iterator has closed");
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
1409
|
const auto target = ToString(env, argv[1]);
|
|
1430
1410
|
iterator->first_ = true;
|
|
1431
1411
|
iterator->Seek(target);
|
|
@@ -1453,28 +1433,14 @@ private:
|
|
|
1453
1433
|
Iterator* iterator_;
|
|
1454
1434
|
};
|
|
1455
1435
|
|
|
1456
|
-
/**
|
|
1457
|
-
* Called by NAPI_METHOD(iterator_) and also when closing
|
|
1458
|
-
* open iterators during NAPI_METHOD(db_close).
|
|
1459
|
-
*/
|
|
1460
|
-
static void iterator_do_close (napi_env env, Iterator* iterator, napi_value cb) {
|
|
1461
|
-
if (!iterator->isClosing_) {
|
|
1462
|
-
auto worker = new CloseIteratorWorker(env, iterator, cb);
|
|
1463
|
-
iterator->isClosing_ = true;
|
|
1464
|
-
|
|
1465
|
-
if (iterator->nexting_) {
|
|
1466
|
-
iterator->closeWorker_ = worker;
|
|
1467
|
-
} else {
|
|
1468
|
-
worker->Queue(env);
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
1436
|
NAPI_METHOD(iterator_close) {
|
|
1474
1437
|
NAPI_ARGV(2);
|
|
1475
1438
|
NAPI_ITERATOR_CONTEXT();
|
|
1476
1439
|
|
|
1477
|
-
|
|
1440
|
+
const auto callback = argv[1];
|
|
1441
|
+
|
|
1442
|
+
auto worker = new CloseIteratorWorker(env, iterator, callback);
|
|
1443
|
+
worker->Queue(env);
|
|
1478
1444
|
|
|
1479
1445
|
return 0;
|
|
1480
1446
|
}
|
|
@@ -1528,14 +1494,6 @@ struct NextWorker final : public BaseWorker {
|
|
|
1528
1494
|
}
|
|
1529
1495
|
|
|
1530
1496
|
void DoFinally (napi_env env) override {
|
|
1531
|
-
// clean up & handle the next/end state
|
|
1532
|
-
iterator_->nexting_ = false;
|
|
1533
|
-
|
|
1534
|
-
if (iterator_->closeWorker_) {
|
|
1535
|
-
iterator_->closeWorker_->Queue(env);
|
|
1536
|
-
iterator_->closeWorker_ = nullptr;
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
1497
|
BaseWorker::DoFinally(env);
|
|
1540
1498
|
}
|
|
1541
1499
|
|
|
@@ -1555,48 +1513,63 @@ NAPI_METHOD(iterator_nextv) {
|
|
|
1555
1513
|
|
|
1556
1514
|
const auto callback = argv[2];
|
|
1557
1515
|
|
|
1558
|
-
if (iterator->isClosing_) {
|
|
1559
|
-
napi_value argv = CreateCodeError(env, "LEVEL_ITERATOR_NOT_OPEN", "Iterator is not open");
|
|
1560
|
-
NAPI_STATUS_THROWS(CallFunction(env, callback, 1, &argv));
|
|
1561
|
-
return 0;
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
1516
|
auto worker = new NextWorker(env, iterator, size, callback);
|
|
1565
|
-
iterator->nexting_ = true;
|
|
1566
1517
|
worker->Queue(env);
|
|
1567
1518
|
|
|
1568
1519
|
return 0;
|
|
1569
1520
|
}
|
|
1570
1521
|
|
|
1571
|
-
/**
|
|
1572
|
-
* Worker class for batch write operation.
|
|
1573
|
-
*/
|
|
1574
1522
|
struct BatchWorker final : public PriorityWorker {
|
|
1575
1523
|
BatchWorker (napi_env env,
|
|
1576
1524
|
Database* database,
|
|
1577
1525
|
napi_value callback,
|
|
1578
|
-
|
|
1579
|
-
const bool sync
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
options_.sync = sync;
|
|
1584
|
-
}
|
|
1526
|
+
napi_value array,
|
|
1527
|
+
const bool sync)
|
|
1528
|
+
: PriorityWorker(env, database, callback, "rocks_level.batch.do"), sync_(sync) {
|
|
1529
|
+
uint32_t length;
|
|
1530
|
+
NAPI_STATUS_THROWS_VOID(napi_get_array_length(env, array, &length));
|
|
1585
1531
|
|
|
1586
|
-
|
|
1587
|
-
|
|
1532
|
+
for (uint32_t i = 0; i < length; i++) {
|
|
1533
|
+
napi_value element;
|
|
1534
|
+
NAPI_STATUS_THROWS_VOID(napi_get_element(env, array, i, &element));
|
|
1535
|
+
|
|
1536
|
+
if (!IsObject(env, element)) continue;
|
|
1537
|
+
|
|
1538
|
+
const auto type = StringProperty(env, element, "type");
|
|
1539
|
+
|
|
1540
|
+
if (type == "del") {
|
|
1541
|
+
if (!HasProperty(env, element, "key")) continue;
|
|
1542
|
+
const auto key = ToString(env, GetProperty(env, element, "key"));
|
|
1543
|
+
|
|
1544
|
+
batch_.Delete(key);
|
|
1545
|
+
if (!hasData_) hasData_ = true;
|
|
1546
|
+
} else if (type == "put") {
|
|
1547
|
+
if (!HasProperty(env, element, "key")) continue;
|
|
1548
|
+
if (!HasProperty(env, element, "value")) continue;
|
|
1549
|
+
|
|
1550
|
+
const auto key = ToString(env, GetProperty(env, element, "key"));
|
|
1551
|
+
const auto value = ToString(env, GetProperty(env, element, "value"));
|
|
1552
|
+
|
|
1553
|
+
batch_.Put(key, value);
|
|
1554
|
+
if (!hasData_) hasData_ = true;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1588
1557
|
}
|
|
1589
1558
|
|
|
1590
1559
|
void DoExecute () override {
|
|
1591
1560
|
if (hasData_) {
|
|
1592
|
-
|
|
1561
|
+
rocksdb::WriteOptions options;
|
|
1562
|
+
options.sync = sync_;
|
|
1563
|
+
SetStatus(database_->WriteBatch(options, &batch_));
|
|
1564
|
+
} else {
|
|
1565
|
+
SetStatus(rocksdb::Status::OK());
|
|
1593
1566
|
}
|
|
1594
1567
|
}
|
|
1595
1568
|
|
|
1596
1569
|
private:
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1570
|
+
rocksdb::WriteBatch batch_;
|
|
1571
|
+
const bool sync_;
|
|
1572
|
+
bool hasData_;
|
|
1600
1573
|
};
|
|
1601
1574
|
|
|
1602
1575
|
NAPI_METHOD(batch_do) {
|
|
@@ -1607,39 +1580,7 @@ NAPI_METHOD(batch_do) {
|
|
|
1607
1580
|
const auto sync = BooleanProperty(env, argv[2], "sync", false);
|
|
1608
1581
|
const auto callback = argv[3];
|
|
1609
1582
|
|
|
1610
|
-
|
|
1611
|
-
napi_get_array_length(env, array, &length);
|
|
1612
|
-
|
|
1613
|
-
leveldb::WriteBatch* batch = new leveldb::WriteBatch();
|
|
1614
|
-
bool hasData = false;
|
|
1615
|
-
|
|
1616
|
-
for (uint32_t i = 0; i < length; i++) {
|
|
1617
|
-
napi_value element;
|
|
1618
|
-
napi_get_element(env, array, i, &element);
|
|
1619
|
-
|
|
1620
|
-
if (!IsObject(env, element)) continue;
|
|
1621
|
-
|
|
1622
|
-
std::string type = StringProperty(env, element, "type");
|
|
1623
|
-
|
|
1624
|
-
if (type == "del") {
|
|
1625
|
-
if (!HasProperty(env, element, "key")) continue;
|
|
1626
|
-
const auto key = ToString(env, GetProperty(env, element, "key"));
|
|
1627
|
-
|
|
1628
|
-
batch->Delete(key);
|
|
1629
|
-
if (!hasData) hasData = true;
|
|
1630
|
-
} else if (type == "put") {
|
|
1631
|
-
if (!HasProperty(env, element, "key")) continue;
|
|
1632
|
-
if (!HasProperty(env, element, "value")) continue;
|
|
1633
|
-
|
|
1634
|
-
const auto key = ToString(env, GetProperty(env, element, "key"));
|
|
1635
|
-
const auto value = ToString(env, GetProperty(env, element, "value"));
|
|
1636
|
-
|
|
1637
|
-
batch->Put(key, value);
|
|
1638
|
-
if (!hasData) hasData = true;
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
auto worker = new BatchWorker(env, database, callback, batch, sync, hasData);
|
|
1583
|
+
auto worker = new BatchWorker(env, database, callback, array, sync);
|
|
1643
1584
|
worker->Queue(env);
|
|
1644
1585
|
|
|
1645
1586
|
return 0;
|
|
@@ -1647,7 +1588,7 @@ NAPI_METHOD(batch_do) {
|
|
|
1647
1588
|
|
|
1648
1589
|
static void FinalizeBatch (napi_env env, void* data, void* hint) {
|
|
1649
1590
|
if (data) {
|
|
1650
|
-
delete reinterpret_cast<
|
|
1591
|
+
delete reinterpret_cast<rocksdb::WriteBatch*>(data);
|
|
1651
1592
|
}
|
|
1652
1593
|
}
|
|
1653
1594
|
|
|
@@ -1655,12 +1596,10 @@ NAPI_METHOD(batch_init) {
|
|
|
1655
1596
|
NAPI_ARGV(1);
|
|
1656
1597
|
NAPI_DB_CONTEXT();
|
|
1657
1598
|
|
|
1658
|
-
auto batch = new
|
|
1599
|
+
auto batch = new rocksdb::WriteBatch();
|
|
1659
1600
|
|
|
1660
1601
|
napi_value result;
|
|
1661
|
-
NAPI_STATUS_THROWS(napi_create_external(env, batch,
|
|
1662
|
-
FinalizeBatch,
|
|
1663
|
-
nullptr, &result));
|
|
1602
|
+
NAPI_STATUS_THROWS(napi_create_external(env, batch, FinalizeBatch, nullptr, &result));
|
|
1664
1603
|
return result;
|
|
1665
1604
|
}
|
|
1666
1605
|
|
|
@@ -1712,7 +1651,7 @@ struct BatchWriteWorker final : public PriorityWorker {
|
|
|
1712
1651
|
}
|
|
1713
1652
|
|
|
1714
1653
|
void DoExecute () override {
|
|
1715
|
-
|
|
1654
|
+
rocksdb::WriteOptions options;
|
|
1716
1655
|
options.sync = sync_;
|
|
1717
1656
|
SetStatus(database_->WriteBatch(options, batch_));
|
|
1718
1657
|
}
|
|
@@ -1723,7 +1662,7 @@ struct BatchWriteWorker final : public PriorityWorker {
|
|
|
1723
1662
|
}
|
|
1724
1663
|
|
|
1725
1664
|
private:
|
|
1726
|
-
|
|
1665
|
+
rocksdb::WriteBatch* batch_;
|
|
1727
1666
|
const bool sync_;
|
|
1728
1667
|
napi_ref batchRef_;
|
|
1729
1668
|
};
|
package/binding.gyp
CHANGED
package/deps/rocksdb/rocksdb.gyp
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"variables": {
|
|
3
|
+
"openssl_fips" : "0"
|
|
4
|
+
},
|
|
2
5
|
'targets': [{
|
|
3
6
|
'target_name': 'rocksdb'
|
|
4
7
|
, 'type': 'static_library'
|
|
@@ -16,7 +19,9 @@
|
|
|
16
19
|
'SNAPPY=1',
|
|
17
20
|
'ROCKSDB_BACKTRACE=1',
|
|
18
21
|
'ROCKSDB_SUPPORT_THREAD_LOCAL=1',
|
|
19
|
-
'USE_SSE=1'
|
|
22
|
+
'USE_SSE=1',
|
|
23
|
+
'NIOSTARTS_CONTEXT=1'
|
|
24
|
+
'NPERF_CONTEXT=1'
|
|
20
25
|
]
|
|
21
26
|
, 'include_dirs': [
|
|
22
27
|
'rocksdb/'
|
|
@@ -75,52 +80,50 @@
|
|
|
75
80
|
]
|
|
76
81
|
, 'defines': [
|
|
77
82
|
'ROCKSDB_PLATFORM_POSIX=1'
|
|
83
|
+
, 'ROCKSDB_LIB_IO_POSIX=1'
|
|
84
|
+
]
|
|
85
|
+
, 'ccflags': [
|
|
86
|
+
'-fno-omit-frame-pointer'
|
|
87
|
+
, '-momit-leaf-frame-pointer'
|
|
88
|
+
, '-fno-builtin-memcmp'
|
|
89
|
+
]
|
|
90
|
+
, 'cflags': [
|
|
91
|
+
'-std=c++17'
|
|
78
92
|
]
|
|
79
|
-
, 'ccflags': []
|
|
80
|
-
, 'cflags': [ '-std=c++17' ]
|
|
81
93
|
, 'cflags!': [ '-fno-tree-vrp', '-fno-rtti' ]
|
|
82
94
|
, 'cflags_cc!': [ '-fno-rtti' ]
|
|
83
95
|
}]
|
|
84
|
-
, ['OS != "win"', {
|
|
85
|
-
'cflags': [
|
|
86
|
-
'-Wno-sign-compare'
|
|
87
|
-
, '-Wno-unused-but-set-variable'
|
|
88
|
-
]
|
|
89
|
-
}]
|
|
90
96
|
, ['OS == "linux"', {
|
|
91
97
|
'defines': [
|
|
92
|
-
'OS_LINUX=1'
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
'ROCKSDB_LIB_IO_POSIX=1',
|
|
111
|
-
# "-TBB=1",
|
|
98
|
+
'OS_LINUX=1'
|
|
99
|
+
, 'ROCKSDB_FALLOCATE_PRESENT=1'
|
|
100
|
+
, 'ROCKSDB_MALLOC_USABLE_SIZE=1'
|
|
101
|
+
, 'ROCKSDB_PTHREAD_ADAPTIVE_MUTEX=1'
|
|
102
|
+
, 'ROCKSDB_RANGESYNC_PRESENT=1'
|
|
103
|
+
, 'ROCKSDB_SCHED_GETCPU_PRESENT=1'
|
|
104
|
+
# , 'ROCKSDB_IOURING_PRESENT=1'
|
|
105
|
+
, 'HAVE_SSE42=1'
|
|
106
|
+
, 'HAVE_BMI=1'
|
|
107
|
+
, 'HAVE_LZCNT=1'
|
|
108
|
+
, 'HAVE_AVX2=1'
|
|
109
|
+
, 'HAVE_PCLMUL=1'
|
|
110
|
+
, 'HAVE_UINT128_EXTENSION=1'
|
|
111
|
+
, 'HAVE_ALIGNED_NEW=1'
|
|
112
|
+
, 'HAVE_FULLFSYNC=1'
|
|
113
|
+
# , 'LIBURING=1'
|
|
114
|
+
# , 'NUMA=1'
|
|
115
|
+
# , "TBB=1",
|
|
112
116
|
]
|
|
113
|
-
, '
|
|
114
|
-
'-
|
|
115
|
-
, '-pthread'
|
|
116
|
-
, '-msse4.2'
|
|
117
|
+
, 'cflags': [
|
|
118
|
+
'-msse4.2'
|
|
117
119
|
, '-mpclmul'
|
|
120
|
+
, '-mavx'
|
|
118
121
|
, '-mavx2'
|
|
119
122
|
, '-mbmi'
|
|
120
123
|
, '-mlzcnt'
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
]
|
|
125
|
+
, 'ccflags': [
|
|
126
|
+
'-flto'
|
|
124
127
|
]
|
|
125
128
|
, 'cflags!': [ '-fno-exceptions' ]
|
|
126
129
|
, 'cflags_cc!': [ '-fno-exceptions' ]
|
|
@@ -131,19 +134,10 @@
|
|
|
131
134
|
}]
|
|
132
135
|
, ['OS == "mac"', {
|
|
133
136
|
'defines': [
|
|
134
|
-
'OS_MACOSX=1'
|
|
135
|
-
'DROCKSDB_PLATFORM_POSIX=1',
|
|
136
|
-
'ROCKSDB_LIB_IO_POSIX=1'
|
|
137
|
+
'OS_MACOSX=1'
|
|
137
138
|
]
|
|
138
|
-
, 'libraries': []
|
|
139
|
-
, 'ccflags': []
|
|
140
139
|
, 'xcode_settings': {
|
|
141
|
-
|
|
142
|
-
'-Wno-sign-compare'
|
|
143
|
-
, '-Wno-unused-variable'
|
|
144
|
-
, '-Wno-unused-function'
|
|
145
|
-
]
|
|
146
|
-
, 'OTHER_CPLUSPLUSFLAGS': [
|
|
140
|
+
'OTHER_CPLUSPLUSFLAGS': [
|
|
147
141
|
'-mmacosx-version-min=10.14'
|
|
148
142
|
, '-std=c++17'
|
|
149
143
|
, '-stdlib=libc++'
|
package/deps/snappy/snappy.gyp
CHANGED
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|