From 17d6a993fc17d533460c5f40f3908c708e057c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 23 May 2024 18:45:17 +0200 Subject: Merging upstream version 18.2.3. Signed-off-by: Daniel Baumann --- src/common/CommandTable.h | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/common/CommandTable.h') diff --git a/src/common/CommandTable.h b/src/common/CommandTable.h index 53218d653..e777d72dc 100644 --- a/src/common/CommandTable.h +++ b/src/common/CommandTable.h @@ -23,6 +23,8 @@ class CommandOp public: ConnectionRef con; ceph_tid_t tid; + // multi_target_id == 0 means single target command + ceph_tid_t multi_target_id; std::vector cmd; ceph::buffer::list inbl; @@ -48,9 +50,11 @@ class CommandOp } } - CommandOp(const ceph_tid_t t) : tid(t), on_finish(nullptr), + CommandOp(const ceph_tid_t t) : tid(t), multi_target_id(0), on_finish(nullptr), outbl(nullptr), outs(nullptr) {} CommandOp() : tid(0), on_finish(nullptr), outbl(nullptr), outs(nullptr) {} + CommandOp(const ceph_tid_t t, const ceph_tid_t multi_id) : tid(t), multi_target_id(multi_id), + on_finish(nullptr), outbl(nullptr), outs(nullptr) {} }; /** @@ -62,23 +66,38 @@ class CommandTable { protected: ceph_tid_t last_tid; + ceph_tid_t last_multi_target_id; + std::map commands; + std::map > multi_targets; public: CommandTable() - : last_tid(0) + : last_tid(0), last_multi_target_id(0) {} ~CommandTable() { ceph_assert(commands.empty()); + for (const auto& pair : multi_targets) { + ceph_assert(pair.second.empty()); + } + } + + ceph_tid_t get_new_multi_target_id() + { + return ++last_multi_target_id; } - T& start_command() + T& start_command(ceph_tid_t multi_id=0) { ceph_tid_t tid = last_tid++; - commands.insert(std::make_pair(tid, T(tid)) ); + commands.insert(std::make_pair(tid, T(tid, multi_id)) ); + + if (multi_id != 0) { + multi_targets[multi_id].insert(tid); + } return commands.at(tid); } @@ -93,6 +112,11 @@ public: return commands.count(tid) > 0; } + std::size_t count_multi_commands(ceph_tid_t multi_id) + { + return multi_targets[multi_id].size(); + } + T& get_command(ceph_tid_t tid) { return commands.at(tid); @@ -100,11 +124,18 @@ public: void erase(ceph_tid_t tid) { + ceph_tid_t multi_id = commands.at(tid).multi_target_id; commands.erase(tid); + multi_targets[multi_id].erase(tid); + + if(count_multi_commands(multi_id) == 0) { + multi_targets.erase(multi_id); + } } void clear() { commands.clear(); + multi_targets.clear(); } }; -- cgit v1.2.3