]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_replica_log.h
update sources to v12.1.0
[ceph.git] / ceph / src / rgw / rgw_replica_log.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
10 */
11
12 #ifndef RGW_REPLICA_LOG_H_
13 #define RGW_REPLICA_LOG_H_
14
15 #include <string>
16 #include "cls/replica_log/cls_replica_log_types.h"
17 #include "include/types.h"
18 #include "include/utime.h"
19 #include "include/rados/librados.hpp"
20 #include "rgw_common.h"
21
22 class RGWRados;
23 class CephContext;
24
25 #define META_REPLICA_LOG_OBJ_PREFIX "meta.replicalog."
26 #define DATA_REPLICA_LOG_OBJ_PREFIX "data.replicalog."
27
28 typedef cls_replica_log_item_marker RGWReplicaItemMarker;
29 typedef cls_replica_log_progress_marker RGWReplicaProgressMarker;
30
31 struct RGWReplicaBounds {
32 string marker;
33 utime_t oldest_time;
34 list<RGWReplicaProgressMarker> markers;
35
36 void dump(Formatter *f) const;
37 void decode_json(JSONObj *obj);
38 };
39
40 class RGWReplicaLogger {
41 protected:
42 CephContext *cct;
43 RGWRados *store;
44 int open_ioctx(librados::IoCtx& ctx, const rgw_pool& pool);
45
46 explicit RGWReplicaLogger(RGWRados *_store);
47
48 int update_bound(const string& oid, const rgw_pool& pool,
49 const string& daemon_id, const string& marker,
50 const utime_t& time,
51 const list<RGWReplicaItemMarker> *entries,
52 bool need_to_exist);
53 int write_bounds(const string& oid, const rgw_pool& pool,
54 RGWReplicaBounds& bounds);
55 int delete_bound(const string& oid, const rgw_pool& pool,
56 const string& daemon_id, bool purge_all,
57 bool need_to_exist);
58 int get_bounds(const string& oid, const rgw_pool& pool,
59 RGWReplicaBounds& bounds);
60 };
61
62 class RGWReplicaObjectLogger : private RGWReplicaLogger {
63 rgw_pool pool;
64 string prefix;
65
66 void get_shard_oid(int id, string& oid) {
67 char buf[16];
68 snprintf(buf, sizeof(buf), "%d", id);
69 oid = prefix + buf;
70 }
71
72 public:
73 RGWReplicaObjectLogger(RGWRados *_store,
74 const rgw_pool& _pool,
75 const string& _prefix);
76
77 int create_log_objects(int shards);
78 int update_bound(int shard, const string& daemon_id, const string& marker,
79 const utime_t& time,
80 const list<RGWReplicaItemMarker> *entries) {
81 string oid;
82 get_shard_oid(shard, oid);
83 return RGWReplicaLogger::update_bound(oid, pool,
84 daemon_id, marker, time, entries, false);
85 }
86 int delete_bound(int shard, const string& daemon_id, bool purge_all) {
87 string oid;
88 get_shard_oid(shard, oid);
89 return RGWReplicaLogger::delete_bound(oid, pool,
90 daemon_id, purge_all, false);
91 }
92 int get_bounds(int shard, RGWReplicaBounds& bounds) {
93 string oid;
94 get_shard_oid(shard, oid);
95 return RGWReplicaLogger::get_bounds(oid, pool, bounds);
96 }
97 };
98
99 class RGWReplicaBucketLogger : private RGWReplicaLogger {
100 rgw_pool pool;
101 string prefix;
102
103 string obj_name(const rgw_bucket& bucket, int shard_id, bool index_by_instance);
104
105 public:
106 explicit RGWReplicaBucketLogger(RGWRados *_store);
107 int update_bound(const rgw_bucket& bucket, int shard_id, const string& daemon_id,
108 const string& marker, const utime_t& time,
109 const list<RGWReplicaItemMarker> *entries);
110 int delete_bound(const rgw_bucket& bucket, int shard_id, const string& daemon_id, bool purge_all);
111 int get_bounds(const rgw_bucket& bucket, int shard_id, RGWReplicaBounds& bounds);
112 int convert_old_bounds(const rgw_bucket& bucket, int shard_id, RGWReplicaBounds& bounds);
113 };
114
115 #endif /* RGW_REPLICA_LOG_H_ */