]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Ceph - scalable distributed file system | |
3 | * | |
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. | |
8 | */ | |
9 | ||
10 | #include <errno.h> | |
11 | ||
31f18b77 | 12 | #include "cls/replica_log/cls_replica_log_client.h" |
7c673cae FG |
13 | #include "include/rados/librados.hpp" |
14 | ||
15 | using namespace librados; | |
16 | ||
17 | void cls_replica_log_prepare_marker(cls_replica_log_progress_marker& progress, | |
18 | const string& entity, const string& marker, | |
19 | const utime_t& time, | |
20 | const list<pair<string, utime_t> > *entries) | |
21 | { | |
22 | progress.entity_id = entity; | |
23 | progress.position_marker = marker; | |
24 | progress.position_time = time; | |
25 | if (entries) { | |
26 | list<pair<string, utime_t> >::const_iterator i; | |
27 | for (i = entries->begin(); i != entries->end(); ++i) { | |
28 | cls_replica_log_item_marker item(i->first, i->second); | |
29 | progress.items.push_back(item); | |
30 | } | |
31 | } | |
32 | } | |
33 | ||
34 | void cls_replica_log_extract_marker(const cls_replica_log_progress_marker& progress, | |
35 | string& entity, string& marker, | |
36 | utime_t& time, | |
37 | list<pair<string, utime_t> >& entries) | |
38 | { | |
39 | entity = progress.entity_id; | |
40 | marker = progress.position_marker; | |
41 | time = progress.position_time; | |
42 | list<cls_replica_log_item_marker>::const_iterator i; | |
43 | for (i = progress.items.begin(); i != progress.items.end(); ++i) { | |
44 | entries.push_back(make_pair(i->item_name, i->item_timestamp)); | |
45 | } | |
46 | } | |
47 | ||
48 | void cls_replica_log_update_bound(librados::ObjectWriteOperation& o, | |
49 | const cls_replica_log_progress_marker& progress) | |
50 | { | |
51 | cls_replica_log_set_marker_op op(progress); | |
52 | bufferlist in; | |
53 | ::encode(op, in); | |
54 | o.exec("replica_log", "set", in); | |
55 | } | |
56 | ||
57 | void cls_replica_log_delete_bound(librados::ObjectWriteOperation& o, | |
58 | const string& entity) | |
59 | { | |
60 | cls_replica_log_delete_marker_op op(entity); | |
61 | bufferlist in; | |
62 | ::encode(op, in); | |
63 | o.exec("replica_log", "delete", in); | |
64 | } | |
65 | ||
66 | int cls_replica_log_get_bounds(librados::IoCtx& io_ctx, const string& oid, | |
67 | string& position_marker, | |
68 | utime_t& oldest_time, | |
69 | list<cls_replica_log_progress_marker>& markers) | |
70 | { | |
71 | bufferlist in; | |
72 | bufferlist out; | |
73 | cls_replica_log_get_bounds_op op; | |
74 | ::encode(op, in); | |
75 | int r = io_ctx.exec(oid, "replica_log", "get", in, out); | |
76 | if (r < 0) | |
77 | return r; | |
78 | ||
79 | cls_replica_log_get_bounds_ret ret; | |
80 | try { | |
81 | bufferlist::iterator i = out.begin(); | |
82 | ::decode(ret, i); | |
83 | } catch (buffer::error& err) { | |
84 | return -EIO; | |
85 | } | |
86 | ||
87 | position_marker = ret.position_marker; | |
88 | oldest_time = ret.oldest_time; | |
89 | markers = ret.markers; | |
90 | ||
91 | return 0; | |
92 | } |