Skip to content

Commit 88274f1

Browse files
rock-gitchuandew
authored andcommitted
[fix][mds] Fixup known issues.
1 parent ae44e43 commit 88274f1

File tree

7 files changed

+303
-30
lines changed

7 files changed

+303
-30
lines changed

src/mds/background/gc.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static IntRange CalBlockIndex(uint64_t block_size, uint64_t chunk_offset, const
9191
void CleanDelSliceTask::Run() {
9292
auto status = CleanDelSlice();
9393
if (!status.ok()) {
94-
DINGO_LOG(ERROR) << fmt::format("[gc.delslice] clean deleted slice fail, {}", status.error_str());
94+
DINGO_LOG(ERROR) << fmt::format("[gc.delslice.{}] clean deleted slice fail, {}", ino_, status.error_str());
9595
}
9696

9797
// forget task
@@ -112,7 +112,7 @@ Status CleanDelSliceTask::CleanDelSlice() {
112112
cache::BlockKey block_key(slice.fs_id(), slice.ino(), slice.slice_id(), block_index,
113113
slice_range.compaction_version());
114114

115-
DINGO_LOG(INFO) << fmt::format("[gc.delslice] delete block key({}).", block_key.StoreKey());
115+
DINGO_LOG(INFO) << fmt::format("[gc.delslice.{}] delete block key({}).", ino_, block_key.StoreKey());
116116
keys.push_back(block_key.StoreKey());
117117
}
118118
}
@@ -140,15 +140,15 @@ Status CleanDelSliceTask::CleanDelSlice() {
140140
return status;
141141
}
142142

143-
DINGO_LOG(INFO) << fmt::format("[gc.delslice] clean slice finish, slice({}).", slice_id_trace);
143+
DINGO_LOG(INFO) << fmt::format("[gc.delslice.{}] clean slice finish, slice({}).", ino_, slice_id_trace);
144144

145145
return Status::OK();
146146
}
147147

