summaryrefslogtreecommitdiffstats
path: root/src/mds/LogEvent.cc
blob: 3df8f327c6c9ca019999e107604b4a880e73ec41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */

#include "common/config.h"
#include "LogEvent.h"

#include "MDSRank.h"

// events i know of
#include "events/ESubtreeMap.h"
#include "events/EExport.h"
#include "events/EImportStart.h"
#include "events/EImportFinish.h"
#include "events/EFragment.h"

#include "events/EResetJournal.h"
#include "events/ESession.h"
#include "events/ESessions.h"

#include "events/EUpdate.h"
#include "events/EPeerUpdate.h"
#include "events/EOpen.h"
#include "events/ECommitted.h"
#include "events/EPurged.h"

#include "events/ETableClient.h"
#include "events/ETableServer.h"

#include "events/ENoOp.h"

#define dout_context g_ceph_context


std::unique_ptr<LogEvent> LogEvent::decode_event(bufferlist::const_iterator p)
{
  // parse type, length
  EventType type;
  std::unique_ptr<LogEvent> event;
  using ceph::decode;
  decode(type, p);

  if (EVENT_NEW_ENCODING == type) {
    try {
      DECODE_START(1, p);
      decode(type, p);
      event = decode_event(p, type);
      DECODE_FINISH(p);
    }
    catch (const buffer::error &e) {
      generic_dout(0) << "failed to decode LogEvent (type maybe " << type << ")" << dendl;
      return NULL;
    }
  } else { // we are using classic encoding
    event = decode_event(p, type);
  }
  return event;
}


std::string_view LogEvent::get_type_str() const
{
  switch(_type) {
  case EVENT_SUBTREEMAP: return "SUBTREEMAP";
  case EVENT_SUBTREEMAP_TEST: return "SUBTREEMAP_TEST";
  case EVENT_EXPORT: return "EXPORT";
  case EVENT_IMPORTSTART: return "IMPORTSTART";
  case EVENT_IMPORTFINISH: return "IMPORTFINISH";
  case EVENT_FRAGMENT: return "FRAGMENT";
  case EVENT_RESETJOURNAL: return "RESETJOURNAL";
  case EVENT_SESSION: return "SESSION";
  case EVENT_SESSIONS_OLD: return "SESSIONS_OLD";
  case EVENT_SESSIONS: return "SESSIONS";
  case EVENT_UPDATE: return "UPDATE";
  case EVENT_PEERUPDATE: return "PEERUPDATE";
  case EVENT_OPEN: return "OPEN";
  case EVENT_COMMITTED: return "COMMITTED";
  case EVENT_PURGED: return "PURGED";
  case EVENT_TABLECLIENT: return "TABLECLIENT";
  case EVENT_TABLESERVER: return "TABLESERVER";
  case EVENT_NOOP: return "NOOP";

  default:
    generic_dout(0) << "get_type_str: unknown type " << _type << dendl;
    return "UNKNOWN";
  }
}

const std::map<std::string, LogEvent::EventType> LogEvent::types = {
  {"SUBTREEMAP", EVENT_SUBTREEMAP},
  {"SUBTREEMAP_TEST", EVENT_SUBTREEMAP_TEST},
  {"EXPORT", EVENT_EXPORT},
  {"IMPORTSTART", EVENT_IMPORTSTART},
  {"IMPORTFINISH", EVENT_IMPORTFINISH},
  {"FRAGMENT", EVENT_FRAGMENT},
  {"RESETJOURNAL", EVENT_RESETJOURNAL},
  {"SESSION", EVENT_SESSION},
  {"SESSIONS_OLD", EVENT_SESSIONS_OLD},
  {"SESSIONS", EVENT_SESSIONS},
  {"UPDATE", EVENT_UPDATE},
  {"PEERUPDATE", EVENT_PEERUPDATE},
  {"OPEN", EVENT_OPEN},
  {"COMMITTED", EVENT_COMMITTED},
  {"PURGED", EVENT_PURGED},
  {"TABLECLIENT", EVENT_TABLECLIENT},
  {"TABLESERVER", EVENT_TABLESERVER},
  {"NOOP", EVENT_NOOP}
};

/*
 * Resolve type string to type enum
 *
 * Return -1 if not found
 */
LogEvent::EventType LogEvent::str_to_type(std::string_view str)
{
  return LogEvent::types.at(std::string(str));
}


std::unique_ptr<LogEvent> LogEvent::decode_event(bufferlist::const_iterator& p, LogEvent::EventType type)
{
  const auto length = p.get_remaining();
  generic_dout(15) << "decode_log_event type " << type << ", size " << length << dendl;
  
  // create event
  std::unique_ptr<LogEvent> le;
  switch (type) {
  case EVENT_SUBTREEMAP:
    le = std::make_unique<ESubtreeMap>();
    break;
  case EVENT_SUBTREEMAP_TEST: 
    le = std::make_unique<ESubtreeMap>();
    le->set_type(type);
    break;
  case EVENT_EXPORT:
    le = std::make_unique<EExport>();
    break;
  case EVENT_IMPORTSTART:
    le = std::make_unique<EImportStart>();
    break;
  case EVENT_IMPORTFINISH:
    le = std::make_unique<EImportFinish>();
    break;
  case EVENT_FRAGMENT:
    le = std::make_unique<EFragment>();
    break;
  case EVENT_RESETJOURNAL:
    le = std::make_unique<EResetJournal>();
    break;
  case EVENT_SESSION:
    le = std::make_unique<ESession>();
    break;
  case EVENT_SESSIONS_OLD:
    {
      auto e = std::make_unique<ESessions>();
      e->mark_old_encoding();
      le = std::move(e);
    }
    break;
  case EVENT_SESSIONS:
    le = std::make_unique<ESessions>();
    break;
  case EVENT_UPDATE:
    le = std::make_unique<EUpdate>();
    break;
  case EVENT_PEERUPDATE:
    le = std::make_unique<EPeerUpdate>();
    break;
  case EVENT_OPEN:
    le = std::make_unique<EOpen>();
    break;
  case EVENT_COMMITTED:
    le = std::make_unique<ECommitted>();
    break;
  case EVENT_PURGED:
    le = std::make_unique<EPurged>();
    break;
  case EVENT_TABLECLIENT:
    le = std::make_unique<ETableClient>();
    break;
  case EVENT_TABLESERVER:
    le = std::make_unique<ETableServer>();
    break;
  case EVENT_NOOP:
    le = std::make_unique<ENoOp>();
    break;
  default:
    generic_dout(0) << "uh oh, unknown log event type " << type << " length " << length << dendl;
    return nullptr;
  }

  // decode
  try {
    le->decode(p);
  }
  catch (const buffer::error &e) {
    generic_dout(0) << "failed to decode LogEvent type " << type << dendl;
    return nullptr;
  }

  ceph_assert(p.end());
  return le;
}