dk-bdb 0.2.4
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.
- data/LICENSE +20 -0
- data/README.md +102 -0
- data/VERSION +1 -0
- data/examples/replication.rb +29 -0
- data/ext/bdb.c +3421 -0
- data/ext/bdb.h +104 -0
- data/ext/extconf.rb +59 -0
- data/lib/bdb/base.rb +68 -0
- data/lib/bdb/database.rb +207 -0
- data/lib/bdb/environment.rb +135 -0
- data/lib/bdb/partitioned_database.rb +74 -0
- data/lib/bdb/replication.rb +68 -0
- data/lib/bdb/result_set.rb +41 -0
- data/test/benchmark.rb +31 -0
- data/test/cursor_test.rb +150 -0
- data/test/database_test.rb +18 -0
- data/test/database_test_helper.rb +37 -0
- data/test/db_test.rb +157 -0
- data/test/deadlock_test.rb +125 -0
- data/test/env_test.rb +101 -0
- data/test/replication_test.rb +47 -0
- data/test/stat_test.rb +22 -0
- data/test/test_helper.rb +14 -0
- data/test/txn_test.rb +74 -0
- metadata +92 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Dan Janowski <danj@3skel.com>, Matt Bauer <bauer@pedalbrain.com>
|
|
2
|
+
Copyright (c) 2009 Justin Balthrop <code@justinbalthrop.com>
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
8
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
9
|
+
so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Description
|
|
2
|
+
===
|
|
3
|
+
|
|
4
|
+
Ruby bindings for Berkeley DB versions 4.2-4.7.
|
|
5
|
+
|
|
6
|
+
Download
|
|
7
|
+
========
|
|
8
|
+
|
|
9
|
+
Currently this library is available via git at:
|
|
10
|
+
|
|
11
|
+
git://github.com/DenisKnauf/bdb.git
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Installation
|
|
15
|
+
============
|
|
16
|
+
|
|
17
|
+
From Git
|
|
18
|
+
--------
|
|
19
|
+
|
|
20
|
+
You can check out the latest source from git:
|
|
21
|
+
|
|
22
|
+
git clone git://github.com/DenisKnauf/bdb.git
|
|
23
|
+
|
|
24
|
+
As a Gem
|
|
25
|
+
========
|
|
26
|
+
|
|
27
|
+
At the moment this library is not available on Rubyforge. To install it as a
|
|
28
|
+
gem, do the following (for custom compiled version 4.8):
|
|
29
|
+
|
|
30
|
+
wget http://github.com/downloads/DenisKnauf/bdb/bdb-VERSION.gem
|
|
31
|
+
sudo env ARCHFLAGS="-arch i386" gem install bdb-VERSION.gem -- --with-db-dir=/usr/local/BerkeleyDB.4.8
|
|
32
|
+
|
|
33
|
+
For Berkeley DB v4.7 installed from MacPorts do the following:
|
|
34
|
+
|
|
35
|
+
sudo env ARCHFLAGS="-arch i386" gem install bdb-VERSION.gem -- --with-db-include=/opt/local/include/db47 --with-db-lib=/opt/local/lib/db47
|
|
36
|
+
|
|
37
|
+
This assumes you're on OS X and BerkeleyDB wasn't compiled as a universal binary.
|
|
38
|
+
|
|
39
|
+
Sample Usage
|
|
40
|
+
============
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
env = Bdb::Env.new(0)
|
|
44
|
+
env_flags = Bdb::DB_CREATE | # Create the environment if it does not already exist.
|
|
45
|
+
Bdb::DB_INIT_TXN | # Initialize transactions
|
|
46
|
+
Bdb::DB_INIT_LOCK | # Initialize locking.
|
|
47
|
+
Bdb::DB_INIT_LOG | # Initialize logging
|
|
48
|
+
Bdb::DB_INIT_MPOOL # Initialize the in-memory cache.
|
|
49
|
+
env.open(File.join(File.dirname(__FILE__), 'tmp'), env_flags, 0);
|
|
50
|
+
|
|
51
|
+
db = env.db
|
|
52
|
+
db.open(nil, 'db1.db', nil, Bdb::Db::BTREE, Bdb::DB_CREATE | Bdb::DB_AUTO_COMMIT, 0)
|
|
53
|
+
|
|
54
|
+
txn = env.txn_begin(nil, 0)
|
|
55
|
+
db.put(txn, 'key', 'value', 0)
|
|
56
|
+
txn.commit(0)
|
|
57
|
+
|
|
58
|
+
value = db.get(nil, 'key', nil, 0)
|
|
59
|
+
|
|
60
|
+
db.close(0)
|
|
61
|
+
env.close
|
|
62
|
+
|
|
63
|
+
API
|
|
64
|
+
===
|
|
65
|
+
|
|
66
|
+
This interface is most closely based on the DB4 C api and tries to maintain close
|
|
67
|
+
interface proximity.
|
|
68
|
+
[That API is published by Oracle](http://www.oracle.com/technology/documentation/berkeley-db/db/api_reference/C/frame_main.html).
|
|
69
|
+
|
|
70
|
+
All function arguments systematically omit the leading DB handles and TXN handles.
|
|
71
|
+
A few calls omit the flags parameter when the documentation indicates that no
|
|
72
|
+
flag values are used - cursor.close is one.
|
|
73
|
+
|
|
74
|
+
Alternative API
|
|
75
|
+
---------------
|
|
76
|
+
|
|
77
|
+
You can use [SBDB](http://github.com/DenisKnauf/sbdb), too. It is easier to use, but base on this library.
|
|
78
|
+
|
|
79
|
+
Notes
|
|
80
|
+
=====
|
|
81
|
+
|
|
82
|
+
The defines generator is imperfect and includes some defines that are not
|
|
83
|
+
flags. While it could be improved, it is easier to delete the incorrect ones.
|
|
84
|
+
Thus, if you decide to rebuild the defines, you will need to edit the resulting
|
|
85
|
+
file. This may be necessary if using a different release of DB4 than the ones
|
|
86
|
+
the authors developed against. In nearly every case the defines generator works
|
|
87
|
+
flawlessly.
|
|
88
|
+
|
|
89
|
+
The authors have put all possible caution into ensuring that DB and Ruby cooperate.
|
|
90
|
+
The memory access was one aspect carefully considered. Since Ruby copies
|
|
91
|
+
when doing String#new, all key/data retrieval from DB is done with a 0 flag,
|
|
92
|
+
meaning that DB will be responsible. See [*this* news group posting](http://groups.google.com/group/comp.databases.berkeley-db/browse_frm/thread/4f70a9999b64ce6a/c06b94692e3cbc41?tvc=1&q=dbt+malloc#c06b94692e3cbc41)
|
|
93
|
+
about the effect of that.
|
|
94
|
+
|
|
95
|
+
The only other design consideration of consequence was associate. The prior
|
|
96
|
+
version used a Ruby thread local variable and kept track of the current
|
|
97
|
+
database in use. The authors decided to take a simpler approach since Ruby is green
|
|
98
|
+
threads. A global array stores the VALUE of the Proc for a given association
|
|
99
|
+
by the file descriptor number of the underlying database. This is looked
|
|
100
|
+
up when the first layer callback is made. It would have been better considered
|
|
101
|
+
if DB allowed the passing of a (void *) user data into the alloc that would
|
|
102
|
+
be supplied during callback. So far this design has not produced any problems.
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.2.4
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bdb/database'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
role = ARGV.shift || 'client'
|
|
6
|
+
|
|
7
|
+
MASTER = 'localhost:8888'
|
|
8
|
+
CLIENT = 'localhost:9999'
|
|
9
|
+
|
|
10
|
+
DIR = "/tmp/#{role}"
|
|
11
|
+
FileUtils.rmtree DIR
|
|
12
|
+
FileUtils.mkdir DIR
|
|
13
|
+
|
|
14
|
+
puts "Starting #{role}..."
|
|
15
|
+
|
|
16
|
+
Bdb::Environment.replicate DIR, :from => MASTER, :to => CLIENT, :host => role == 'master' ? MASTER : CLIENT
|
|
17
|
+
db = Bdb::Database.new('foo', :path => DIR)
|
|
18
|
+
|
|
19
|
+
loop do
|
|
20
|
+
100.times do |i|
|
|
21
|
+
if role == 'master'
|
|
22
|
+
db.set(i, db[i].to_i + 1)
|
|
23
|
+
puts "#{i}: #{db[i]}"
|
|
24
|
+
else
|
|
25
|
+
puts "#{i}: #{db[i]}"
|
|
26
|
+
end
|
|
27
|
+
sleep 0.1
|
|
28
|
+
end
|
|
29
|
+
end
|