2 * Ceph - scalable distributed file system
4 * This is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License version 2.1, as published by the Free Software
7 * Foundation. See file COPYING.
9 * Copyright 2013 Inktank
12 #ifndef CLS_REPLICA_LOG_TYPES_H_
13 #define CLS_REPLICA_LOG_TYPES_H_
15 #include "include/utime.h"
16 #include "include/encoding.h"
17 #include "include/types.h"
22 struct cls_replica_log_item_marker {
23 string item_name; // the name of the item we're marking
24 utime_t item_timestamp; // the time stamp at which the item was outdated
26 cls_replica_log_item_marker() {}
27 cls_replica_log_item_marker(const string& name, const utime_t& time) :
28 item_name(name), item_timestamp(time) {}
30 void encode(bufferlist& bl) const {
31 ENCODE_START(1, 1, bl);
32 ::encode(item_name, bl);
33 ::encode(item_timestamp, bl);
37 void decode(bufferlist::iterator& bl) {
39 ::decode(item_name, bl);
40 ::decode(item_timestamp, bl);
44 void dump(Formatter *f) const;
45 void decode_json(JSONObj *obj);
46 static void generate_test_instances(std::list<cls_replica_log_item_marker*>& ls);
48 WRITE_CLASS_ENCODER(cls_replica_log_item_marker)
50 struct cls_replica_log_progress_marker {
51 string entity_id; // the name of the entity setting the progress marker
52 string position_marker; // represents a log listing position on the master
53 utime_t position_time; // the timestamp associated with the position marker
54 std::list<cls_replica_log_item_marker> items; /* any items not caught up
55 to the position marker*/
57 cls_replica_log_progress_marker() {}
58 cls_replica_log_progress_marker(const string& entity, const string& marker,
59 const utime_t& time ) :
60 entity_id(entity), position_marker(marker),
61 position_time(time) {}
62 cls_replica_log_progress_marker(const string& entity, const string& marker,
64 const std::list<cls_replica_log_item_marker>& b) :
65 entity_id(entity), position_marker(marker),
69 void encode(bufferlist& bl) const {
70 ENCODE_START(1, 1, bl);
71 ::encode(entity_id, bl);
72 ::encode(position_marker, bl);
73 ::encode(position_time, bl);
78 void decode(bufferlist::iterator& bl) {
80 ::decode(entity_id, bl);
81 ::decode(position_marker, bl);
82 ::decode(position_time, bl);
87 void dump(Formatter *f) const;
88 void decode_json(JSONObj *obj);
89 static void generate_test_instances(std::list<cls_replica_log_progress_marker*>& ls);
91 WRITE_CLASS_ENCODER(cls_replica_log_progress_marker)
93 class cls_replica_log_bound {
95 * Right now, we are lazy and only support a single marker at a time. In the
96 * future, we might support more than one, so the interface is designed to
99 string position_marker; // represents a log listing position on the master
100 utime_t position_time; // the timestamp associated with the position marker
101 bool marker_exists; // has the marker been set?
102 cls_replica_log_progress_marker marker; // the status of the current locker
105 cls_replica_log_bound() : marker_exists(false) {}
107 int update_marker(const cls_replica_log_progress_marker& new_mark) {
108 // only one marker at a time right now
109 if (marker_exists && (marker.entity_id != new_mark.entity_id)) {
112 // can't go backwards with our one marker!
113 if (marker_exists && (marker.position_time > new_mark.position_time)) {
118 position_marker = new_mark.position_marker;
119 position_time = new_mark.position_time;
120 marker_exists = true;
121 // hey look, updating is idempotent; did you notice that?
125 int delete_marker(const string& entity_id) {
127 // ENOENT if our marker doesn't match the passed ID
128 if (marker.entity_id != entity_id) {
131 // you can't delete it if there are unclean entries
132 if (!marker.items.empty()) {
137 marker_exists = false;
138 marker = cls_replica_log_progress_marker();
139 // hey look, deletion is idempotent! Hurray.
143 std::string get_lowest_marker_bound() {
144 return position_marker;
147 utime_t get_lowest_time_bound() {
148 return position_time;
151 utime_t get_oldest_time() {
152 utime_t oldest = position_time;
153 list<cls_replica_log_item_marker>::const_iterator i;
154 for ( i = marker.items.begin(); i != marker.items.end(); ++i) {
155 if (i->item_timestamp < oldest)
156 oldest = i->item_timestamp;
161 void get_markers(list<cls_replica_log_progress_marker>& ls) {
163 ls.push_back(marker);
167 void encode(bufferlist& bl) const {
168 ENCODE_START(1, 1, bl);
169 ::encode(position_marker, bl);
170 ::encode(position_time, bl);
171 ::encode(marker_exists, bl);
173 ::encode(marker, bl);
177 void decode(bufferlist::iterator& bl) {
179 ::decode(position_marker, bl);
180 ::decode(position_time, bl);
181 ::decode(marker_exists, bl);
183 ::decode(marker, bl);
188 void dump(Formatter *f) const;
189 void decode_json(JSONObj *obj);
190 static void generate_test_instances(std::list<cls_replica_log_bound*>& ls);
192 WRITE_CLASS_ENCODER(cls_replica_log_bound)
194 #endif /* CLS_REPLICA_LOG_TYPES_H_ */