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.415 by root, Thu Apr 10 15:35:16 2008 UTC vs.
Revision 1.417 by root, Fri Apr 11 14:09:57 2008 UTC

3404 cf::cleanup "SIG$signal"; 3404 cf::cleanup "SIG$signal";
3405 }; 3405 };
3406 } 3406 }
3407} 3407}
3408 3408
3409sub write_runtime { 3409sub write_runtime_sync {
3410 my $runtime = "$LOCALDIR/runtime"; 3410 my $runtime = "$LOCALDIR/runtime";
3411 3411
3412 # first touch the runtime file to show we are still running: 3412 # first touch the runtime file to show we are still running:
3413 # the fsync below can take a very very long time. 3413 # the fsync below can take a very very long time.
3414 3414
3440 and return; 3440 and return;
3441 3441
3442 warn "runtime file written.\n"; 3442 warn "runtime file written.\n";
3443 3443
3444 1 3444 1
3445}
3446
3447our $uuid_lock;
3448our $uuid_skip;
3449
3450sub write_uuid_sync($) {
3451 $uuid_skip ||= $_[0];
3452
3453 return if $uuid_lock;
3454 local $uuid_lock = 1;
3455
3456 my $uuid = "$LOCALDIR/uuid";
3457
3458 my $fh = aio_open "$uuid~", O_WRONLY | O_CREAT, 0644
3459 or return;
3460
3461 my $value = uuid_str $uuid_skip + uuid_seq uuid_cur;
3462 $uuid_skip = 0;
3463
3464 (aio_write $fh, 0, (length $value), $value, 0) <= 0
3465 and return;
3466
3467 # always fsync - this file is important
3468 aio_fsync $fh
3469 and return;
3470
3471 close $fh
3472 or return;
3473
3474 aio_rename "$uuid~", $uuid
3475 and return;
3476
3477 warn "uuid file written ($value).\n";
3478
3479 1
3480
3481}
3482
3483sub write_uuid($$) {
3484 my ($skip, $sync) = @_;
3485
3486 $sync ? write_uuid_sync $skip
3487 : async { write_uuid_sync $skip };
3445} 3488}
3446 3489
3447sub emergency_save() { 3490sub emergency_save() {
3448 my $freeze_guard = cf::freeze_mainloop; 3491 my $freeze_guard = cf::freeze_mainloop;
3449 3492
3471 warn "end emergency map save\n"; 3514 warn "end emergency map save\n";
3472 3515
3473 warn "begin emergency database checkpoint\n"; 3516 warn "begin emergency database checkpoint\n";
3474 BDB::db_env_txn_checkpoint $DB_ENV; 3517 BDB::db_env_txn_checkpoint $DB_ENV;
3475 warn "end emergency database checkpoint\n"; 3518 warn "end emergency database checkpoint\n";
3519
3520 warn "begin write uuid\n";
3521 write_uuid_sync 1;
3522 warn "end write uuid\n";
3476 }; 3523 };
3477 3524
3478 warn "leave emergency perl save\n"; 3525 warn "leave emergency perl save\n";
3479} 3526}
3480 3527
3495 warn "reloading..."; 3542 warn "reloading...";
3496 3543
3497 warn "entering sync_job"; 3544 warn "entering sync_job";
3498 3545
3499 cf::sync_job { 3546 cf::sync_job {
3500 cf::write_runtime; # external watchdog should not bark 3547 cf::write_runtime_sync; # external watchdog should not bark
3501 cf::emergency_save; 3548 cf::emergency_save;
3502 cf::write_runtime; # external watchdog should not bark 3549 cf::write_runtime_sync; # external watchdog should not bark
3503 3550
3504 warn "syncing database to disk"; 3551 warn "syncing database to disk";
3505 BDB::db_env_txn_checkpoint $DB_ENV; 3552 BDB::db_env_txn_checkpoint $DB_ENV;
3506 3553
3507 # if anything goes wrong in here, we should simply crash as we already saved 3554 # if anything goes wrong in here, we should simply crash as we already saved
3662 3709
3663 if ($NOW >= $NEXT_RUNTIME_WRITE) { 3710 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3664 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.; 3711 $NEXT_RUNTIME_WRITE = List::Util::max $NEXT_RUNTIME_WRITE + 10, $NOW + 5.;
3665 Coro::async_pool { 3712 Coro::async_pool {
3666 $Coro::current->{desc} = "runtime saver"; 3713 $Coro::current->{desc} = "runtime saver";
3667 write_runtime 3714 write_runtime_sync
3668 or warn "ERROR: unable to write runtime file: $!"; 3715 or warn "ERROR: unable to write runtime file: $!";
3669 }; 3716 };
3670 } 3717 }
3671 3718
3672 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) { 3719 if (my $sig = shift @WAIT_FOR_TICK_BEGIN) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines