ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.362 by root, Mon Sep 10 12:44:06 2007 UTC vs.
Revision 1.363 by root, Mon Sep 10 17:24:36 2007 UTC

80our $NEXT_TICK; 80our $NEXT_TICK;
81our $NOW; 81our $NOW;
82our $USE_FSYNC = 1; # use fsync to write maps - default off 82our $USE_FSYNC = 1; # use fsync to write maps - default off
83 83
84our $BDB_POLL_WATCHER; 84our $BDB_POLL_WATCHER;
85our $BDB_CHECKPOINT_WATCHER;
86our $BDB_TRICKLE_WATCHER;
85our $DB_ENV; 87our $DB_ENV;
86 88
87our %CFG; 89our %CFG;
88 90
89our $UPTIME; $UPTIME ||= time; 91our $UPTIME; $UPTIME ||= time;
507=item cf::db_put $family => $key => $value 509=item cf::db_put $family => $key => $value
508 510
509Stores the given C<$value> in the family. It can currently store binary 511Stores the given C<$value> in the family. It can currently store binary
510data only (use Compress::LZF::sfreeze_cr/sthaw to convert to/from binary). 512data only (use Compress::LZF::sfreeze_cr/sthaw to convert to/from binary).
511 513
514=item $db = cf::db_table "name"
515
516Create and/or open a new database table. The string must not be "db" and must be unique
517within each server.
518
512=cut 519=cut
520
521sub db_table($) {
522 my ($name) = @_;
523 my $db = BDB::db_create $DB_ENV;
524
525 eval {
526 $db->set_flags (BDB::CHKSUM);
527
528 utf8::encode $name;
529 BDB::db_open $db, undef, $name, undef, BDB::BTREE,
530 BDB::CREATE | BDB::AUTO_COMMIT, 0666;
531 cf::cleanup "db_open(db): $!" if $!;
532 };
533 cf::cleanup "db_open(db): $@" if $@;
534
535 $db
536}
513 537
514our $DB; 538our $DB;
515 539
516sub db_init { 540sub db_init {
517 unless ($DB) {
518 $DB = BDB::db_create $DB_ENV;
519
520 cf::sync_job { 541 cf::sync_job {
521 eval { 542 $DB ||= db_table "db";
522 $DB->set_flags (BDB::CHKSUM);
523
524 BDB::db_open $DB, undef, "db", undef, BDB::BTREE,
525 BDB::CREATE | BDB::AUTO_COMMIT, 0666;
526 cf::cleanup "db_open(db): $!" if $!;
527 };
528 cf::cleanup "db_open(db): $@" if $@;
529 };
530 } 543 };
531} 544}
532 545
533sub db_get($$) { 546sub db_get($$) {
534 my $key = "$_[0]/$_[1]"; 547 my $key = "$_[0]/$_[1]";
535 548
3513 3526
3514 }, 3527 },
3515); 3528);
3516 3529
3517{ 3530{
3531 BDB::min_parallel 8;
3518 BDB::max_poll_time $TICK * 0.1; 3532 BDB::max_poll_time $TICK * 0.1;
3519 $BDB_POLL_WATCHER = Event->io ( 3533 $BDB_POLL_WATCHER = Event->io (
3520 reentrant => 0, 3534 reentrant => 0,
3521 fd => BDB::poll_fileno, 3535 fd => BDB::poll_fileno,
3522 poll => 'r', 3536 poll => 'r',
3523 prio => 0, 3537 prio => 0,
3524 data => WF_AUTOCANCEL, 3538 data => WF_AUTOCANCEL,
3525 cb => \&BDB::poll_cb, 3539 cb => \&BDB::poll_cb,
3526 ); 3540 );
3527 BDB::min_parallel 8;
3528 3541
3529 BDB::set_sync_prepare { 3542 BDB::set_sync_prepare {
3530 my $status; 3543 my $status;
3531 my $current = $Coro::current; 3544 my $current = $Coro::current;
3532 ( 3545 (
3553 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, 3566 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE,
3554 0666; 3567 0666;
3555 3568
3556 cf::cleanup "db_env_open($BDBDIR): $!" if $!; 3569 cf::cleanup "db_env_open($BDBDIR): $!" if $!;
3557 3570
3558 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC, 1); 3571 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC
3572 | BDB::LOG_AUTOREMOVE, 1);
3559 $DB_ENV->set_lk_detect; 3573 $DB_ENV->set_lk_detect;
3560 }; 3574 };
3561 3575
3562 cf::cleanup "db_env_open(db): $@" if $@; 3576 cf::cleanup "db_env_open(db): $@" if $@;
3563 }; 3577 };
3564 } 3578 }
3579
3580 $BDB_CHECKPOINT_WATCHER = Event->timer (
3581 after => 11,
3582 interval => 60,
3583 hard => 1,
3584 prio => 0,
3585 data => WF_AUTOCANCEL,
3586 cb => sub {
3587 BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { };
3588 },
3589 );
3590 $BDB_TRICKLE_WATCHER = Event->timer (
3591 after => 5,
3592 interval => 10,
3593 hard => 1,
3594 prio => 0,
3595 data => WF_AUTOCANCEL,
3596 cb => sub {
3597 BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { };
3598 },
3599 );
3565} 3600}
3566 3601
3567{ 3602{
3568 IO::AIO::min_parallel 8; 3603 IO::AIO::min_parallel 8;
3569 3604

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines