]>
Commit | Line | Data |
---|---|---|
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 | |
34 | #define EVENT_SLAVEUPDATE 21 | |
35 | #define EVENT_OPEN 22 | |
36 | #define EVENT_COMMITTED 23 | |
37 | ||
38 | #define EVENT_TABLECLIENT 42 | |
39 | #define EVENT_TABLESERVER 43 | |
40 | ||
41 | #define EVENT_SUBTREEMAP_TEST 50 | |
42 | #define EVENT_NOOP 51 | |
43 | ||
44 | ||
45 | #include "include/buffer_fwd.h" | |
46 | #include "include/Context.h" | |
47 | #include "include/utime.h" | |
48 | ||
49 | class MDSRank; | |
50 | class LogSegment; | |
51 | class EMetaBlob; | |
52 | ||
53 | // generic log event | |
54 | class LogEvent { | |
55 | public: | |
56 | typedef __u32 EventType; | |
57 | ||
58 | private: | |
59 | EventType _type; | |
60 | uint64_t _start_off; | |
61 | static LogEvent *decode_event(bufferlist& bl, bufferlist::iterator& p, EventType type); | |
62 | ||
63 | protected: | |
64 | utime_t stamp; | |
65 | ||
66 | friend class MDLog; | |
67 | ||
68 | public: | |
69 | LogSegment *_segment; | |
70 | ||
71 | explicit LogEvent(int t) | |
72 | : _type(t), _start_off(0), _segment(0) { } | |
73 | virtual ~LogEvent() { } | |
74 | ||
75 | string get_type_str() const; | |
76 | static EventType str_to_type(std::string const &str); | |
77 | EventType get_type() const { return _type; } | |
78 | void set_type(EventType t) { _type = t; } | |
79 | ||
80 | uint64_t get_start_off() const { return _start_off; } | |
81 | void set_start_off(uint64_t o) { _start_off = o; } | |
82 | ||
83 | utime_t get_stamp() const { return stamp; } | |
84 | void set_stamp(utime_t t) { stamp = t; } | |
85 | ||
86 | // encoding | |
87 | virtual void encode(bufferlist& bl, uint64_t features) const = 0; | |
88 | virtual void decode(bufferlist::iterator &bl) = 0; | |
89 | static LogEvent *decode(bufferlist &bl); | |
90 | virtual void dump(Formatter *f) const = 0; | |
91 | ||
92 | void encode_with_header(bufferlist& bl, uint64_t features) { | |
93 | ::encode(EVENT_NEW_ENCODING, bl); | |
94 | ENCODE_START(1, 1, bl) | |
95 | ::encode(_type, bl); | |
96 | encode(bl, features); | |
97 | ENCODE_FINISH(bl); | |
98 | } | |
99 | ||
100 | virtual void print(ostream& out) const { | |
101 | out << "event(" << _type << ")"; | |
102 | } | |
103 | ||
104 | /*** live journal ***/ | |
105 | /* update_segment() - adjust any state we need to in the LogSegment | |
106 | */ | |
107 | virtual void update_segment() { } | |
108 | ||
109 | /*** recovery ***/ | |
110 | /* replay() - replay given event. this is idempotent. | |
111 | */ | |
112 | virtual void replay(MDSRank *m) { ceph_abort(); } | |
113 | ||
114 | /** | |
115 | * If the subclass embeds a MetaBlob, return it here so that | |
116 | * tools can examine metablobs while traversing lists of LogEvent. | |
117 | */ | |
118 | virtual EMetaBlob *get_metablob() { return NULL; } | |
119 | }; | |
120 | ||
121 | inline ostream& operator<<(ostream& out, const LogEvent &le) { | |
122 | le.print(out); | |
123 | return out; | |
124 | } | |
125 | ||
126 | #endif |