summaryrefslogtreecommitdiffstats
path: root/src/cls/journal/cls_journal_types.cc
blob: 6e9dfde87818fd55d46233d180fe62821549be12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "cls/journal/cls_journal_types.h"
#include "include/stringify.h"
#include "common/Formatter.h"

using ceph::bufferlist;
using ceph::Formatter;

namespace cls {
namespace journal {

void ObjectPosition::encode(bufferlist& bl) const {
  ENCODE_START(1, 1, bl);
  encode(object_number, bl);
  encode(tag_tid, bl);
  encode(entry_tid, bl);
  ENCODE_FINISH(bl);
}

void ObjectPosition::decode(bufferlist::const_iterator& iter) {
  DECODE_START(1, iter);
  decode(object_number, iter);
  decode(tag_tid, iter);
  decode(entry_tid, iter);
  DECODE_FINISH(iter);
}

void ObjectPosition::dump(Formatter *f) const {
  f->dump_unsigned("object_number", object_number);
  f->dump_unsigned("tag_tid", tag_tid);
  f->dump_unsigned("entry_tid", entry_tid);
}

void ObjectPosition::generate_test_instances(std::list<ObjectPosition *> &o) {
  o.push_back(new ObjectPosition());
  o.push_back(new ObjectPosition(1, 2, 3));
}

void ObjectSetPosition::encode(bufferlist& bl) const {
  ENCODE_START(1, 1, bl);
  encode(object_positions, bl);
  ENCODE_FINISH(bl);
}

void ObjectSetPosition::decode(bufferlist::const_iterator& iter) {
  DECODE_START(1, iter);
  decode(object_positions, iter);
  DECODE_FINISH(iter);
}

void ObjectSetPosition::dump(Formatter *f) const {
  f->open_array_section("object_positions");
  for (auto &pos : object_positions) {
    f->open_object_section("object_position");
    pos.dump(f);
    f->close_section();
  }
  f->close_section();
}

void ObjectSetPosition::generate_test_instances(
    std::list<ObjectSetPosition *> &o) {
  o.push_back(new ObjectSetPosition());
  o.push_back(new ObjectSetPosition({{0, 1, 120}, {121, 2, 121}}));
}

void Client::encode(bufferlist& bl) const {
  ENCODE_START(1, 1, bl);
  encode(id, bl);
  encode(data, bl);
  encode(commit_position, bl);
  encode(static_cast<uint8_t>(state), bl);
  ENCODE_FINISH(bl);
}

void Client::decode(bufferlist::const_iterator& iter) {
  DECODE_START(1, iter);
  decode(id, iter);
  decode(data, iter);
  decode(commit_position, iter);

  uint8_t state_raw;
  decode(state_raw, iter);
  state = static_cast<ClientState>(state_raw);
  DECODE_FINISH(iter);
}

void Client::dump(Formatter *f) const {
  f->dump_string("id", id);

  std::stringstream data_ss;
  data.hexdump(data_ss);
  f->dump_string("data", data_ss.str());

  f->open_object_section("commit_position");
  commit_position.dump(f);
  f->close_section();

  f->dump_string("state", stringify(state));
}

void Client::generate_test_instances(std::list<Client *> &o) {
  bufferlist data;
  data.append(std::string(128, '1'));

  o.push_back(new Client());
  o.push_back(new Client("id", data));
  o.push_back(new Client("id", data, {{{1, 2, 120}, {2, 3, 121}}}));
}

void Tag::encode(bufferlist& bl) const {
  ENCODE_START(1, 1, bl);
  encode(tid, bl);
  encode(tag_class, bl);
  encode(data, bl);
  ENCODE_FINISH(bl);
}

void Tag::decode(bufferlist::const_iterator& iter) {
  DECODE_START(1, iter);
  decode(tid, iter);
  decode(tag_class, iter);
  decode(data, iter);
  DECODE_FINISH(iter);
}

void Tag::dump(Formatter *f) const {
  f->dump_unsigned("tid", tid);
  f->dump_unsigned("tag_class", tag_class);

  std::stringstream data_ss;
  data.hexdump(data_ss);
  f->dump_string("data", data_ss.str());
}

void Tag::generate_test_instances(std::list<Tag *> &o) {
  o.push_back(new Tag());

  bufferlist data;
  data.append(std::string(128, '1'));
  o.push_back(new Tag(123, 234, data));
}

std::ostream &operator<<(std::ostream &os, const ClientState &state) {
  switch (state) {
  case CLIENT_STATE_CONNECTED:
    os << "connected";
    break;
  case CLIENT_STATE_DISCONNECTED:
    os << "disconnected";
    break;
  default:
    os << "unknown (" << static_cast<uint32_t>(state) << ")";
    break;
  }
  return os;
}

std::ostream &operator<<(std::ostream &os,
                         const ObjectPosition &object_position) {
  os << "["
     << "object_number=" << object_position.object_number << ", "
     << "tag_tid=" << object_position.tag_tid << ", "
     << "entry_tid=" << object_position.entry_tid << "]";
  return os;
}

std::ostream &operator<<(std::ostream &os,
                         const ObjectSetPosition &object_set_position) {
  os << "[positions=[";
  std::string delim;
  for (auto &object_position : object_set_position.object_positions) {
    os << delim << object_position;
    delim = ", ";
  }
  os << "]]";
  return os;
}

std::ostream &operator<<(std::ostream &os, const Client &client) {
  os << "[id=" << client.id << ", "
     << "commit_position=" << client.commit_position << ", "
     << "state=" << client.state << "]";
  return os;
}

std::ostream &operator<<(std::ostream &os, const Tag &tag) {
  os << "[tid=" << tag.tid << ", "
     << "tag_class=" << tag.tag_class << ", "
     << "data=";
  tag.data.hexdump(os);
  os << "]";
  return os;
}

} // namespace journal
} // namespace cls