summaryrefslogtreecommitdiff
path: root/lib/rbot/dbhash.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2006-02-10 18:52:56 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2006-02-10 18:52:56 +0000
commit44688c76d937c2dade10aaa7bb7e70e508b33684 (patch)
tree30d0751ea9feab5c039f64e60e2811e2821a11fb /lib/rbot/dbhash.rb
parent2ed83d89e5fad7d0bed1003fdc60b538a4187162 (diff)
use a db env for the databases to avoid some corruption problems (I hope)
Diffstat (limited to 'lib/rbot/dbhash.rb')
-rw-r--r--lib/rbot/dbhash.rb22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/rbot/dbhash.rb b/lib/rbot/dbhash.rb
index 611ec087..0c09e17c 100644
--- a/lib/rbot/dbhash.rb
+++ b/lib/rbot/dbhash.rb
@@ -50,16 +50,12 @@ module Irc
def DBHash.create_db(name)
debug "DBHash: creating empty db #{name}"
return BDB::Hash.open(name, nil,
- BDB::CREATE | BDB::EXCL | BDB::TRUNCATE,
- 0600, "set_pagesize" => 1024,
- "set_cachesize" => [(0), (32 * 1024), (0)])
+ BDB::CREATE | BDB::EXCL, 0600)
end
def DBHash.open_db(name)
debug "DBHash: opening existing db #{name}"
- return BDB::Hash.open(name, nil,
- "r+", 0600, "set_pagesize" => 1024,
- "set_cachesize" => [(0), (32 * 1024), (0)])
+ return BDB::Hash.open(name, nil, "r+", 0600)
end
end
@@ -67,12 +63,16 @@ module Irc
# DBTree is a BTree equivalent of DBHash, with case insensitive lookups.
class DBTree
-
+ @@env=nil
# absfilename:: use +key+ as an actual filename, don't prepend the bot's
# config path and don't append ".db"
def initialize(bot, key, absfilename=false)
@bot = bot
@key = key
+ if @@env.nil?
+ @@env = BDB::Env.open("#{@bot.botclass}", BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)
+ end
+
if absfilename && File.exist?(key)
# db already exists, use it
@db = DBTree.open_db(key)
@@ -95,16 +95,14 @@ module Irc
def DBTree.create_db(name)
debug "DBTree: creating empty db #{name}"
return BDB::CIBtree.open(name, nil,
- BDB::CREATE | BDB::EXCL | BDB::TRUNCATE,
- 0600, "set_pagesize" => 1024,
- "set_cachesize" => [(0), (32 * 1024), (0)])
+ BDB::CREATE | BDB::EXCL,
+ 0600, "env" => @@env)
end
def DBTree.open_db(name)
debug "DBTree: opening existing db #{name}"
return BDB::CIBtree.open(name, nil,
- "r+", 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0])
+ "r+", 0600, "env" => @@env)
end
end