@nxtedition/rocksdb 5.2.2 → 5.2.13
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 +597 -100
- package/binding.gyp +5 -4
- package/chained-batch.js +13 -18
- package/deps/rocksdb/rocksdb/README.md +32 -0
- package/deps/rocksdb/rocksdb/hdfs/README +23 -0
- package/deps/rocksdb/rocksdb/port/README +10 -0
- package/deps/rocksdb/rocksdb/third-party/folly/folly/synchronization/test/DistributedMutexTest.cpp +1145 -0
- package/deps/rocksdb/rocksdb/utilities/transactions/lock/range/range_tree/lib/README +13 -0
- package/deps/rocksdb/rocksdb.gyp +44 -62
- package/deps/snappy/snappy-1.1.7/README.md +149 -0
- package/index.js +189 -0
- package/iterator.js +88 -24
- package/package.json +23 -17
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/deps/rocksdb/rocksdb/cmake/modules/CxxFlags.cmake +0 -7
- package/deps/rocksdb/rocksdb/cmake/modules/FindJeMalloc.cmake +0 -29
- package/deps/rocksdb/rocksdb/cmake/modules/FindNUMA.cmake +0 -29
- package/deps/rocksdb/rocksdb/cmake/modules/FindSnappy.cmake +0 -29
- package/deps/rocksdb/rocksdb/cmake/modules/FindTBB.cmake +0 -33
- package/deps/rocksdb/rocksdb/cmake/modules/Findgflags.cmake +0 -29
- package/deps/rocksdb/rocksdb/cmake/modules/Findlz4.cmake +0 -29
- package/deps/rocksdb/rocksdb/cmake/modules/Findzstd.cmake +0 -29
- package/deps/rocksdb/rocksdb/cmake/modules/ReadVersion.cmake +0 -10
- package/leveldown.js +0 -113
- package/package-lock.json +0 -23687
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
The files in this directory originally come from
|
|
2
|
+
https://github.com/percona/PerconaFT/.
|
|
3
|
+
|
|
4
|
+
This directory only includes the "locktree" part of PerconaFT, and its
|
|
5
|
+
dependencies.
|
|
6
|
+
|
|
7
|
+
The following modifications were made:
|
|
8
|
+
- Make locktree usable outside of PerconaFT library
|
|
9
|
+
- Add shared read-only lock support
|
|
10
|
+
|
|
11
|
+
The files named *_subst.* are substitutes of the PerconaFT's files, they
|
|
12
|
+
contain replacements of PerconaFT's functionality.
|
|
13
|
+
|
package/deps/rocksdb/rocksdb.gyp
CHANGED
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
]
|
|
14
14
|
}
|
|
15
15
|
, 'defines': [
|
|
16
|
-
'SNAPPY=1'
|
|
16
|
+
'SNAPPY=1',
|
|
17
|
+
'ROCKSDB_BACKTRACE=1',
|
|
18
|
+
'ROCKSDB_SUPPORT_THREAD_LOCAL=1',
|
|
19
|
+
'USE_SSE=1'
|
|
17
20
|
]
|
|
18
21
|
, 'include_dirs': [
|
|
19
22
|
'rocksdb/'
|
|
@@ -73,16 +76,12 @@
|
|
|
73
76
|
, 'defines': [
|
|
74
77
|
'ROCKSDB_PLATFORM_POSIX=1'
|
|
75
78
|
]
|
|
76
|
-
, 'ccflags': [
|
|
77
|
-
|
|
78
|
-
, '-fPIC'
|
|
79
|
-
]
|
|
80
|
-
, 'cflags': [ '-std=c++0x' ]
|
|
79
|
+
, 'ccflags': []
|
|
80
|
+
, 'cflags': [ '-std=c++17' ]
|
|
81
81
|
, 'cflags!': [ '-fno-tree-vrp', '-fno-rtti' ]
|
|
82
82
|
, 'cflags_cc!': [ '-fno-rtti' ]
|
|
83
|
-
# , 'cflags_cc+': [ '-frtti' ]
|
|
84
83
|
}]
|
|
85
|
-
, ['OS != "win"'
|
|
84
|
+
, ['OS != "win"', {
|
|
86
85
|
'cflags': [
|
|
87
86
|
'-Wno-sign-compare'
|
|
88
87
|
, '-Wno-unused-but-set-variable'
|
|
@@ -91,66 +90,50 @@
|
|
|
91
90
|
, ['OS == "linux"', {
|
|
92
91
|
'defines': [
|
|
93
92
|
'OS_LINUX=1',
|
|
94
|
-
'ROCKSDB_LIB_IO_POSIX=1'
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
'
|
|
93
|
+
'ROCKSDB_LIB_IO_POSIX=1',
|
|
94
|
+
'ROCKSDB_FALLOCATE_PRESENT=1',
|
|
95
|
+
'ROCKSDB_MALLOC_USABLE_SIZE=1',
|
|
96
|
+
'ROCKSDB_PTHREAD_ADAPTIVE_MUTEX=1',
|
|
97
|
+
'ROCKSDB_RANGESYNC_PRESENT=1',
|
|
98
|
+
'ROCKSDB_SCHED_GETCPU_PRESENT=1',
|
|
99
|
+
# 'ROCKSDB_IOURING_PRESENT=1',
|
|
100
|
+
# 'HAVE_SSE42=1',
|
|
101
|
+
'HAVE_BMI=1',
|
|
102
|
+
'HAVE_LZCNT=1'
|
|
103
|
+
'HAVE_AVX2=1',
|
|
104
|
+
'HAVE_PCLMUL=1',
|
|
105
|
+
'HAVE_UINT128_EXTENSION=1',
|
|
106
|
+
'HAVE_ALIGNED_NEW=1',
|
|
107
|
+
# 'LIBURING=1'
|
|
108
|
+
# 'NUMA=1'
|
|
109
|
+
'ROCKSDB_PLATFORM_POSIX=1',
|
|
110
|
+
'ROCKSDB_LIB_IO_POSIX=1',
|
|
111
|
+
# "-TBB=1",
|
|
98
112
|
]
|
|
99
113
|
, 'ccflags': [
|
|
100
|
-
'-
|
|
101
|
-
|
|
114
|
+
'-flto'
|
|
115
|
+
, '-pthread'
|
|
116
|
+
, '-msse4.2'
|
|
117
|
+
, '-mpclmul'
|
|
118
|
+
, '-mavx2'
|
|
119
|
+
, '-mbmi'
|
|
120
|
+
, '-mlzcnt'
|
|
121
|
+
, '-fexceptions'
|
|
122
|
+
, '-faligned-new'
|
|
123
|
+
, '-latomic'
|
|
102
124
|
]
|
|
103
125
|
, 'cflags!': [ '-fno-exceptions' ]
|
|
104
126
|
, 'cflags_cc!': [ '-fno-exceptions' ]
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
'OS_FREEBSD=1'
|
|
109
|
-
, '_REENTRANT=1'
|
|
110
|
-
]
|
|
111
|
-
, 'libraries': [
|
|
112
|
-
'-lpthread'
|
|
113
|
-
]
|
|
114
|
-
, 'ccflags': [
|
|
115
|
-
'-pthread'
|
|
116
|
-
]
|
|
117
|
-
, 'cflags': [
|
|
118
|
-
'-Wno-sign-compare'
|
|
119
|
-
]
|
|
120
|
-
}]
|
|
121
|
-
, ['OS == "openbsd"', {
|
|
122
|
-
'defines': [
|
|
123
|
-
'OS_OPENBSD=1'
|
|
124
|
-
, '_REENTRANT=1'
|
|
125
|
-
]
|
|
126
|
-
, 'libraries': [
|
|
127
|
-
'-lpthread'
|
|
128
|
-
]
|
|
129
|
-
, 'ccflags': [
|
|
130
|
-
'-pthread'
|
|
131
|
-
]
|
|
132
|
-
, 'cflags': [
|
|
133
|
-
'-Wno-sign-compare'
|
|
134
|
-
]
|
|
135
|
-
}]
|
|
136
|
-
, ['OS == "solaris"', {
|
|
137
|
-
'defines': [
|
|
138
|
-
'OS_SOLARIS=1'
|
|
139
|
-
, '_REENTRANT=1'
|
|
140
|
-
]
|
|
141
|
-
, 'libraries': [
|
|
142
|
-
'-lrt'
|
|
143
|
-
, '-lpthread'
|
|
144
|
-
]
|
|
145
|
-
, 'ccflags': [
|
|
146
|
-
'-pthread'
|
|
127
|
+
, 'ldflags': [
|
|
128
|
+
'-flto'
|
|
129
|
+
, '-fuse-linker-plugin'
|
|
147
130
|
]
|
|
148
131
|
}]
|
|
149
132
|
, ['OS == "mac"', {
|
|
150
133
|
'defines': [
|
|
151
134
|
'OS_MACOSX=1',
|
|
152
|
-
'
|
|
153
|
-
'
|
|
135
|
+
'DROCKSDB_PLATFORM_POSIX=1',
|
|
136
|
+
'ROCKSDB_LIB_IO_POSIX=1'
|
|
154
137
|
]
|
|
155
138
|
, 'libraries': []
|
|
156
139
|
, 'ccflags': []
|
|
@@ -161,18 +144,17 @@
|
|
|
161
144
|
, '-Wno-unused-function'
|
|
162
145
|
]
|
|
163
146
|
, 'OTHER_CPLUSPLUSFLAGS': [
|
|
164
|
-
'-mmacosx-version-min=10.
|
|
165
|
-
, '-std=c++
|
|
147
|
+
'-mmacosx-version-min=10.14'
|
|
148
|
+
, '-std=c++17'
|
|
166
149
|
, '-stdlib=libc++'
|
|
167
150
|
, '-fno-omit-frame-pointer'
|
|
168
151
|
, '-momit-leaf-frame-pointer'
|
|
169
152
|
, '-arch x86_64'
|
|
170
153
|
, '-arch arm64'
|
|
171
154
|
]
|
|
172
|
-
# , 'OTHER_LDFLAGS': ['-stdlib=libc++']
|
|
173
155
|
, 'GCC_ENABLE_CPP_RTTI': 'YES'
|
|
174
156
|
, 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
|
|
175
|
-
, 'MACOSX_DEPLOYMENT_TARGET': '10.
|
|
157
|
+
, 'MACOSX_DEPLOYMENT_TARGET': '10.14'
|
|
176
158
|
}
|
|
177
159
|
}]
|
|
178
160
|
]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Snappy, a fast compressor/decompressor.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Introduction
|
|
5
|
+
============
|
|
6
|
+
|
|
7
|
+
Snappy is a compression/decompression library. It does not aim for maximum
|
|
8
|
+
compression, or compatibility with any other compression library; instead,
|
|
9
|
+
it aims for very high speeds and reasonable compression. For instance,
|
|
10
|
+
compared to the fastest mode of zlib, Snappy is an order of magnitude faster
|
|
11
|
+
for most inputs, but the resulting compressed files are anywhere from 20% to
|
|
12
|
+
100% bigger. (For more information, see "Performance", below.)
|
|
13
|
+
|
|
14
|
+
Snappy has the following properties:
|
|
15
|
+
|
|
16
|
+
* Fast: Compression speeds at 250 MB/sec and beyond, with no assembler code.
|
|
17
|
+
See "Performance" below.
|
|
18
|
+
* Stable: Over the last few years, Snappy has compressed and decompressed
|
|
19
|
+
petabytes of data in Google's production environment. The Snappy bitstream
|
|
20
|
+
format is stable and will not change between versions.
|
|
21
|
+
* Robust: The Snappy decompressor is designed not to crash in the face of
|
|
22
|
+
corrupted or malicious input.
|
|
23
|
+
* Free and open source software: Snappy is licensed under a BSD-type license.
|
|
24
|
+
For more information, see the included COPYING file.
|
|
25
|
+
|
|
26
|
+
Snappy has previously been called "Zippy" in some Google presentations
|
|
27
|
+
and the like.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
Performance
|
|
31
|
+
===========
|
|
32
|
+
|
|
33
|
+
Snappy is intended to be fast. On a single core of a Core i7 processor
|
|
34
|
+
in 64-bit mode, it compresses at about 250 MB/sec or more and decompresses at
|
|
35
|
+
about 500 MB/sec or more. (These numbers are for the slowest inputs in our
|
|
36
|
+
benchmark suite; others are much faster.) In our tests, Snappy usually
|
|
37
|
+
is faster than algorithms in the same class (e.g. LZO, LZF, QuickLZ,
|
|
38
|
+
etc.) while achieving comparable compression ratios.
|
|
39
|
+
|
|
40
|
+
Typical compression ratios (based on the benchmark suite) are about 1.5-1.7x
|
|
41
|
+
for plain text, about 2-4x for HTML, and of course 1.0x for JPEGs, PNGs and
|
|
42
|
+
other already-compressed data. Similar numbers for zlib in its fastest mode
|
|
43
|
+
are 2.6-2.8x, 3-7x and 1.0x, respectively. More sophisticated algorithms are
|
|
44
|
+
capable of achieving yet higher compression rates, although usually at the
|
|
45
|
+
expense of speed. Of course, compression ratio will vary significantly with
|
|
46
|
+
the input.
|
|
47
|
+
|
|
48
|
+
Although Snappy should be fairly portable, it is primarily optimized
|
|
49
|
+
for 64-bit x86-compatible processors, and may run slower in other environments.
|
|
50
|
+
In particular:
|
|
51
|
+
|
|
52
|
+
- Snappy uses 64-bit operations in several places to process more data at
|
|
53
|
+
once than would otherwise be possible.
|
|
54
|
+
- Snappy assumes unaligned 32- and 64-bit loads and stores are cheap.
|
|
55
|
+
On some platforms, these must be emulated with single-byte loads
|
|
56
|
+
and stores, which is much slower.
|
|
57
|
+
- Snappy assumes little-endian throughout, and needs to byte-swap data in
|
|
58
|
+
several places if running on a big-endian platform.
|
|
59
|
+
|
|
60
|
+
Experience has shown that even heavily tuned code can be improved.
|
|
61
|
+
Performance optimizations, whether for 64-bit x86 or other platforms,
|
|
62
|
+
are of course most welcome; see "Contact", below.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Building
|
|
66
|
+
========
|
|
67
|
+
|
|
68
|
+
CMake is supported and autotools will soon be deprecated.
|
|
69
|
+
You need CMake 3.4 or above to build:
|
|
70
|
+
|
|
71
|
+
mkdir build
|
|
72
|
+
cd build && cmake ../ && make
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Usage
|
|
76
|
+
=====
|
|
77
|
+
|
|
78
|
+
Note that Snappy, both the implementation and the main interface,
|
|
79
|
+
is written in C++. However, several third-party bindings to other languages
|
|
80
|
+
are available; see the home page at http://google.github.io/snappy/
|
|
81
|
+
for more information. Also, if you want to use Snappy from C code, you can
|
|
82
|
+
use the included C bindings in snappy-c.h.
|
|
83
|
+
|
|
84
|
+
To use Snappy from your own C++ program, include the file "snappy.h" from
|
|
85
|
+
your calling file, and link against the compiled library.
|
|
86
|
+
|
|
87
|
+
There are many ways to call Snappy, but the simplest possible is
|
|
88
|
+
|
|
89
|
+
snappy::Compress(input.data(), input.size(), &output);
|
|
90
|
+
|
|
91
|
+
and similarly
|
|
92
|
+
|
|
93
|
+
snappy::Uncompress(input.data(), input.size(), &output);
|
|
94
|
+
|
|
95
|
+
where "input" and "output" are both instances of std::string.
|
|
96
|
+
|
|
97
|
+
There are other interfaces that are more flexible in various ways, including
|
|
98
|
+
support for custom (non-array) input sources. See the header file for more
|
|
99
|
+
information.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Tests and benchmarks
|
|
103
|
+
====================
|
|
104
|
+
|
|
105
|
+
When you compile Snappy, snappy_unittest is compiled in addition to the
|
|
106
|
+
library itself. You do not need it to use the compressor from your own library,
|
|
107
|
+
but it contains several useful components for Snappy development.
|
|
108
|
+
|
|
109
|
+
First of all, it contains unit tests, verifying correctness on your machine in
|
|
110
|
+
various scenarios. If you want to change or optimize Snappy, please run the
|
|
111
|
+
tests to verify you have not broken anything. Note that if you have the
|
|
112
|
+
Google Test library installed, unit test behavior (especially failures) will be
|
|
113
|
+
significantly more user-friendly. You can find Google Test at
|
|
114
|
+
|
|
115
|
+
http://github.com/google/googletest
|
|
116
|
+
|
|
117
|
+
You probably also want the gflags library for handling of command-line flags;
|
|
118
|
+
you can find it at
|
|
119
|
+
|
|
120
|
+
http://gflags.github.io/gflags/
|
|
121
|
+
|
|
122
|
+
In addition to the unit tests, snappy contains microbenchmarks used to
|
|
123
|
+
tune compression and decompression performance. These are automatically run
|
|
124
|
+
before the unit tests, but you can disable them using the flag
|
|
125
|
+
--run_microbenchmarks=false if you have gflags installed (otherwise you will
|
|
126
|
+
need to edit the source).
|
|
127
|
+
|
|
128
|
+
Finally, snappy can benchmark Snappy against a few other compression libraries
|
|
129
|
+
(zlib, LZO, LZF, and QuickLZ), if they were detected at configure time.
|
|
130
|
+
To benchmark using a given file, give the compression algorithm you want to test
|
|
131
|
+
Snappy against (e.g. --zlib) and then a list of one or more file names on the
|
|
132
|
+
command line. The testdata/ directory contains the files used by the
|
|
133
|
+
microbenchmark, which should provide a reasonably balanced starting point for
|
|
134
|
+
benchmarking. (Note that baddata[1-3].snappy are not intended as benchmarks; they
|
|
135
|
+
are used to verify correctness in the presence of corrupted data in the unit
|
|
136
|
+
test.)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
Contact
|
|
140
|
+
=======
|
|
141
|
+
|
|
142
|
+
Snappy is distributed through GitHub. For the latest version, a bug tracker,
|
|
143
|
+
and other information, see
|
|
144
|
+
|
|
145
|
+
http://google.github.io/snappy/
|
|
146
|
+
|
|
147
|
+
or the repository at
|
|
148
|
+
|
|
149
|
+
https://github.com/google/snappy
|
package/index.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { AbstractLevel } = require('abstract-level')
|
|
4
|
+
const ModuleError = require('module-error')
|
|
5
|
+
const { fromCallback } = require('catering')
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
const binding = require('./binding')
|
|
8
|
+
const { ChainedBatch } = require('./chained-batch')
|
|
9
|
+
const { Iterator } = require('./iterator')
|
|
10
|
+
|
|
11
|
+
const kPromise = Symbol('promise')
|
|
12
|
+
const kContext = Symbol('context')
|
|
13
|
+
const kLocation = Symbol('location')
|
|
14
|
+
|
|
15
|
+
class RocksLevel extends AbstractLevel {
|
|
16
|
+
constructor (location, options, _) {
|
|
17
|
+
// To help migrating to abstract-level
|
|
18
|
+
if (typeof options === 'function' || typeof _ === 'function') {
|
|
19
|
+
throw new ModuleError('The levelup-style callback argument has been removed', {
|
|
20
|
+
code: 'LEVEL_LEGACY'
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof location !== 'string' || location === '') {
|
|
25
|
+
throw new TypeError("The first argument 'location' must be a non-empty string")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
super({
|
|
29
|
+
encodings: {
|
|
30
|
+
buffer: true,
|
|
31
|
+
utf8: true
|
|
32
|
+
},
|
|
33
|
+
seek: true,
|
|
34
|
+
createIfMissing: true,
|
|
35
|
+
errorIfExists: true,
|
|
36
|
+
additionalMethods: {
|
|
37
|
+
approximateSize: true,
|
|
38
|
+
compactRange: true
|
|
39
|
+
}
|
|
40
|
+
}, options)
|
|
41
|
+
|
|
42
|
+
this[kLocation] = location
|
|
43
|
+
this[kContext] = binding.db_init()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get location () {
|
|
47
|
+
return this[kLocation]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_open (options, callback) {
|
|
51
|
+
if (options.createIfMissing) {
|
|
52
|
+
fs.mkdir(this[kLocation], { recursive: true }, (err) => {
|
|
53
|
+
if (err) return callback(err)
|
|
54
|
+
binding.db_open(this[kContext], this[kLocation], options, callback)
|
|
55
|
+
})
|
|
56
|
+
} else {
|
|
57
|
+
binding.db_open(this[kContext], this[kLocation], options, callback)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_close (callback) {
|
|
62
|
+
binding.db_close(this[kContext], callback)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_put (key, value, options, callback) {
|
|
66
|
+
binding.db_put(this[kContext], key, value, options, callback)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_get (key, options, callback) {
|
|
70
|
+
binding.db_get(this[kContext], key, options, callback)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
_getMany (keys, options, callback) {
|
|
74
|
+
binding.db_get_many(this[kContext], keys, options, callback)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_del (key, options, callback) {
|
|
78
|
+
binding.db_del(this[kContext], key, options, callback)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_clear (options, callback) {
|
|
82
|
+
binding.db_clear(this[kContext], options, callback)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_chainedBatch () {
|
|
86
|
+
return new ChainedBatch(this, this[kContext])
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_batch (operations, options, callback) {
|
|
90
|
+
binding.batch_do(this[kContext], operations, options, callback)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
approximateSize (start, end, options, callback) {
|
|
94
|
+
if (arguments.length < 2 || typeof start === 'function' || typeof end === 'function') {
|
|
95
|
+
throw new TypeError("The arguments 'start' and 'end' are required")
|
|
96
|
+
} else if (typeof options === 'function') {
|
|
97
|
+
callback = options
|
|
98
|
+
options = null
|
|
99
|
+
} else if (typeof options !== 'object') {
|
|
100
|
+
options = null
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
callback = fromCallback(callback, kPromise)
|
|
104
|
+
|
|
105
|
+
if (this.status === 'opening') {
|
|
106
|
+
this.defer(() => this.approximateSize(start, end, options, callback))
|
|
107
|
+
} else if (this.status !== 'open') {
|
|
108
|
+
this.nextTick(callback, new ModuleError('Database is not open: cannot call approximateSize()', {
|
|
109
|
+
code: 'LEVEL_DATABASE_NOT_OPEN'
|
|
110
|
+
}))
|
|
111
|
+
} else {
|
|
112
|
+
const keyEncoding = this.keyEncoding(options && options.keyEncoding)
|
|
113
|
+
start = keyEncoding.encode(start)
|
|
114
|
+
end = keyEncoding.encode(end)
|
|
115
|
+
binding.db_approximate_size(this[kContext], start, end, callback)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return callback[kPromise]
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
compactRange (start, end, options, callback) {
|
|
122
|
+
if (arguments.length < 2 || typeof start === 'function' || typeof end === 'function') {
|
|
123
|
+
throw new TypeError("The arguments 'start' and 'end' are required")
|
|
124
|
+
} else if (typeof options === 'function') {
|
|
125
|
+
callback = options
|
|
126
|
+
options = null
|
|
127
|
+
} else if (typeof options !== 'object') {
|
|
128
|
+
options = null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
callback = fromCallback(callback, kPromise)
|
|
132
|
+
|
|
133
|
+
if (this.status === 'opening') {
|
|
134
|
+
this.defer(() => this.compactRange(start, end, options, callback))
|
|
135
|
+
} else if (this.status !== 'open') {
|
|
136
|
+
this.nextTick(callback, new ModuleError('Database is not open: cannot call compactRange()', {
|
|
137
|
+
code: 'LEVEL_DATABASE_NOT_OPEN'
|
|
138
|
+
}))
|
|
139
|
+
} else {
|
|
140
|
+
const keyEncoding = this.keyEncoding(options && options.keyEncoding)
|
|
141
|
+
start = keyEncoding.encode(start)
|
|
142
|
+
end = keyEncoding.encode(end)
|
|
143
|
+
binding.db_compact_range(this[kContext], start, end, callback)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return callback[kPromise]
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getProperty (property) {
|
|
150
|
+
if (typeof property !== 'string') {
|
|
151
|
+
throw new TypeError("The first argument 'property' must be a string")
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Is synchronous, so can't be deferred
|
|
155
|
+
if (this.status !== 'open') {
|
|
156
|
+
throw new ModuleError('Database is not open', {
|
|
157
|
+
code: 'LEVEL_DATABASE_NOT_OPEN'
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return binding.db_get_property(this[kContext], property)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_iterator (options) {
|
|
165
|
+
return new Iterator(this, this[kContext], options)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static destroy (location, callback) {
|
|
169
|
+
if (typeof location !== 'string' || location === '') {
|
|
170
|
+
throw new TypeError("The first argument 'location' must be a non-empty string")
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
callback = fromCallback(callback, kPromise)
|
|
174
|
+
binding.destroy_db(location, callback)
|
|
175
|
+
return callback[kPromise]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static repair (location, callback) {
|
|
179
|
+
if (typeof location !== 'string' || location === '') {
|
|
180
|
+
throw new TypeError("The first argument 'location' must be a non-empty string")
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
callback = fromCallback(callback, kPromise)
|
|
184
|
+
binding.repair_db(location, callback)
|
|
185
|
+
return callback[kPromise]
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
exports.RocksLevel = RocksLevel
|
package/iterator.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { AbstractIterator } = require('abstract-
|
|
3
|
+
const { AbstractIterator } = require('abstract-level')
|
|
4
4
|
const binding = require('./binding')
|
|
5
5
|
|
|
6
6
|
const kContext = Symbol('context')
|
|
7
|
-
const
|
|
7
|
+
const kCache = Symbol('cache')
|
|
8
|
+
const kFinished = Symbol('finished')
|
|
9
|
+
const kFirst = Symbol('first')
|
|
10
|
+
const kPosition = Symbol('position')
|
|
11
|
+
const kHandleNext = Symbol('handleNext')
|
|
12
|
+
const kHandleNextv = Symbol('handleNextv')
|
|
13
|
+
const kCallback = Symbol('callback')
|
|
14
|
+
const empty = []
|
|
8
15
|
|
|
9
16
|
class Iterator extends AbstractIterator {
|
|
10
|
-
constructor (db, options) {
|
|
11
|
-
super(db)
|
|
17
|
+
constructor (db, context, options) {
|
|
18
|
+
super(db, options)
|
|
12
19
|
|
|
13
|
-
this[kContext] = binding.iterator_init(
|
|
14
|
-
this[kFinalized] = false
|
|
20
|
+
this[kContext] = binding.iterator_init(context, options)
|
|
15
21
|
|
|
16
|
-
this
|
|
22
|
+
this[kHandleNext] = this[kHandleNext].bind(this)
|
|
23
|
+
this[kHandleNextv] = this[kHandleNextv].bind(this)
|
|
24
|
+
this[kCallback] = null
|
|
25
|
+
this[kFirst] = true
|
|
26
|
+
this[kCache] = empty
|
|
27
|
+
this[kFinished] = false
|
|
28
|
+
this[kPosition] = 0
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
_seek (target) {
|
|
@@ -21,35 +33,87 @@ class Iterator extends AbstractIterator {
|
|
|
21
33
|
throw new Error('cannot seek() to an empty target')
|
|
22
34
|
}
|
|
23
35
|
|
|
24
|
-
this
|
|
36
|
+
this[kFirst] = true
|
|
37
|
+
this[kCache] = empty
|
|
38
|
+
this[kFinished] = false
|
|
39
|
+
this[kPosition] = 0
|
|
40
|
+
|
|
25
41
|
binding.iterator_seek(this[kContext], target)
|
|
26
|
-
this[kFinalized] = false
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
_next (callback) {
|
|
30
|
-
if (this
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
if (this[kPosition] < this[kCache].length) {
|
|
46
|
+
const key = this[kCache][this[kPosition]++]
|
|
47
|
+
const val = this[kCache][this[kPosition]++]
|
|
48
|
+
process.nextTick(callback, null, key, val)
|
|
49
|
+
} else if (this[kFinished]) {
|
|
33
50
|
process.nextTick(callback)
|
|
34
51
|
} else {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
this[kCallback] = callback
|
|
53
|
+
|
|
54
|
+
if (this[kFirst]) {
|
|
55
|
+
// It's common to only want one entry initially or after a seek()
|
|
56
|
+
this[kFirst] = false
|
|
57
|
+
binding.iterator_nextv(this[kContext], 1, this[kHandleNext])
|
|
58
|
+
} else {
|
|
59
|
+
// Limit the size of the cache to prevent starving the event loop
|
|
60
|
+
// while we're recursively calling process.nextTick().
|
|
61
|
+
binding.iterator_nextv(this[kContext], 1000, this[kHandleNext])
|
|
62
|
+
}
|
|
44
63
|
}
|
|
45
64
|
|
|
46
65
|
return this
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
[kHandleNext] (err, items, finished) {
|
|
69
|
+
const callback = this[kCallback]
|
|
70
|
+
if (err) return callback(err)
|
|
71
|
+
|
|
72
|
+
this[kCache] = items
|
|
73
|
+
this[kFinished] = finished
|
|
74
|
+
this[kPosition] = 0
|
|
75
|
+
|
|
76
|
+
this._next(callback)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_nextv (size, options, callback) {
|
|
80
|
+
if (this[kFinished]) {
|
|
81
|
+
process.nextTick(callback, null, [])
|
|
82
|
+
} else {
|
|
83
|
+
this[kCallback] = callback
|
|
84
|
+
this[kFirst] = false
|
|
85
|
+
binding.iterator_nextv(this[kContext], size, this[kHandleNextv])
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
[kHandleNextv] (err, items, finished) {
|
|
90
|
+
const callback = this[kCallback]
|
|
91
|
+
if (err) return callback(err)
|
|
92
|
+
this[kFinished] = finished
|
|
93
|
+
|
|
94
|
+
const entries = []
|
|
95
|
+
for (let n = 0; n < items.length; n += 2) {
|
|
96
|
+
entries.push([items[n + 0], items[n + 1]])
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
callback(null, entries)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
_close (callback) {
|
|
103
|
+
this[kCache] = empty
|
|
104
|
+
this[kCallback] = null
|
|
105
|
+
|
|
51
106
|
binding.iterator_close(this[kContext], callback)
|
|
52
107
|
}
|
|
108
|
+
|
|
109
|
+
_end (callback) {
|
|
110
|
+
this._close(callback)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Undocumented, exposed for tests only
|
|
114
|
+
get cached () {
|
|
115
|
+
return (this[kCache].length - this[kPosition]) / 2
|
|
116
|
+
}
|
|
53
117
|
}
|
|
54
118
|
|
|
55
|
-
|
|
119
|
+
exports.Iterator = Iterator
|