rocksdb-ruby 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/ext/rocksdb/rocksdb_db_rb.cc +63 -0
- data/ext/rocksdb/rocksdb_db_rb.h +4 -0
- data/ext/rocksdb/rocksdb_rb.cc +2 -0
- data/lib/rocksdb/ruby/version.rb +1 -1
- data/spec/db_options_spec.rb +18 -0
- data/spec/db_spec.rb +11 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d3d57184046e4127d2d843d04e549d85547311
|
4
|
+
data.tar.gz: d062ed4026b6469c6f14a6788894d442e648bf93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f650e958abed13456d2967404041de91a08da1ee303def9f16cc9abfbc8a5e4a6143daac8cdc922e7a0d1970e91c7fab5cbe4843c27b51fc63a9c231a9a4485
|
7
|
+
data.tar.gz: 12e3da582a353960c906e1b4cc76a5f1d0a84fb7ada488d0d6ed5bd6f91754e26d27625e0e45c1b5d48c67e9a3cecc2657b9e048cd0379ded83e3f5607b13980
|
@@ -28,7 +28,12 @@ extern "C" {
|
|
28
28
|
if(v == Qtrue){
|
29
29
|
readonly = true;
|
30
30
|
}
|
31
|
+
set_opt(&options, &v_options);
|
31
32
|
}
|
33
|
+
//std::cout << options.max_bytes_for_level_base << "\n";
|
34
|
+
//std::cout << options.max_grandparent_overlap_factor << "\n";
|
35
|
+
//std::cout << options.delete_obsolete_files_period_micros << "\n";
|
36
|
+
|
32
37
|
options.create_if_missing = true;
|
33
38
|
if(readonly){
|
34
39
|
status = rocksdb::DB::OpenForReadOnly(options, db_file_name, &db);
|
@@ -41,6 +46,26 @@ extern "C" {
|
|
41
46
|
return status.ok() ? Qtrue : Qfalse;
|
42
47
|
}
|
43
48
|
|
49
|
+
void set_opt_unit_val(uint64_t* opt, char* name, VALUE *v_options){
|
50
|
+
|
51
|
+
VALUE v2 = rb_hash_aref(*v_options, ID2SYM(rb_intern(name)));
|
52
|
+
if(RB_TYPE_P(v2, T_FIXNUM)){
|
53
|
+
*opt = NUM2INT(v2);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
void set_opt_int_val(int* opt, char* name, VALUE *v_options){
|
57
|
+
VALUE v2 = rb_hash_aref(*v_options, ID2SYM(rb_intern(name)));
|
58
|
+
if(RB_TYPE_P(v2, T_FIXNUM)){
|
59
|
+
*opt = NUM2INT(v2);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
void set_opt(rocksdb::Options* options, VALUE *v_options){
|
64
|
+
set_opt_unit_val(&options->max_bytes_for_level_base, (char *) "max_bytes_for_level_base", v_options);
|
65
|
+
set_opt_int_val(&options->max_grandparent_overlap_factor, (char *) "max_grandparent_overlap_factor", v_options);
|
66
|
+
set_opt_unit_val(&options->delete_obsolete_files_period_micros, (char *) "delete_obsolete_files_period_micros", v_options);
|
67
|
+
}
|
68
|
+
|
44
69
|
VALUE db_alloc(VALUE klass){
|
45
70
|
rocksdb_pointer* db_pointer = ALLOC(rocksdb_pointer);
|
46
71
|
return Data_Wrap_Struct(klass, 0, db_free, db_pointer);
|
@@ -189,6 +214,44 @@ extern "C" {
|
|
189
214
|
return self;
|
190
215
|
}
|
191
216
|
|
217
|
+
VALUE rocksdb_db_each_index(VALUE self){
|
218
|
+
if(!rb_block_given_p()){
|
219
|
+
return rocksdb_db_new_iterator(self);
|
220
|
+
}
|
221
|
+
|
222
|
+
rocksdb_pointer* db_pointer;
|
223
|
+
Data_Get_Struct(self, rocksdb_pointer, db_pointer);
|
224
|
+
rocksdb::Iterator* it = db_pointer->db->NewIterator(rocksdb::ReadOptions());
|
225
|
+
|
226
|
+
for (it->SeekToFirst(); it->Valid(); it->Next()) {
|
227
|
+
rb_yield(rb_enc_str_new(it->key().data(), it->key().size(), rb_utf8_encoding()));
|
228
|
+
}
|
229
|
+
|
230
|
+
delete it;
|
231
|
+
return self;
|
232
|
+
}
|
233
|
+
|
234
|
+
VALUE rocksdb_db_each_with_index(VALUE self){
|
235
|
+
if(!rb_block_given_p()){
|
236
|
+
return rocksdb_db_new_iterator(self);
|
237
|
+
}
|
238
|
+
|
239
|
+
rocksdb_pointer* db_pointer;
|
240
|
+
Data_Get_Struct(self, rocksdb_pointer, db_pointer);
|
241
|
+
rocksdb::Iterator* it = db_pointer->db->NewIterator(rocksdb::ReadOptions());
|
242
|
+
|
243
|
+
for (it->SeekToFirst(); it->Valid(); it->Next()) {
|
244
|
+
VALUE a = rb_enc_str_new(it->key().data(), it->key().size(), rb_utf8_encoding());
|
245
|
+
VALUE b = rb_enc_str_new(it->value().data(), it->value().size(), rb_utf8_encoding());
|
246
|
+
rb_yield_values(2, a, b);
|
247
|
+
}
|
248
|
+
|
249
|
+
delete it;
|
250
|
+
return self;
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
192
255
|
VALUE rocksdb_db_reverse_each(VALUE self){
|
193
256
|
rocksdb_pointer* db_pointer;
|
194
257
|
Data_Get_Struct(self, rocksdb_pointer, db_pointer);
|
data/ext/rocksdb/rocksdb_db_rb.h
CHANGED
@@ -16,6 +16,10 @@ extern "C" {
|
|
16
16
|
VALUE rocksdb_db_new_iterator(VALUE self);
|
17
17
|
VALUE rocksdb_db_each(VALUE self);
|
18
18
|
VALUE rocksdb_db_each_index(VALUE self);
|
19
|
+
VALUE rocksdb_db_each_with_index(VALUE self);
|
19
20
|
VALUE rocksdb_db_reverse_each(VALUE self);
|
20
21
|
void db_free(rocksdb_pointer* db_pointer);
|
22
|
+
void set_opt(rocksdb::Options* opt, VALUE *v_options);
|
23
|
+
void set_opt_unit_val(uint64_t* opt, char* name, VALUE *v_options);
|
24
|
+
void set_opt_int_val(int* opt, char* name, VALUE *v_options);
|
21
25
|
}
|
data/ext/rocksdb/rocksdb_rb.cc
CHANGED
@@ -32,6 +32,8 @@ extern "C" {
|
|
32
32
|
rb_define_method(cRocksdb_db, "new_iterator", (METHOD)rocksdb_db_new_iterator, 0);
|
33
33
|
|
34
34
|
rb_define_method(cRocksdb_db, "each", (METHOD)rocksdb_db_each, 0);
|
35
|
+
rb_define_method(cRocksdb_db, "each_index", (METHOD)rocksdb_db_each_index, 0);
|
36
|
+
rb_define_method(cRocksdb_db, "each_with_index", (METHOD)rocksdb_db_each_with_index, 0);
|
35
37
|
rb_define_method(cRocksdb_db, "reverse_each", (METHOD)rocksdb_db_reverse_each, 0);
|
36
38
|
|
37
39
|
cRocksdb_write_batch = rb_define_class_under(cRocksdb, "Batch", rb_cObject);
|
data/lib/rocksdb/ruby/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require "rocksdb"
|
4
|
+
|
5
|
+
describe RocksDB do
|
6
|
+
before do
|
7
|
+
@rocksdb = RocksDB::DB.new "/tmp/file3", {:max_bytes_for_level_base => 10485760, :max_grandparent_overlap_factor => 20}
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should get data' do
|
11
|
+
@rocksdb.put("test:multi_db", "10")
|
12
|
+
expect(@rocksdb.get("test:multi_db")).to eq "10"
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
@rocksdb.close
|
17
|
+
end
|
18
|
+
end
|
data/spec/db_spec.rb
CHANGED
@@ -81,8 +81,19 @@ describe RocksDB do
|
|
81
81
|
expect(value).not_to be_empty
|
82
82
|
rev_array << value
|
83
83
|
end
|
84
|
+
|
84
85
|
|
85
86
|
expect(array).to eq rev_array.reverse
|
87
|
+
|
88
|
+
@rocksdb.each_index do |key|
|
89
|
+
expect(key).not_to be_empty
|
90
|
+
end
|
91
|
+
|
92
|
+
@rocksdb.each_with_index do |key, value|
|
93
|
+
expect(key).not_to be_empty
|
94
|
+
expect(value).not_to be_empty
|
95
|
+
end
|
96
|
+
|
86
97
|
iter.close
|
87
98
|
end
|
88
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocksdb-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isamu Arimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/rocksdb/ruby.rb
|
81
81
|
- lib/rocksdb/ruby/version.rb
|
82
82
|
- rocksdb-ruby.gemspec
|
83
|
+
- spec/db_options_spec.rb
|
83
84
|
- spec/db_readonly_spec.rb
|
84
85
|
- spec/db_spec.rb
|
85
86
|
- spec/iterator_spec.rb
|
@@ -105,11 +106,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
version: '0'
|
106
107
|
requirements: []
|
107
108
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.6
|
109
110
|
signing_key:
|
110
111
|
specification_version: 4
|
111
112
|
summary: A simple RocksDB library for Ruby
|
112
113
|
test_files:
|
114
|
+
- spec/db_options_spec.rb
|
113
115
|
- spec/db_readonly_spec.rb
|
114
116
|
- spec/db_spec.rb
|
115
117
|
- spec/iterator_spec.rb
|