@nxtedition/rocksdb 5.2.35 → 5.2.38

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.
Files changed (207) hide show
  1. package/binding.cc +136 -164
  2. package/binding.gyp +1 -1
  3. package/deps/liburing/liburing/COPYING +502 -0
  4. package/deps/liburing/liburing/COPYING.GPL +339 -0
  5. package/deps/liburing/liburing/LICENSE +7 -0
  6. package/deps/liburing/liburing/Makefile +84 -0
  7. package/deps/liburing/liburing/Makefile.quiet +11 -0
  8. package/deps/liburing/liburing/README +46 -0
  9. package/deps/liburing/liburing/configure +420 -0
  10. package/deps/liburing/liburing/debian/README.Debian +7 -0
  11. package/deps/liburing/liburing/debian/changelog +27 -0
  12. package/deps/liburing/liburing/debian/compat +1 -0
  13. package/deps/liburing/liburing/debian/control +48 -0
  14. package/deps/liburing/liburing/debian/copyright +49 -0
  15. package/deps/liburing/liburing/debian/liburing-dev.install +4 -0
  16. package/deps/liburing/liburing/debian/liburing-dev.manpages +6 -0
  17. package/deps/liburing/liburing/debian/liburing1-udeb.install +1 -0
  18. package/deps/liburing/liburing/debian/liburing1.install +1 -0
  19. package/deps/liburing/liburing/debian/liburing1.symbols +32 -0
  20. package/deps/liburing/liburing/debian/patches/series +1 -0
  21. package/deps/liburing/liburing/debian/rules +81 -0
  22. package/deps/liburing/liburing/debian/source/format +1 -0
  23. package/deps/liburing/liburing/debian/source/local-options +2 -0
  24. package/deps/liburing/liburing/debian/source/options +1 -0
  25. package/deps/liburing/liburing/debian/watch +3 -0
  26. package/deps/liburing/liburing/examples/Makefile +29 -0
  27. package/deps/liburing/liburing/examples/io_uring-cp.c +279 -0
  28. package/deps/liburing/liburing/examples/io_uring-test.c +112 -0
  29. package/deps/liburing/liburing/examples/link-cp.c +193 -0
  30. package/deps/liburing/liburing/examples/ucontext-cp.c +273 -0
  31. package/deps/liburing/liburing/liburing.pc.in +12 -0
  32. package/deps/liburing/liburing/liburing.spec +66 -0
  33. package/deps/liburing/liburing/make-debs.sh +53 -0
  34. package/deps/liburing/liburing/man/io_uring.7 +736 -0
  35. package/deps/liburing/liburing/man/io_uring_enter.2 +1403 -0
  36. package/deps/liburing/liburing/man/io_uring_get_sqe.3 +37 -0
  37. package/deps/liburing/liburing/man/io_uring_queue_exit.3 +27 -0
  38. package/deps/liburing/liburing/man/io_uring_queue_init.3 +44 -0
  39. package/deps/liburing/liburing/man/io_uring_register.2 +605 -0
  40. package/deps/liburing/liburing/man/io_uring_setup.2 +515 -0
  41. package/deps/liburing/liburing/src/Makefile +76 -0
  42. package/deps/liburing/liburing/src/include/liburing/barrier.h +73 -0
  43. package/deps/liburing/liburing/src/include/liburing/io_uring.h +422 -0
  44. package/deps/liburing/liburing/src/include/liburing.h +775 -0
  45. package/deps/liburing/liburing/src/liburing.map +46 -0
  46. package/deps/liburing/liburing/src/queue.c +403 -0
  47. package/deps/liburing/liburing/src/register.c +299 -0
  48. package/deps/liburing/liburing/src/setup.c +356 -0
  49. package/deps/liburing/liburing/src/syscall.c +73 -0
  50. package/deps/liburing/liburing/src/syscall.h +20 -0
  51. package/deps/liburing/liburing/test/232c93d07b74-test.c +305 -0
  52. package/deps/liburing/liburing/test/35fa71a030ca-test.c +329 -0
  53. package/deps/liburing/liburing/test/500f9fbadef8-test.c +89 -0
  54. package/deps/liburing/liburing/test/7ad0e4b2f83c-test.c +93 -0
  55. package/deps/liburing/liburing/test/8a9973408177-test.c +106 -0
  56. package/deps/liburing/liburing/test/917257daa0fe-test.c +53 -0
  57. package/deps/liburing/liburing/test/Makefile +312 -0
  58. package/deps/liburing/liburing/test/a0908ae19763-test.c +58 -0
  59. package/deps/liburing/liburing/test/a4c0b3decb33-test.c +180 -0
  60. package/deps/liburing/liburing/test/accept-link.c +251 -0
  61. package/deps/liburing/liburing/test/accept-reuse.c +164 -0
  62. package/deps/liburing/liburing/test/accept-test.c +79 -0
  63. package/deps/liburing/liburing/test/accept.c +476 -0
  64. package/deps/liburing/liburing/test/across-fork.c +283 -0
  65. package/deps/liburing/liburing/test/b19062a56726-test.c +53 -0
  66. package/deps/liburing/liburing/test/b5837bd5311d-test.c +77 -0
  67. package/deps/liburing/liburing/test/ce593a6c480a-test.c +135 -0
  68. package/deps/liburing/liburing/test/close-opath.c +122 -0
  69. package/deps/liburing/liburing/test/config +10 -0
  70. package/deps/liburing/liburing/test/connect.c +398 -0
  71. package/deps/liburing/liburing/test/cq-full.c +96 -0
  72. package/deps/liburing/liburing/test/cq-overflow.c +294 -0
  73. package/deps/liburing/liburing/test/cq-peek-batch.c +102 -0
  74. package/deps/liburing/liburing/test/cq-ready.c +94 -0
  75. package/deps/liburing/liburing/test/cq-size.c +58 -0
  76. package/deps/liburing/liburing/test/d4ae271dfaae-test.c +96 -0
  77. package/deps/liburing/liburing/test/d77a67ed5f27-test.c +65 -0
  78. package/deps/liburing/liburing/test/defer.c +307 -0
  79. package/deps/liburing/liburing/test/double-poll-crash.c +186 -0
  80. package/deps/liburing/liburing/test/eeed8b54e0df-test.c +114 -0
  81. package/deps/liburing/liburing/test/empty-eownerdead.c +42 -0
  82. package/deps/liburing/liburing/test/eventfd-disable.c +151 -0
  83. package/deps/liburing/liburing/test/eventfd-ring.c +97 -0
  84. package/deps/liburing/liburing/test/eventfd.c +112 -0
  85. package/deps/liburing/liburing/test/fadvise.c +202 -0
  86. package/deps/liburing/liburing/test/fallocate.c +249 -0
  87. package/deps/liburing/liburing/test/fc2a85cb02ef-test.c +138 -0
  88. package/deps/liburing/liburing/test/file-register.c +843 -0
  89. package/deps/liburing/liburing/test/file-update.c +173 -0
  90. package/deps/liburing/liburing/test/files-exit-hang-poll.c +128 -0
  91. package/deps/liburing/liburing/test/files-exit-hang-timeout.c +134 -0
  92. package/deps/liburing/liburing/test/fixed-link.c +90 -0
  93. package/deps/liburing/liburing/test/fsync.c +224 -0
  94. package/deps/liburing/liburing/test/hardlink.c +136 -0
  95. package/deps/liburing/liburing/test/helpers.c +135 -0
  96. package/deps/liburing/liburing/test/helpers.h +67 -0
  97. package/deps/liburing/liburing/test/io-cancel.c +537 -0
  98. package/deps/liburing/liburing/test/io_uring_enter.c +296 -0
  99. package/deps/liburing/liburing/test/io_uring_register.c +664 -0
  100. package/deps/liburing/liburing/test/io_uring_setup.c +192 -0
  101. package/deps/liburing/liburing/test/iopoll.c +366 -0
  102. package/deps/liburing/liburing/test/lfs-openat-write.c +117 -0
  103. package/deps/liburing/liburing/test/lfs-openat.c +273 -0
  104. package/deps/liburing/liburing/test/link-timeout.c +1107 -0
  105. package/deps/liburing/liburing/test/link.c +496 -0
  106. package/deps/liburing/liburing/test/link_drain.c +229 -0
  107. package/deps/liburing/liburing/test/madvise.c +195 -0
  108. package/deps/liburing/liburing/test/mkdir.c +108 -0
  109. package/deps/liburing/liburing/test/multicqes_drain.c +383 -0
  110. package/deps/liburing/liburing/test/nop-all-sizes.c +107 -0
  111. package/deps/liburing/liburing/test/nop.c +115 -0
  112. package/deps/liburing/liburing/test/open-close.c +146 -0
  113. package/deps/liburing/liburing/test/openat2.c +240 -0
  114. package/deps/liburing/liburing/test/personality.c +204 -0
  115. package/deps/liburing/liburing/test/pipe-eof.c +81 -0
  116. package/deps/liburing/liburing/test/pipe-reuse.c +105 -0
  117. package/deps/liburing/liburing/test/poll-cancel-ton.c +139 -0
  118. package/deps/liburing/liburing/test/poll-cancel.c +135 -0
  119. package/deps/liburing/liburing/test/poll-link.c +227 -0
  120. package/deps/liburing/liburing/test/poll-many.c +208 -0
  121. package/deps/liburing/liburing/test/poll-mshot-update.c +273 -0
  122. package/deps/liburing/liburing/test/poll-ring.c +48 -0
  123. package/deps/liburing/liburing/test/poll-v-poll.c +353 -0
  124. package/deps/liburing/liburing/test/poll.c +109 -0
  125. package/deps/liburing/liburing/test/probe.c +137 -0
  126. package/deps/liburing/liburing/test/read-write.c +876 -0
  127. package/deps/liburing/liburing/test/register-restrictions.c +633 -0
  128. package/deps/liburing/liburing/test/rename.c +134 -0
  129. package/deps/liburing/liburing/test/ring-leak.c +173 -0
  130. package/deps/liburing/liburing/test/ring-leak2.c +249 -0
  131. package/deps/liburing/liburing/test/rsrc_tags.c +449 -0
  132. package/deps/liburing/liburing/test/runtests-loop.sh +16 -0
  133. package/deps/liburing/liburing/test/runtests.sh +170 -0
  134. package/deps/liburing/liburing/test/rw_merge_test.c +97 -0
  135. package/deps/liburing/liburing/test/self.c +91 -0
  136. package/deps/liburing/liburing/test/send_recv.c +291 -0
  137. package/deps/liburing/liburing/test/send_recvmsg.c +345 -0
  138. package/deps/liburing/liburing/test/sendmsg_fs_cve.c +198 -0
  139. package/deps/liburing/liburing/test/shared-wq.c +84 -0
  140. package/deps/liburing/liburing/test/short-read.c +75 -0
  141. package/deps/liburing/liburing/test/shutdown.c +163 -0
  142. package/deps/liburing/liburing/test/sigfd-deadlock.c +74 -0
  143. package/deps/liburing/liburing/test/socket-rw-eagain.c +156 -0
  144. package/deps/liburing/liburing/test/socket-rw.c +147 -0
  145. package/deps/liburing/liburing/test/splice.c +511 -0
  146. package/deps/liburing/liburing/test/sq-full-cpp.cc +45 -0
  147. package/deps/liburing/liburing/test/sq-full.c +45 -0
  148. package/deps/liburing/liburing/test/sq-poll-dup.c +200 -0
  149. package/deps/liburing/liburing/test/sq-poll-kthread.c +168 -0
  150. package/deps/liburing/liburing/test/sq-poll-share.c +137 -0
  151. package/deps/liburing/liburing/test/sq-space_left.c +159 -0
  152. package/deps/liburing/liburing/test/sqpoll-cancel-hang.c +159 -0
  153. package/deps/liburing/liburing/test/sqpoll-disable-exit.c +195 -0
  154. package/deps/liburing/liburing/test/sqpoll-exit-hang.c +77 -0
  155. package/deps/liburing/liburing/test/sqpoll-sleep.c +68 -0
  156. package/deps/liburing/liburing/test/statx.c +172 -0
  157. package/deps/liburing/liburing/test/stdout.c +232 -0
  158. package/deps/liburing/liburing/test/submit-link-fail.c +154 -0
  159. package/deps/liburing/liburing/test/submit-reuse.c +239 -0
  160. package/deps/liburing/liburing/test/symlink.c +116 -0
  161. package/deps/liburing/liburing/test/teardowns.c +58 -0
  162. package/deps/liburing/liburing/test/thread-exit.c +131 -0
  163. package/deps/liburing/liburing/test/timeout-new.c +246 -0
  164. package/deps/liburing/liburing/test/timeout-overflow.c +204 -0
  165. package/deps/liburing/liburing/test/timeout.c +1354 -0
  166. package/deps/liburing/liburing/test/unlink.c +111 -0
  167. package/deps/liburing/liburing/test/wakeup-hang.c +162 -0
  168. package/deps/liburing/liburing.gyp +20 -0
  169. package/deps/rocksdb/rocksdb/README.md +32 -0
  170. package/deps/rocksdb/rocksdb/db/corruption_test.cc +62 -0
  171. package/deps/rocksdb/rocksdb/db/db_impl/db_impl.h +7 -62
  172. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_files.cc +25 -11
  173. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_open.cc +74 -155
  174. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.cc +1 -2
  175. package/deps/rocksdb/rocksdb/db/db_impl/db_impl_secondary.h +2 -2
  176. package/deps/rocksdb/rocksdb/env/fs_posix.cc +13 -0
  177. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.cc +4 -2
  178. package/deps/rocksdb/rocksdb/file/file_prefetch_buffer.h +22 -4
  179. package/deps/rocksdb/rocksdb/file/prefetch_test.cc +5 -0
  180. package/deps/rocksdb/rocksdb/include/rocksdb/file_system.h +15 -0
  181. package/deps/rocksdb/rocksdb/include/rocksdb/statistics.h +5 -0
  182. package/deps/rocksdb/rocksdb/include/rocksdb/version.h +1 -1
  183. package/deps/rocksdb/rocksdb/microbench/README.md +60 -0
  184. package/deps/rocksdb/rocksdb/monitoring/statistics.cc +3 -0
  185. package/deps/rocksdb/rocksdb/monitoring/stats_history_test.cc +3 -7
  186. package/deps/rocksdb/rocksdb/plugin/README.md +43 -0
  187. package/deps/rocksdb/rocksdb/port/README +10 -0
  188. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader.h +2 -1
  189. package/deps/rocksdb/rocksdb/table/block_based/block_based_table_reader_test.cc +44 -29
  190. package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_tree/lib/README +13 -0
  191. package/deps/rocksdb/rocksdb.gyp +3 -4
  192. package/deps/snappy/snappy-1.1.7/README.md +149 -0
  193. package/package.json +1 -1
  194. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  195. package/prebuilds/darwin-x64/node.napi.node +0 -0
  196. package/prebuilds/linux-x64/node.napi.node +0 -0
  197. package/deps/rocksdb/rocksdb/cmake/modules/CxxFlags.cmake +0 -7
  198. package/deps/rocksdb/rocksdb/cmake/modules/FindJeMalloc.cmake +0 -29
  199. package/deps/rocksdb/rocksdb/cmake/modules/FindNUMA.cmake +0 -29
  200. package/deps/rocksdb/rocksdb/cmake/modules/FindSnappy.cmake +0 -29
  201. package/deps/rocksdb/rocksdb/cmake/modules/FindTBB.cmake +0 -33
  202. package/deps/rocksdb/rocksdb/cmake/modules/Findgflags.cmake +0 -29
  203. package/deps/rocksdb/rocksdb/cmake/modules/Findlz4.cmake +0 -29
  204. package/deps/rocksdb/rocksdb/cmake/modules/Finduring.cmake +0 -26
  205. package/deps/rocksdb/rocksdb/cmake/modules/Findzstd.cmake +0 -29
  206. package/deps/rocksdb/rocksdb/cmake/modules/ReadVersion.cmake +0 -10
  207. package/package-lock.json +0 -23687