148148
void CleanDelFileTask::Run() {
149149
auto status = CleanDelFile(attr_);
150150
if (!status.ok()) {
151-
DINGO_LOG(ERROR) << fmt::format("[gc.delfile] clean delfile fail, status({}).", status.error_str());
151+
DINGO_LOG(ERROR) << fmt::format("[gc.delfile.{}] clean delfile fail, status({}).", attr_.ino(), status.error_str());
152152
}
153153

154154
// forget task
@@ -176,7 +176,7 @@ static Status GetChunks(OperationProcessorSPtr operation_processor, uint32_t fs_
176176
}
177177

178178
Status CleanDelFileTask::CleanDelFile(const AttrEntry& attr) {
179-
DINGO_LOG(INFO) << fmt::format("[gc.delfile] clean delfile, ino({}) nlink({}) len({}) version({}).", attr.ino(),
179+
DINGO_LOG(INFO) << fmt::format("[gc.delfile.{}] clean delfile, nlink({}) len({}) version({}).", attr.ino(),
180180
attr.nlink(), attr.length(), attr.version());
181181
// get file chunks
182182
std::vector<ChunkEntry> chunks;
@@ -194,7 +194,7 @@ Status CleanDelFileTask::CleanDelFile(const AttrEntry& attr) {
194194
for (uint32_t block_index = range.start; block_index < range.end; ++block_index) {
195195
cache::BlockKey block_key(attr.fs_id(), attr.ino(), slice.id(), block_index, slice.compaction_version());
196196

197-
DINGO_LOG(INFO) << fmt::format("[gc.delfile] delete block key({}).", block_key.StoreKey());
197+
DINGO_LOG(INFO) << fmt::format("[gc.delfile.{}] delete block key({}).", attr.ino(), block_key.StoreKey());
198198
keys.push_back(block_key.StoreKey());
199199
}
200200
}
@@ -216,7 +216,7 @@ Status CleanDelFileTask::CleanDelFile(const AttrEntry& attr) {
216216
return status;
217217
}
218218

219-
DINGO_LOG(INFO) << fmt::format("[gc.delfile] clean file({}/{}) finish.", attr.fs_id(), attr.ino());
219+
DINGO_LOG(INFO) << fmt::format("[gc.delfile.{}] clean file({}/{}) finish.", attr.ino(), attr.fs_id(), attr.ino());
220220

221221
return Status::OK();
222222
}
@@ -335,7 +335,7 @@ Status GcProcessor::ManualCleanDelSlice(Trace& trace, uint32_t fs_id, Ino ino, u
335335

336336
ScanDelSliceOperation operation(
337337
trace, fs_id, ino, chunk_index, [&](const std::string& key, const std::string& value) -> bool {
338-
auto task = CleanDelSliceTask::New(operation_processor_, block_accessor, nullptr, key, value);
338+
auto task = CleanDelSliceTask::New(operation_processor_, block_accessor, nullptr, ino, key, value);
339339
auto status = task->CleanDelSlice();
340340
if (!status.ok()) {
341341
LOG(ERROR) << fmt::format("[gc.delslice] clean delfile fail, status({}).", status.error_str());
@@ -525,7 +525,7 @@ void GcProcessor::ScanDelSlice(const FsInfoEntry& fs_info) {
525525
}
526526

527527
task_memo_->Remember(key);
528-
if (!Execute(ino, CleanDelSliceTask::New(operation_processor_, block_accessor, task_memo_, key, value))) {
528+
if (!Execute(ino, CleanDelSliceTask::New(operation_processor_, block_accessor, task_memo_, ino, key, value))) {
529529
task_memo_->Forget(key);
530530
return false;
531531
}

src/mds/background/gc.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,19 @@ class TaskMemo {
9797
class CleanDelSliceTask : public TaskRunnable {
9898
public:
9999
CleanDelSliceTask(OperationProcessorSPtr operation_processor, blockaccess::BlockAccesserSPtr block_accessor,
100-
TaskMemoSPtr task_memo, const std::string& key, const std::string& value)
100+
TaskMemoSPtr task_memo, Ino ino, const std::string& key, const std::string& value)
101101
: operation_processor_(operation_processor),
102102
data_accessor_(block_accessor),
103+
ino_(ino),
103104
key_(key),
104105
value_(value),
105106
task_memo_(task_memo) {}
106107
~CleanDelSliceTask() override = default;
107108

108109
static CleanDelSliceTaskSPtr New(OperationProcessorSPtr operation_processor,
109-
blockaccess::BlockAccesserSPtr block_accessor, TaskMemoSPtr task_memo,
110+
blockaccess::BlockAccesserSPtr block_accessor, TaskMemoSPtr task_memo, Ino ino,
110111
const std::string& key, const std::string& value) {
111-
return std::make_shared<CleanDelSliceTask>(operation_processor, block_accessor, task_memo, key, value);
112+
return std::make_shared<CleanDelSliceTask>(operation_processor, block_accessor, task_memo, ino, key, value);
112113
}
113114
std::string Type() override { return "CLEAN_DELETED_SLICE"; }
114115

@@ -119,6 +120,8 @@ class CleanDelSliceTask : public TaskRunnable {
119120

120121
Status CleanDelSlice();
121122

123+
const Ino ino_;
124+
122125
const std::string key_;
123126
const std::string value_;
124127

src/mds/filesystem/filesystem.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,12 +1944,11 @@ Status FileSystem::WriteSlice(Context& ctx, Ino, Ino ino, const std::vector<Delt
19441944
if (CompactChunkOperation::MaybeCompact(fs_info, ino, attr.length(), chunk)) {
19451945
DINGO_LOG(INFO) << fmt::format("[fs.{}] trigger compact chunk({}) for ino({}).", fs_id_, chunk.index(), ino);
19461946

1947-
auto post_handler = [&](OperationSPtr operation) {
1947+
auto post_handler = [this](OperationSPtr operation) {
19481948
auto origin_operation = std::dynamic_pointer_cast<CompactChunkOperation>(operation);
19491949
auto& result = origin_operation->GetResult();
1950-
auto& attr = result.attr;
19511950
// update chunk cache
1952-
chunk_cache_.PutIf(attr.ino(), std::move(result.effected_chunk));
1951+
chunk_cache_.PutIf(origin_operation->GetIno(), std::move(result.effected_chunk));
19531952
};
19541953
operation_processor_->AsyncRun(CompactChunkOperation::New(fs_info, ino, chunk.index(), attr.length()),
19551954
post_handler);

src/mds/filesystem/store_operation.cc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ std::vector<std::string> UpsertChunkOperation::PrefetchKey() {
893893
}
894894

895895
Status UpsertChunkOperation::RunInBatch(TxnUPtr& txn, AttrEntry& attr, const std::vector<KeyValue>& prefetch_kvs) {
896+
result_.effected_chunks.clear();
897+
896898
uint64_t prev_length = attr.length();
897899
for (const auto& delta_slices : delta_slices_) {
898900
ChunkEntry chunk;
@@ -1580,17 +1582,13 @@ TrashSliceList CompactChunkOperation::GenTrashSlices(const FsInfoEntry& fs_info,
15801582
}
15811583

15821584
size_t out_of_length_count = trash_slices.slices_size();
1583-
DINGO_LOG(INFO) << fmt::format("[operation.{}.{}] out-of-file-length trash slices count({}).", fs_id, ino,
1584-
out_of_length_count);
15851585

15861586
// 2. complete overlapped slices
15871587
// |______4________| slices
15881588
// |__1__|___2___|____3_____| slices
15891589
// |________________________| chunk
15901590
// slice-2 is complete overlapped by slice-4
15911591
// sort by offset
1592-
std::stable_sort(chunk_copy.slices.begin(), chunk_copy.slices.end(), // NOLINT
1593-
[](const Slice& a, const Slice& b) { return a.offset < b.offset; });
15941592

15951593
// get offset ranges
15961594
std::set<uint64_t> offsets;
@@ -1653,8 +1651,6 @@ TrashSliceList CompactChunkOperation::GenTrashSlices(const FsInfoEntry& fs_info,
16531651
}
16541652

16551653
size_t complete_overlapped_count = trash_slices.slices_size() - out_of_length_count;
1656-
DINGO_LOG(INFO) << fmt::format("[operation.{}.{}] complete overlapped trash slice count({}).", fs_id, ino,
1657-
complete_overlapped_count);
16581654

16591655
// 3. partial overlapped slices
16601656
// |______4________| slices
@@ -1720,16 +1716,18 @@ TrashSliceList CompactChunkOperation::GenTrashSlices(const FsInfoEntry& fs_info,
17201716
// }
17211717

17221718
size_t partial_overlapped_count = trash_slices.slices_size() - out_of_length_count - complete_overlapped_count;
1723-
DINGO_LOG(INFO) << fmt::format("[operation.{}.{}] partial overlapped trash slice count({}) total({})", fs_id, ino,
1724-
partial_overlapped_count, trash_slices.slices_size());
17251719

1726-
if (FLAGS_mds_compact_chunk_detail_log_enable) {
1727-
for (const auto& slice : trash_slices.slices()) {
1728-
DINGO_LOG(INFO) << fmt::format("[operation.{}.{}] trash slice, chunk_index({}) slice_id({}), is_partial({}).",
1729-
fs_id, ino, slice.chunk_index(), slice.slice_id(), slice.is_partial());
1730-
}
1720+
std::string slice_id_str;
1721+
slice_id_str.reserve(trash_slices.slices_size() * 9);
1722+
for (const auto& slice : trash_slices.slices()) {
1723+
slice_id_str += std::to_string(slice.slice_id());
1724+
slice_id_str += ",";
17311725
}
17321726

1727+
DINGO_LOG(INFO) << fmt::format("[operation.{}.{}.{}] trash slice, count({}/{}/{}/{}) slice_ids({}).", fs_id, ino,
1728+
chunk.index(), out_of_length_count, complete_overlapped_count,
1729+
partial_overlapped_count, trash_slices.slices_size(), slice_id_str);
1730+
17331731
return trash_slices;
17341732
}
17351733

@@ -1812,14 +1810,14 @@ Status CompactChunkOperation::Run(TxnUPtr& txn) {
18121810
// reduce compact frequency
18131811
if (!is_force_ && chunk.last_compaction_time_ms() + FLAGS_mds_compact_chunk_interval_ms >
18141812
static_cast<uint64_t>(Helper::TimestampMs())) {
1815-
return Status::OK();
1813+
return Status(pb::error::ENOT_MATCH, "not match compact condition");
18161814
}
18171815

18181816
auto trash_slice_list = CompactChunk(txn, fs_id, ino_, file_length_, chunk);
18191817
if (!trash_slice_list.slices().empty()) {
18201818
chunk.set_version(chunk.version() + 1);
18211819
chunk.set_last_compaction_time_ms(Helper::TimestampMs());
1822-
txn->Put(MetaCodec::EncodeChunkKey(fs_id, ino_, chunk.index()), MetaCodec::EncodeChunkValue(chunk));
1820+
txn->Put(key, MetaCodec::EncodeChunkValue(chunk));
18231821

18241822
result_.trash_slice_list = std::move(trash_slice_list);
18251823
result_.effected_chunk = std::move(chunk);

src/mds/filesystem/store_operation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,11 @@ class CompactChunkOperation : public Operation {
10101010

10111011
static bool MaybeCompact(const FsInfoEntry& fs_info, Ino ino, uint64_t file_length, const ChunkEntry& chunk);
10121012

1013+
static TrashSliceList TestGenTrashSlices(const FsInfoEntry& fs_info, Ino ino, uint64_t file_length,
1014+
const ChunkEntry& chunk) {
1015+
return GenTrashSlices(fs_info, ino, file_length, chunk);
1016+
}
1017+
10131018
private:
10141019
static TrashSliceList GenTrashSlices(const FsInfoEntry& fs_info, Ino ino, uint64_t file_length,
10151020
const ChunkEntry& chunk);

0 commit comments

Comments
 (0)