MCPcopy Create free account
hub / github.com/ElementsProject/elements / DeleteObsoleteFiles

Method DeleteObsoleteFiles

src/leveldb/db/db_impl.cc:223–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223void DBImpl::DeleteObsoleteFiles() {
224 mutex_.AssertHeld();
225
226 if (!bg_error_.ok()) {
227 // After a background error, we don't know whether a new version may
228 // or may not have been committed, so we cannot safely garbage collect.
229 return;
230 }
231
232 // Make a set of all of the live files
233 std::set<uint64_t> live = pending_outputs_;
234 versions_->AddLiveFiles(&live);
235
236 std::vector<std::string> filenames;
237 env_->GetChildren(dbname_, &filenames); // Ignoring errors on purpose
238 uint64_t number;
239 FileType type;
240 std::vector<std::string> files_to_delete;
241 for (std::string& filename : filenames) {
242 if (ParseFileName(filename, &number, &type)) {
243 bool keep = true;
244 switch (type) {
245 case kLogFile:
246 keep = ((number >= versions_->LogNumber()) ||
247 (number == versions_->PrevLogNumber()));
248 break;
249 case kDescriptorFile:
250 // Keep my manifest file, and any newer incarnations'
251 // (in case there is a race that allows other incarnations)
252 keep = (number >= versions_->ManifestFileNumber());
253 break;
254 case kTableFile:
255 keep = (live.find(number) != live.end());
256 break;
257 case kTempFile:
258 // Any temp files that are currently being written to must
259 // be recorded in pending_outputs_, which is inserted into "live"
260 keep = (live.find(number) != live.end());
261 break;
262 case kCurrentFile:
263 case kDBLockFile:
264 case kInfoLogFile:
265 keep = true;
266 break;
267 }
268
269 if (!keep) {
270 files_to_delete.push_back(std::move(filename));
271 if (type == kTableFile) {
272 table_cache_->Evict(number);
273 }
274 Log(options_.info_log, "Delete type=%d #%lld\n", static_cast<int>(type),
275 static_cast<unsigned long long>(number));
276 }
277 }
278 }
279
280 // While deleting all files unblock other threads. All files being deleted

Callers 1

OpenMethod · 0.80

Calls 14

ParseFileNameFunction · 0.85
LogFunction · 0.85
AddLiveFilesMethod · 0.80
LogNumberMethod · 0.80
PrevLogNumberMethod · 0.80
ManifestFileNumberMethod · 0.80
findMethod · 0.80
EvictMethod · 0.80
UnlockMethod · 0.80
LockMethod · 0.80
GetChildrenMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected