uses SBDB-provided gc for databases

This commit is contained in:
Denis Knauf 2010-02-05 19:14:03 +01:00
parent 496c7437a7
commit 2f2b4fd558

View file

@ -65,21 +65,16 @@ class Rotate
end end
def db k def db k
h = hashing k n = @rdb[ h]
db = @dbs[h] if n
unless db n = UUIDTools::UUID.parse_raw n
n = @rdb[ h] else
if n n = UUIDTools::UUID.timestamp_create
n = UUIDTools::UUID.parse_raw n @rdb[ h] = n.raw
else
n = UUIDTools::UUID.timestamp_create
@rdb[ h] = n.raw
end
info :open => n.to_s
db = @env.open SBDB::Btree, n.to_s, 'logs', Bdb::DB_CREATE | Bdb::DB_AUTO_COMMIT, nil
@dbs[h] = db
end end
db info :open => n.to_s
@env[ n.to_s, 'logs', SBDB::Btree, SBDB::CREATE | SBDB::AUTO_COMMIT]
@env[ "#{n}.newids", 'logs', SBDB::Queue, SBDB::CREATE | SBDB::AUTO_COMMIT]
end end
def sync def sync
@ -132,29 +127,25 @@ info :create => {:home => $conf[:home]}
Dir.mkdir $conf[:home] rescue Errno::EEXIST Dir.mkdir $conf[:home] rescue Errno::EEXIST
info :open => SBDB::Env info :open => SBDB::Env
SBDB::Env.new( $conf[:home], SBDB::CREATE | SBDB::INIT_TXN | SBDB::INIT_LOCK | SBDB::INIT_LOG | SBDB::INIT_MPOOL | Bdb::DB_AUTO_COMMIT) do |dbenv| SBDB::Env.new( $conf[:home], SBDB::CREATE | SBDB::Env::INIT_TRANSACTION | Bdb::DB_AUTO_COMMIT) do |dbenv|
info :open => SBDB::Btree info :open => Rotate
dbenv.open( SBDB::Btree, 'rotates.db', 'rotates', SBDB::CREATE | Bdb::DB_AUTO_COMMIT, nil) do |rdb| dbs = Rotate.new dbenv[ 'rotates.db', 'rotates', SBDB::Btree, SBDB::CREATE | Bdb::DB_AUTO_COMMIT]
info :open => Rotate info :open => S2L
dbs = Rotate.new rdb serv = S2L.new :sock => TCPServer.new( *$conf[:server]), :dbs => dbs
info :open => S2L retries = Retries.new *$conf[:retries]
serv = S2L.new :sock => TCPServer.new( *$conf[:server]), :dbs => dbs begin
retries = Retries.new *$conf[:retries] info :run => serv
begin serv.run
info :run => serv info :shutdown => :stoped
serv.run rescue Interrupt
info :shutdown => :stoped info :shutdown => :interrupted
rescue Interrupt rescue SignalException
info :shutdown => :interrupted info :shutdown => :signal
rescue SignalException rescue Object
info :shutdown => :signal error :exception=>$!, :backtrace=>$!.backtrace
rescue Object retries.retry? and retry
error :exception=>$!, :backtrace=>$!.backtrace fatal "Too many retries (#{retries.count})"
retries.retry? and retry info :shutdown => :fatal
fatal "Too many retries (#{retries.count})"
info :shutdown => :fatal
end
info :close => rdb
end end
info :close => dbenv info :close => dbenv
end end