… | |
… | |
349 | my $runtime = cf::localdir . "/runtime"; |
349 | my $runtime = cf::localdir . "/runtime"; |
350 | |
350 | |
351 | my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 |
351 | my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 |
352 | or return; |
352 | or return; |
353 | |
353 | |
|
|
354 | my $value = $cf::RUNTIME + 90 + 10; |
354 | my $value = $cf::RUNTIME + 1 + 10; # 10 is the runtime save interval, for a monotonic clock |
355 | # 10 is the runtime save interval, for a monotonic clock |
|
|
356 | # 60 allows for the watchdog to kill the server. |
|
|
357 | |
355 | (aio_write $fh, 0, (length $value), $value, 0) <= 0 |
358 | (aio_write $fh, 0, (length $value), $value, 0) <= 0 |
356 | and return; |
359 | and return; |
357 | |
360 | |
358 | aio_fsync $fh |
361 | aio_fsync $fh |
359 | and return; |
362 | and return; |
… | |
… | |
1339 | |
1342 | |
1340 | $map->load_header |
1343 | $map->load_header |
1341 | or return; |
1344 | or return; |
1342 | |
1345 | |
1343 | if ($map->should_reset) { |
1346 | if ($map->should_reset) { |
|
|
1347 | # doing this can freeze the server in a sync job, obviously |
1344 | $cf::WAIT_FOR_TICK->wait; |
1348 | #$cf::WAIT_FOR_TICK->wait; |
1345 | $map->reset; |
1349 | $map->reset; |
1346 | undef $guard; |
1350 | undef $guard; |
1347 | $map = find $path |
1351 | $map = find $path |
1348 | or return; |
1352 | or return; |
1349 | } |
1353 | } |
… | |
… | |
1456 | |
1460 | |
1457 | undef $MAP_PREFETCH{$path}; |
1461 | undef $MAP_PREFETCH{$path}; |
1458 | $MAP_PREFETCHER ||= cf::async { |
1462 | $MAP_PREFETCHER ||= cf::async { |
1459 | while (%MAP_PREFETCH) { |
1463 | while (%MAP_PREFETCH) { |
1460 | for my $path (keys %MAP_PREFETCH) { |
1464 | for my $path (keys %MAP_PREFETCH) { |
1461 | warn "prefetching $path...\n";#d# |
|
|
1462 | my $map = find $path |
1465 | my $map = find $path |
1463 | or next; |
1466 | or next; |
1464 | $map->load; |
1467 | $map->load; |
1465 | |
1468 | |
1466 | delete $MAP_PREFETCH{$path}; |
1469 | delete $MAP_PREFETCH{$path}; |
… | |
… | |
2477 | |
2480 | |
2478 | $WRITE_RUNTIME_WATCHER = Event->timer ( |
2481 | $WRITE_RUNTIME_WATCHER = Event->timer ( |
2479 | data => WF_AUTOCANCEL, |
2482 | data => WF_AUTOCANCEL, |
2480 | after => 1, |
2483 | after => 1, |
2481 | interval => 10, |
2484 | interval => 10, |
|
|
2485 | prio => 6, # keep it lowest so it acts like a watchdog |
2482 | cb => Coro::unblock_sub { |
2486 | cb => Coro::unblock_sub { |
2483 | write_runtime |
2487 | write_runtime |
2484 | or warn "ERROR: unable to write runtime file: $!"; |
2488 | or warn "ERROR: unable to write runtime file: $!"; |
2485 | }, |
2489 | }, |
2486 | ); |
2490 | ); |