]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/LogEvent.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / mds / LogEvent.h
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#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
f67539c2 34#define EVENT_PEERUPDATE 21
7c673cae
FG
35#define EVENT_OPEN 22
36#define EVENT_COMMITTED 23
9f95a23c 37#define EVENT_PURGED 24
7c673cae
FG
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
50class MDSRank;
51class LogSegment;
52class EMetaBlob;
53
54// generic log event
55class LogEvent {
56public:
11fdf7f2 57 typedef __u32 EventType;
9f95a23c 58 friend class MDLog;
7c673cae 59
11fdf7f2
TL
60 LogEvent() = delete;
61 explicit LogEvent(int t) : _type(t) {}
62 LogEvent(const LogEvent&) = delete;
63 LogEvent& operator=(const LogEvent&) = delete;
64 virtual ~LogEvent() {}
7c673cae 65
11fdf7f2
TL
66 std::string_view get_type_str() const;
67 static EventType str_to_type(std::string_view str);
7c673cae
FG
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;
11fdf7f2
TL
79 virtual void decode(bufferlist::const_iterator &) = 0;
80 static std::unique_ptr<LogEvent> decode_event(bufferlist::const_iterator);
7c673cae
FG
81 virtual void dump(Formatter *f) const = 0;
82
83 void encode_with_header(bufferlist& bl, uint64_t features) {
11fdf7f2
TL
84 using ceph::encode;
85 encode(EVENT_NEW_ENCODING, bl);
7c673cae 86 ENCODE_START(1, 1, bl)
11fdf7f2
TL
87 encode(_type, bl);
88 this->encode(bl, features);
7c673cae
FG
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; }
94b18763 111
11fdf7f2 112protected:
11fdf7f2
TL
113 LogSegment* get_segment() { return _segment; }
114 LogSegment const* get_segment() const { return _segment; }
115
9f95a23c
TL
116 utime_t stamp;
117
94b18763
FG
118private:
119 static const std::map<std::string, LogEvent::EventType> types;
11fdf7f2
TL
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;
7c673cae
FG
126};
127
128inline ostream& operator<<(ostream& out, const LogEvent &le) {
129 le.print(out);
130 return out;
131}
132
133#endif