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.520 by root, Fri Apr 16 02:37:50 2010 UTC vs.
Revision 1.533 by root, Thu Apr 29 07:59:17 2010 UTC

106our $RANDOMDIR = "$LOCALDIR/random"; 106our $RANDOMDIR = "$LOCALDIR/random";
107our $BDBDIR = "$LOCALDIR/db"; 107our $BDBDIR = "$LOCALDIR/db";
108our $PIDFILE = "$LOCALDIR/pid"; 108our $PIDFILE = "$LOCALDIR/pid";
109our $RUNTIMEFILE = "$LOCALDIR/runtime"; 109our $RUNTIMEFILE = "$LOCALDIR/runtime";
110 110
111our %RESOURCE; 111our %RESOURCE; # unused
112 112
113our $OUTPUT_RATE_MIN = 4000; 113our $OUTPUT_RATE_MIN = 3000;
114our $OUTPUT_RATE_MAX = 100000; 114our $OUTPUT_RATE_MAX = 1000000;
115
116our $MAX_LINKS = 32; # how many chained exits to follow
117our $VERBOSE_IO = 1;
115 118
116our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 119our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
117our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 120our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
118our $NEXT_TICK; 121our $NEXT_TICK;
119our $USE_FSYNC = 1; # use fsync to write maps - default on 122our $USE_FSYNC = 1; # use fsync to write maps - default on
165 168
166our $EMERGENCY_POSITION; 169our $EMERGENCY_POSITION;
167 170
168sub cf::map::normalise; 171sub cf::map::normalise;
169 172
173sub in_main() {
174 $Coro::current == $Coro::main
175}
176
170############################################################################# 177#############################################################################
171 178
172%REFLECT = (); 179%REFLECT = ();
173for (@REFLECT) { 180for (@REFLECT) {
174 my $reflect = JSON::XS::decode_json $_; 181 my $reflect = JSON::XS::decode_json $_;
245 252
246=back 253=back
247 254
248=cut 255=cut
249 256
257sub error(@) { LOG llevError, join "", @_ }
258sub warn (@) { LOG llevWarn , join "", @_ }
259sub info (@) { LOG llevInfo , join "", @_ }
260sub debug(@) { LOG llevDebug, join "", @_ }
261sub trace(@) { LOG llevTrace, join "", @_ }
262
250$Coro::State::WARNHOOK = sub { 263$Coro::State::WARNHOOK = sub {
251 my $msg = join "", @_; 264 my $msg = join "", @_;
252 265
253 $msg .= "\n" 266 $msg .= "\n"
254 unless $msg =~ /\n$/; 267 unless $msg =~ /\n$/;
255 268
256 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge; 269 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge;
257 270
258 LOG llevError, $msg; 271 LOG llevWarn, $msg;
259}; 272};
260 273
261$Coro::State::DIEHOOK = sub { 274$Coro::State::DIEHOOK = sub {
262 return unless $^S eq 0; # "eq", not "==" 275 return unless $^S eq 0; # "eq", not "=="
263 276
264 warn Carp::longmess $_[0]; 277 error Carp::longmess $_[0];
265 278
266 if ($Coro::current == $Coro::main) {#d# 279 if (in_main) {#d#
267 warn "DIEHOOK called in main context, Coro bug?\n";#d# 280 error "DIEHOOK called in main context, Coro bug?\n";#d#
268 return;#d# 281 return;#d#
269 }#d# 282 }#d#
270 283
271 # kill coroutine otherwise 284 # kill coroutine otherwise
272 Coro::terminate 285 Coro::terminate
521 my @res; 534 my @res;
522 535
523 (async { 536 (async {
524 $Coro::current->desc ("sync job coro"); 537 $Coro::current->desc ("sync job coro");
525 @res = eval { $job->() }; 538 @res = eval { $job->() };
526 warn $@ if $@; 539 error $@ if $@;
527 undef $busy; 540 undef $busy;
528 })->prio (Coro::PRIO_MAX); 541 })->prio (Coro::PRIO_MAX);
529 542
530 while ($busy) { 543 while ($busy) {
531 if (Coro::nready) { 544 if (Coro::nready) {
742 755
743 my $t1 = Time::HiRes::time; 756 my $t1 = Time::HiRes::time;
744 my $data = $process->(\@data); 757 my $data = $process->(\@data);
745 my $t2 = Time::HiRes::time; 758 my $t2 = Time::HiRes::time;
746 759
747 warn "cache: '$id' processed in ", $t2 - $t1, "s\n"; 760 info "cache: '$id' processed in ", $t2 - $t1, "s\n";
748 761
749 db_put cache => "$id/data", $data; 762 db_put cache => "$id/data", $data;
750 db_put cache => "$id/md5" , $md5; 763 db_put cache => "$id/md5" , $md5;
751 db_put cache => "$id/meta", $meta; 764 db_put cache => "$id/meta", $meta;
752 765
762 775
763=cut 776=cut
764 777
765sub datalog($@) { 778sub datalog($@) {
766 my ($type, %kv) = @_; 779 my ($type, %kv) = @_;
767 warn "DATALOG ", JSON::XS->new->ascii->encode ({ %kv, type => $type }); 780 info "DATALOG ", JSON::XS->new->ascii->encode ({ %kv, type => $type });
768} 781}
769 782
770=back 783=back
771 784
772=cut 785=cut
967 980
968 } elsif (exists $cb_id{$type}) { 981 } elsif (exists $cb_id{$type}) {
969 _attach_cb $registry, $cb_id{$type}, $prio, shift @arg; 982 _attach_cb $registry, $cb_id{$type}, $prio, shift @arg;
970 983
971 } elsif (ref $type) { 984 } elsif (ref $type) {
972 warn "attaching objects not supported, ignoring.\n"; 985 error "attaching objects not supported, ignoring.\n";
973 986
974 } else { 987 } else {
975 shift @arg; 988 shift @arg;
976 warn "attach argument '$type' not supported, ignoring.\n"; 989 error "attach argument '$type' not supported, ignoring.\n";
977 } 990 }
978 } 991 }
979} 992}
980 993
981sub _object_attach { 994sub _object_attach {
991 _attach $registry, $klass, @attach; 1004 _attach $registry, $klass, @attach;
992 } 1005 }
993 1006
994 $obj->{$name} = \%arg; 1007 $obj->{$name} = \%arg;
995 } else { 1008 } else {
996 warn "object uses attachment '$name' which is not available, postponing.\n"; 1009 info "object uses attachment '$name' which is not available, postponing.\n";
997 } 1010 }
998 1011
999 $obj->{_attachment}{$name} = undef; 1012 $obj->{_attachment}{$name} = undef;
1000} 1013}
1001 1014
1060 1073
1061 for (@$callbacks) { 1074 for (@$callbacks) {
1062 eval { &{$_->[1]} }; 1075 eval { &{$_->[1]} };
1063 1076
1064 if ($@) { 1077 if ($@) {
1065 warn "$@";
1066 warn "... while processing $EVENT[$event][0](@_) event, skipping processing altogether.\n"; 1078 error "$@", "... while processing $EVENT[$event][0](@_) event, skipping processing altogether.\n";
1067 override; 1079 override;
1068 } 1080 }
1069 1081
1070 return 1 if $override; 1082 return 1 if $override;
1071 } 1083 }
1150 for (@$attach) { 1162 for (@$attach) {
1151 my ($klass, @attach) = @$_; 1163 my ($klass, @attach) = @$_;
1152 _attach $registry, $klass, @attach; 1164 _attach $registry, $klass, @attach;
1153 } 1165 }
1154 } else { 1166 } else {
1155 warn "object uses attachment '$name' that is not available, postponing.\n"; 1167 info "object uses attachment '$name' that is not available, postponing.\n";
1156 } 1168 }
1157 } 1169 }
1158} 1170}
1159 1171
1160cf::attachable->attach ( 1172cf::attachable->attach (
1187 my ($filename, $rdata, $objs) = @_; 1199 my ($filename, $rdata, $objs) = @_;
1188 1200
1189 sync_job { 1201 sync_job {
1190 if (length $$rdata) { 1202 if (length $$rdata) {
1191 utf8::decode (my $decname = $filename); 1203 utf8::decode (my $decname = $filename);
1192 warn sprintf "saving %s (%d,%d)\n", 1204 trace sprintf "saving %s (%d,%d)\n",
1193 $decname, length $$rdata, scalar @$objs; 1205 $decname, length $$rdata, scalar @$objs
1206 if $VERBOSE_IO;
1194 1207
1195 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 1208 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
1196 aio_chmod $fh, SAVE_MODE; 1209 aio_chmod $fh, SAVE_MODE;
1197 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 1210 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
1198 if ($cf::USE_FSYNC) { 1211 if ($cf::USE_FSYNC) {
1220 aio_rename "$filename~", $filename; 1233 aio_rename "$filename~", $filename;
1221 1234
1222 $filename =~ s%/[^/]+$%%; 1235 $filename =~ s%/[^/]+$%%;
1223 aio_pathsync $filename if $cf::USE_FSYNC; 1236 aio_pathsync $filename if $cf::USE_FSYNC;
1224 } else { 1237 } else {
1225 warn "unable to save objects: $filename~: $!\n"; 1238 error "unable to save objects: $filename~: $!\n";
1226 } 1239 }
1227 } else { 1240 } else {
1228 aio_unlink $filename; 1241 aio_unlink $filename;
1229 aio_unlink "$filename.pst"; 1242 aio_unlink "$filename.pst";
1230 } 1243 }
1254 my $st = eval { Coro::Storable::thaw $av }; 1267 my $st = eval { Coro::Storable::thaw $av };
1255 $av = $st->{objs}; 1268 $av = $st->{objs};
1256 } 1269 }
1257 1270
1258 utf8::decode (my $decname = $filename); 1271 utf8::decode (my $decname = $filename);
1259 warn sprintf "loading %s (%d,%d)\n", 1272 trace sprintf "loading %s (%d,%d)\n",
1260 $decname, length $data, scalar @{$av || []}; 1273 $decname, length $data, scalar @{$av || []}
1274 if $VERBOSE_IO;
1261 1275
1262 ($data, $av) 1276 ($data, $av)
1263} 1277}
1264 1278
1265=head2 COMMAND CALLBACKS 1279=head2 COMMAND CALLBACKS
1357 1371
1358 $pl->ext_reply ($reply, @reply) 1372 $pl->ext_reply ($reply, @reply)
1359 if $reply; 1373 if $reply;
1360 1374
1361 } else { 1375 } else {
1362 warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; 1376 error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n";
1363 } 1377 }
1364 1378
1365 cf::override; 1379 cf::override;
1366 }, 1380 },
1367); 1381);
1378 1392
1379 $grp 1393 $grp
1380} 1394}
1381 1395
1382sub load_extensions { 1396sub load_extensions {
1397 info "loading extensions...";
1398
1383 cf::sync_job { 1399 cf::sync_job {
1384 my %todo; 1400 my %todo;
1385 1401
1386 for my $path (<$LIBDIR/*.ext>) { 1402 for my $path (<$LIBDIR/*.ext>) {
1387 next unless -r $path; 1403 next unless -r $path;
1427 for (split /,\s*/, $v->{meta}{depends}) { 1443 for (split /,\s*/, $v->{meta}{depends}) {
1428 next ext 1444 next ext
1429 unless exists $done{$_}; 1445 unless exists $done{$_};
1430 } 1446 }
1431 1447
1432 warn "... pass $pass, loading '$k' into '$v->{pkg}'\n"; 1448 trace "... pass $pass, loading '$k' into '$v->{pkg}'\n";
1433 1449
1434 my $active = eval $v->{source}; 1450 my $active = eval $v->{source};
1435 1451
1436 if (length $@) { 1452 if (length $@) {
1437 warn "$v->{path}: $@\n"; 1453 error "$v->{path}: $@\n";
1438 1454
1439 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1455 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1440 if exists $v->{meta}{mandatory}; 1456 if exists $v->{meta}{mandatory};
1457
1458 warn "$v->{base}: optional extension cannot be loaded, skipping.\n";
1459 delete $todo{$k};
1441 } else { 1460 } else {
1442 $done{$k} = delete $todo{$k}; 1461 $done{$k} = delete $todo{$k};
1443 push @EXTS, $v->{pkg}; 1462 push @EXTS, $v->{pkg};
1444 $progress = 1; 1463 $progress = 1;
1445 1464
1446 warn "$v->{base}: extension inactive.\n" 1465 info "$v->{base}: extension inactive.\n"
1447 unless $active; 1466 unless $active;
1448 } 1467 }
1449 } 1468 }
1450 1469
1451 unless ($progress) { 1470 unless ($progress) {
1623 $pl->password ("*"); # this should lock out the player until we have nuked the dir 1642 $pl->password ("*"); # this should lock out the player until we have nuked the dir
1624 1643
1625 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; 1644 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active;
1626 $pl->deactivate; 1645 $pl->deactivate;
1627 my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; 1646 my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy;
1628 $pl->ob->check_score;
1629 $pl->invoke (cf::EVENT_PLAYER_QUIT); 1647 $pl->invoke (cf::EVENT_PLAYER_QUIT);
1630 $pl->ns->destroy if $pl->ns; 1648 $pl->ns->destroy if $pl->ns;
1631 1649
1632 my $path = playerdir $pl; 1650 my $path = playerdir $pl;
1633 my $temp = "$path~$cf::RUNTIME~deleting~"; 1651 my $temp = "$path~$cf::RUNTIME~deleting~";
1688 \@logins 1706 \@logins
1689} 1707}
1690 1708
1691=item $player->maps 1709=item $player->maps
1692 1710
1711=item cf::player::maps $login
1712
1693Returns an arrayref of map paths that are private for this 1713Returns an arrayref of map paths that are private for this
1694player. May block. 1714player. May block.
1695 1715
1696=cut 1716=cut
1697 1717
1758 1778
1759=cut 1779=cut
1760 1780
1761sub find_by_path($) { 1781sub find_by_path($) {
1762 my ($path) = @_; 1782 my ($path) = @_;
1783
1784 $path =~ s/^~[^\/]*//; # skip ~login
1763 1785
1764 my ($match, $specificity); 1786 my ($match, $specificity);
1765 1787
1766 for my $region (list) { 1788 for my $region (list) {
1767 if ($region->{match} && $path =~ $region->{match}) { 1789 if ($region->{match} && $path =~ $region->{match}) {
1831 1853
1832 $EXT_MAP{$pkg} = [$prio, qr<$regex>]; 1854 $EXT_MAP{$pkg} = [$prio, qr<$regex>];
1833} 1855}
1834 1856
1835# also paths starting with '/' 1857# also paths starting with '/'
1836$EXT_MAP{"cf::map"} = [0, qr{^(?=/)}]; 1858$EXT_MAP{"cf::map::wrap"} = [0, qr{^(?=/)}];
1837 1859
1838sub thawer_merge { 1860sub thawer_merge {
1839 my ($self, $merge) = @_; 1861 my ($self, $merge) = @_;
1840 1862
1841 # we have to keep some variables in memory intact 1863 # we have to keep some variables in memory intact
2151 or next; 2173 or next;
2152 $neigh = find $neigh, $map 2174 $neigh = find $neigh, $map
2153 or next; 2175 or next;
2154 $neigh->load; 2176 $neigh->load;
2155 2177
2178 # now find the diagonal neighbours
2156 push @neigh, 2179 push @neigh,
2157 [$neigh->tile_path (($_ + 3) % 4), $neigh], 2180 [$neigh->tile_path (($_ + 3) % 4), $neigh],
2158 [$neigh->tile_path (($_ + 1) % 4), $neigh]; 2181 [$neigh->tile_path (($_ + 1) % 4), $neigh];
2159 } 2182 }
2160 2183
2298 2321
2299 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2322 my $lock = cf::lock_acquire "map_data:$self->{path}";
2300 2323
2301 return if $self->players; 2324 return if $self->players;
2302 2325
2303 warn "resetting map ", $self->path, "\n"; 2326 cf::trace "resetting map ", $self->path, "\n";
2304 2327
2305 $self->in_memory (cf::MAP_SWAPPED); 2328 $self->in_memory (cf::MAP_SWAPPED);
2306 2329
2307 # need to save uniques path 2330 # need to save uniques path
2308 unless ($self->{deny_save}) { 2331 unless ($self->{deny_save}) {
2332 2355
2333 delete $cf::MAP{$self->path}; 2356 delete $cf::MAP{$self->path};
2334 2357
2335 $self->unlink_save; 2358 $self->unlink_save;
2336 2359
2337 bless $self, "cf::map"; 2360 bless $self, "cf::map::wrap";
2338 delete $self->{deny_reset}; 2361 delete $self->{deny_reset};
2339 $self->{deny_save} = 1; 2362 $self->{deny_save} = 1;
2340 $self->reset_timeout (1); 2363 $self->reset_timeout (1);
2341 $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); 2364 $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++));
2342 2365
2572 2595
2573Freezes the player and moves him/her to a special map (C<{link}>). 2596Freezes the player and moves him/her to a special map (C<{link}>).
2574 2597
2575The player should be reasonably safe there for short amounts of time (e.g. 2598The player should be reasonably safe there for short amounts of time (e.g.
2576for loading a map). You I<MUST> call C<leave_link> as soon as possible, 2599for loading a map). You I<MUST> call C<leave_link> as soon as possible,
2577though, as the palyer cannot control the character while it is on the link 2600though, as the player cannot control the character while it is on the link
2578map. 2601map.
2579 2602
2580Will never block. 2603Will never block.
2581 2604
2582=item $player_object->leave_link ($map, $x, $y) 2605=item $player_object->leave_link ($map, $x, $y)
2603sub cf::object::player::enter_link { 2626sub cf::object::player::enter_link {
2604 my ($self) = @_; 2627 my ($self) = @_;
2605 2628
2606 $self->deactivate_recursive; 2629 $self->deactivate_recursive;
2607 2630
2631 ++$self->{_link_recursion};
2632
2608 return if UNIVERSAL::isa $self->map, "ext::map_link"; 2633 return if UNIVERSAL::isa $self->map, "ext::map_link";
2609 2634
2610 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] 2635 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y]
2611 if $self->map && $self->map->{path} ne "{link}"; 2636 if $self->map && $self->map->{path} ne "{link}";
2612 2637
2643 $map->load_neighbours; 2668 $map->load_neighbours;
2644 2669
2645 return unless $self->contr->active; 2670 return unless $self->contr->active;
2646 2671
2647 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2672 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2648 $self->enter_map ($map, $x, $y); 2673 if ($self->enter_map ($map, $x, $y)) {
2649 2674 # entering was successful
2675 delete $self->{_link_recursion};
2650 # only activate afterwards, to support waiting in hooks 2676 # only activate afterwards, to support waiting in hooks
2651 $self->activate_recursive; 2677 $self->activate_recursive;
2652} 2678 }
2653 2679
2680}
2681
2654=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) 2682=item $player_object->goto ($path, $x, $y[, $check->($map, $x, $y, $player)[, $done->($player)]])
2655 2683
2656Moves the player to the given map-path and coordinates by first freezing 2684Moves the player to the given map-path and coordinates by first freezing
2657her, loading and preparing them map, calling the provided $check callback 2685her, loading and preparing them map, calling the provided $check callback
2658that has to return the map if sucecssful, and then unfreezes the player on 2686that has to return the map if sucecssful, and then unfreezes the player on
2659the new (success) or old (failed) map position. In either case, $done will 2687the new (success) or old (failed) map position. In either case, $done will
2666 2694
2667our $GOTOGEN; 2695our $GOTOGEN;
2668 2696
2669sub cf::object::player::goto { 2697sub cf::object::player::goto {
2670 my ($self, $path, $x, $y, $check, $done) = @_; 2698 my ($self, $path, $x, $y, $check, $done) = @_;
2699
2700 if ($self->{_link_recursion} >= $MAX_LINKS) {
2701 error "FATAL: link recursion exceeded, ", $self->name, " goto $path $x $y, redirecting.";
2702 $self->failmsg ("Something went wrong inside the server - please contact an administrator!");
2703 ($path, $x, $y) = @$EMERGENCY_POSITION;
2704 }
2671 2705
2672 # do generation counting so two concurrent goto's will be executed in-order 2706 # do generation counting so two concurrent goto's will be executed in-order
2673 my $gen = $self->{_goto_generation} = ++$GOTOGEN; 2707 my $gen = $self->{_goto_generation} = ++$GOTOGEN;
2674 2708
2675 $self->enter_link; 2709 $self->enter_link;
2699 my $map = eval { 2733 my $map = eval {
2700 my $map = defined $path ? cf::map::find $path : undef; 2734 my $map = defined $path ? cf::map::find $path : undef;
2701 2735
2702 if ($map) { 2736 if ($map) {
2703 $map = $map->customise_for ($self); 2737 $map = $map->customise_for ($self);
2704 $map = $check->($map) if $check && $map; 2738 $map = $check->($map, $x, $y, $self) if $check && $map;
2705 } else { 2739 } else {
2706 $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); 2740 $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED);
2707 } 2741 }
2708 2742
2709 $map 2743 $map
2717 if ($gen == $self->{_goto_generation}) { 2751 if ($gen == $self->{_goto_generation}) {
2718 delete $self->{_goto_generation}; 2752 delete $self->{_goto_generation};
2719 $self->leave_link ($map, $x, $y); 2753 $self->leave_link ($map, $x, $y);
2720 } 2754 }
2721 2755
2722 $done->() if $done; 2756 $done->($self) if $done;
2723 })->prio (1); 2757 })->prio (1);
2724} 2758}
2725 2759
2726=item $player_object->enter_exit ($exit_object) 2760=item $player_object->enter_exit ($exit_object)
2727 2761
2820 $self->message ("Something went wrong deep within the deliantra server. " 2854 $self->message ("Something went wrong deep within the deliantra server. "
2821 . "I'll try to bring you back to the map you were before. " 2855 . "I'll try to bring you back to the map you were before. "
2822 . "Please report this to the dungeon master!", 2856 . "Please report this to the dungeon master!",
2823 cf::NDI_UNIQUE | cf::NDI_RED); 2857 cf::NDI_UNIQUE | cf::NDI_RED);
2824 2858
2825 warn "ERROR in enter_exit: $@"; 2859 error "ERROR in enter_exit: $@";
2826 $self->leave_link; 2860 $self->leave_link;
2827 } 2861 }
2828 })->prio (1); 2862 })->prio (1);
2829} 2863}
2830 2864
3143 3177
3144 $ns->ext_reply ($reply, @reply) 3178 $ns->ext_reply ($reply, @reply)
3145 if $reply; 3179 if $reply;
3146 3180
3147 } else { 3181 } else {
3148 warn "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n"; 3182 error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n";
3149 } 3183 }
3150 3184
3151 cf::override; 3185 cf::override;
3152 }, 3186 },
3153); 3187);
3283 local @cf::_safe_eval_args = values %vars; 3317 local @cf::_safe_eval_args = values %vars;
3284 @res = wantarray ? eval eval : scalar eval $eval; 3318 @res = wantarray ? eval eval : scalar eval $eval;
3285 } 3319 }
3286 3320
3287 if ($@) { 3321 if ($@) {
3288 warn "$@"; 3322 warn "$@",
3289 warn "while executing safe code '$code'\n"; 3323 "while executing safe code '$code'\n",
3290 warn "with arguments " . (join " ", %vars) . "\n"; 3324 "with arguments " . (join " ", %vars) . "\n";
3291 } 3325 }
3292 3326
3293 wantarray ? @res : $res[0] 3327 wantarray ? @res : $res[0]
3294} 3328}
3295 3329
3329 # for this (global event?) 3363 # for this (global event?)
3330 %ext::player_env::MUSIC_FACE_CACHE = (); 3364 %ext::player_env::MUSIC_FACE_CACHE = ();
3331 3365
3332 my $enc = JSON::XS->new->utf8->canonical->relaxed; 3366 my $enc = JSON::XS->new->utf8->canonical->relaxed;
3333 3367
3334 warn "loading facedata from $path\n"; 3368 trace "loading facedata from $path\n";
3335 3369
3336 my $facedata; 3370 my $facedata;
3337 0 < aio_load $path, $facedata 3371 0 < aio_load $path, $facedata
3338 or die "$path: $!"; 3372 or die "$path: $!";
3339 3373
3373 3407
3374 if (my $smooth = cf::face::find $info->{smooth}) { 3408 if (my $smooth = cf::face::find $info->{smooth}) {
3375 cf::face::set_smooth $idx, $smooth; 3409 cf::face::set_smooth $idx, $smooth;
3376 cf::face::set_smoothlevel $idx, $info->{smoothlevel}; 3410 cf::face::set_smoothlevel $idx, $info->{smoothlevel};
3377 } else { 3411 } else {
3378 warn "smooth face '$info->{smooth}' not found for face '$face'"; 3412 error "smooth face '$info->{smooth}' not found for face '$face'";
3379 } 3413 }
3380 3414
3381 cf::cede_to_tick; 3415 cf::cede_to_tick;
3382 } 3416 }
3383 } 3417 }
3401 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3435 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3402 3436
3403 cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; 3437 cf::face::set_data $idx, 0, $info->{data}, $info->{hash};
3404 cf::face::set_type $idx, $info->{type}; 3438 cf::face::set_type $idx, $info->{type};
3405 } else { 3439 } else {
3406 $RESOURCE{$name} = $info; 3440 $RESOURCE{$name} = $info; # unused
3407 } 3441 }
3408 3442
3409 cf::cede_to_tick; 3443 cf::cede_to_tick;
3410 } 3444 }
3411 } 3445 }
3412 3446
3413 cf::global->invoke (EVENT_GLOBAL_RESOURCE_UPDATE); 3447 cf::global->invoke (EVENT_GLOBAL_RESOURCE_UPDATE);
3414 3448
3415 1 3449 1
3416} 3450}
3417
3418cf::global->attach (on_resource_update => sub {
3419 if (my $soundconf = $RESOURCE{"res/sound.conf"}) {
3420 $soundconf = JSON::XS->new->utf8->relaxed->decode ($soundconf->{data});
3421
3422 for (0 .. SOUND_CAST_SPELL_0 - 1) {
3423 my $sound = $soundconf->{compat}[$_]
3424 or next;
3425
3426 my $face = cf::face::find "sound/$sound->[1]";
3427 cf::sound::set $sound->[0] => $face;
3428 cf::sound::old_sound_index $_, $face; # gcfclient-compat
3429 }
3430
3431 while (my ($k, $v) = each %{$soundconf->{event}}) {
3432 my $face = cf::face::find "sound/$v";
3433 cf::sound::set $k => $face;
3434 }
3435 }
3436});
3437 3451
3438register_exticmd fx_want => sub { 3452register_exticmd fx_want => sub {
3439 my ($ns, $want) = @_; 3453 my ($ns, $want) = @_;
3440 3454
3441 while (my ($k, $v) = each %$want) { 3455 while (my ($k, $v) = each %$want) {
3480sub reload_treasures { 3494sub reload_treasures {
3481 load_resource_file "$DATADIR/treasures" 3495 load_resource_file "$DATADIR/treasures"
3482 or die "unable to load treasurelists\n"; 3496 or die "unable to load treasurelists\n";
3483} 3497}
3484 3498
3499sub reload_sound {
3500 trace "loading sound config from $DATADIR/sound\n";
3501
3502 0 < Coro::AIO::aio_load "$DATADIR/sound", my $data
3503 or die "$DATADIR/sound $!";
3504
3505 my $soundconf = JSON::XS->new->utf8->relaxed->decode ($data);
3506
3507 for (0 .. SOUND_CAST_SPELL_0 - 1) {
3508 my $sound = $soundconf->{compat}[$_]
3509 or next;
3510
3511 my $face = cf::face::find "sound/$sound->[1]";
3512 cf::sound::set $sound->[0] => $face;
3513 cf::sound::old_sound_index $_, $face; # gcfclient-compat
3514 }
3515
3516 while (my ($k, $v) = each %{$soundconf->{event}}) {
3517 my $face = cf::face::find "sound/$v";
3518 cf::sound::set $k => $face;
3519 }
3520}
3521
3485sub reload_resources { 3522sub reload_resources {
3486 warn "reloading resource files...\n"; 3523 trace "reloading resource files...\n";
3487 3524
3488 reload_facedata; 3525 reload_facedata;
3526 reload_sound;
3489 reload_archetypes; 3527 reload_archetypes;
3490 reload_regions; 3528 reload_regions;
3491 reload_treasures; 3529 reload_treasures;
3492 3530
3493 warn "finished reloading resource files\n"; 3531 trace "finished reloading resource files\n";
3494} 3532}
3495 3533
3496sub reload_config { 3534sub reload_config {
3497 warn "reloading config file...\n"; 3535 trace "reloading config file...\n";
3498 3536
3499 open my $fh, "<:utf8", "$CONFDIR/config" 3537 open my $fh, "<:utf8", "$CONFDIR/config"
3500 or return; 3538 or return;
3501 3539
3502 local $/; 3540 local $/;
3503 *CFG = YAML::XS::Load scalar <$fh>; 3541 *CFG = YAML::XS::Load scalar <$fh>;
3504 3542
3505 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; 3543 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38];
3506 3544
3507 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; 3545 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset};
3508 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; 3546 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset};
3509 3547
3510 if (exists $CFG{mlockall}) { 3548 if (exists $CFG{mlockall}) {
3513 and die "WARNING: m(un)lockall failed: $!\n"; 3551 and die "WARNING: m(un)lockall failed: $!\n";
3514 }; 3552 };
3515 warn $@ if $@; 3553 warn $@ if $@;
3516 } 3554 }
3517 3555
3518 warn "finished reloading resource files\n"; 3556 trace "finished reloading resource files\n";
3519} 3557}
3520 3558
3521sub pidfile() { 3559sub pidfile() {
3522 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT 3560 sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT
3523 or die "$PIDFILE: $!"; 3561 or die "$PIDFILE: $!";
3536 seek $fh, 0, 0; 3574 seek $fh, 0, 0;
3537 print $fh $$; 3575 print $fh $$;
3538} 3576}
3539 3577
3540sub main_loop { 3578sub main_loop {
3541 warn "EV::loop starting\n"; 3579 trace "EV::loop starting\n";
3542 if (1) { 3580 if (1) {
3543 EV::loop; 3581 EV::loop;
3544 } 3582 }
3545 warn "EV::loop returned\n"; 3583 trace "EV::loop returned\n";
3546 goto &main_loop unless $REALLY_UNLOOP; 3584 goto &main_loop unless $REALLY_UNLOOP;
3547} 3585}
3548 3586
3549sub main { 3587sub main {
3550 cf::init_globals; # initialise logging 3588 cf::init_globals; # initialise logging
3598 3636
3599 (pop @POST_INIT)->(0) while @POST_INIT; 3637 (pop @POST_INIT)->(0) while @POST_INIT;
3600 }; 3638 };
3601 3639
3602 cf::object::thawer::errors_are_fatal 0; 3640 cf::object::thawer::errors_are_fatal 0;
3603 warn "parse errors in files are no longer fatal from this point on.\n"; 3641 info "parse errors in files are no longer fatal from this point on.\n";
3604 3642
3605 main_loop; 3643 main_loop;
3606} 3644}
3607 3645
3608############################################################################# 3646#############################################################################
3649 or return; 3687 or return;
3650 3688
3651 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE 3689 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE
3652 and return; 3690 and return;
3653 3691
3654 warn sprintf "runtime file written (%gs).\n", AE::time - $t0; 3692 trace sprintf "runtime file written (%gs).\n", AE::time - $t0;
3655 3693
3656 1 3694 1
3657} 3695}
3658 3696
3659our $uuid_lock; 3697our $uuid_lock;
3671 or return; 3709 or return;
3672 3710
3673 my $value = uuid_seq uuid_cur; 3711 my $value = uuid_seq uuid_cur;
3674 3712
3675 unless ($value) { 3713 unless ($value) {
3676 warn "cowardly refusing to write zero uuid value!\n"; 3714 info "cowardly refusing to write zero uuid value!\n";
3677 return; 3715 return;
3678 } 3716 }
3679 3717
3680 my $value = uuid_str $value + $uuid_skip; 3718 my $value = uuid_str $value + $uuid_skip;
3681 $uuid_skip = 0; 3719 $uuid_skip = 0;
3691 or return; 3729 or return;
3692 3730
3693 aio_rename "$uuid~", $uuid 3731 aio_rename "$uuid~", $uuid
3694 and return; 3732 and return;
3695 3733
3696 warn "uuid file written ($value).\n"; 3734 trace "uuid file written ($value).\n";
3697 3735
3698 1 3736 1
3699 3737
3700} 3738}
3701 3739
3707} 3745}
3708 3746
3709sub emergency_save() { 3747sub emergency_save() {
3710 my $freeze_guard = cf::freeze_mainloop; 3748 my $freeze_guard = cf::freeze_mainloop;
3711 3749
3712 warn "emergency_perl_save: enter\n"; 3750 info "emergency_perl_save: enter\n";
3713 3751
3714 cf::sync_job { 3752 cf::sync_job {
3715 # this is a trade-off: we want to be very quick here, so 3753 # this is a trade-off: we want to be very quick here, so
3716 # save all maps without fsync, and later call a global sync 3754 # save all maps without fsync, and later call a global sync
3717 # (which in turn might be very very slow) 3755 # (which in turn might be very very slow)
3718 local $USE_FSYNC = 0; 3756 local $USE_FSYNC = 0;
3719 3757
3720 # use a peculiar iteration method to avoid tripping on perl 3758 # use a peculiar iteration method to avoid tripping on perl
3721 # refcount bugs in for. also avoids problems with players 3759 # refcount bugs in for. also avoids problems with players
3722 # and maps saved/destroyed asynchronously. 3760 # and maps saved/destroyed asynchronously.
3723 warn "emergency_perl_save: begin player save\n"; 3761 info "emergency_perl_save: begin player save\n";
3724 for my $login (keys %cf::PLAYER) { 3762 for my $login (keys %cf::PLAYER) {
3725 my $pl = $cf::PLAYER{$login} or next; 3763 my $pl = $cf::PLAYER{$login} or next;
3726 $pl->valid or next; 3764 $pl->valid or next;
3727 delete $pl->{unclean_save}; # not strictly necessary, but cannot hurt 3765 delete $pl->{unclean_save}; # not strictly necessary, but cannot hurt
3728 $pl->save; 3766 $pl->save;
3729 } 3767 }
3730 warn "emergency_perl_save: end player save\n"; 3768 info "emergency_perl_save: end player save\n";
3731 3769
3732 warn "emergency_perl_save: begin map save\n"; 3770 info "emergency_perl_save: begin map save\n";
3733 for my $path (keys %cf::MAP) { 3771 for my $path (keys %cf::MAP) {
3734 my $map = $cf::MAP{$path} or next; 3772 my $map = $cf::MAP{$path} or next;
3735 $map->valid or next; 3773 $map->valid or next;
3736 $map->save; 3774 $map->save;
3737 } 3775 }
3738 warn "emergency_perl_save: end map save\n"; 3776 info "emergency_perl_save: end map save\n";
3739 3777
3740 warn "emergency_perl_save: begin database checkpoint\n"; 3778 info "emergency_perl_save: begin database checkpoint\n";
3741 BDB::db_env_txn_checkpoint $DB_ENV; 3779 BDB::db_env_txn_checkpoint $DB_ENV;
3742 warn "emergency_perl_save: end database checkpoint\n"; 3780 info "emergency_perl_save: end database checkpoint\n";
3743 3781
3744 warn "emergency_perl_save: begin write uuid\n"; 3782 info "emergency_perl_save: begin write uuid\n";
3745 write_uuid_sync 1; 3783 write_uuid_sync 1;
3746 warn "emergency_perl_save: end write uuid\n"; 3784 info "emergency_perl_save: end write uuid\n";
3747 }; 3785 };
3748 3786
3749 warn "emergency_perl_save: starting sync()\n"; 3787 info "emergency_perl_save: starting sync()\n";
3750 IO::AIO::aio_sync sub { 3788 IO::AIO::aio_sync sub {
3751 warn "emergency_perl_save: finished sync()\n"; 3789 info "emergency_perl_save: finished sync()\n";
3752 }; 3790 };
3753 3791
3754 warn "emergency_perl_save: leave\n"; 3792 info "emergency_perl_save: leave\n";
3755} 3793}
3756 3794
3757sub post_cleanup { 3795sub post_cleanup {
3758 my ($make_core) = @_; 3796 my ($make_core) = @_;
3759 3797
3760 warn Carp::longmess "post_cleanup backtrace" 3798 error Carp::longmess "post_cleanup backtrace"
3761 if $make_core; 3799 if $make_core;
3762 3800
3763 my $fh = pidfile; 3801 my $fh = pidfile;
3764 unlink $PIDFILE if <$fh> == $$; 3802 unlink $PIDFILE if <$fh> == $$;
3765} 3803}
3789 } 3827 }
3790} 3828}
3791 3829
3792sub do_reload_perl() { 3830sub do_reload_perl() {
3793 # can/must only be called in main 3831 # can/must only be called in main
3794 if ($Coro::current != $Coro::main) { 3832 if (in_main) {
3795 warn "can only reload from main coroutine"; 3833 error "can only reload from main coroutine";
3796 return; 3834 return;
3797 } 3835 }
3798 3836
3799 return if $RELOAD++; 3837 return if $RELOAD++;
3800 3838
3801 my $t1 = AE::time; 3839 my $t1 = AE::time;
3802 3840
3803 while ($RELOAD) { 3841 while ($RELOAD) {
3804 warn "reloading..."; 3842 info "reloading...";
3805 3843
3806 warn "entering sync_job"; 3844 trace "entering sync_job";
3807 3845
3808 cf::sync_job { 3846 cf::sync_job {
3809 cf::write_runtime_sync; # external watchdog should not bark 3847 cf::write_runtime_sync; # external watchdog should not bark
3810 cf::emergency_save; 3848 cf::emergency_save;
3811 cf::write_runtime_sync; # external watchdog should not bark 3849 cf::write_runtime_sync; # external watchdog should not bark
3812 3850
3813 warn "syncing database to disk"; 3851 trace "syncing database to disk";
3814 BDB::db_env_txn_checkpoint $DB_ENV; 3852 BDB::db_env_txn_checkpoint $DB_ENV;
3815 3853
3816 # if anything goes wrong in here, we should simply crash as we already saved 3854 # if anything goes wrong in here, we should simply crash as we already saved
3817 3855
3818 warn "flushing outstanding aio requests"; 3856 trace "flushing outstanding aio requests";
3819 while (IO::AIO::nreqs || BDB::nreqs) { 3857 while (IO::AIO::nreqs || BDB::nreqs) {
3820 Coro::EV::timer_once 0.01; # let the sync_job do it's thing 3858 Coro::EV::timer_once 0.01; # let the sync_job do it's thing
3821 } 3859 }
3822 3860
3823 warn "cancelling all extension coros"; 3861 trace "cancelling all extension coros";
3824 $_->cancel for values %EXT_CORO; 3862 $_->cancel for values %EXT_CORO;
3825 %EXT_CORO = (); 3863 %EXT_CORO = ();
3826 3864
3827 warn "removing commands"; 3865 trace "removing commands";
3828 %COMMAND = (); 3866 %COMMAND = ();
3829 3867
3830 warn "removing ext/exti commands"; 3868 trace "removing ext/exti commands";
3831 %EXTCMD = (); 3869 %EXTCMD = ();
3832 %EXTICMD = (); 3870 %EXTICMD = ();
3833 3871
3834 warn "unloading/nuking all extensions"; 3872 trace "unloading/nuking all extensions";
3835 for my $pkg (@EXTS) { 3873 for my $pkg (@EXTS) {
3836 warn "... unloading $pkg"; 3874 trace "... unloading $pkg";
3837 3875
3838 if (my $cb = $pkg->can ("unload")) { 3876 if (my $cb = $pkg->can ("unload")) {
3839 eval { 3877 eval {
3840 $cb->($pkg); 3878 $cb->($pkg);
3841 1 3879 1
3842 } or warn "$pkg unloaded, but with errors: $@"; 3880 } or error "$pkg unloaded, but with errors: $@";
3843 } 3881 }
3844 3882
3845 warn "... clearing $pkg"; 3883 trace "... clearing $pkg";
3846 clear_package $pkg; 3884 clear_package $pkg;
3847 } 3885 }
3848 3886
3849 warn "unloading all perl modules loaded from $LIBDIR"; 3887 trace "unloading all perl modules loaded from $LIBDIR";
3850 while (my ($k, $v) = each %INC) { 3888 while (my ($k, $v) = each %INC) {
3851 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; 3889 next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/;
3852 3890
3853 warn "... unloading $k"; 3891 trace "... unloading $k";
3854 delete $INC{$k}; 3892 delete $INC{$k};
3855 3893
3856 $k =~ s/\.pm$//; 3894 $k =~ s/\.pm$//;
3857 $k =~ s/\//::/g; 3895 $k =~ s/\//::/g;
3858 3896
3861 } 3899 }
3862 3900
3863 clear_package $k; 3901 clear_package $k;
3864 } 3902 }
3865 3903
3866 warn "getting rid of safe::, as good as possible"; 3904 trace "getting rid of safe::, as good as possible";
3867 clear_package "safe::$_" 3905 clear_package "safe::$_"
3868 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); 3906 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region);
3869 3907
3870 warn "unloading cf.pm \"a bit\""; 3908 trace "unloading cf.pm \"a bit\"";
3871 delete $INC{"cf.pm"}; 3909 delete $INC{"cf.pm"};
3872 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; 3910 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES;
3873 3911
3874 # don't, removes xs symbols, too, 3912 # don't, removes xs symbols, too,
3875 # and global variables created in xs 3913 # and global variables created in xs
3876 #clear_package __PACKAGE__; 3914 #clear_package __PACKAGE__;
3877 3915
3878 warn "unload completed, starting to reload now"; 3916 info "unload completed, starting to reload now";
3879 3917
3880 warn "reloading cf.pm"; 3918 trace "reloading cf.pm";
3881 require cf; 3919 require cf;
3882 cf::_connect_to_perl_1; 3920 cf::_connect_to_perl_1;
3883 3921
3884 warn "loading config and database again"; 3922 trace "loading config and database again";
3885 cf::reload_config; 3923 cf::reload_config;
3886 3924
3887 warn "loading extensions"; 3925 trace "loading extensions";
3888 cf::load_extensions; 3926 cf::load_extensions;
3889 3927
3890 if ($REATTACH_ON_RELOAD) { 3928 if ($REATTACH_ON_RELOAD) {
3891 warn "reattaching attachments to objects/players"; 3929 trace "reattaching attachments to objects/players";
3892 _global_reattach; # objects, sockets 3930 _global_reattach; # objects, sockets
3893 warn "reattaching attachments to maps"; 3931 trace "reattaching attachments to maps";
3894 reattach $_ for values %MAP; 3932 reattach $_ for values %MAP;
3895 warn "reattaching attachments to players"; 3933 trace "reattaching attachments to players";
3896 reattach $_ for values %PLAYER; 3934 reattach $_ for values %PLAYER;
3897 } 3935 }
3898 3936
3899 warn "running post_init jobs"; 3937 trace "running post_init jobs";
3900 (pop @POST_INIT)->(1) while @POST_INIT; 3938 (pop @POST_INIT)->(1) while @POST_INIT;
3901 3939
3902 warn "leaving sync_job"; 3940 trace "leaving sync_job";
3903 3941
3904 1 3942 1
3905 } or do { 3943 } or do {
3906 warn $@; 3944 error $@;
3907 cf::cleanup "error while reloading, exiting."; 3945 cf::cleanup "error while reloading, exiting.";
3908 }; 3946 };
3909 3947
3910 warn "reloaded"; 3948 info "reloaded";
3911 --$RELOAD; 3949 --$RELOAD;
3912 } 3950 }
3913 3951
3914 $t1 = AE::time - $t1; 3952 $t1 = AE::time - $t1;
3915 warn "reload completed in ${t1}s\n"; 3953 info "reload completed in ${t1}s\n";
3916}; 3954};
3917 3955
3918our $RELOAD_WATCHER; # used only during reload 3956our $RELOAD_WATCHER; # used only during reload
3919 3957
3920sub reload_perl() { 3958sub reload_perl() {
3980 if ($NOW >= $NEXT_RUNTIME_WRITE) { 4018 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3981 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; 4019 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
3982 Coro::async_pool { 4020 Coro::async_pool {
3983 $Coro::current->{desc} = "runtime saver"; 4021 $Coro::current->{desc} = "runtime saver";
3984 write_runtime_sync 4022 write_runtime_sync
3985 or warn "ERROR: unable to write runtime file: $!"; 4023 or error "ERROR: unable to write runtime file: $!";
3986 }; 4024 };
3987 } 4025 }
3988 4026
3989 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { 4027 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {
3990 $sig->send; 4028 $sig->send;
3998 4036
3999 if (0) { 4037 if (0) {
4000 if ($NEXT_TICK) { 4038 if ($NEXT_TICK) {
4001 my $jitter = $TICK_START - $NEXT_TICK; 4039 my $jitter = $TICK_START - $NEXT_TICK;
4002 $JITTER = $JITTER * 0.75 + $jitter * 0.25; 4040 $JITTER = $JITTER * 0.75 + $jitter * 0.25;
4003 warn "jitter $JITTER\n";#d# 4041 debug "jitter $JITTER\n";#d#
4004 } 4042 }
4005 } 4043 }
4006} 4044}
4007 4045
4008{ 4046{
4018 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; 4056 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7;
4019 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; 4057 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7;
4020 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT); 4058 $DB_ENV->set_timeout (30, BDB::SET_TXN_TIMEOUT);
4021 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT); 4059 $DB_ENV->set_timeout (30, BDB::SET_LOCK_TIMEOUT);
4022 4060
4061 (Coro::async { # async to keep sync_job from complaining
4023 cf::sync_job { 4062 cf::sync_job {
4024 eval { 4063 eval {
4025 BDB::db_env_open 4064 BDB::db_env_open
4026 $DB_ENV, 4065 $DB_ENV,
4027 $BDBDIR, 4066 $BDBDIR,
4028 BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN 4067 BDB::INIT_LOCK | BDB::INIT_LOG | BDB::INIT_MPOOL | BDB::INIT_TXN
4029 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE, 4068 | BDB::RECOVER | BDB::REGISTER | BDB::USE_ENVIRON | BDB::CREATE,
4030 0666; 4069 0666;
4031 4070
4032 cf::cleanup "db_env_open($BDBDIR): $!" if $!; 4071 cf::cleanup "db_env_open($BDBDIR): $!" if $!;
4072 };
4073
4074 cf::cleanup "db_env_open(db): $@" if $@;
4033 }; 4075 };
4034 4076 })->join;
4035 cf::cleanup "db_env_open(db): $@" if $@;
4036 };
4037 } 4077 }
4038 4078
4039 $BDB_DEADLOCK_WATCHER = EV::periodic 0, 3, 0, sub { 4079 $BDB_DEADLOCK_WATCHER = EV::periodic 0, 3, 0, sub {
4040 BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { }; 4080 BDB::db_env_lock_detect $DB_ENV, 0, BDB::LOCK_DEFAULT, 0, sub { };
4041 }; 4081 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines