1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #ifndef CEPH_RGW_SYNC_LOG_H
5 #define CEPH_RGW_SYNC_LOG_H
9 #include "common/ceph_mutex.h"
10 #include "common/shunique_lock.h"
11 #include "common/admin_socket.h"
16 #include <shared_mutex>
17 #include <boost/circular_buffer.hpp>
20 std::stringstream ss; \
25 #define RGW_SNS_FLAG_ACTIVE 1
26 #define RGW_SNS_FLAG_ERROR 2
29 class RGWSyncTraceManager
;
30 class RGWSyncTraceNode
;
31 class RGWSyncTraceServiceMapThread
;
33 using RGWSyncTraceNodeRef
= std::shared_ptr
<RGWSyncTraceNode
>;
35 class RGWSyncTraceNode final
{
36 friend class RGWSyncTraceManager
;
39 RGWSyncTraceNodeRef parent
;
44 ceph::mutex lock
= ceph::make_mutex("RGWSyncTraceNode::lock");
51 std::string resource_name
;
55 boost::circular_buffer
<std::string
> history
;
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
);
63 void set_resource_name(const std::string
& s
) {
67 const std::string
& get_resource_name() {
71 void set_flag(uint16_t s
) {
74 void unset_flag(uint16_t s
) {
77 bool test_flags(uint16_t f
) {
78 return (state
& f
) == f
;
80 void log(int level
, const std::string
& s
);
82 std::string
to_str() {
83 return prefix
+ " " + status
;
86 const std::string
& get_prefix() {
90 std::ostream
& operator<<(std::ostream
& os
) {
95 boost::circular_buffer
<std::string
>& get_history() {
99 bool match(const std::string
& search_term
, bool search_history
);
102 class RGWSyncTraceManager
: public AdminSocketHook
{
103 friend class RGWSyncTraceNode
;
105 mutable std::shared_timed_mutex lock
;
106 using shunique_lock
= ceph::shunique_lock
<decltype(lock
)>;
109 RGWSyncTraceServiceMapThread
*service_map_thread
{nullptr};
111 std::map
<uint64_t, RGWSyncTraceNodeRef
> nodes
;
112 boost::circular_buffer
<RGWSyncTraceNodeRef
> complete_nodes
;
114 std::atomic
<uint64_t> count
= { 0 };
116 std::list
<std::array
<std::string
, 3> > admin_commands
;
118 uint64_t alloc_handle() {
121 void finish_node(RGWSyncTraceNode
*node
);
124 RGWSyncTraceManager(CephContext
*_cct
, int max_lru
) : cct(_cct
), complete_nodes(max_lru
) {}
125 ~RGWSyncTraceManager();
127 void init(RGWRados
*store
);
129 const RGWSyncTraceNodeRef root_node
;
131 RGWSyncTraceNodeRef
add_node(const RGWSyncTraceNodeRef
& parent
,
132 const std::string
& type
,
133 const std::string
& id
= "");
135 int hook_to_admin_command();
136 int call(std::string_view command
, const cmdmap_t
& cmdmap
,
139 bufferlist
& out
) override
;
140 std::string
get_active_names();