--- deliantra/server/lib/cf.pm 2007/09/11 16:05:35 1.366 +++ deliantra/server/lib/cf.pm 2007/09/19 22:07:16 1.374 @@ -82,6 +82,7 @@ our $USE_FSYNC = 1; # use fsync to write maps - default off our $BDB_POLL_WATCHER; +our $BDB_DEADLOCK_WATCHER; our $BDB_CHECKPOINT_WATCHER; our $BDB_TRICKLE_WATCHER; our $DB_ENV; @@ -355,6 +356,8 @@ $SLOT_QUEUE->cancel if $SLOT_QUEUE; $SLOT_QUEUE = Coro::async { + $Coro::current->desc ("timeslot manager"); + my $signal = new Coro::Signal; while () { @@ -434,6 +437,7 @@ my @res; (async { + $Coro::current->desc ("sync job coro"); @res = eval { $job->() }; warn $@ if $@; undef $busy; @@ -1027,8 +1031,6 @@ sub object_freezer_save { my ($filename, $rdata, $objs) = @_; - my $guard = cf::lock_acquire "io"; - sync_job { if (length $$rdata) { utf8::decode (my $decname = $filename); @@ -1063,8 +1065,6 @@ aio_unlink "$filename.pst"; } }; - - undef $guard; } sub object_freezer_as_string { @@ -1080,8 +1080,6 @@ my ($data, $av); - my $guard = cf::lock_acquire "io"; - (aio_load $filename, $data) >= 0 or return; @@ -1089,7 +1087,6 @@ (aio_load "$filename.pst", $av) >= 0 or return; - undef $guard; $av = eval { (Storable::thaw $av)->{objs} }; } @@ -1354,7 +1351,6 @@ my $f = new_from_file cf::object::thawer path $login or return; - $f->next; my $pl = cf::player::load_pl $f or return; local $cf::PLAYER_LOADING{$login} = $pl; @@ -2045,6 +2041,8 @@ $MAP_PREFETCH{$path} |= $load; $MAP_PREFETCHER ||= cf::async { + $Coro::current->{desc} = "map prefetcher"; + while (%MAP_PREFETCH) { while (my ($k, $v) = each %MAP_PREFETCH) { if (my $map = find $k) { @@ -2080,6 +2078,7 @@ local $self->{last_access} = $self->last_access;#d# cf::async { + $Coro::current->{desc} = "map player save"; $_->contr->save for $self->players; }; @@ -2460,26 +2459,35 @@ $self->enter_link; (async { + $Coro::current->{desc} = "player::goto $path $x $y"; + # *tag paths override both path and x|y if ($path =~ /^\*(.*)$/) { if (my @obs = grep $_->map, ext::map_tags::find $1) { my $ob = $obs[rand @obs]; - # todo: use ob_blocked to check all tiles of the destination "object" - # for suitability. + # see if we actually can go there + if (@obs = grep !$self->blocked ($_->map, $_->x, $_->y), $ob, $ob->tail) { + $ob = $obs[rand @obs]; + } else { + $self->message ("Wow, it's pretty crowded in there.", cf::NDI_UNIQUE | cf::NDI_RED); + } + # else put us there anyways for now #d# ($path, $x, $y) = ($ob->map, $ob->x, $ob->y); + } else { + ($path, $x, $y) = (undef, undef, undef); } } my $map = eval { - my $map = cf::map::find $path; + my $map = defined $path ? cf::map::find $path : undef; if ($map) { $map = $map->customise_for ($self); $map = $check->($map) if $check && $map; } else { - $self->message ("The exit to '$path' is closed", cf::NDI_UNIQUE | cf::NDI_RED); + $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); } $map @@ -2579,6 +2587,8 @@ if $exit->flag (FLAG_DAMNED); (async { + $Coro::current->{desc} = "enter_exit $slaying $hp $sp"; + $self->deactivate_recursive; # just to be sure unless (eval { $self->goto ($slaying, $hp, $sp); @@ -3177,6 +3187,7 @@ local $Coro::idle = sub { Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# (async { + $Coro::current->{desc} = "IDLE BUG HANDLER"; Event::one_event; })->prio (Coro::PRIO_MAX); }; @@ -3430,7 +3441,10 @@ if ($who->flag (FLAG_WIZ)) { $who->message ("reloading server."); - async { reload_perl }; + async { + $Coro::current->{desc} = "perl_reload"; + reload_perl; + }; } }; @@ -3459,9 +3473,6 @@ $signal->wait; } -our $stat_fh; -sysopen $stat_fh, "/tmp/cfstats", Fcntl::O_APPEND | Fcntl::O_CREAT | Fcntl::O_WRONLY, 0600;#d# - $TICK_WATCHER = Event->timer ( reentrant => 0, parked => 1, @@ -3475,8 +3486,6 @@ return; } - my @pl = cf::player::list; my $stats = sprintf "%.2f %d %d %d", $RUNTIME, (scalar @pl), cf::object::actives_size, cf::object::objects_size; #d# - $NOW = $tick_start = Event::time; cf::server_tick; # one server iteration @@ -3487,14 +3496,12 @@ if ($NOW >= $NEXT_RUNTIME_WRITE) { $NEXT_RUNTIME_WRITE = $NOW + 10; Coro::async_pool { + $Coro::current->{desc} = "runtime saver"; write_runtime or warn "ERROR: unable to write runtime file: $!"; }; } -# my $AFTER = Event::time; -# warn $AFTER - $NOW;#d# - if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { $sig->send; } @@ -3514,10 +3521,6 @@ $LOADAVG = $LOADAVG * 0.75 + $LOAD * 0.25; _post_tick; - - # gather some statistics#d# - $stats .= sprintf " %d\n", 10000 * ($NOW - $tick_start);#d# - IO::AIO::aio_write $stat_fh, undef, undef, $stats, 0;#d# }, ); @@ -3550,6 +3553,10 @@ unless ($DB_ENV) { $DB_ENV = BDB::db_env_create; + $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC + | BDB::LOG_AUTOREMOVE, 1); + $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); + $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); cf::sync_job { eval { @@ -3561,16 +3568,22 @@ 0666; cf::cleanup "db_env_open($BDBDIR): $!" if $!; - - $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_DEADLOCK_WATCHER = Event->timer ( + after => 3, + interval => 1, + hard => 1, + prio => 0, + data => WF_AUTOCANCEL, + cb => sub { + BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { }; + }, + ); $BDB_CHECKPOINT_WATCHER = Event->timer ( after => 11, interval => 60, @@ -3619,6 +3632,8 @@ if ($_log_backtrace < 2) { ++$_log_backtrace; async { + $Coro::current->{desc} = "abt $msg"; + my @bt = fork_call { @addr = map { sprintf "%x", $_ } @addr; my $self = (-f "/proc/$$/exe") ? "/proc/$$/exe" : $^X;