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 Inktank 2013
12 #include "objclass/objclass.h"
14 #include "cls_replica_log_types.h"
15 #include "cls_replica_log_ops.h"
20 static const string replica_log_prefix
= "rl_";
21 static const string replica_log_bounds
= replica_log_prefix
+ "bounds";
23 static int get_bounds(cls_method_context_t hctx
, cls_replica_log_bound
& bound
)
26 int rc
= cls_cxx_map_get_val(hctx
, replica_log_bounds
, &bounds_bl
);
32 bufferlist::iterator bounds_bl_i
= bounds_bl
.begin();
33 ::decode(bound
, bounds_bl_i
);
34 } catch (buffer::error
& err
) {
35 bound
= cls_replica_log_bound();
36 CLS_LOG(0, "ERROR: get_bounds(): failed to decode on-disk bounds object");
43 static int write_bounds(cls_method_context_t hctx
,
44 const cls_replica_log_bound
& bound
)
47 ::encode(bound
, bounds_bl
);
48 return cls_cxx_map_set_val(hctx
, replica_log_bounds
, &bounds_bl
);
51 static int cls_replica_log_set(cls_method_context_t hctx
,
52 bufferlist
*in
, bufferlist
*out
)
54 bufferlist::iterator in_iter
= in
->begin();
56 cls_replica_log_set_marker_op op
;
58 ::decode(op
, in_iter
);
59 } catch (buffer::error
& err
) {
60 CLS_LOG(0, "ERROR: cls_replica_log_set(): failed to decode op");
64 cls_replica_log_bound bound
;
65 int rc
= get_bounds(hctx
, bound
);
66 if (rc
< 0 && rc
!= -ENOENT
) {
70 rc
= bound
.update_marker(op
.marker
);
75 return write_bounds(hctx
, bound
);
78 static int cls_replica_log_delete(cls_method_context_t hctx
,
79 bufferlist
*in
, bufferlist
*out
)
81 bufferlist::iterator in_iter
= in
->begin();
83 cls_replica_log_delete_marker_op op
;
85 ::decode(op
, in_iter
);
86 } catch (buffer::error
& err
) {
87 CLS_LOG(0, "ERROR: cls_replica_log_delete(): failed to decode op");
91 cls_replica_log_bound bound
;
92 int rc
= get_bounds(hctx
, bound
);
93 if (rc
< 0 && rc
!= -ENOENT
) {
97 rc
= bound
.delete_marker(op
.entity_id
);
102 return write_bounds(hctx
, bound
);
105 static int cls_replica_log_get(cls_method_context_t hctx
,
106 bufferlist
*in
, bufferlist
*out
)
108 bufferlist::iterator in_iter
= in
->begin();
110 cls_replica_log_get_bounds_op op
;
112 ::decode(op
, in_iter
);
113 } catch (buffer::error
& err
) {
114 CLS_LOG(0, "ERROR: cls_replica_log_get(): failed to decode op");
118 cls_replica_log_bound bound
;
119 int rc
= get_bounds(hctx
, bound
);
124 cls_replica_log_get_bounds_ret ret
;
125 ret
.oldest_time
= bound
.get_oldest_time();
126 ret
.position_marker
= bound
.get_lowest_marker_bound();
127 bound
.get_markers(ret
.markers
);
133 CLS_INIT(replica_log
)
135 CLS_LOG(1, "Loaded replica log class!");
137 cls_handle_t h_class
;
138 cls_method_handle_t h_replica_log_set
;
139 cls_method_handle_t h_replica_log_delete
;
140 cls_method_handle_t h_replica_log_get
;
142 cls_register("replica_log", &h_class
);
144 cls_register_cxx_method(h_class
, "set", CLS_METHOD_RD
| CLS_METHOD_WR
,
145 cls_replica_log_set
, &h_replica_log_set
);
146 cls_register_cxx_method(h_class
, "get", CLS_METHOD_RD
,
147 cls_replica_log_get
, &h_replica_log_get
);
148 cls_register_cxx_method(h_class
, "delete", CLS_METHOD_RD
| CLS_METHOD_WR
,
149 cls_replica_log_delete
, &h_replica_log_delete
);