]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/LogEvent.cc
update sources to v12.2.5
[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
44LogEvent *LogEvent::decode(bufferlist& bl)
45{
46 // parse type, length
47 bufferlist::iterator p = bl.begin();
48 EventType type;
49 LogEvent *event = NULL;
50 ::decode(type, p);
51
52 if (EVENT_NEW_ENCODING == type) {
53 try {
54 DECODE_START(1, p);
55 ::decode(type, p);
56 event = decode_event(bl, p, type);
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
64 event = decode_event(bl, p, type);
65 }
66 return event;
67}
68
69
70std::string LogEvent::get_type_str() const
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 */
94b18763 122LogEvent::EventType LogEvent::str_to_type(boost::string_view str)
7c673cae 123{
94b18763 124 return LogEvent::types.at(std::string(str));
7c673cae
FG
125}
126
127
128LogEvent *LogEvent::decode_event(bufferlist& bl, bufferlist::iterator& p, LogEvent::EventType type)
129{
130 int length = bl.length() - p.get_off();
131 generic_dout(15) << "decode_log_event type " << type << ", size " << length << dendl;
132
133 // create event
134 LogEvent *le;
135 switch (type) {
136 case EVENT_SUBTREEMAP: le = new ESubtreeMap; break;
137 case EVENT_SUBTREEMAP_TEST:
138 le = new ESubtreeMap;
139 le->set_type(type);
140 break;
141 case EVENT_EXPORT: le = new EExport; break;
142 case EVENT_IMPORTSTART: le = new EImportStart; break;
143 case EVENT_IMPORTFINISH: le = new EImportFinish; break;
144 case EVENT_FRAGMENT: le = new EFragment; break;
145
146 case EVENT_RESETJOURNAL: le = new EResetJournal; break;
147
148 case EVENT_SESSION: le = new ESession; break;
149 case EVENT_SESSIONS_OLD: le = new ESessions; (static_cast<ESessions *>(le))->mark_old_encoding(); break;
150 case EVENT_SESSIONS: le = new ESessions; break;
151
152 case EVENT_UPDATE: le = new EUpdate; break;
153 case EVENT_SLAVEUPDATE: le = new ESlaveUpdate; break;
154 case EVENT_OPEN: le = new EOpen; break;
155 case EVENT_COMMITTED: le = new ECommitted; break;
156
157 case EVENT_TABLECLIENT: le = new ETableClient; break;
158 case EVENT_TABLESERVER: le = new ETableServer; break;
159
160 case EVENT_NOOP: le = new ENoOp; break;
161
162 default:
163 generic_dout(0) << "uh oh, unknown log event type " << type << " length " << length << dendl;
164 return NULL;
165 }
166
167 // decode
168 try {
169 le->decode(p);
170 }
171 catch (const buffer::error &e) {
172 generic_dout(0) << "failed to decode LogEvent type " << type << dendl;
173 delete le;
174 return NULL;
175 }
176
177 assert(p.end());
178 return le;
179}
180