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.534 by root, Thu Apr 29 08:13:51 2010 UTC vs.
Revision 1.535 by root, Thu Apr 29 08:21:28 2010 UTC

3758 # save all maps without fsync, and later call a global sync 3758 # save all maps without fsync, and later call a global sync
3759 # (which in turn might be very very slow) 3759 # (which in turn might be very very slow)
3760 local $USE_FSYNC = 0; 3760 local $USE_FSYNC = 0;
3761 3761
3762 cf::sync_job { 3762 cf::sync_job {
3763 cf::write_runtime_sync; # external watchdog should not bark
3764
3763 # use a peculiar iteration method to avoid tripping on perl 3765 # use a peculiar iteration method to avoid tripping on perl
3764 # refcount bugs in for. also avoids problems with players 3766 # refcount bugs in for. also avoids problems with players
3765 # and maps saved/destroyed asynchronously. 3767 # and maps saved/destroyed asynchronously.
3766 info "emergency_perl_save: begin player save\n"; 3768 info "emergency_perl_save: begin player save\n";
3767 for my $login (keys %cf::PLAYER) { 3769 for my $login (keys %cf::PLAYER) {
3770 delete $pl->{unclean_save}; # not strictly necessary, but cannot hurt 3772 delete $pl->{unclean_save}; # not strictly necessary, but cannot hurt
3771 $pl->save; 3773 $pl->save;
3772 } 3774 }
3773 info "emergency_perl_save: end player save\n"; 3775 info "emergency_perl_save: end player save\n";
3774 3776
3777 cf::write_runtime_sync; # external watchdog should not bark
3778
3775 info "emergency_perl_save: begin map save\n"; 3779 info "emergency_perl_save: begin map save\n";
3776 for my $path (keys %cf::MAP) { 3780 for my $path (keys %cf::MAP) {
3777 my $map = $cf::MAP{$path} or next; 3781 my $map = $cf::MAP{$path} or next;
3778 $map->valid or next; 3782 $map->valid or next;
3779 $map->save; 3783 $map->save;
3780 } 3784 }
3781 info "emergency_perl_save: end map save\n"; 3785 info "emergency_perl_save: end map save\n";
3782 3786
3787 cf::write_runtime_sync; # external watchdog should not bark
3788
3783 info "emergency_perl_save: begin database checkpoint\n"; 3789 info "emergency_perl_save: begin database checkpoint\n";
3784 BDB::db_env_txn_checkpoint $DB_ENV; 3790 BDB::db_env_txn_checkpoint $DB_ENV;
3785 info "emergency_perl_save: end database checkpoint\n"; 3791 info "emergency_perl_save: end database checkpoint\n";
3786 3792
3787 info "emergency_perl_save: begin write uuid\n"; 3793 info "emergency_perl_save: begin write uuid\n";
3788 write_uuid_sync 1; 3794 write_uuid_sync 1;
3789 info "emergency_perl_save: end write uuid\n"; 3795 info "emergency_perl_save: end write uuid\n";
3790 };
3791 3796
3797 cf::write_runtime_sync; # external watchdog should not bark
3798
3799 trace "emergency_perl_save: syncing database to disk";
3800 BDB::db_env_txn_checkpoint $DB_ENV;
3801
3792 info "emergency_perl_save: starting sync()\n"; 3802 info "emergency_perl_save: starting sync()\n";
3793 IO::AIO::aio_sync sub { 3803 IO::AIO::aio_sync sub {
3794 info "emergency_perl_save: finished sync()\n"; 3804 info "emergency_perl_save: finished sync()\n";
3805 };
3806
3807 cf::write_runtime_sync; # external watchdog should not bark
3808
3809 trace "emergency_perl_save: flushing outstanding aio requests";
3810 while (IO::AIO::nreqs || BDB::nreqs) {
3811 Coro::EV::timer_once 0.01; # let the sync_job do it's thing
3812 }
3813
3814 cf::write_runtime_sync; # external watchdog should not bark
3795 }; 3815 };
3796 3816
3797 info "emergency_perl_save: leave\n"; 3817 info "emergency_perl_save: leave\n";
3798} 3818}
3799 3819
3800sub post_cleanup { 3820sub post_cleanup {
3801 my ($make_core) = @_; 3821 my ($make_core) = @_;
3822
3823 IO::AIO::flush;
3824
3825 IO::AIO::flush;
3802 3826
3803 error Carp::longmess "post_cleanup backtrace" 3827 error Carp::longmess "post_cleanup backtrace"
3804 if $make_core; 3828 if $make_core;
3805 3829
3806 my $fh = pidfile; 3830 my $fh = pidfile;
3847 info "reloading..."; 3871 info "reloading...";
3848 3872
3849 trace "entering sync_job"; 3873 trace "entering sync_job";
3850 3874
3851 cf::sync_job { 3875 cf::sync_job {
3852 cf::write_runtime_sync; # external watchdog should not bark
3853 cf::emergency_save; 3876 cf::emergency_save;
3854 cf::write_runtime_sync; # external watchdog should not bark
3855
3856 trace "syncing database to disk";
3857 BDB::db_env_txn_checkpoint $DB_ENV;
3858
3859 # if anything goes wrong in here, we should simply crash as we already saved
3860
3861 trace "flushing outstanding aio requests";
3862 while (IO::AIO::nreqs || BDB::nreqs) {
3863 Coro::EV::timer_once 0.01; # let the sync_job do it's thing
3864 }
3865 3877
3866 trace "cancelling all extension coros"; 3878 trace "cancelling all extension coros";
3867 $_->cancel for values %EXT_CORO; 3879 $_->cancel for values %EXT_CORO;
3868 %EXT_CORO = (); 3880 %EXT_CORO = ();
3869 3881

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines