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.533 by root, Thu Apr 29 07:59:17 2010 UTC vs.
Revision 1.534 by root, Thu Apr 29 08:13:51 2010 UTC

518=cut 518=cut
519 519
520sub sync_job(&) { 520sub sync_job(&) {
521 my ($job) = @_; 521 my ($job) = @_;
522 522
523 if ($Coro::current == $Coro::main) { 523 if (in_main) {
524 my $time = AE::time; 524 my $time = AE::time;
525 525
526 # this is the main coro, too bad, we have to block 526 # this is the main coro, too bad, we have to block
527 # till the operation succeeds, freezing the server :/ 527 # till the operation succeeds, freezing the server :/
528 528
529 LOG llevError, Carp::longmess "sync job";#d# 529 #LOG llevError, Carp::longmess "sync job";#d#
530 530
531 my $freeze_guard = freeze_mainloop; 531 my $freeze_guard = freeze_mainloop;
532 532
533 my $busy = 1; 533 my $busy = 1;
534 my @res; 534 my @res;
657within each server. 657within each server.
658 658
659=cut 659=cut
660 660
661sub db_table($) { 661sub db_table($) {
662 cf::error "db_get called from main context"
663 if $Coro::current == $Coro::main;
664
662 my ($name) = @_; 665 my ($name) = @_;
663 my $db = BDB::db_create $DB_ENV; 666 my $db = BDB::db_create $DB_ENV;
664 667
665 eval { 668 eval {
666 $db->set_flags (BDB::CHKSUM); 669 $db->set_flags (BDB::CHKSUM);
676} 679}
677 680
678our $DB; 681our $DB;
679 682
680sub db_init { 683sub db_init {
681 cf::sync_job {
682 $DB ||= db_table "db"; 684 $DB ||= db_table "db";
683 };
684} 685}
685 686
686sub db_get($$) { 687sub db_get($$) {
687 my $key = "$_[0]/$_[1]"; 688 my $key = "$_[0]/$_[1]";
688 689
689 cf::sync_job { 690 cf::error "db_get called from main context"
691 if $Coro::current == $Coro::main;
692
690 BDB::db_get $DB, undef, $key, my $data; 693 BDB::db_get $DB, undef, $key, my $data;
691 694
692 $! ? () 695 $! ? ()
693 : $data 696 : $data
694 }
695} 697}
696 698
697sub db_put($$$) { 699sub db_put($$$) {
698 BDB::dbreq_pri 4; 700 BDB::dbreq_pri 4;
699 BDB::db_put $DB, undef, "$_[0]/$_[1]", $_[2], 0, sub { }; 701 BDB::db_put $DB, undef, "$_[0]/$_[1]", $_[2], 0, sub { };
2190} 2192}
2191 2193
2192sub find_sync { 2194sub find_sync {
2193 my ($path, $origin) = @_; 2195 my ($path, $origin) = @_;
2194 2196
2195 cf::sync_job { find $path, $origin } 2197 return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync"
2198 if $Coro::current == $Coro::main;
2199
2200 find $path, $origin
2196} 2201}
2197 2202
2198sub do_load_sync { 2203sub do_load_sync {
2199 my ($map) = @_; 2204 my ($map) = @_;
2200 2205
2201 cf::LOG cf::llevDebug | cf::logBacktrace, "do_load_sync" 2206 return cf::LOG cf::llevError | cf::logBacktrace, "do_load_sync"
2202 if $Coro::current == $Coro::main; 2207 if $Coro::current == $Coro::main;
2203 2208
2204 cf::sync_job { $map->load }; 2209 $map->load;
2205} 2210}
2206 2211
2207our %MAP_PREFETCH; 2212our %MAP_PREFETCH;
2208our $MAP_PREFETCHER = undef; 2213our $MAP_PREFETCHER = undef;
2209 2214
3747sub emergency_save() { 3752sub emergency_save() {
3748 my $freeze_guard = cf::freeze_mainloop; 3753 my $freeze_guard = cf::freeze_mainloop;
3749 3754
3750 info "emergency_perl_save: enter\n"; 3755 info "emergency_perl_save: enter\n";
3751 3756
3757 # this is a trade-off: we want to be very quick here, so
3758 # save all maps without fsync, and later call a global sync
3759 # (which in turn might be very very slow)
3760 local $USE_FSYNC = 0;
3761
3752 cf::sync_job { 3762 cf::sync_job {
3753 # this is a trade-off: we want to be very quick here, so
3754 # save all maps without fsync, and later call a global sync
3755 # (which in turn might be very very slow)
3756 local $USE_FSYNC = 0;
3757
3758 # use a peculiar iteration method to avoid tripping on perl 3763 # use a peculiar iteration method to avoid tripping on perl
3759 # refcount bugs in for. also avoids problems with players 3764 # refcount bugs in for. also avoids problems with players
3760 # and maps saved/destroyed asynchronously. 3765 # and maps saved/destroyed asynchronously.
3761 info "emergency_perl_save: begin player save\n"; 3766 info "emergency_perl_save: begin player save\n";
3762 for my $login (keys %cf::PLAYER) { 3767 for my $login (keys %cf::PLAYER) {
4056 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; 4061 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7;
4057 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; 4062 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7;
4058 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); 4063 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT);
4059 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); 4064 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT);
4060 4065
4061 (Coro::async { # async to keep sync_job from complaining
4062 cf::sync_job { 4066 cf::sync_job {
4063 eval { 4067 eval {
4064 BDB::db_env_open 4068 BDB::db_env_open
4065 $DB_ENV, 4069 $DB_ENV,
4066 $BDBDIR, 4070 $BDBDIR,
4067 BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN 4071 BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN
4068 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, 4072 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE,
4069 0666; 4073 0666;
4070 4074
4071 cf::cleanup "db_env_open($BDBDIR): $!" if $!; 4075 cf::cleanup "db_env_open($BDBDIR): $!" if $!;
4072 };
4073
4074 cf::cleanup "db_env_open(db): $@" if $@;
4075 }; 4076 };
4076 })->join; 4077
4078 cf::cleanup "db_env_open(db): $@" if $@;
4079 };
4077 } 4080 }
4078 4081
4079 $BDB_DEADLOCK_WATCHER = EV::periodic 0, 3, 0, sub { 4082 $BDB_DEADLOCK_WATCHER = EV::periodic 0, 3, 0, sub {
4080 BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { }; 4083 BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { };
4081 }; 4084 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines