1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_CLS_JOURNAL_TYPES_H
5 #define CEPH_CLS_JOURNAL_TYPES_H
7 #include "include/int_types.h"
8 #include "include/buffer_fwd.h"
9 #include "include/encoding.h"
21 static const uint64_t JOURNAL_MAX_RETURN = 256;
23 struct ObjectPosition {
24 uint64_t object_number;
28 ObjectPosition() : object_number(0), tag_tid(0), entry_tid(0) {}
29 ObjectPosition(uint64_t _object_number, uint64_t _tag_tid,
31 : object_number(_object_number), tag_tid(_tag_tid), entry_tid(_entry_tid) {}
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);
39 void encode(bufferlist& bl) const;
40 void decode(bufferlist::iterator& iter);
41 void dump(Formatter *f) const;
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;
49 return entry_tid < rhs.entry_tid;
52 static void generate_test_instances(std::list<ObjectPosition *> &o);
55 typedef std::list<ObjectPosition> ObjectPositions;
57 struct ObjectSetPosition {
58 // stored in most-recent -> least recent committed entry order
59 ObjectPositions object_positions;
61 ObjectSetPosition() {}
62 ObjectSetPosition(const ObjectPositions &_object_positions)
63 : object_positions(_object_positions) {}
65 void encode(bufferlist& bl) const;
66 void decode(bufferlist::iterator& iter);
67 void dump(Formatter *f) const;
69 inline bool operator==(const ObjectSetPosition &rhs) const {
70 return (object_positions == rhs.object_positions);
73 static void generate_test_instances(std::list<ObjectSetPosition *> &o);
77 CLIENT_STATE_CONNECTED = 0,
78 CLIENT_STATE_DISCONNECTED = 1
84 ObjectSetPosition commit_position;
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) {}
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 &&
99 inline bool operator<(const Client &rhs) const {
100 return (id < rhs.id);
103 void encode(bufferlist& bl) const;
104 void decode(bufferlist::iterator& iter);
105 void dump(Formatter *f) const;
107 static void generate_test_instances(std::list<Client *> &o);
111 static const uint64_t TAG_CLASS_NEW = static_cast<uint64_t>(-1);
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) {}
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));
126 inline bool operator<(const Tag &rhs) const {
127 return (tid < rhs.tid);
130 void encode(bufferlist& bl) const;
131 void decode(bufferlist::iterator& iter);
132 void dump(Formatter *f) const;
134 static void generate_test_instances(std::list<Tag *> &o);
137 WRITE_CLASS_ENCODER(ObjectPosition);
138 WRITE_CLASS_ENCODER(ObjectSetPosition);
139 WRITE_CLASS_ENCODER(Client);
140 WRITE_CLASS_ENCODER(Tag);
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);
151 } // namespace journal
154 using cls::journal::encode;
155 using cls::journal::decode;
157 #endif // CEPH_CLS_JOURNAL_TYPES_H