Skip to content

Commit 4ce58d9

Browse files
committed
fs: rebuild zone lifetime while mount
Signed-off-by: Yu Wang <ywang_wnlo@qq.com>
1 parent b04ca0c commit 4ce58d9

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

fs/fs_zenfs.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ IOStatus ZenFS::Repair() {
333333
return IOStatus::OK();
334334
}
335335

336+
void ZenFS::RebuildZoneLifeTime() {
337+
std::map<std::string, std::shared_ptr<ZoneFile>>::iterator it;
338+
for (it = files_.begin(); it != files_.end(); it++) {
339+
std::shared_ptr<ZoneFile> zFile = it->second;
340+
std::vector<ZoneExtent*> extents = zFile->GetExtents();
341+
Env::WriteLifeTimeHint file_lifetime = zFile->GetWriteLifeTimeHint();
342+
for (const auto* ext : extents) {
343+
Zone* zone = ext->zone_;
344+
if (zone->lifetime_ < file_lifetime) zone->lifetime_ = file_lifetime;
345+
}
346+
}
347+
}
348+
336349
std::string ZenFS::FormatPathLexically(fs::path filepath) {
337350
fs::path ret = fs::path("/") / filepath.lexically_normal();
338351
return ret.string();
@@ -1471,6 +1484,8 @@ Status ZenFS::Mount(bool readonly) {
14711484
}
14721485
}
14731486

1487+
RebuildZoneLifeTime();
1488+
14741489
Info(logger_, "Superblock sequence %d", (int)superblock_->GetSeq());
14751490
Info(logger_, "Finish threshold %u", superblock_->GetFinishTreshold());
14761491
Info(logger_, "Filesystem mount OK");

fs/fs_zenfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ class ZenFS : public FileSystemWrapper {
252252

253253
IOStatus Repair();
254254

255+
void RebuildZoneLifeTime();
256+
255257
/* Must hold files_mtx_ */
256258
IOStatus DeleteDirRecursiveNoLock(const std::string& d,
257259
const IOOptions& options,

0 commit comments

Comments
 (0)