refactor(metadata_v2): clean up timing in walk_data_order

This commit is contained in:
Marcus Holland-Moritz 2024-08-20 10:40:50 +02:00
parent 1c5f345181
commit 3d5532085c

View File

@ -1472,6 +1472,9 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
entries.reserve(meta_.inodes().size()); entries.reserve(meta_.inodes().size());
} }
{
auto tv = LOG_TIMED_VERBOSE;
{ {
auto td = LOG_TIMED_DEBUG; auto td = LOG_TIMED_DEBUG;
@ -1479,22 +1482,33 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
entries.emplace_back(self_index, parent_index); entries.emplace_back(self_index, parent_index);
}); });
td << "collected " << entries.size() << " entries";
}
if (auto dep = meta_.dir_entries()) { if (auto dep = meta_.dir_entries()) {
// 1. partition non-files / files // 1. partition non-files / files
auto mid = decltype(entries)::iterator mid;
std::stable_partition(entries.begin(), entries.end(), {
auto td = LOG_TIMED_DEBUG;
mid = std::stable_partition(entries.begin(), entries.end(),
[de = *dep, beg = file_inode_offset_, [de = *dep, beg = file_inode_offset_,
end = dev_inode_offset_](auto const& e) { end = dev_inode_offset_](auto const& e) {
int ino = de[e.first].inode_num(); int ino = de[e.first].inode_num();
return ino < beg or ino >= end; return ino < beg or ino >= end;
}); });
td << "partitioned " << entries.size() << " entries into "
<< std::distance(entries.begin(), mid) << " non-files and "
<< std::distance(mid, entries.end()) << " files";
}
// 2. order files by chunk block number // 2. order files by chunk block number
// 2a. build mapping inode -> first chunk block // 2a. build mapping inode -> first chunk block
std::vector<uint32_t> first_chunk_block; std::vector<uint32_t> first_chunk_block;
{ {
auto td2 = LOG_TIMED_DEBUG; auto td = LOG_TIMED_DEBUG;
first_chunk_block.resize(dep->size()); first_chunk_block.resize(dep->size());
@ -1509,12 +1523,12 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
} }
} }
td2 << "prepare first chunk block vector"; td << "prepare first chunk block vector";
} }
// 2b. sort second partition accordingly // 2b. sort second partition accordingly
{ {
auto td2 = LOG_TIMED_DEBUG; auto td = LOG_TIMED_DEBUG;
std::stable_sort(mid, entries.end(), std::stable_sort(mid, entries.end(),
[&first_chunk_block](auto const& a, auto const& b) { [&first_chunk_block](auto const& a, auto const& b) {
@ -1522,7 +1536,7 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
first_chunk_block[b.first]; first_chunk_block[b.first];
}); });
td2 << "final sort of " << std::distance(mid, entries.end()) td << "final sort of " << std::distance(mid, entries.end())
<< " file entries"; << " file entries";
} }
} else { } else {
@ -1533,7 +1547,7 @@ void metadata_<LoggerPolicy>::walk_data_order_impl(
}); });
} }
td << "ordered " << entries.size() << " entries by file data order"; tv << "ordered " << entries.size() << " entries by file data order";
} }
for (auto [self_index, parent_index] : entries) { for (auto [self_index, parent_index] : entries) {