]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/LogEvent.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / mds / LogEvent.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include "common/config.h"
16 #include "LogEvent.h"
17
18 #include "MDSRank.h"
19
20 // events i know of
21 #include "events/ESubtreeMap.h"
22 #include "events/EExport.h"
23 #include "events/EImportStart.h"
24 #include "events/EImportFinish.h"
25 #include "events/EFragment.h"
26
27 #include "events/EResetJournal.h"
28 #include "events/ESession.h"
29 #include "events/ESessions.h"
30
31 #include "events/EUpdate.h"
32 #include "events/EPeerUpdate.h"
33 #include "events/EOpen.h"
34 #include "events/ECommitted.h"
35 #include "events/EPurged.h"
36
37 #include "events/ETableClient.h"
38 #include "events/ETableServer.h"
39
40 #include "events/ENoOp.h"
41
42 #define dout_context g_ceph_context
43
44
45 std::unique_ptr<LogEvent> LogEvent::decode_event(bufferlist::const_iterator p)
46 {
47 // parse type, length
48 EventType type;
49 std::unique_ptr<LogEvent> event;
50 using ceph::decode;
51 decode(type, p);
52
53 if (EVENT_NEW_ENCODING == type) {
54 try {
55 DECODE_START(1, p);
56 decode(type, p);
57 event = decode_event(p, type);
58 DECODE_FINISH(p);
59 }
60 catch (const buffer::error &e) {
61 generic_dout(0) << "failed to decode LogEvent (type maybe " << type << ")" << dendl;
62 return NULL;
63 }
64 } else { // we are using classic encoding
65 event = decode_event(p, type);
66 }
67 return event;
68 }
69
70
71 std::string_view LogEvent::get_type_str() const
72 {
73 switch(_type) {
74 case EVENT_SUBTREEMAP: return "SUBTREEMAP";
75 case EVENT_SUBTREEMAP_TEST: return "SUBTREEMAP_TEST";
76 case EVENT_EXPORT: return "EXPORT";
77 case EVENT_IMPORTSTART: return "IMPORTSTART";
78 case EVENT_IMPORTFINISH: return "IMPORTFINISH";
79 case EVENT_FRAGMENT: return "FRAGMENT";
80 case EVENT_RESETJOURNAL: return "RESETJOURNAL";
81 case EVENT_SESSION: return "SESSION";
82 case EVENT_SESSIONS_OLD: return "SESSIONS_OLD";
83 case EVENT_SESSIONS: return "SESSIONS";
84 case EVENT_UPDATE: return "UPDATE";
85 case EVENT_PEERUPDATE: return "PEERUPDATE";
86 case EVENT_OPEN: return "OPEN";
87 case EVENT_COMMITTED: return "COMMITTED";
88 case EVENT_PURGED: return "PURGED";
89 case EVENT_TABLECLIENT: return "TABLECLIENT";
90 case EVENT_TABLESERVER: return "TABLESERVER";
91 case EVENT_NOOP: return "NOOP";
92
93 default:
94 generic_dout(0) << "get_type_str: unknown type " << _type << dendl;
95 return "UNKNOWN";
96 }
97 }
98
99 const std::map<std::string, LogEvent::EventType> LogEvent::types = {
100 {"SUBTREEMAP", EVENT_SUBTREEMAP},
101 {"SUBTREEMAP_TEST", EVENT_SUBTREEMAP_TEST},
102 {"EXPORT", EVENT_EXPORT},
103 {"IMPORTSTART", EVENT_IMPORTSTART},
104 {"IMPORTFINISH", EVENT_IMPORTFINISH},
105 {"FRAGMENT", EVENT_FRAGMENT},
106 {"RESETJOURNAL", EVENT_RESETJOURNAL},
107 {"SESSION", EVENT_SESSION},
108 {"SESSIONS_OLD", EVENT_SESSIONS_OLD},
109 {"SESSIONS", EVENT_SESSIONS},
110 {"UPDATE", EVENT_UPDATE},
111 {"PEERUPDATE", EVENT_PEERUPDATE},
112 {"OPEN", EVENT_OPEN},
113 {"COMMITTED", EVENT_COMMITTED},
114 {"PURGED", EVENT_PURGED},
115 {"TABLECLIENT", EVENT_TABLECLIENT},
116 {"TABLESERVER", EVENT_TABLESERVER},
117 {"NOOP", EVENT_NOOP}
118 };
119
120 /*
121 * Resolve type string to type enum
122 *
123 * Return -1 if not found
124 */
125 LogEvent::EventType LogEvent::str_to_type(std::string_view str)
126 {
127 return LogEvent::types.at(std::string(str));
128 }
129
130
131 std::unique_ptr<LogEvent> LogEvent::decode_event(bufferlist::const_iterator& p, LogEvent::EventType type)
132 {
133 const auto length = p.get_remaining();
134 generic_dout(15) << "decode_log_event type " << type << ", size " << length << dendl;
135
136 // create event
137 std::unique_ptr<LogEvent> le;
138 switch (type) {
139 case EVENT_SUBTREEMAP:
140 le = std::make_unique<ESubtreeMap>();
141 break;
142 case EVENT_SUBTREEMAP_TEST:
143 le = std::make_unique<ESubtreeMap>();
144 le->set_type(type);
145 break;
146 case EVENT_EXPORT:
147 le = std::make_unique<EExport>();
148 break;
149 case EVENT_IMPORTSTART:
150 le = std::make_unique<EImportStart>();
151 break;
152 case EVENT_IMPORTFINISH:
153 le = std::make_unique<EImportFinish>();
154 break;
155 case EVENT_FRAGMENT:
156 le = std::make_unique<EFragment>();
157 break;
158 case EVENT_RESETJOURNAL:
159 le = std::make_unique<EResetJournal>();
160 break;
161 case EVENT_SESSION:
162 le = std::make_unique<ESession>();
163 break;
164 case EVENT_SESSIONS_OLD:
165 {
166 auto e = std::make_unique<ESessions>();
167 e->mark_old_encoding();
168 le = std::move(e);
169 }
170 break;
171 case EVENT_SESSIONS:
172 le = std::make_unique<ESessions>();
173 break;
174 case EVENT_UPDATE:
175 le = std::make_unique<EUpdate>();
176 break;
177 case EVENT_PEERUPDATE:
178 le = std::make_unique<EPeerUpdate>();
179 break;
180 case EVENT_OPEN:
181 le = std::make_unique<EOpen>();
182 break;
183 case EVENT_COMMITTED:
184 le = std::make_unique<ECommitted>();
185 break;
186 case EVENT_PURGED:
187 le = std::make_unique<EPurged>();
188 break;
189 case EVENT_TABLECLIENT:
190 le = std::make_unique<ETableClient>();
191 break;
192 case EVENT_TABLESERVER:
193 le = std::make_unique<ETableServer>();
194 break;
195 case EVENT_NOOP:
196 le = std::make_unique<ENoOp>();
197 break;
198 default:
199 generic_dout(0) << "uh oh, unknown log event type " << type << " length " << length << dendl;
200 return nullptr;
201 }
202
203 // decode
204 try {
205 le->decode(p);
206 }
207 catch (const buffer::error &e) {
208 generic_dout(0) << "failed to decode LogEvent type " << type << dendl;
209 return nullptr;
210 }
211
212 ceph_assert(p.end());
213 return le;
214 }
215