--- deliantra/server/lib/cf.pm 2007/09/10 12:44:06 1.362 +++ deliantra/server/lib/cf.pm 2007/09/10 17:24:36 1.363 @@ -82,6 +82,8 @@ our $USE_FSYNC = 1; # use fsync to write maps - default off our $BDB_POLL_WATCHER; +our $BDB_CHECKPOINT_WATCHER; +our $BDB_TRICKLE_WATCHER; our $DB_ENV; our %CFG; @@ -509,25 +511,36 @@ Stores the given C<$value> in the family. It can currently store binary data only (use Compress::LZF::sfreeze_cr/sthaw to convert to/from binary). +=item $db = cf::db_table "name" + +Create and/or open a new database table. The string must not be "db" and must be unique +within each server. + =cut -our $DB; +sub db_table($) { + my ($name) = @_; + my $db = BDB::db_create $DB_ENV; -sub db_init { - unless ($DB) { - $DB = BDB::db_create $DB_ENV; + eval { + $db->set_flags (BDB::CHKSUM); - cf::sync_job { - eval { - $DB->set_flags (BDB::CHKSUM); + utf8::encode $name; + BDB::db_open $db, undef, $name, undef, BDB::BTREE, + BDB::CREATE | BDB::AUTO_COMMIT, 0666; + cf::cleanup "db_open(db): $!" if $!; + }; + cf::cleanup "db_open(db): $@" if $@; - BDB::db_open $DB, undef, "db", undef, BDB::BTREE, - BDB::CREATE | BDB::AUTO_COMMIT, 0666; - cf::cleanup "db_open(db): $!" if $!; - }; - cf::cleanup "db_open(db): $@" if $@; - }; - } + $db +} + +our $DB; + +sub db_init { + cf::sync_job { + $DB ||= db_table "db"; + }; } sub db_get($$) { @@ -3515,6 +3528,7 @@ ); { + BDB::min_parallel 8; BDB::max_poll_time $TICK * 0.1; $BDB_POLL_WATCHER = Event->io ( reentrant => 0, @@ -3524,7 +3538,6 @@ data => WF_AUTOCANCEL, cb => \&BDB::poll_cb, ); - BDB::min_parallel 8; BDB::set_sync_prepare { my $status; @@ -3555,13 +3568,35 @@ cf::cleanup "db_env_open($BDBDIR): $!" if $!; - $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC, 1); + $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC + | BDB::LOG_AUTOREMOVE, 1); $DB_ENV->set_lk_detect; }; cf::cleanup "db_env_open(db): $@" if $@; }; } + + $BDB_CHECKPOINT_WATCHER = Event->timer ( + after => 11, + interval => 60, + hard => 1, + prio => 0, + data => WF_AUTOCANCEL, + cb => sub { + BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; + }, + ); + $BDB_TRICKLE_WATCHER = Event->timer ( + after => 5, + interval => 10, + hard => 1, + prio => 0, + data => WF_AUTOCANCEL, + cb => sub { + BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { }; + }, + ); } {