… | |
… | |
48 | our $TICK_WATCHER; |
48 | our $TICK_WATCHER; |
49 | our $AIO_POLL_WATCHER; |
49 | our $AIO_POLL_WATCHER; |
50 | our $WRITE_RUNTIME_WATCHER; |
50 | our $WRITE_RUNTIME_WATCHER; |
51 | our $NEXT_TICK; |
51 | our $NEXT_TICK; |
52 | our $NOW; |
52 | our $NOW; |
|
|
53 | our $USE_FSYNC; # use fsync to write maps - default off |
53 | |
54 | |
54 | our %CFG; |
55 | our %CFG; |
55 | |
56 | |
56 | our $UPTIME; $UPTIME ||= time; |
57 | our $UPTIME; $UPTIME ||= time; |
57 | our $RUNTIME; |
58 | our $RUNTIME; |
… | |
… | |
358 | # 60 allows for the watchdog to kill the server. |
359 | # 60 allows for the watchdog to kill the server. |
359 | |
360 | |
360 | (aio_write $fh, 0, (length $value), $value, 0) <= 0 |
361 | (aio_write $fh, 0, (length $value), $value, 0) <= 0 |
361 | and return; |
362 | and return; |
362 | |
363 | |
|
|
364 | # always fsync - this file is important |
363 | aio_fsync $fh |
365 | aio_fsync $fh |
364 | and return; |
366 | and return; |
365 | |
367 | |
366 | close $fh |
368 | close $fh |
367 | or return; |
369 | or return; |
… | |
… | |
752 | $filename, length $$rdata, scalar @$objs; |
754 | $filename, length $$rdata, scalar @$objs; |
753 | |
755 | |
754 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
756 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
755 | chmod SAVE_MODE, $fh; |
757 | chmod SAVE_MODE, $fh; |
756 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
758 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
757 | aio_fsync $fh; |
759 | aio_fsync $fh if $cf::USE_FSYNC; |
758 | close $fh; |
760 | close $fh; |
759 | |
761 | |
760 | if (@$objs) { |
762 | if (@$objs) { |
761 | if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { |
763 | if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { |
762 | chmod SAVE_MODE, $fh; |
764 | chmod SAVE_MODE, $fh; |
763 | my $data = Storable::nfreeze { version => 1, objs => $objs }; |
765 | my $data = Storable::nfreeze { version => 1, objs => $objs }; |
764 | aio_write $fh, 0, (length $data), $data, 0; |
766 | aio_write $fh, 0, (length $data), $data, 0; |
765 | aio_fsync $fh; |
767 | aio_fsync $fh if $cf::USE_FSYNC; |
766 | close $fh; |
768 | close $fh; |
767 | aio_rename "$filename.pst~", "$filename.pst"; |
769 | aio_rename "$filename.pst~", "$filename.pst"; |
768 | } |
770 | } |
769 | } else { |
771 | } else { |
770 | aio_unlink "$filename.pst"; |
772 | aio_unlink "$filename.pst"; |