rocksdb-native 0.0.1 → 0.0.2

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/CMakeLists.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  cmake_minimum_required(VERSION 3.25)
2
2
 
3
- project(rocksdb_native C)
3
+ project(rocksdb_native C CXX)
4
4
 
5
5
  include(bare)
6
6
 
package/binding.c CHANGED
@@ -24,7 +24,6 @@ typedef struct {
24
24
  uint32_t create_if_missing;
25
25
  uint32_t max_background_jobs;
26
26
  uint32_t bytes_per_sync;
27
- uint32_t compaction_style;
28
27
  uint32_t table_block_size;
29
28
  uint32_t table_cache_index_and_filter_blocks;
30
29
  uint32_t table_pin_l0_filter_and_index_blocks_in_cache;
@@ -154,6 +153,10 @@ on_worker_status_cb (uv_work_t *req, int st) {
154
153
  rocksdb_native_t *self = (rocksdb_native_t *) req;
155
154
 
156
155
  js_env_t *env = self->env;
156
+
157
+ js_handle_scope_t *scope;
158
+ js_open_handle_scope(env, &scope);
159
+
157
160
  js_value_t *ctx;
158
161
  js_value_t *on_status;
159
162
 
@@ -170,6 +173,7 @@ on_worker_status_cb (uv_work_t *req, int st) {
170
173
  }
171
174
 
172
175
  js_call_function(env, ctx, on_status, 1, &value, NULL);
176
+ js_close_handle_scope(env, scope);
173
177
  }
174
178
 
175
179
  static uint64_t
@@ -195,15 +199,20 @@ on_worker_open (uv_work_t *req) {
195
199
 
196
200
  rocksdb_options_set_max_background_jobs(opts, o->options.max_background_jobs);
197
201
  rocksdb_options_set_bytes_per_sync(opts, o->options.bytes_per_sync);
198
- rocksdb_options_set_compaction_style(opts, o->options.compaction_style);
199
202
 
200
203
  rocksdb_block_based_options_set_block_size(topts, o->options.table_block_size);
201
204
  rocksdb_block_based_options_set_cache_index_and_filter_blocks(topts, o->options.table_cache_index_and_filter_blocks);
202
205
  rocksdb_block_based_options_set_pin_l0_filter_and_index_blocks_in_cache(topts, o->options.table_pin_l0_filter_and_index_blocks_in_cache);
203
206
  rocksdb_block_based_options_set_format_version(topts, o->options.table_format_version);
204
207
 
208
+ rocksdb_filterpolicy_t *filter = rocksdb_filterpolicy_create_bloom(10);
209
+ rocksdb_block_based_options_set_filter_policy(topts, filter);
210
+
205
211
  rocksdb_options_set_block_based_table_factory(opts, topts);
206
212
 
213
+ rocksdb_options_set_hash_link_list_rep(opts, 200000);
214
+ rocksdb_options_set_allow_concurrent_memtable_write(opts, 0);
215
+
207
216
  if (o->options.enable_blob_files) {
208
217
  rocksdb_options_set_enable_blob_files(opts, 1);
209
218
  if (o->options.min_blob_size) rocksdb_options_set_min_blob_size(opts, o->options.min_blob_size);
@@ -261,6 +270,7 @@ on_worker_close (uv_work_t *req) {
261
270
  rocksdb_native_t *self = (rocksdb_native_t *) req;
262
271
  uv_handle_t *handle = (uv_handle_t *) self;
263
272
 
273
+ rocksdb_cancel_all_background_work(self->db, 1);
264
274
  rocksdb_close(self->db);
265
275
 
266
276
  handle->data = NULL;
@@ -310,7 +320,7 @@ on_worker_batch (uv_work_t *req) {
310
320
 
311
321
  static void
312
322
  free_db_read (js_env_t *env, void *data, void *hint) {
313
- free(data);
323
+ rocksdb_free(data);
314
324
  }
315
325
 
316
326
  static void
@@ -319,6 +329,10 @@ on_worker_batch_cb (uv_work_t *req, int st) {
319
329
  rocksdb_native_batch_t *r = &(self->read_batch);
320
330
 
321
331
  js_env_t *env = self->env;
332
+
333
+ js_handle_scope_t *scope;
334
+ js_open_handle_scope(env, &scope);
335
+
322
336
  js_value_t *gets;
323
337
  js_create_array_with_length(env, r->size, &gets);
324
338
 
@@ -347,6 +361,7 @@ on_worker_batch_cb (uv_work_t *req, int st) {
347
361
  };
348
362
 
349
363
  js_call_function(env, ctx, on_batch, 1, values, NULL);
364
+ js_close_handle_scope(env, scope);
350
365
  }
351
366
 
352
367
  static js_value_t *
package/index.js CHANGED
@@ -54,7 +54,6 @@ module.exports = class RocksDB extends ReadyResource {
54
54
  createIfMissing = true,
55
55
  maxBackgroundJobs = 6,
56
56
  bytesPerSync = 1048576,
57
- compactionStyle = 3, // https://github.com/facebook/rocksdb/blob/main/include/rocksdb/advanced_options.h#L41
58
57
  // (block) table options
59
58
  tableBlockSize = 16384,
60
59
  tableCacheIndexAndFilterBlocks = true,
@@ -74,7 +73,6 @@ module.exports = class RocksDB extends ReadyResource {
74
73
  this.createIfMissing = createIfMissing
75
74
  this.maxBackgroundJobs = maxBackgroundJobs
76
75
  this.bytesPerSync = bytesPerSync
77
- this.compactionStyle = compactionStyle
78
76
 
79
77
  this.tableBlockSize = tableBlockSize
80
78
  this.tableCacheIndexAndFilterBlocks = tableCacheIndexAndFilterBlocks
@@ -105,22 +103,21 @@ module.exports = class RocksDB extends ReadyResource {
105
103
 
106
104
  const opening = new Promise(resolve => { this._statusResolve = resolve })
107
105
 
108
- const opts = new Uint32Array(14)
106
+ const opts = new Uint32Array(13)
109
107
 
110
108
  opts[0] = this.readOnly ? 1 : 0
111
109
  opts[1] = this.createIfMissing ? 1 : 0
112
110
  opts[2] = this.maxBackgroundJobs
113
111
  opts[3] = this.bytesPerSync
114
- opts[4] = this.compactionStyle
115
- opts[5] = this.tableBlockSize
116
- opts[6] = this.tableCacheIndexAndFilterBlocks ? 1 : 0
117
- opts[7] = this.tablePinL0FilterAndIndexBlocksInCache ? 1 : 0
118
- opts[8] = this.tableFormatVersion
119
- opts[9] = this.enableBlobFiles ? 1 : 0
120
- opts[10] = this.minBlobSize
121
- opts[11] = this.blobFileSize & 0xffffffff
122
- opts[12] = Math.floor(this.blobFileSize / 0x100000000)
123
- opts[13] = this.enableBlobGarbageCollection ? 1 : 0
112
+ opts[4] = this.tableBlockSize
113
+ opts[5] = this.tableCacheIndexAndFilterBlocks ? 1 : 0
114
+ opts[6] = this.tablePinL0FilterAndIndexBlocksInCache ? 1 : 0
115
+ opts[7] = this.tableFormatVersion
116
+ opts[8] = this.enableBlobFiles ? 1 : 0
117
+ opts[9] = this.minBlobSize
118
+ opts[10] = this.blobFileSize & 0xffffffff
119
+ opts[11] = Math.floor(this.blobFileSize / 0x100000000)
120
+ opts[12] = this.enableBlobGarbageCollection ? 1 : 0
124
121
 
125
122
  binding.rocksdb_native_open(this._handle, this.path, opts)
126
123
 
@@ -158,20 +155,28 @@ module.exports = class RocksDB extends ReadyResource {
158
155
  }
159
156
 
160
157
  _onbatch (getValues) {
161
- for (let i = 0; i < this._writes.promises.length; i++) {
162
- const { resolve } = this._writes.promises[i]
163
- resolve()
158
+ if (this._writes !== null) {
159
+ for (let i = 0; i < this._writes.promises.length; i++) {
160
+ const { resolve } = this._writes.promises[i]
161
+ resolve()
162
+ }
163
+ this._writes = null
164
164
  }
165
165
 
166
- for (let i = 0; i < this._reads.promises.length; i++) {
167
- const { resolve } = this._reads.promises[i]
168
- const buffer = getValues[i]
169
- resolve(buffer === null ? null : Buffer.from(buffer, 0, buffer.byteLength))
166
+ if (this._reads !== null) {
167
+ for (let i = 0; i < this._reads.promises.length; i++) {
168
+ const { resolve } = this._reads.promises[i]
169
+ const buffer = getValues[i]
170
+ resolve(buffer === null ? null : Buffer.from(buffer, 0, buffer.byteLength))
171
+ }
172
+ this._reads = null
170
173
  }
171
174
 
172
- this._reads = this._writes = null
173
-
174
175
  while (this._flushes.length > 0) this._flushes.shift()()
176
+
177
+ if (this._nextReads.keys.length || this._nextWrites.keys.length) {
178
+ this._flushMaybe()
179
+ }
175
180
  }
176
181
 
177
182
  _encodeKey (k) {
@@ -197,9 +202,14 @@ module.exports = class RocksDB extends ReadyResource {
197
202
 
198
203
  if (this._reads.keys.length) {
199
204
  this._nextReads = new ReadBatch()
205
+ } else {
206
+ this._reads = null
200
207
  }
208
+
201
209
  if (this._writes.keys.length) {
202
210
  this._nextWrites = new WriteBatch()
211
+ } else {
212
+ this._writes = null
203
213
  }
204
214
  }
205
215
 
@@ -219,6 +229,7 @@ module.exports = class RocksDB extends ReadyResource {
219
229
  if (this.opened === false) await this.ready()
220
230
  if (this.closing) throw new Error('DB is closed')
221
231
  if (this.readOnly === true) throw new Error('DB is readOnly')
232
+ if (ops.length === 0) return
222
233
 
223
234
  const all = new Array(ops.length)
224
235
 
@@ -254,6 +265,7 @@ module.exports = class RocksDB extends ReadyResource {
254
265
  async getBatch (keys) {
255
266
  if (this.opened === false) await this.ready()
256
267
  if (this.closing) throw new Error('DB is closed')
268
+ if (keys.length === 0) return
257
269
 
258
270
  const all = new Array(keys.length)
259
271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "RocksDB native bindings",
5
5
  "main": "index.js",
6
6
  "files": [