package/binding.cc CHANGED
@@ -19,6 +19,7 @@
19
19
  #include <set>
20
20
  #include <string>
21
21
  #include <vector>
22
+ #include <thread>
22
23
 
23
24
  class NullLogger : public rocksdb::Logger {
24
25
  public:
@@ -38,15 +39,6 @@ struct Iterator;
38
39
  } \
39
40
  }
40
41
 
41
- #define NAPI_PENDING_EXCEPTION() \
42
- { \
43
- bool result; \
44
- NAPI_STATUS_THROWS(napi_is_exception_pending(env, &result)); \
45
- if (result) { \
46
- return nullptr; \
47
- } \
48
- }
49
-
50
42
  #define NAPI_DB_CONTEXT() \
51
43
  Database* database = nullptr; \
52
44
  NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], (void**)&database));
@@ -71,12 +63,6 @@ static bool IsBuffer(napi_env env, napi_value value) {
71
63
  return isBuffer;
72
64
  }
73
65
 
74
- static bool IsObject(napi_env env, napi_value value) {
75
- napi_valuetype type;
76
- napi_typeof(env, value, &type);
77
- return type == napi_object;
78
- }
79
-
80
66
  static napi_value CreateError(napi_env env, const std::optional<std::string_view>& code, const std::string_view& msg) {
81
67
  napi_value codeValue = nullptr;
82
68
  if (code) {
@@ -96,12 +82,12 @@ static bool HasProperty(napi_env env, napi_value obj, const std::string_view& ke
96
82
  }
97
83
 
98
84
  static napi_value GetProperty(napi_env env, napi_value obj, const std::string_view& key) {
99
- napi_value value;
85
+ napi_value value = nullptr;
100
86
  napi_get_named_property(env, obj, key.data(), &value);
101
87
  return value;
102
88
  }
103
89
 
104
- static bool BooleanProperty(napi_env env, napi_value obj, const std::string_view& key, bool defaultValue) {
90
+ static std::optional<bool> BooleanProperty(napi_env env, napi_value obj, const std::string_view& key) {
105
91
  if (HasProperty(env, obj, key.data())) {
106
92
  const auto value = GetProperty(env, obj, key.data());
107
93
  bool result;
@@ -109,7 +95,7 @@ static bool BooleanProperty(napi_env env, napi_value obj, const std::string_view
109
95
  return result;
110
96
  }
111
97
 
112
- return defaultValue;
98
+ return {};
113
99
  }
114
100
 
115
101
  static bool EncodingIsBuffer(napi_env env, napi_value obj, const std::string_view& option) {
@@ -125,7 +111,7 @@ static bool EncodingIsBuffer(napi_env env, napi_value obj, const std::string_vie
125
111
  return false;
126
112
  }
127
113
 
128
- static uint32_t Uint32Property(napi_env env, napi_value obj, const std::string_view& key, uint32_t defaultValue) {
114
+ static std::optional<uint32_t> Uint32Property(napi_env env, napi_value obj, const std::string_view& key) {
129
115
  if (HasProperty(env, obj, key.data())) {
130
116
  const auto value = GetProperty(env, obj, key.data());
131
117
  uint32_t result;
@@ -133,10 +119,10 @@ static uint32_t Uint32Property(napi_env env, napi_value obj, const std::string_v
133
119
  return result;
134
120
  }
135
121
 
136
- return defaultValue;
122
+ return {};
137
123
  }
138
124
 
139
- static int Int32Property(napi_env env, napi_value obj, const std::string_view& key, int defaultValue) {
125
+ static std::optional<int> Int32Property(napi_env env, napi_value obj, const std::string_view& key) {
140
126
  if (HasProperty(env, obj, key.data())) {
141
127
  const auto value = GetProperty(env, obj, key.data());
142
128
  int result;
@@ -144,7 +130,7 @@ static int Int32Property(napi_env env, napi_value obj, const std::string_view& k
144
130
  return result;
145
131
  }
146
132
 
147
- return defaultValue;
133
+ return {};
148
134
  }
149
135
 
150
136
  static std::string ToString(napi_env env, napi_value from, const std::string& defaultValue = "") {
@@ -164,26 +150,11 @@ static std::string ToString(napi_env env, napi_value from, const std::string& de
164
150
  return defaultValue;
165
151
  }
166
152
 
167
- static std::string StringProperty(napi_env env,
168
- napi_value obj,
169
- const std::string_view& key,
170
- const std::string& defaultValue = "") {
171
- if (HasProperty(env, obj, key)) {
172
- napi_value value = GetProperty(env, obj, key);
173
- if (IsString(env, value)) {
174
- return ToString(env, value);
175
- }
176
- }
177
-
178
- return defaultValue;
179
- }
180
-
181
- static std::optional<std::string> RangeOption(napi_env env, napi_value opts, const std::string_view& name) {
153
+ static std::optional<std::string> StringProperty(napi_env env, napi_value opts, const std::string_view& name) {
182
154
  if (HasProperty(env, opts, name)) {
183
155
  const auto value = GetProperty(env, opts, name);
184
156
  return ToString(env, value);
185
157
  }
186
-
187
158
  return {};
188
159
  }
189
160
 
@@ -238,31 +209,42 @@ napi_status Convert(napi_env env, std::string s, bool asBuffer, napi_value& resu
238
209
  }
239
210
  }
240
211
 
241
- struct NapiSlice : public rocksdb::Slice {
242
- NapiSlice(napi_env env, napi_value from) {
243
- if (IsString(env, from)) {
244
- NAPI_STATUS_THROWS_VOID(napi_get_value_string_utf8(env, from, nullptr, 0, &size_));
245
- char* data;
246
- if (size_ + 1 < stack_.size()) {
247
- data = stack_.data();
248
- } else {
249
- heap_.reset(new char[size_ + 1]);
250
- data = heap_.get();
251
- }
252
- data[size_] = 0;
253
- NAPI_STATUS_THROWS_VOID(napi_get_value_string_utf8(env, from, data, size_ + 1, &size_));
254
- data_ = data;
255
- } else if (IsBuffer(env, from)) {
256
- void* data;
257
- NAPI_STATUS_THROWS_VOID(napi_get_buffer_info(env, from, &data, &size_));
258
- data_ = static_cast<char*>(data);
259
- }
212
+ napi_status Convert(napi_env env, rocksdb::PinnableSlice s, bool asBuffer, napi_value& result) {
213
+ if (asBuffer) {
214
+ auto ptr = new rocksdb::PinnableSlice(std::move(s));
215
+ return napi_create_external_buffer(env, ptr->size(), const_cast<char*>(ptr->data()),
216
+ Finalize<rocksdb::PinnableSlice>, ptr, &result);
217
+ } else {
218
+ return napi_create_string_utf8(env, s.data(), s.size(), &result);
260
219
  }
220
+ }
261
221
 
222
+ struct NapiSlice : public rocksdb::Slice {
262
223
  std::unique_ptr<char[]> heap_;
263
224
  std::array<char, 1024> stack_;
264
225
  };
265
226
 
227
+ napi_status ToNapiSlice(napi_env env, napi_value from, NapiSlice& slice) {
228
+ if (IsString(env, from)) {
229
+ NAPI_STATUS_RETURN(napi_get_value_string_utf8(env, from, nullptr, 0, &slice.size_));
230
+ char* data;
231
+ if (slice.size_ + 1 < slice.stack_.size()) {
232
+ data = slice.stack_.data();
233
+ } else {
234
+ slice.heap_.reset(new char[slice.size_ + 1]);
235
+ data = slice.heap_.get();
236
+ }
237
+ data[slice.size_] = 0;
238
+ NAPI_STATUS_RETURN(napi_get_value_string_utf8(env, from, data, slice.size_ + 1, &slice.size_));
239
+ slice.data_ = data;
240
+ } else if (IsBuffer(env, from)) {
241
+ void* data;
242
+ NAPI_STATUS_RETURN(napi_get_buffer_info(env, from, &data, &slice.size_));
243
+ slice.data_ = static_cast<char*>(data);
244
+ }
245
+ return napi_ok;
246
+ }
247
+
266
248
  /**
267
249
  * Base worker class. Handles the async work. Derived classes can override the
268
250
  * following virtual methods (listed in the order in which they're called):
@@ -383,21 +365,21 @@ struct BaseIterator {
383
365
  limit_(limit),
384
366
  fillCache_(fillCache) {
385
367
  if (lte) {
386
- upper_bound_ = std::make_unique<rocksdb::PinnableSlice>();
368
+ upper_bound_ = rocksdb::PinnableSlice();
387
369
  *upper_bound_->GetSelf() = std::move(*lte) + '\0';
388
370
  upper_bound_->PinSelf();
389
371
  } else if (lt) {
390
- upper_bound_ = std::make_unique<rocksdb::PinnableSlice>();
372
+ upper_bound_ = rocksdb::PinnableSlice();
391
373
  *upper_bound_->GetSelf() = std::move(*lt);
392
374
  upper_bound_->PinSelf();
393
375
  }
394
376
 
395
377
  if (gte) {
396
- lower_bound_ = std::make_unique<rocksdb::PinnableSlice>();
378
+ lower_bound_ = rocksdb::PinnableSlice();
397
379
  *lower_bound_->GetSelf() = std::move(*gte);
398
380
  lower_bound_->PinSelf();
399
381
  } else if (gt) {
400
- lower_bound_ = std::make_unique<rocksdb::PinnableSlice>();
382
+ lower_bound_ = rocksdb::PinnableSlice();
401
383
  *lower_bound_->GetSelf() = std::move(*gt) + '\0';
402
384
  lower_bound_->PinSelf();
403
385
  }
@@ -477,8 +459,8 @@ struct BaseIterator {
477
459
  iterator_.reset(database_->db_->NewIterator(options));
478
460
  }
479
461
 
480
- std::unique_ptr<rocksdb::PinnableSlice> lower_bound_;
481
- std::unique_ptr<rocksdb::PinnableSlice> upper_bound_;
462
+ std::optional<rocksdb::PinnableSlice> lower_bound_;
463
+ std::optional<rocksdb::PinnableSlice> upper_bound_;
482
464
  std::shared_ptr<const rocksdb::Snapshot> snapshot_;
483
465
  std::unique_ptr<rocksdb::Iterator> iterator_;
484
466
  const bool reverse_;
@@ -506,9 +488,7 @@ struct Iterator final : public BaseIterator {
506
488
  values_(values),
507
489
  keyAsBuffer_(keyAsBuffer),
508
490
  valueAsBuffer_(valueAsBuffer),
509
- highWaterMarkBytes_(highWaterMarkBytes),
510
- first_(true),
511
- ref_(nullptr) {}
491
+ highWaterMarkBytes_(highWaterMarkBytes) {}
512
492
 
513
493
  void Attach(napi_env env, napi_value context) {
514
494
  napi_create_reference(env, context, 1, &ref_);
@@ -527,10 +507,10 @@ struct Iterator final : public BaseIterator {
527
507
  const bool keyAsBuffer_;
528
508
  const bool valueAsBuffer_;
529
509
  const uint32_t highWaterMarkBytes_;
530
- bool first_;
510
+ bool first_ = true;
531
511
 
532
512
  private:
533
- napi_ref ref_;
513
+ napi_ref ref_ = nullptr;
534
514
  };
535
515
 
536
516
  /**
@@ -593,11 +573,10 @@ struct OpenWorker final : public Worker {
593
573
  readOnly_(readOnly),
594
574
  location_(location) {}
595
575
 
596
- rocksdb::Status Execute(Database& database) override {
597
- rocksdb::DB* db;
598
- const auto status = readOnly_
599
- ? rocksdb::DB::OpenForReadOnly(options_, location_, &db)
600
- : rocksdb::DB::Open(options_, location_, &db);
576
+ rocksdb::Status Execute(Database& database) override {
577
+ rocksdb::DB* db = nullptr;
578
+ const auto status = readOnly_ ? rocksdb::DB::OpenForReadOnly(options_, location_, &db)
579
+ : rocksdb::DB::Open(options_, location_, &db);
601
580
  database.db_.reset(db);
602
581
  return status;
603
582
  }
@@ -613,19 +592,21 @@ NAPI_METHOD(db_open) {
613
592
 
614
593
  rocksdb::Options options;
615
594
 
616
- options.IncreaseParallelism(Uint32Property(env, argv[2], "parallelism", 4));
595
+ options.IncreaseParallelism(
596
+ Uint32Property(env, argv[2], "parallelism").value_or(std::thread::hardware_concurrency() / 2));
617
597
 
618
598
  const auto location = ToString(env, argv[1]);
619
- options.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing", true);
620
- options.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists", false);
621
- options.compression =
622
- BooleanProperty(env, argv[2], "compression", true) ? rocksdb::kSnappyCompression : rocksdb::kNoCompression;
623
- options.max_open_files = Uint32Property(env, argv[2], "maxOpenFiles", 1000);
624
- options.max_log_file_size = Uint32Property(env, argv[2], "maxFileSize", 2 << 20);
625
- options.write_buffer_size = Uint32Property(env, argv[2], "writeBufferSize", 4 << 20);
599
+ options.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing").value_or(true);
600
+ options.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists").value_or(false);
601
+ options.compression = BooleanProperty(env, argv[2], "compression").value_or((true)) ? rocksdb::kSnappyCompression
602
+ : rocksdb::kNoCompression;
626
603
  options.use_adaptive_mutex = true;
604
+ options.enable_pipelined_write = true;
627
605
 
628
- const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel");
606
+ // TODO: Consider direct IO (https://github.com/facebook/rocksdb/wiki/Direct-IO) once
607
+ // secondary compressed cache is stable.
608
+
609
+ const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel").value_or("");
629
610
  if (infoLogLevel.size() > 0) {
630
611
  rocksdb::InfoLogLevel lvl = {};
631
612
 
@@ -652,8 +633,8 @@ NAPI_METHOD(db_open) {
652
633
  options.info_log.reset(new NullLogger());
653
634
  }
654
635
 
655
- const auto readOnly = BooleanProperty(env, argv[2], "readOnly", false);
656
- const auto cacheSize = Uint32Property(env, argv[2], "cacheSize", 8 << 20);
636
+ const auto readOnly = BooleanProperty(env, argv[2], "readOnly").value_or(false);
637
+ const auto cacheSize = Uint32Property(env, argv[2], "cacheSize").value_or(8 << 20);
657
638
 
658
639
  rocksdb::BlockBasedTableOptions tableOptions;
659
640
 
@@ -663,18 +644,18 @@ NAPI_METHOD(db_open) {
663
644
  tableOptions.no_block_cache = true;
664
645
  }
665
646
 
666
- tableOptions.block_size = Uint32Property(env, argv[2], "blockSize", 4096);
667
- tableOptions.block_restart_interval = Uint32Property(env, argv[2], "blockRestartInterval", 16);
668
- tableOptions.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10));
647
+ tableOptions.block_size = Uint32Property(env, argv[2], "blockSize").value_or(4096);
648
+ tableOptions.block_restart_interval = Uint32Property(env, argv[2], "blockRestartInterval").value_or(16);
649
+ tableOptions.filter_policy.reset(rocksdb::NewRibbonFilterPolicy(10));
669
650
  tableOptions.format_version = 5;
670
- tableOptions.checksum = rocksdb::kxxHash64;
651
+ tableOptions.checksum = rocksdb::kXXH3;
652
+ tableOptions.optimize_filters_for_memory = BooleanProperty(env, argv[2], "optimizeFiltersForMemory").value_or(true);
653
+ tableOptions.cache_index_and_filter_blocks = BooleanProperty(env, argv[2], "cacheIndexAndFilterBlocks").value_or(true);
671
654
 
672
655
  options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(tableOptions));
673
656
 
674
657
  const auto callback = argv[3];
675
658
 
676
- NAPI_PENDING_EXCEPTION();
677
-
678
659
  auto worker = new OpenWorker(env, database, callback, location, options, readOnly);
679
660
  worker->Queue(env);
680
661
 
@@ -713,10 +694,11 @@ NAPI_METHOD(db_put) {
713
694
  NAPI_ARGV(4);
714
695
  NAPI_DB_CONTEXT();
715
696
 
716
- const auto key = NapiSlice(env, argv[1]);
717
- const auto val = NapiSlice(env, argv[2]);
697
+ NapiSlice key;
698
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[1], key));
718
699
 
719
- NAPI_PENDING_EXCEPTION();
700
+ NapiSlice val;
701
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[2], val));
720
702
 
721
703
  rocksdb::WriteOptions options;
722
704
  return ToError(env, database->db_->Put(options, key, val));
@@ -778,11 +760,9 @@ NAPI_METHOD(db_get) {
778
760
  const auto key = ToString(env, argv[1]);
779
761
  const auto options = argv[2];
780
762
  const auto asBuffer = EncodingIsBuffer(env, options, "valueEncoding");
781
- const auto fillCache = BooleanProperty(env, options, "fillCache", true);
763
+ const auto fillCache = BooleanProperty(env, options, "fillCache").value_or(true);
782
764
  const auto callback = argv[3];
783
765
 
784
- NAPI_PENDING_EXCEPTION();
785
-
786
766
  auto worker = new GetWorker(env, database, callback, key, asBuffer, fillCache);
787
767
  worker->Queue(env);
788
768
 
@@ -792,12 +772,12 @@ NAPI_METHOD(db_get) {
792
772
  struct GetManyWorker final : public Worker {
793
773
  GetManyWorker(napi_env env,
794
774
  Database* database,
795
- const std::vector<std::string>& keys,
775
+ std::vector<std::string> keys,
796
776
  napi_value callback,
797
777
  const bool valueAsBuffer,
798
778
  const bool fillCache)
799
779
  : Worker(env, database, callback, "leveldown.get.many"),
800
- keys_(keys),
780
+ keys_(std::move(keys)),
801
781
  valueAsBuffer_(valueAsBuffer),
802
782
  fillCache_(fillCache),
803
783
  snapshot_(database_->db_->GetSnapshot(),
@@ -810,12 +790,24 @@ struct GetManyWorker final : public Worker {
810
790
  options.fill_cache = fillCache_;
811
791
  options.snapshot = snapshot_.get();
812
792
 
813
- status_ = database.db_->MultiGet(options, std::vector<rocksdb::Slice>(keys_.begin(), keys_.end()), &values_);
793
+ const auto numKeys = keys_.size();
794
+
795
+ std::vector<rocksdb::Slice> keys;
796
+ keys.reserve(keys_.size());
797
+ for (const auto& key : keys_) {
798
+ keys.emplace_back(key);
799
+ }
800
+
801
+ statuses_.resize(numKeys);
802
+ values_.resize(numKeys);
803
+
804
+ database.db_->MultiGet(options, database.db_->DefaultColumnFamily(), numKeys, keys.data(), values_.data(),
805
+ statuses_.data());
814
806
 
815
807
  keys_.clear();
816
808
  snapshot_ = nullptr;
817
809
 
818
- for (auto status : status_) {
810
+ for (auto status : statuses_) {
819
811
  if (!status.ok() && !status.IsNotFound()) {
820
812
  return status;
821
813
  }
@@ -832,7 +824,7 @@ struct GetManyWorker final : public Worker {
832
824
 
833
825
  for (size_t idx = 0; idx < size; idx++) {
834
826
  napi_value element;
835
- if (status_[idx].ok()) {
827
+ if (statuses_[idx].ok()) {
836
828
  NAPI_STATUS_RETURN(Convert(env, std::move(values_[idx]), valueAsBuffer_, element));
837
829
  } else {
838
830
  NAPI_STATUS_RETURN(napi_get_undefined(env, &element));
@@ -841,7 +833,7 @@ struct GetManyWorker final : public Worker {
841
833
  }
842
834
 
843
835
  values_.clear();
844
- status_.clear();
836
+ statuses_.clear();
845
837
 
846
838
  napi_value argv[2];
847
839
  NAPI_STATUS_RETURN(napi_get_null(env, &argv[0]));
@@ -856,8 +848,8 @@ struct GetManyWorker final : public Worker {
856
848
 
857
849
  private:
858
850
  std::vector<std::string> keys_;
859
- std::vector<std::string> values_;
860
- std::vector<rocksdb::Status> status_;
851
+ std::vector<rocksdb::PinnableSlice> values_;
852
+ std::vector<rocksdb::Status> statuses_;
861
853
  const bool valueAsBuffer_;
862
854
  const bool fillCache_;
863
855
  std::shared_ptr<const rocksdb::Snapshot> snapshot_;
@@ -884,12 +876,10 @@ NAPI_METHOD(db_get_many) {
884
876
 
885
877
  const auto options = argv[2];
886
878
  const bool asBuffer = EncodingIsBuffer(env, options, "valueEncoding");
887
- const bool fillCache = BooleanProperty(env, options, "fillCache", true);
879
+ const bool fillCache = BooleanProperty(env, options, "fillCache").value_or(true);
888
880
  const auto callback = argv[3];
889
881
 
890
- NAPI_PENDING_EXCEPTION();
891
-
892
- auto worker = new GetManyWorker(env, database, keys, callback, asBuffer, fillCache);
882
+ auto worker = new GetManyWorker(env, database, std::move(keys), callback, asBuffer, fillCache);
893
883
  worker->Queue(env);
894
884
 
895
885
  return 0;
@@ -899,9 +889,8 @@ NAPI_METHOD(db_del) {
899
889
  NAPI_ARGV(3);
900
890
  NAPI_DB_CONTEXT();
901
891
 
902
- const auto key = NapiSlice(env, argv[1]);
903
-
904
- NAPI_PENDING_EXCEPTION();
892
+ NapiSlice key;
893
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[1], key));
905
894
 
906
895
  rocksdb::WriteOptions options;
907
896
  return ToError(env, database->db_->Delete(options, key));
@@ -911,15 +900,13 @@ NAPI_METHOD(db_clear) {
911
900
  NAPI_ARGV(2);
912
901
  NAPI_DB_CONTEXT();
913
902
 
914
- const auto reverse = BooleanProperty(env, argv[1], "reverse", false);
915
- const auto limit = Int32Property(env, argv[1], "limit", -1);
916
-
917
- const auto lt = RangeOption(env, argv[1], "lt");
918
- const auto lte = RangeOption(env, argv[1], "lte");
919
- const auto gt = RangeOption(env, argv[1], "gt");
920
- const auto gte = RangeOption(env, argv[1], "gte");
903
+ const auto reverse = BooleanProperty(env, argv[1], "reverse").value_or(false);
904
+ const auto limit = Int32Property(env, argv[1], "limit").value_or(-1);
921
905
 
922
- NAPI_PENDING_EXCEPTION();
906
+ const auto lt = StringProperty(env, argv[1], "lt");
907
+ const auto lte = StringProperty(env, argv[1], "lte");
908
+ const auto gt = StringProperty(env, argv[1], "gt");
909
+ const auto gte = StringProperty(env, argv[1], "gte");
923
910
 
924
911
  // TODO (perf): Use DeleteRange.
925
912
 
@@ -966,9 +953,8 @@ NAPI_METHOD(db_get_property) {
966
953
  NAPI_ARGV(2);
967
954
  NAPI_DB_CONTEXT();
968
955
 
969
- const auto property = NapiSlice(env, argv[1]);
970
-
971
- NAPI_PENDING_EXCEPTION();
956
+ NapiSlice property;
957
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[1], property));
972
958
 
973
959
  std::string value;
974
960
  database->db_->GetProperty(property, &value);
@@ -984,24 +970,22 @@ NAPI_METHOD(iterator_init) {
984
970
  NAPI_DB_CONTEXT();
985
971
 
986
972
  const auto options = argv[1];
987
- const auto reverse = BooleanProperty(env, options, "reverse", false);
988
- const auto keys = BooleanProperty(env, options, "keys", true);
989
- const auto values = BooleanProperty(env, options, "values", true);
990
- const auto fillCache = BooleanProperty(env, options, "fillCache", false);
973
+ const auto reverse = BooleanProperty(env, options, "reverse").value_or(false);
974
+ const auto keys = BooleanProperty(env, options, "keys").value_or(true);
975
+ const auto values = BooleanProperty(env, options, "values").value_or(true);
976
+ const auto fillCache = BooleanProperty(env, options, "fillCache").value_or(false);
991
977
  const bool keyAsBuffer = EncodingIsBuffer(env, options, "keyEncoding");
992
978
  const bool valueAsBuffer = EncodingIsBuffer(env, options, "valueEncoding");
993
- const auto limit = Int32Property(env, options, "limit", -1);
994
- const auto highWaterMarkBytes = Uint32Property(env, options, "highWaterMarkBytes", 16 * 1024);
995
-
996
- const auto lt = RangeOption(env, options, "lt");
997
- const auto lte = RangeOption(env, options, "lte");
998
- const auto gt = RangeOption(env, options, "gt");
999
- const auto gte = RangeOption(env, options, "gte");
979
+ const auto limit = Int32Property(env, options, "limit").value_or(-1);
980
+ const auto highWaterMarkBytes = Uint32Property(env, options, "highWaterMarkBytes").value_or(16 * 1024);
1000
981
 
1001
- NAPI_PENDING_EXCEPTION();
982
+ const auto lt = StringProperty(env, options, "lt");
983
+ const auto lte = StringProperty(env, options, "lte");
984
+ const auto gt = StringProperty(env, options, "gt");
985
+ const auto gte = StringProperty(env, options, "gte");
1002
986
 
1003
- auto iterator = std::make_unique<Iterator>(database, reverse, keys, values, limit, lt, lte, gt, gte, fillCache, keyAsBuffer,
1004
- valueAsBuffer, highWaterMarkBytes);
987
+ auto iterator = std::make_unique<Iterator>(database, reverse, keys, values, limit, lt, lte, gt, gte, fillCache,
988
+ keyAsBuffer, valueAsBuffer, highWaterMarkBytes);
1005
989
 
1006
990
  napi_value result;
1007
991
  NAPI_STATUS_THROWS(napi_create_external(env, iterator.get(), Finalize<Iterator>, iterator.get(), &result));
@@ -1017,9 +1001,8 @@ NAPI_METHOD(iterator_seek) {
1017
1001
  NAPI_ARGV(2);
1018
1002
  NAPI_ITERATOR_CONTEXT();
1019
1003
 
1020
- const auto target = NapiSlice(env, argv[1]);
1021
-
1022
- NAPI_PENDING_EXCEPTION();
1004
+ NapiSlice target;
1005
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[1], target));
1023
1006
 
1024
1007
  iterator->first_ = true;
1025
1008
  iterator->Seek(target);
@@ -1147,33 +1130,22 @@ NAPI_METHOD(batch_do) {
1147
1130
  napi_value element;
1148
1131
  NAPI_STATUS_THROWS(napi_get_element(env, operations, i, &element));
1149
1132
 
1150
- if (!IsObject(env, element))
1151
- continue;
1152
-
1153
- const auto type = StringProperty(env, element, "type");
1133
+ NapiSlice type;
1134
+ NAPI_STATUS_THROWS(ToNapiSlice(env, GetProperty(env, element, "type"), type));
1154
1135
 
1155
1136
  if (type == "del") {
1156
- if (!HasProperty(env, element, "key"))
1157
- continue;
1158
-
1159
- const auto key = NapiSlice(env, GetProperty(env, element, "key"));
1160
-
1137
+ NapiSlice key;
1138
+ NAPI_STATUS_THROWS(ToNapiSlice(env, GetProperty(env, element, "key"), key));
1161
1139
  batch.Delete(key);
1162
1140
  } else if (type == "put") {
1163
- if (!HasProperty(env, element, "key"))
1164
- continue;
1165
- if (!HasProperty(env, element, "value"))
1166
- continue;
1167
-
1168
- const auto key = NapiSlice(env, GetProperty(env, element, "key"));
1169
- const auto value = NapiSlice(env, GetProperty(env, element, "value"));
1170
-
1141
+ NapiSlice key;
1142
+ NAPI_STATUS_THROWS(ToNapiSlice(env, GetProperty(env, element, "key"), key));
1143
+ NapiSlice value;
1144
+ NAPI_STATUS_THROWS(ToNapiSlice(env, GetProperty(env, element, "value"), value));
1171
1145
  batch.Put(key, value);
1172
1146
  }
1173
1147
  }
1174
1148
 
1175
- NAPI_PENDING_EXCEPTION();
1176
-
1177
1149
  rocksdb::WriteOptions options;
1178
1150
  return ToError(env, database->db_->Write(options, &batch));
1179
1151
  }
@@ -1193,10 +1165,11 @@ NAPI_METHOD(batch_put) {
1193
1165
  NAPI_ARGV(3);
1194
1166
  NAPI_BATCH_CONTEXT();
1195
1167
 
1196
- const auto key = NapiSlice(env, argv[1]);
1197
- const auto val = NapiSlice(env, argv[2]);
1168
+ NapiSlice key;
1169
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[1], key));
1198
1170
 
1199
- NAPI_PENDING_EXCEPTION();
1171
+ NapiSlice val;
1172
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[2], val));
1200
1173
 
1201
1174
  batch->Put(key, val);
1202
1175
 
@@ -1207,9 +1180,8 @@ NAPI_METHOD(batch_del) {
1207
1180
  NAPI_ARGV(2);
1208
1181
  NAPI_BATCH_CONTEXT();
1209
1182
 
1210
- const auto key = NapiSlice(env, argv[1]);
1211
-
1212
- NAPI_PENDING_EXCEPTION();
1183
+ NapiSlice key;
1184
+ NAPI_STATUS_THROWS(ToNapiSlice(env, argv[1], key));
1213
1185
 
1214
1186
  batch->Delete(key);
1215
1187
 
package/binding.gyp CHANGED
@@ -62,7 +62,7 @@
62
62
  ],
63
63
  "OTHER_CPLUSPLUSFLAGS": [
64
64
  "-mmacosx-version-min=10.15",
65
- "-std=c++17",
65
+ "-std=c++20",
66
66
  "-fno-omit-frame-pointer",
67
67
  "-momit-leaf-frame-pointer",
68
68
  "-arch x86_64",