]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/journal/cls_journal_types.h
update sources to v12.1.0
[ceph.git] / ceph / src / cls / journal / cls_journal_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_CLS_JOURNAL_TYPES_H
5 #define CEPH_CLS_JOURNAL_TYPES_H
6
7 #include "include/int_types.h"
8 #include "include/buffer_fwd.h"
9 #include "include/encoding.h"
10 #include <iosfwd>
11 #include <list>
12 #include <string>
13
14 namespace ceph {
15 class Formatter;
16 }
17
18 namespace cls {
19 namespace journal {
20
21 static const uint64_t JOURNAL_MAX_RETURN = 256;
22
23 struct ObjectPosition {
24 uint64_t object_number;
25 uint64_t tag_tid;
26 uint64_t entry_tid;
27
28 ObjectPosition() : object_number(0), tag_tid(0), entry_tid(0) {}
29 ObjectPosition(uint64_t _object_number, uint64_t _tag_tid,
30 uint64_t _entry_tid)
31 : object_number(_object_number), tag_tid(_tag_tid), entry_tid(_entry_tid) {}
32
33 inline bool operator==(const ObjectPosition& rhs) const {
34 return (object_number == rhs.object_number &&
35 tag_tid == rhs.tag_tid &&
36 entry_tid == rhs.entry_tid);
37 }
38
39 void encode(bufferlist& bl) const;
40 void decode(bufferlist::iterator& iter);
41 void dump(Formatter *f) const;
42
43 inline bool operator<(const ObjectPosition &rhs) const {
44 if (object_number != rhs.object_number) {
45 return object_number < rhs.object_number;
46 } else if (tag_tid != rhs.tag_tid) {
47 return tag_tid < rhs.tag_tid;
48 }
49 return entry_tid < rhs.entry_tid;
50 }
51
52 static void generate_test_instances(std::list<ObjectPosition *> &o);
53 };
54
55 typedef std::list<ObjectPosition> ObjectPositions;
56
57 struct ObjectSetPosition {
58 // stored in most-recent -> least recent committed entry order
59 ObjectPositions object_positions;
60
61 ObjectSetPosition() {}
62 ObjectSetPosition(const ObjectPositions &_object_positions)
63 : object_positions(_object_positions) {}
64
65 void encode(bufferlist& bl) const;
66 void decode(bufferlist::iterator& iter);
67 void dump(Formatter *f) const;
68
69 inline bool operator==(const ObjectSetPosition &rhs) const {
70 return (object_positions == rhs.object_positions);
71 }
72
73 static void generate_test_instances(std::list<ObjectSetPosition *> &o);
74 };
75
76 enum ClientState {
77 CLIENT_STATE_CONNECTED = 0,
78 CLIENT_STATE_DISCONNECTED = 1
79 };
80
81 struct Client {
82 std::string id;
83 bufferlist data;
84 ObjectSetPosition commit_position;
85 ClientState state;
86
87 Client() : state(CLIENT_STATE_CONNECTED) {}
88 Client(const std::string& _id, const bufferlist &_data,
89 const ObjectSetPosition &_commit_position = ObjectSetPosition(),
90 ClientState _state = CLIENT_STATE_CONNECTED)
91 : id(_id), data(_data), commit_position(_commit_position), state(_state) {}
92
93 inline bool operator==(const Client &rhs) const {
94 return (id == rhs.id &&
95 data.contents_equal(rhs.data) &&
96 commit_position == rhs.commit_position &&
97 state == rhs.state);
98 }
99 inline bool operator<(const Client &rhs) const {
100 return (id < rhs.id);
101 }
102
103 void encode(bufferlist& bl) const;
104 void decode(bufferlist::iterator& iter);
105 void dump(Formatter *f) const;
106
107 static void generate_test_instances(std::list<Client *> &o);
108 };
109
110 struct Tag {
111 static const uint64_t TAG_CLASS_NEW = static_cast<uint64_t>(-1);
112
113 uint64_t tid;
114 uint64_t tag_class;
115 bufferlist data;
116
117 Tag() : tid(0), tag_class(0) {}
118 Tag(uint64_t tid, uint64_t tag_class, const bufferlist &data)
119 : tid(tid), tag_class(tag_class), data(data) {}
120
121 inline bool operator==(const Tag &rhs) const {
122 return (tid == rhs.tid &&
123 tag_class == rhs.tag_class &&
124 data.contents_equal(rhs.data));
125 }
126 inline bool operator<(const Tag &rhs) const {
127 return (tid < rhs.tid);
128 }
129
130 void encode(bufferlist& bl) const;
131 void decode(bufferlist::iterator& iter);
132 void dump(Formatter *f) const;
133
134 static void generate_test_instances(std::list<Tag *> &o);
135 };
136
137 WRITE_CLASS_ENCODER(ObjectPosition);
138 WRITE_CLASS_ENCODER(ObjectSetPosition);
139 WRITE_CLASS_ENCODER(Client);
140 WRITE_CLASS_ENCODER(Tag);
141
142 std::ostream &operator<<(std::ostream &os, const ClientState &state);
143 std::ostream &operator<<(std::ostream &os,
144 const ObjectPosition &object_position);
145 std::ostream &operator<<(std::ostream &os,
146 const ObjectSetPosition &object_set_position);
147 std::ostream &operator<<(std::ostream &os,
148 const Client &client);
149 std::ostream &operator<<(std::ostream &os, const Tag &tag);
150
151 } // namespace journal
152 } // namespace cls
153
154 using cls::journal::encode;
155 using cls::journal::decode;
156
157 #endif // CEPH_CLS_JOURNAL_TYPES_H