]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 TL |
3 | |
4 | #ifndef CEPH_RGW_SYNC_LOG_H | |
5 | #define CEPH_RGW_SYNC_LOG_H | |
6 | ||
7 | #include <atomic> | |
8 | ||
9f95a23c | 9 | #include "common/ceph_mutex.h" |
11fdf7f2 TL |
10 | #include "common/shunique_lock.h" |
11 | #include "common/admin_socket.h" | |
12 | ||
13 | #include <set> | |
14 | #include <ostream> | |
15 | #include <string> | |
16 | #include <shared_mutex> | |
17 | #include <boost/circular_buffer.hpp> | |
18 | ||
19 | #define SSTR(o) ({ \ | |
20 | std::stringstream ss; \ | |
21 | ss << o; \ | |
22 | ss.str(); \ | |
23 | }) | |
24 | ||
25 | #define RGW_SNS_FLAG_ACTIVE 1 | |
26 | #define RGW_SNS_FLAG_ERROR 2 | |
27 | ||
28 | class RGWRados; | |
29 | class RGWSyncTraceManager; | |
30 | class RGWSyncTraceNode; | |
31 | class RGWSyncTraceServiceMapThread; | |
32 | ||
33 | using RGWSyncTraceNodeRef = std::shared_ptr<RGWSyncTraceNode>; | |
34 | ||
35 | class RGWSyncTraceNode final { | |
36 | friend class RGWSyncTraceManager; | |
37 | ||
38 | CephContext *cct; | |
39 | RGWSyncTraceNodeRef parent; | |
40 | ||
41 | uint16_t state{0}; | |
42 | std::string status; | |
43 | ||
9f95a23c | 44 | ceph::mutex lock = ceph::make_mutex("RGWSyncTraceNode::lock"); |
11fdf7f2 TL |
45 | |
46 | std::string type; | |
47 | std::string id; | |
48 | ||
49 | std::string prefix; | |
50 | ||
51 | std::string resource_name; | |
52 | ||
53 | uint64_t handle; | |
54 | ||
20effc67 | 55 | boost::circular_buffer<std::string> history; |
11fdf7f2 TL |
56 | |
57 | // private constructor, create with RGWSyncTraceManager::add_node() | |
58 | RGWSyncTraceNode(CephContext *_cct, uint64_t _handle, | |
59 | const RGWSyncTraceNodeRef& _parent, | |
60 | const std::string& _type, const std::string& _id); | |
61 | ||
62 | public: | |
20effc67 | 63 | void set_resource_name(const std::string& s) { |
11fdf7f2 TL |
64 | resource_name = s; |
65 | } | |
66 | ||
20effc67 | 67 | const std::string& get_resource_name() { |
11fdf7f2 TL |
68 | return resource_name; |
69 | } | |
70 | ||
71 | void set_flag(uint16_t s) { | |
72 | state |= s; | |
73 | } | |
74 | void unset_flag(uint16_t s) { | |
75 | state &= ~s; | |
76 | } | |
77 | bool test_flags(uint16_t f) { | |
78 | return (state & f) == f; | |
79 | } | |
80 | void log(int level, const std::string& s); | |
81 | ||
82 | std::string to_str() { | |
83 | return prefix + " " + status; | |
84 | } | |
85 | ||
20effc67 | 86 | const std::string& get_prefix() { |
11fdf7f2 TL |
87 | return prefix; |
88 | } | |
89 | ||
90 | std::ostream& operator<<(std::ostream& os) { | |
91 | os << to_str(); | |
92 | return os; | |
93 | } | |
94 | ||
20effc67 | 95 | boost::circular_buffer<std::string>& get_history() { |
11fdf7f2 TL |
96 | return history; |
97 | } | |
98 | ||
20effc67 | 99 | bool match(const std::string& search_term, bool search_history); |
11fdf7f2 TL |
100 | }; |
101 | ||
102 | class RGWSyncTraceManager : public AdminSocketHook { | |
103 | friend class RGWSyncTraceNode; | |
104 | ||
105 | mutable std::shared_timed_mutex lock; | |
106 | using shunique_lock = ceph::shunique_lock<decltype(lock)>; | |
107 | ||
108 | CephContext *cct; | |
109 | RGWSyncTraceServiceMapThread *service_map_thread{nullptr}; | |
110 | ||
111 | std::map<uint64_t, RGWSyncTraceNodeRef> nodes; | |
112 | boost::circular_buffer<RGWSyncTraceNodeRef> complete_nodes; | |
113 | ||
114 | std::atomic<uint64_t> count = { 0 }; | |
115 | ||
20effc67 | 116 | std::list<std::array<std::string, 3> > admin_commands; |
11fdf7f2 TL |
117 | |
118 | uint64_t alloc_handle() { | |
119 | return ++count; | |
120 | } | |
121 | void finish_node(RGWSyncTraceNode *node); | |
122 | ||
123 | public: | |
124 | RGWSyncTraceManager(CephContext *_cct, int max_lru) : cct(_cct), complete_nodes(max_lru) {} | |
125 | ~RGWSyncTraceManager(); | |
126 | ||
127 | void init(RGWRados *store); | |
128 | ||
129 | const RGWSyncTraceNodeRef root_node; | |
130 | ||
131 | RGWSyncTraceNodeRef add_node(const RGWSyncTraceNodeRef& parent, | |
132 | const std::string& type, | |
133 | const std::string& id = ""); | |
134 | ||
135 | int hook_to_admin_command(); | |
9f95a23c TL |
136 | int call(std::string_view command, const cmdmap_t& cmdmap, |
137 | Formatter *f, | |
138 | std::ostream& ss, | |
139 | bufferlist& out) override; | |
20effc67 | 140 | std::string get_active_names(); |
11fdf7f2 TL |
141 | }; |
142 | ||
143 | ||
144 | #endif |