rocksdb-ffi 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 418f08a08ef63ebd020e564c356caffe4b1a0d5b7369671f593c688f3fe1a71a
4
- data.tar.gz: 3eeafe7ffc7fc2ca09e97a21584e3d6a90dabf788373fc9205b99bd1cf724bd8
3
+ metadata.gz: 66601f422c933c7afb867e8f7ec679826bd95f3105a1958a722e7d58f40b9972
4
+ data.tar.gz: 2d1c8540cdfdcc9130199655c94d701b968e1bec8611d4445ec78201b447469c
5
5
  SHA512:
6
- metadata.gz: 5473bb61e2338c41efedb1af337640d6ca070395c87f933bab5ce3117807594301eebf55cfbbb6a9eb8f12828de267e1ef300ead98797ba10f1a733210334f34
7
- data.tar.gz: 0171a8b32370ff31edff39398e27d1af0a81d98e267cf40494268f08faefd54f010c217c9db7513864e33ffb2fc716aff2eac56b147a3225271aa560b51f38f4
6
+ metadata.gz: 4f65eee7416e962a23998d80da458b0aa787617eb20aa67d548ceccb02f10aa01dc3b825278bcbfa961339f7a41dbf3e2628a42ecd711fad25979730a3a8595d
7
+ data.tar.gz: 24b92957d2b0068f1ca2d690734e700e5c3168655ed17a938075f713b61b15f1606705b6df0a9560f31dbb9f3512bb0dfa13f0e1e933bf2770433bf75826b3d2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.2.1
4
+
5
+ * Fix memory leak due to missing `rocksdb_free` in `#get`
6
+
7
+ ## v0.2.0
8
+
9
+ * Add `#each_prefix`
10
+
3
11
  ## v0.1.0
4
12
 
5
13
  * Initial release
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rocksdb-ffi (0.2.1)
5
+ ffi
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ diff-lcs (1.5.0)
12
+ ffi (1.16.3)
13
+ json (2.6.3)
14
+ parallel (1.22.1)
15
+ parser (3.2.1.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.1.1)
18
+ rake (13.0.6)
19
+ regexp_parser (2.7.0)
20
+ rexml (3.2.5)
21
+ rspec (3.12.0)
22
+ rspec-core (~> 3.12.0)
23
+ rspec-expectations (~> 3.12.0)
24
+ rspec-mocks (~> 3.12.0)
25
+ rspec-core (3.12.1)
26
+ rspec-support (~> 3.12.0)
27
+ rspec-expectations (3.12.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-mocks (3.12.3)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-support (3.12.0)
34
+ rubocop (1.46.0)
35
+ json (~> 2.3)
36
+ parallel (~> 1.10)
37
+ parser (>= 3.2.0.0)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ regexp_parser (>= 1.8, < 3.0)
40
+ rexml (>= 3.2.5, < 4.0)
41
+ rubocop-ast (>= 1.26.0, < 2.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 2.4.0, < 3.0)
44
+ rubocop-ast (1.27.0)
45
+ parser (>= 3.2.1.0)
46
+ ruby-progressbar (1.11.0)
47
+ unicode-display_width (2.4.2)
48
+
49
+ PLATFORMS
50
+ x86_64-linux
51
+
52
+ DEPENDENCIES
53
+ rake (~> 13.0)
54
+ rocksdb-ffi!
55
+ rspec (~> 3.0)
56
+ rubocop
57
+
58
+ BUNDLED WITH
59
+ 2.3.26
data/README.md CHANGED
@@ -36,12 +36,26 @@ rocksdb.each_key do |key|
36
36
  # ...
37
37
  end
38
38
 
39
+ rocksdb.each_prefix("prefix") do |key, value|
40
+ # ...
41
+ end
42
+
43
+ rocksdb.flush
44
+
39
45
  rocksdb.close
40
46
 
41
47
  rocksdb.open("/path/to/other/db")
42
48
  ```
43
49
 
44
- The library is tested against ruby 3.0/3.1/3.2 and rocksdb 7.2. That's it for now!
50
+ The library is tested against:
51
+
52
+ * ruby 2.7 with rocksdb 7.2
53
+ * ruby 3.0 with rocksdb 7.2
54
+ * ruby 3.1 with rocksdb 7.2
55
+ * ruby 3.1 with rocksdb 7.7
56
+ * ruby 3.2 with rocksdb 7.2
57
+ * ruby 3.2 with rocksdb 7.7
58
+ * ruby 3.2 with rocksdb 7.9
45
59
 
46
60
  ## Thread-safety
47
61
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RocksDB
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/rocksdb.rb CHANGED
@@ -24,6 +24,7 @@ class RocksDB
24
24
  attach_function :rocksdb_create_iterator, [:pointer, :pointer], :pointer
25
25
  attach_function :rocksdb_iter_valid, [:pointer], :uchar
26
26
  attach_function :rocksdb_iter_seek_to_first, [:pointer], :void
27
+ attach_function :rocksdb_iter_seek, [:pointer, :string, :size_t], :void
27
28
  attach_function :rocksdb_iter_next, [:pointer], :void
28
29
  attach_function :rocksdb_iter_key, [:pointer, :pointer], :pointer
29
30
  attach_function :rocksdb_iter_value, [:pointer, :pointer], :pointer
@@ -113,7 +114,11 @@ class RocksDB
113
114
 
114
115
  return if res.null?
115
116
 
116
- read_string(res, length)
117
+ value = read_string(res, length)
118
+
119
+ Lib.rocksdb_free(res)
120
+
121
+ value
117
122
  end
118
123
 
119
124
  def delete(key)
@@ -164,6 +169,19 @@ class RocksDB
164
169
  end
165
170
  end
166
171
 
172
+ def each_prefix(prefix)
173
+ raise(ClosedError, "Database is closed") if @closed
174
+
175
+ return enum_for(__method__, prefix) unless block_given?
176
+
177
+ iterate_prefix(prefix) do |key, iterator|
178
+ value_length = FFI::MemoryPointer.new(:size_t, 1)
179
+ value = read_string(Lib.rocksdb_iter_value(iterator, value_length), value_length)
180
+
181
+ yield(key, value)
182
+ end
183
+ end
184
+
167
185
  private
168
186
 
169
187
  def iterate
@@ -182,6 +200,27 @@ class RocksDB
182
200
  end
183
201
  end
184
202
 
203
+ def iterate_prefix(prefix)
204
+ iterator = Lib.rocksdb_create_iterator(@db, @read_options)
205
+
206
+ begin
207
+ Lib.rocksdb_iter_seek(iterator, prefix, prefix.bytesize)
208
+
209
+ while Lib.rocksdb_iter_valid(iterator) != 0
210
+ key_length = FFI::MemoryPointer.new(:size_t, 1)
211
+ key = read_string(Lib.rocksdb_iter_key(iterator, key_length), key_length)
212
+
213
+ return unless key.start_with?(prefix)
214
+
215
+ yield(key, iterator)
216
+
217
+ Lib.rocksdb_iter_next(iterator)
218
+ end
219
+ ensure
220
+ Lib.rocksdb_iter_destroy(iterator)
221
+ end
222
+ end
223
+
185
224
  def check_error(error)
186
225
  pointer = error.read_pointer
187
226
  return if pointer.null?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocksdb-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -36,6 +36,7 @@ files:
36
36
  - CHANGELOG.md
37
37
  - CODE_OF_CONDUCT.md
38
38
  - Gemfile
39
+ - Gemfile.lock
39
40
  - LICENSE.txt
40
41
  - README.md
41
42
  - Rakefile