]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/LogEvent.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / mds / LogEvent.h
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 #ifndef CEPH_LOGEVENT_H
16 #define CEPH_LOGEVENT_H
17
18 #define EVENT_NEW_ENCODING 0 // indicates that the encoding is versioned
19 #define EVENT_UNUSED 1 // was previously EVENT_STRING
20
21 #define EVENT_SUBTREEMAP 2
22 #define EVENT_EXPORT 3
23 #define EVENT_IMPORTSTART 4
24 #define EVENT_IMPORTFINISH 5
25 #define EVENT_FRAGMENT 6
26
27 #define EVENT_RESETJOURNAL 9
28
29 #define EVENT_SESSION 10
30 #define EVENT_SESSIONS_OLD 11
31 #define EVENT_SESSIONS 12
32
33 #define EVENT_UPDATE 20
34 #define EVENT_SLAVEUPDATE 21
35 #define EVENT_OPEN 22
36 #define EVENT_COMMITTED 23
37 #define EVENT_PURGED 24
38
39 #define EVENT_TABLECLIENT 42
40 #define EVENT_TABLESERVER 43
41
42 #define EVENT_SUBTREEMAP_TEST 50
43 #define EVENT_NOOP 51
44
45
46 #include "include/buffer_fwd.h"
47 #include "include/Context.h"
48 #include "include/utime.h"
49
50 class MDSRank;
51 class LogSegment;
52 class EMetaBlob;
53
54 // generic log event
55 class LogEvent {
56 public:
57 typedef __u32 EventType;
58 friend class MDLog;
59
60 LogEvent() = delete;
61 explicit LogEvent(int t) : _type(t) {}
62 LogEvent(const LogEvent&) = delete;
63 LogEvent& operator=(const LogEvent&) = delete;
64 virtual ~LogEvent() {}
65
66 std::string_view get_type_str() const;
67 static EventType str_to_type(std::string_view str);
68 EventType get_type() const { return _type; }
69 void set_type(EventType t) { _type = t; }
70
71 uint64_t get_start_off() const { return _start_off; }
72 void set_start_off(uint64_t o) { _start_off = o; }
73
74 utime_t get_stamp() const { return stamp; }
75 void set_stamp(utime_t t) { stamp = t; }
76
77 // encoding
78 virtual void encode(bufferlist& bl, uint64_t features) const = 0;
79 virtual void decode(bufferlist::const_iterator &) = 0;
80 static std::unique_ptr<LogEvent> decode_event(bufferlist::const_iterator);
81 virtual void dump(Formatter *f) const = 0;
82
83 void encode_with_header(bufferlist& bl, uint64_t features) {
84 using ceph::encode;
85 encode(EVENT_NEW_ENCODING, bl);
86 ENCODE_START(1, 1, bl)
87 encode(_type, bl);
88 this->encode(bl, features);
89 ENCODE_FINISH(bl);
90 }
91
92 virtual void print(ostream& out) const {
93 out << "event(" << _type << ")";
94 }
95
96 /*** live journal ***/
97 /* update_segment() - adjust any state we need to in the LogSegment
98 */
99 virtual void update_segment() { }
100
101 /*** recovery ***/
102 /* replay() - replay given event. this is idempotent.
103 */
104 virtual void replay(MDSRank *m) { ceph_abort(); }
105
106 /**
107 * If the subclass embeds a MetaBlob, return it here so that
108 * tools can examine metablobs while traversing lists of LogEvent.
109 */
110 virtual EMetaBlob *get_metablob() { return NULL; }
111
112 protected:
113 LogSegment* get_segment() { return _segment; }
114 LogSegment const* get_segment() const { return _segment; }
115
116 utime_t stamp;
117
118 private:
119 static const std::map<std::string, LogEvent::EventType> types;
120
121 static std::unique_ptr<LogEvent> decode_event(bufferlist::const_iterator&, EventType);
122
123 EventType _type = 0;
124 uint64_t _start_off = 0;
125 LogSegment *_segment = nullptr;
126 };
127
128 inline ostream& operator<<(ostream& out, const LogEvent &le) {
129 le.print(out);
130 return out;
131 }
132
133 #endif