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