We are removing an entry if: (1) We failed to determine its prospective cache file size. (2) We failed to download it when invoking the mesos-fetcher. (3) We're evicting it to make room for another entry. (4) We failed to validate the cache file. In (1) and (2) the contract is that we'll have failed the entry's future before we call remove, so the entry's future should no longer be pending. In
| 1108 | // no new download conflicts with the manipulation of any pre-existing |
| 1109 | // cache content. |
| 1110 | Try<Nothing> FetcherProcess::Cache::remove( |
| 1111 | const shared_ptr<Cache::Entry>& entry) |
| 1112 | { |
| 1113 | VLOG(1) << "Removing cache entry '" << entry->key |
| 1114 | << "' with filename: " << entry->filename; |
| 1115 | |
| 1116 | CHECK(!entry->completion().isPending()); |
| 1117 | |
| 1118 | CHECK(contains(entry)); |
| 1119 | |
| 1120 | table.erase(entry->key); |
| 1121 | lruSortedEntries.remove(entry); |
| 1122 | |
| 1123 | // We may or may not have started downloading. The download may or may |
| 1124 | // not have been partial. In any case, clean up whatever is there. |
| 1125 | if (os::exists(entry->path().string())) { |
| 1126 | Try<Nothing> rm = os::rm(entry->path().string()); |
| 1127 | if (rm.isError()) { |
| 1128 | return Error("Could not delete fetcher cache file '" + |
| 1129 | entry->path().string() + "' with error: " + rm.error() + |
| 1130 | " for entry '" + entry->key + |
| 1131 | "', leaking cache space: " + stringify(entry->size)); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | // NOTE: There is an assumption that if and only if 'entry->size > 0' |
| 1136 | // then we've claimed cache space for this entry! This currently only |
| 1137 | // gets set in reserveCacheSpace(). |
| 1138 | if (entry->size > 0) { |
| 1139 | releaseSpace(entry->size); |
| 1140 | |
| 1141 | entry->size = 0; |
| 1142 | } |
| 1143 | |
| 1144 | return Nothing(); |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | // Select LRU cache entries for cache eviction. |