summaryrefslogtreecommitdiff
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
parent2ed83d89e5fad7d0bed1003fdc60b538a4187162 (diff)
use a db env for the databases to avoid some corruption problems (I hope)
-rw-r--r--lib/rbot/dbhash.rb22
-rw-r--r--lib/rbot/keywords.rb18
-rw-r--r--lib/rbot/registry.rb25
3 files changed, 27 insertions, 38 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
diff --git a/lib/rbot/keywords.rb b/lib/rbot/keywords.rb
index cc91155c..83185d9f 100644
--- a/lib/rbot/keywords.rb
+++ b/lib/rbot/keywords.rb
@@ -131,12 +131,10 @@ module Irc
puts "upgrading keyword db #{f} (rbot 0.9.5 or prior) database format"
newname = f.gsub(/\.db$/, ".kdb")
old = BDB::Hash.open f, nil,
- "r+", 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0]
- new = BDB::CIBtree.open newname, nil,
- BDB::CREATE | BDB::EXCL | BDB::TRUNCATE,
- 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0]
+ "r+", 0600
+ new = BDB::CIBtree.open(newname, nil,
+ BDB::CREATE | BDB::EXCL,
+ 0600)
old.each {|k,v|
new[k] = v
}
@@ -186,12 +184,10 @@ module Irc
if File.exist?("#{@bot.botclass}/keywords.db")
puts "upgrading old keywords (rbot 0.9.5 or prior) database format"
old = BDB::Hash.open "#{@bot.botclass}/keywords.db", nil,
- "r+", 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0]
+ "r+", 0600
new = BDB::CIBtree.open "#{@bot.botclass}/keyword.db", nil,
- BDB::CREATE | BDB::EXCL | BDB::TRUNCATE,
- 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0]
+ BDB::CREATE | BDB::EXCL,
+ 0600
old.each {|k,v|
new[k] = v
}
diff --git a/lib/rbot/registry.rb b/lib/rbot/registry.rb
index 6388c91d..536305d3 100644
--- a/lib/rbot/registry.rb
+++ b/lib/rbot/registry.rb
@@ -18,12 +18,10 @@ module Irc
if File.exist?("#{@bot.botclass}/registry.db")
puts "upgrading old-style (rbot 0.9.5 or earlier) plugin registry to new format"
old = BDB::Hash.open("#{@bot.botclass}/registry.db", nil,
- "r+", 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0])
+ "r+", 0600)
new = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
- BDB::CREATE | BDB::EXCL | BDB::TRUNCATE,
- 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0])
+ BDB::CREATE | BDB::EXCL,
+ 0600)
old.each {|k,v|
new[k] = v
}
@@ -35,21 +33,21 @@ module Irc
def upgrade_data2
if File.exist?("#{@bot.botclass}/plugin_registry.db")
- Dir.mkdir("#{@bot.botclass}/registry")
+ Dir.mkdir("#{@bot.botclass}/registry") unless File.exist?("#{@bot.botclass}/registry")
+ env = BDB::Env.open("#{@bot.botclass}", BDB::INIT_TRANSACTION | BDB::CREATE | BDB::RECOVER)
dbs = Hash.new
puts "upgrading previous (rbot 0.9.9 or earlier) plugin registry to new split format"
old = BDB::CIBtree.open("#{@bot.botclass}/plugin_registry.db", nil,
- "r+", 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0])
+ "r+", 0600, "env" => env)
old.each {|k,v|
prefix,key = k.split("/", 2)
prefix.downcase!
unless dbs.has_key?(prefix)
puts "creating db #{@bot.botclass}/registry/#{prefix}.db"
dbs[prefix] = BDB::CIBtree.open("#{@bot.botclass}/registry/#{prefix}.db",
- nil, BDB::CREATE | BDB::EXCL | BDB::TRUNCATE,
- 0600, "set_pagesize" => 1024,
- "set_cachesize" => [0, 32 * 1024, 0])
+ nil, BDB::CREATE | BDB::EXCL,
+ 0600, "env" => env)
+
end
dbs[prefix][key] = v
}
@@ -59,6 +57,7 @@ module Irc
puts "closing db #{k}"
v.close
}
+ env.close
end
end
end
@@ -276,10 +275,6 @@ module Irc
end
alias size length
- def flush
- @registry.flush
- end
-
end
end