]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/LogEvent.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / mds / LogEvent.cc
CommitLineData
7c673cae
FG
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/ESlaveUpdate.h"
33#include "events/EOpen.h"
34#include "events/ECommitted.h"
35
36#include "events/ETableClient.h"
37#include "events/ETableServer.h"
38
39#include "events/ENoOp.h"
40
41#define dout_context g_ceph_context
42
43
11fdf7f2 44std::unique_ptr<LogEvent> LogEvent::decode_event(bufferlist::const_iterator p)
7c673cae
FG
45{
46 // parse type, length
7c673cae 47 EventType type;
11fdf7f2
TL
48 std::unique_ptr<LogEvent> event;
49 using ceph::decode;
50 decode(type, p);
7c673cae
FG
51
52 if (EVENT_NEW_ENCODING == type) {
53 try {
54 DECODE_START(1, p);
11fdf7f2
TL
55 decode(type, p);
56 event = decode_event(p, type);
7c673cae
FG
57 DECODE_FINISH(p);
58 }
59 catch (const buffer::error &e) {
60 generic_dout(0) << "failed to decode LogEvent (type maybe " << type << ")" << dendl;
61 return NULL;
62 }
63 } else { // we are using classic encoding
11fdf7f2 64 event = decode_event(p, type);
7c673cae
FG
65 }
66 return event;
67}
68
69
11fdf7f2 70std::string_view LogEvent::get_type_str() const
7c673cae
FG
71{
72 switch(_type) {
73 case EVENT_SUBTREEMAP: return "SUBTREEMAP";
74 case EVENT_SUBTREEMAP_TEST: return "SUBTREEMAP_TEST";
75 case EVENT_EXPORT: return "EXPORT";
76 case EVENT_IMPORTSTART: return "IMPORTSTART";
77 case EVENT_IMPORTFINISH: return "IMPORTFINISH";
78 case EVENT_FRAGMENT: return "FRAGMENT";
79 case EVENT_RESETJOURNAL: return "RESETJOURNAL";
80 case EVENT_SESSION: return "SESSION";
81 case EVENT_SESSIONS_OLD: return "SESSIONS_OLD";
82 case EVENT_SESSIONS: return "SESSIONS";
83 case EVENT_UPDATE: return "UPDATE";
84 case EVENT_SLAVEUPDATE: return "SLAVEUPDATE";
85 case EVENT_OPEN: return "OPEN";
86 case EVENT_COMMITTED: return "COMMITTED";
87 case EVENT_TABLECLIENT: return "TABLECLIENT";
88 case EVENT_TABLESERVER: return "TABLESERVER";
89 case EVENT_NOOP: return "NOOP";
90
91 default:
92 generic_dout(0) << "get_type_str: unknown type " << _type << dendl;
93 return "UNKNOWN";
94 }
95}
96
94b18763
FG
97const std::map<std::string, LogEvent::EventType> LogEvent::types = {
98 {"SUBTREEMAP", EVENT_SUBTREEMAP},
99 {"SUBTREEMAP_TEST", EVENT_SUBTREEMAP_TEST},
100 {"EXPORT", EVENT_EXPORT},
101 {"IMPORTSTART", EVENT_IMPORTSTART},
102 {"IMPORTFINISH", EVENT_IMPORTFINISH},
103 {"FRAGMENT", EVENT_FRAGMENT},
104 {"RESETJOURNAL", EVENT_RESETJOURNAL},
105 {"SESSION", EVENT_SESSION},
106 {"SESSIONS_OLD", EVENT_SESSIONS_OLD},
107 {"SESSIONS", EVENT_SESSIONS},
108 {"UPDATE", EVENT_UPDATE},
109 {"SLAVEUPDATE", EVENT_SLAVEUPDATE},
110 {"OPEN", EVENT_OPEN},
111 {"COMMITTED", EVENT_COMMITTED},
112 {"TABLECLIENT", EVENT_TABLECLIENT},
113 {"TABLESERVER", EVENT_TABLESERVER},
114 {"NOOP", EVENT_NOOP}
115};
7c673cae
FG
116
117/*
118 * Resolve type string to type enum
119 *
120 * Return -1 if not found
121 */
11fdf7f2 122LogEvent::EventType LogEvent::str_to_type(std::string_view str)
7c673cae 123{
94b18763 124 return LogEvent::types.at(std::string(str));
7c673cae
FG
125}
126
127
11fdf7f2 128std::unique_ptr<LogEvent> LogEvent::decode_event(bufferlist::const_iterator& p, LogEvent::EventType type)
7c673cae 129{
11fdf7f2 130 const auto length = p.get_remaining();
7c673cae
FG
131 generic_dout(15) << "decode_log_event type " << type << ", size " << length << dendl;
132
133 // create event
11fdf7f2 134 std::unique_ptr<LogEvent> le;
7c673cae 135 switch (type) {
11fdf7f2
TL
136 case EVENT_SUBTREEMAP:
137 le = std::make_unique<ESubtreeMap>();
138 break;
7c673cae 139 case EVENT_SUBTREEMAP_TEST:
11fdf7f2 140 le = std::make_unique<ESubtreeMap>();
7c673cae
FG
141 le->set_type(type);
142 break;
11fdf7f2
TL
143 case EVENT_EXPORT:
144 le = std::make_unique<EExport>();
145 break;
146 case EVENT_IMPORTSTART:
147 le = std::make_unique<EImportStart>();
148 break;
149 case EVENT_IMPORTFINISH:
150 le = std::make_unique<EImportFinish>();
151 break;
152 case EVENT_FRAGMENT:
153 le = std::make_unique<EFragment>();
154 break;
155 case EVENT_RESETJOURNAL:
156 le = std::make_unique<EResetJournal>();
157 break;
158 case EVENT_SESSION:
159 le = std::make_unique<ESession>();
160 break;
161 case EVENT_SESSIONS_OLD:
162 {
163 auto e = std::make_unique<ESessions>();
164 e->mark_old_encoding();
165 le = std::move(e);
166 }
167 break;
168 case EVENT_SESSIONS:
169 le = std::make_unique<ESessions>();
170 break;
171 case EVENT_UPDATE:
172 le = std::make_unique<EUpdate>();
173 break;
174 case EVENT_SLAVEUPDATE:
175 le = std::make_unique<ESlaveUpdate>();
176 break;
177 case EVENT_OPEN:
178 le = std::make_unique<EOpen>();
179 break;
180 case EVENT_COMMITTED:
181 le = std::make_unique<ECommitted>();
182 break;
183 case EVENT_TABLECLIENT:
184 le = std::make_unique<ETableClient>();
185 break;
186 case EVENT_TABLESERVER:
187 le = std::make_unique<ETableServer>();
188 break;
189 case EVENT_NOOP:
190 le = std::make_unique<ENoOp>();
191 break;
7c673cae
FG
192 default:
193 generic_dout(0) << "uh oh, unknown log event type " << type << " length " << length << dendl;
11fdf7f2 194 return nullptr;
7c673cae
FG
195 }
196
197 // decode
198 try {
199 le->decode(p);
200 }
201 catch (const buffer::error &e) {
202 generic_dout(0) << "failed to decode LogEvent type " << type << dendl;
11fdf7f2 203 return nullptr;
7c673cae
FG
204 }
205
11fdf7f2 206 ceph_assert(p.end());
7c673cae
FG
207 return le;
208}
209