| 699 | |
| 700 | |
| 701 | Future<shared_ptr<FetcherProcess::Cache::Entry>> |
| 702 | FetcherProcess::reserveCacheSpace( |
| 703 | const Try<Bytes>& requestedSpace, |
| 704 | const shared_ptr<FetcherProcess::Cache::Entry>& entry) |
| 705 | { |
| 706 | if (requestedSpace.isError()) { |
| 707 | // Let anyone waiting on this future know that we've |
| 708 | // failed to download and they should bypass the cache |
| 709 | // (any new requests will try again). |
| 710 | entry->fail(); |
| 711 | cache.remove(entry); |
| 712 | |
| 713 | return Failure("Could not determine size of cache file for '" + |
| 714 | entry->key + "' with error: " + |
| 715 | requestedSpace.error()); |
| 716 | } |
| 717 | |
| 718 | Try<Nothing> reservation = cache.reserve(requestedSpace.get()); |
| 719 | |
| 720 | if (reservation.isError()) { |
| 721 | // Let anyone waiting on this future know that we've |
| 722 | // failed to download and they should bypass the cache |
| 723 | // (any new requests will try again). |
| 724 | entry->fail(); |
| 725 | cache.remove(entry); |
| 726 | |
| 727 | return Failure("Failed to reserve space in the cache: " + |
| 728 | reservation.error()); |
| 729 | } |
| 730 | |
| 731 | VLOG(1) << "Claiming fetcher cache space for: " << entry->key; |
| 732 | |
| 733 | cache.claimSpace(requestedSpace.get()); |
| 734 | |
| 735 | // NOTE: We must set the entry size only when we are also claiming |
| 736 | // the space! Other functions rely on this dependency (see |
| 737 | // Cache::remove()). |
| 738 | entry->size = requestedSpace.get(); |
| 739 | |
| 740 | return entry; |
| 741 | } |
| 742 | |
| 743 | |
| 744 | Future<Nothing> FetcherProcess::run( |