]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_sync_trace.h
e66dde7cf41aa5a02266d32829e43f0246fc9cfd
[ceph.git] / ceph / src / rgw / rgw_sync_trace.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #ifndef CEPH_RGW_SYNC_LOG_H
5 #define CEPH_RGW_SYNC_LOG_H
6
7 #include <atomic>
8
9 #include "common/ceph_mutex.h"
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
44 ceph::mutex lock = ceph::make_mutex("RGWSyncTraceNode::lock");
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
55 boost::circular_buffer<std::string> history;
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:
63 void set_resource_name(const std::string& s) {
64 resource_name = s;
65 }
66
67 const std::string& get_resource_name() {
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
86 const std::string& get_prefix() {
87 return prefix;
88 }
89
90 std::ostream& operator<<(std::ostream& os) {
91 os << to_str();
92 return os;
93 }
94
95 boost::circular_buffer<std::string>& get_history() {
96 return history;
97 }
98
99 bool match(const std::string& search_term, bool search_history);
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
116 std::list<std::array<std::string, 3> > admin_commands;
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();
136 int call(std::string_view command, const cmdmap_t& cmdmap,
137 Formatter *f,
138 std::ostream& ss,
139 bufferlist& out) override;
140 std::string get_active_names();
141 };
142
143
144 #endif