| 391 | |
| 392 | |
| 393 | Future<Nothing> LogStorageProcess::_truncate() |
| 394 | { |
| 395 | // Determine the minimum necessary position for all the snapshots. |
| 396 | Option<Log::Position> minimum = None(); |
| 397 | |
| 398 | foreachvalue (const Snapshot& snapshot, snapshots) { |
| 399 | minimum = min(minimum, snapshot.position); |
| 400 | } |
| 401 | |
| 402 | // TODO(benh): It's possible that the minimum position we've found |
| 403 | // will leave a lot of "unnecessary" entries in the log (e.g., a |
| 404 | // snapshot that has been overwritten at a later position). In this |
| 405 | // circumstance we should "compact/defrag" the log by writing/moving |
| 406 | // snapshots to the end of the log first applying any diffs as |
| 407 | // necessary. |
| 408 | |
| 409 | CHECK_SOME(truncated); |
| 410 | |
| 411 | if (minimum.isSome() && minimum.get() > truncated.get()) { |
| 412 | return writer.truncate(minimum.get()) |
| 413 | .then(defer(self(), &Self::__truncate, minimum.get(), lambda::_1)); |
| 414 | |
| 415 | // NOTE: Any failure from Log::Writer::truncate doesn't propagate |
| 416 | // since the expectation is any subsequent Log::Writer::append |
| 417 | // would cause a failure. Furthermore, if the failure was |
| 418 | // temporary any subsequent Log::Writer::truncate should rectify a |
| 419 | // "missing" truncation. |
| 420 | } |
| 421 | |
| 422 | return Nothing(); |
| 423 | } |
| 424 | |
| 425 | |
| 426 | Future<Nothing> LogStorageProcess::__truncate( |