tdb 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/GIT-VERSION-GEN +1 -1
- data/GNUmakefile +4 -2
- data/ext/tdb/extconf.rb +2 -0
- data/ext/tdb/hash_functions.c +40 -0
- data/ext/tdb/tdb.c +17 -2
- data/lib/tdb/mt.rb +1 -7
- data/test/test_tdb_hash_functions.rb +15 -0
- data/test/test_tdb_mt.rb +14 -9
- metadata +7 -4
data/GIT-VERSION-GEN
CHANGED
data/GNUmakefile
CHANGED
@@ -4,6 +4,7 @@ RUBY = ruby
|
|
4
4
|
RAKE = rake
|
5
5
|
RSYNC = rsync
|
6
6
|
GIT_URL = git://git.bogomips.org/ruby-tdb.git
|
7
|
+
CGIT_URL = http://git.bogomips.org/cgit/ruby-tdb.git
|
7
8
|
|
8
9
|
GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
|
9
10
|
@./GIT-VERSION-GEN
|
@@ -65,13 +66,14 @@ ChangeLog: GIT-VERSION-FILE
|
|
65
66
|
mv $@+ $@
|
66
67
|
|
67
68
|
news_atom := http://bogomips.org/ruby-tdb/NEWS.atom.xml
|
68
|
-
cgit_atom :=
|
69
|
+
cgit_atom := $(CGIT_URL)/atom/?h=master
|
69
70
|
atom = <link rel="alternate" title="Atom feed" href="$(1)" \
|
70
71
|
type="application/atom+xml"/>
|
71
72
|
|
72
73
|
# using rdoc 2.5.x
|
73
74
|
doc: .document NEWS ChangeLog
|
74
|
-
rdoc
|
75
|
+
rdoc --webcvs=$(CGIT_URL)/tree/%s \
|
76
|
+
-t "$(shell sed -ne '1s/^= //p' README)"
|
75
77
|
install -m644 COPYING doc/COPYING
|
76
78
|
install -m644 $(shell grep '^[A-Z]' .document) doc/
|
77
79
|
$(RUBY) -i -p -e \
|
data/ext/tdb/extconf.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
#include "rbtdb.h"
|
2
|
+
|
3
|
+
#define HASH_FN(fn) \
|
4
|
+
static VALUE fn(VALUE self,VALUE str) \
|
5
|
+
{ \
|
6
|
+
TDB_DATA data; \
|
7
|
+
StringValue(str); \
|
8
|
+
data.dptr = (unsigned char *)RSTRING_PTR(str); \
|
9
|
+
data.dsize = RSTRING_LEN(str); \
|
10
|
+
return UINT2NUM(rbtdb_##fn(&data)); \
|
11
|
+
}
|
12
|
+
|
13
|
+
HASH_FN(murmur1)
|
14
|
+
HASH_FN(murmur1_aligned)
|
15
|
+
HASH_FN(murmur2)
|
16
|
+
HASH_FN(murmur2a)
|
17
|
+
HASH_FN(murmur2_neutral)
|
18
|
+
HASH_FN(murmur2_aligned)
|
19
|
+
HASH_FN(fnv1a)
|
20
|
+
HASH_FN(djb2)
|
21
|
+
HASH_FN(djb3)
|
22
|
+
HASH_FN(jenkins_lookup3)
|
23
|
+
|
24
|
+
#define HASH_M(fn) rb_define_method(mHashFunctions, "tdb_hash_"#fn, fn, 1)
|
25
|
+
void rbtdb_init_tdb_hash_functions(void)
|
26
|
+
{
|
27
|
+
VALUE cTDB = rb_const_get(rb_cObject, rb_intern("TDB"));
|
28
|
+
VALUE mHashFunctions = rb_define_module_under(cTDB, "HashFunctions");
|
29
|
+
|
30
|
+
HASH_M(murmur1);
|
31
|
+
HASH_M(murmur1_aligned);
|
32
|
+
HASH_M(murmur2);
|
33
|
+
HASH_M(murmur2a);
|
34
|
+
HASH_M(murmur2_neutral);
|
35
|
+
HASH_M(murmur2_aligned);
|
36
|
+
HASH_M(fnv1a);
|
37
|
+
HASH_M(djb2);
|
38
|
+
HASH_M(djb3);
|
39
|
+
HASH_M(jenkins_lookup3);
|
40
|
+
}
|
data/ext/tdb/tdb.c
CHANGED
@@ -8,7 +8,10 @@
|
|
8
8
|
#else
|
9
9
|
# include <st.h>
|
10
10
|
#endif
|
11
|
+
#include <pthread.h>
|
11
12
|
|
13
|
+
/* this protects the global list of tdb objects maintained by libtdb */
|
14
|
+
static pthread_mutex_t big_lock = PTHREAD_MUTEX_INITIALIZER;
|
12
15
|
static VALUE cTDB, cERR;
|
13
16
|
static st_table *exc_hash;
|
14
17
|
static VALUE hashes;
|
@@ -116,8 +119,12 @@ static void gcfree(void *ptr)
|
|
116
119
|
{
|
117
120
|
struct tdb_context *tdb = ptr;
|
118
121
|
|
119
|
-
|
122
|
+
/* no error checking in GC :< */
|
123
|
+
if (tdb) {
|
124
|
+
(void)pthread_mutex_lock(&big_lock);
|
120
125
|
(void)tdb_close(tdb);
|
126
|
+
(void)pthread_mutex_unlock(&big_lock);
|
127
|
+
}
|
121
128
|
}
|
122
129
|
|
123
130
|
static VALUE alloc(VALUE klass)
|
@@ -152,8 +159,10 @@ static VALUE nogvl_open(void *ptr)
|
|
152
159
|
struct open_args *o = ptr;
|
153
160
|
struct tdb_context *tdb;
|
154
161
|
|
162
|
+
pthread_mutex_lock(&big_lock);
|
155
163
|
tdb = tdb_open_ex(o->name, o->hash_size, o->tdb_flags,
|
156
164
|
o->open_flags, o->mode, o->log_ctx, o->hash_fn);
|
165
|
+
pthread_mutex_unlock(&big_lock);
|
157
166
|
|
158
167
|
return (VALUE)tdb;
|
159
168
|
}
|
@@ -274,8 +283,13 @@ static VALUE init(int argc, VALUE *argv, VALUE self)
|
|
274
283
|
static VALUE nogvl_close(void *ptr)
|
275
284
|
{
|
276
285
|
struct tdb_context *tdb = ptr;
|
286
|
+
VALUE rv;
|
277
287
|
|
278
|
-
|
288
|
+
pthread_mutex_lock(&big_lock);
|
289
|
+
rv = (VALUE)tdb_close(tdb);
|
290
|
+
pthread_mutex_unlock(&big_lock);
|
291
|
+
|
292
|
+
return rv;
|
279
293
|
}
|
280
294
|
|
281
295
|
static VALUE tdbclose(VALUE self)
|
@@ -737,6 +751,7 @@ void Init_tdb_ext(void)
|
|
737
751
|
/* Better hashing, but can't be opened by tdb < 1.2.6. */
|
738
752
|
rb_define_const(cTDB, "INCOMPATIBLE_HASH", UINT2NUM(TDB_INCOMPATIBLE_HASH));
|
739
753
|
#endif
|
754
|
+
rbtdb_init_tdb_hash_functions();
|
740
755
|
}
|
741
756
|
|
742
757
|
/*
|
data/lib/tdb/mt.rb
CHANGED
@@ -12,19 +12,13 @@ module TDB::MT
|
|
12
12
|
lockall trylockall unlockall
|
13
13
|
lockall_read trylockall_read unlockall_read
|
14
14
|
lockall_mark lockall_unmark
|
15
|
-
clear
|
15
|
+
clear each
|
16
16
|
)
|
17
17
|
wrap_methods << :repack if TDB.method_defined?(:repack)
|
18
18
|
wrap_methods.each do |meth|
|
19
19
|
eval "def #{meth}(*args); @lock.synchronize { super }; end"
|
20
20
|
end
|
21
21
|
|
22
|
-
def each(&block)
|
23
|
-
@lock.synchronize do
|
24
|
-
super { |k,v| @lock.exclusive_unlock { yield(k,v) } }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
22
|
def threadsafe?
|
29
23
|
true
|
30
24
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
require 'test/unit'
|
3
|
+
$-w = true
|
4
|
+
require 'tdb'
|
5
|
+
|
6
|
+
class TestHashFunctions < Test::Unit::TestCase
|
7
|
+
include TDB::HashFunctions
|
8
|
+
|
9
|
+
def test_hashes
|
10
|
+
TDB::HASHES.each do |name,_|
|
11
|
+
next if :default == name
|
12
|
+
assert_kind_of Integer, __send__("tdb_hash_#{name}", "hello")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/test_tdb_mt.rb
CHANGED
@@ -23,7 +23,6 @@ class Test_TDB_MT < Test::Unit::TestCase
|
|
23
23
|
assert ! @tdb.threadsafe?
|
24
24
|
assert_nothing_raised { @tdb.threadsafe! }
|
25
25
|
assert @tdb.threadsafe?
|
26
|
-
@tdb.each { |k,v| assert_equal v, @tdb[k] }
|
27
26
|
end
|
28
27
|
|
29
28
|
def test_init_threadsafe
|
@@ -39,13 +38,15 @@ class Test_TDB_MT < Test::Unit::TestCase
|
|
39
38
|
end
|
40
39
|
|
41
40
|
def test_thread_safe_torture_test
|
42
|
-
@
|
41
|
+
@tmp = Tempfile.new('tdb_test')
|
42
|
+
File.unlink(@tmp.path)
|
43
|
+
@tdb = TDB.new(@tmp.path)
|
43
44
|
assert_nothing_raised { @tdb.threadsafe! }
|
44
|
-
|
45
|
-
|
45
|
+
Thread.abort_on_exception = true
|
46
|
+
nr = 10000
|
47
|
+
blob = 'foo' * 1000
|
48
|
+
crazy = proc do
|
46
49
|
threads = []
|
47
|
-
blob = 'foo' * 1000
|
48
|
-
nr = 10000
|
49
50
|
t = Thread.new do
|
50
51
|
while true
|
51
52
|
Thread.pass
|
@@ -56,13 +57,17 @@ class Test_TDB_MT < Test::Unit::TestCase
|
|
56
57
|
threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
|
57
58
|
threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
|
58
59
|
threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
|
60
|
+
threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
|
59
61
|
threads << t
|
60
|
-
|
62
|
+
sleep 1
|
61
63
|
t.kill
|
62
64
|
threads.each { |t| t.join }
|
63
65
|
end
|
64
|
-
|
65
|
-
|
66
|
+
10.times { fork &crazy }
|
67
|
+
Process.waitall.each do |(pid,status)|
|
68
|
+
assert status.success?, status.inspect
|
69
|
+
end
|
70
|
+
nr.times { |i| assert_equal blob, @tdb[i.to_s] }
|
66
71
|
end
|
67
72
|
|
68
73
|
def test_check_methods
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ruby tdb hackers
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-14 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- ext/tdb/djb.c
|
58
58
|
- ext/tdb/extconf.rb
|
59
59
|
- ext/tdb/fnv.c
|
60
|
+
- ext/tdb/hash_functions.c
|
60
61
|
- ext/tdb/lookup3.c
|
61
62
|
- ext/tdb/murmur1.c
|
62
63
|
- ext/tdb/murmur2.c
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- setup.rb
|
68
69
|
- tdb.gemspec
|
69
70
|
- test/test_tdb.rb
|
71
|
+
- test/test_tdb_hash_functions.rb
|
70
72
|
- test/test_tdb_mt.rb
|
71
73
|
has_rdoc: true
|
72
74
|
homepage: http://bogomips.org/ruby-tdb/
|
@@ -106,4 +108,5 @@ specification_version: 3
|
|
106
108
|
summary: Trivial Database bindings for Ruby
|
107
109
|
test_files:
|
108
110
|
- test/test_tdb_mt.rb
|
111
|
+
- test/test_tdb_hash_functions.rb
|
109
112
|
- test/test_tdb.rb
|