]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_lc.h
buildsys: fix parallel builds
[ceph.git] / ceph / src / rgw / rgw_lc.h
CommitLineData
7c673cae
FG
1#ifndef CEPH_RGW_LC_H
2#define CEPH_RGW_LC_H
3
4#include <map>
5#include <string>
6#include <iostream>
7#include <include/types.h>
8
9#include "common/debug.h"
10
11#include "include/types.h"
12#include "include/rados/librados.hpp"
13#include "common/Mutex.h"
14#include "common/Cond.h"
15#include "common/Thread.h"
16#include "rgw_common.h"
17#include "rgw_rados.h"
18#include "rgw_multi.h"
19#include "cls/rgw/cls_rgw_types.h"
20
21#include <atomic>
22
7c673cae
FG
23#define HASH_PRIME 7877
24#define MAX_ID_LEN 255
25static string lc_oid_prefix = "lc";
26static string lc_index_lock_name = "lc_process";
27
28extern const char* LC_STATUS[];
29
30typedef enum {
31 lc_uninitial = 0,
32 lc_processing,
33 lc_failed,
34 lc_complete,
35}LC_BUCKET_STATUS;
36
37class LCExpiration
38{
39protected:
40 string days;
41public:
42 LCExpiration() {}
43 ~LCExpiration() {}
44
45 void encode(bufferlist& bl) const {
46 ENCODE_START(2, 2, bl);
47 ::encode(days, bl);
48 ENCODE_FINISH(bl);
49 }
50 void decode(bufferlist::iterator& bl) {
51 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
52 ::decode(days, bl);
53 DECODE_FINISH(bl);
54 }
55 void dump(Formatter *f) const;
56// static void generate_test_instances(list<ACLOwner*>& o);
57 void set_days(const string& _days) { days = _days; }
31f18b77
FG
58 string get_days_str() const{
59 return days;
60 }
7c673cae
FG
61 int get_days() {return atoi(days.c_str()); }
62 bool empty() const{
63 return days.empty();
64 }
65};
66WRITE_CLASS_ENCODER(LCExpiration)
67
68class LCRule
69{
70protected:
71 string id;
72 string prefix;
73 string status;
74 LCExpiration expiration;
75 LCExpiration noncur_expiration;
76 LCExpiration mp_expiration;
31f18b77 77 bool dm_expiration;
7c673cae
FG
78
79public:
80
81 LCRule(){};
82 ~LCRule(){};
83
84 bool get_id(string& _id) {
85 _id = id;
86 return true;
87 }
88
89 string& get_status() {
90 return status;
91 }
92
93 string& get_prefix() {
94 return prefix;
95 }
96
97 LCExpiration& get_expiration() {
98 return expiration;
99 }
100
101 LCExpiration& get_noncur_expiration() {
102 return noncur_expiration;
103 }
104
105 LCExpiration& get_mp_expiration() {
106 return mp_expiration;
107 }
108
31f18b77
FG
109 bool get_dm_expiration() {
110 return dm_expiration;
111 }
112
7c673cae
FG
113 void set_id(string*_id) {
114 id = *_id;
115 }
116
117 void set_prefix(string*_prefix) {
118 prefix = *_prefix;
119 }
120
121 void set_status(string*_status) {
122 status = *_status;
123 }
124
125 void set_expiration(LCExpiration*_expiration) {
126 expiration = *_expiration;
127 }
128
129 void set_noncur_expiration(LCExpiration*_noncur_expiration) {
130 noncur_expiration = *_noncur_expiration;
131 }
132
133 void set_mp_expiration(LCExpiration* _mp_expiration) {
134 mp_expiration = *_mp_expiration;
135 }
136
31f18b77
FG
137 void set_dm_expiration(bool _dm_expiration) {
138 dm_expiration = _dm_expiration;
139 }
140
7c673cae
FG
141 bool validate();
142
143 void encode(bufferlist& bl) const {
31f18b77 144 ENCODE_START(4, 1, bl);
7c673cae
FG
145 ::encode(id, bl);
146 ::encode(prefix, bl);
147 ::encode(status, bl);
148 ::encode(expiration, bl);
149 ::encode(noncur_expiration, bl);
150 ::encode(mp_expiration, bl);
31f18b77 151 ::encode(dm_expiration, bl);
7c673cae
FG
152 ENCODE_FINISH(bl);
153 }
154 void decode(bufferlist::iterator& bl) {
31f18b77 155 DECODE_START_LEGACY_COMPAT_LEN(4, 1, 1, bl);
7c673cae
FG
156 ::decode(id, bl);
157 ::decode(prefix, bl);
158 ::decode(status, bl);
159 ::decode(expiration, bl);
160 if (struct_v >=2) {
161 ::decode(noncur_expiration, bl);
162 }
163 if (struct_v >= 3) {
164 ::decode(mp_expiration, bl);
165 }
31f18b77
FG
166 if (struct_v >= 4) {
167 ::decode(dm_expiration, bl);
168 }
7c673cae
FG
169 DECODE_FINISH(bl);
170 }
171
172};
173WRITE_CLASS_ENCODER(LCRule)
174
175struct lc_op
176{
177 bool status;
31f18b77 178 bool dm_expiration;
7c673cae
FG
179 int expiration;
180 int noncur_expiration;
181 int mp_expiration;
182
31f18b77 183 lc_op() : status(false), dm_expiration(false), expiration(0), noncur_expiration(0), mp_expiration(0) {}
7c673cae
FG
184
185};
186
187class RGWLifecycleConfiguration
188{
189protected:
190 CephContext *cct;
191 map<string, lc_op> prefix_map;
192 multimap<string, LCRule> rule_map;
193 bool _add_rule(LCRule *rule);
194public:
195 RGWLifecycleConfiguration(CephContext *_cct) : cct(_cct) {}
196 RGWLifecycleConfiguration() : cct(NULL) {}
197
198 void set_ctx(CephContext *ctx) {
199 cct = ctx;
200 }
201
202 virtual ~RGWLifecycleConfiguration() {}
203
204// int get_perm(string& id, int perm_mask);
205// int get_group_perm(ACLGroupTypeEnum group, int perm_mask);
206 void encode(bufferlist& bl) const {
207 ENCODE_START(1, 1, bl);
208 ::encode(rule_map, bl);
209 ENCODE_FINISH(bl);
210 }
211 void decode(bufferlist::iterator& bl) {
212 DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl);
213 ::decode(rule_map, bl);
214 multimap<string, LCRule>::iterator iter;
215 for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
216 LCRule& rule = iter->second;
217 _add_rule(&rule);
218 }
219 DECODE_FINISH(bl);
220 }
221 void dump(Formatter *f) const;
222// static void generate_test_instances(list<RGWAccessControlList*>& o);
223
224 void add_rule(LCRule* rule);
225
226 int check_and_add_rule(LCRule* rule);
227
228 bool validate();
229
230 multimap<string, LCRule>& get_rule_map() { return rule_map; }
231 map<string, lc_op>& get_prefix_map() { return prefix_map; }
232/*
233 void create_default(string id, string name) {
234 ACLGrant grant;
235 grant.set_canon(id, name, RGW_PERM_FULL_CONTROL);
236 add_grant(&grant);
237 }
238*/
239};
240WRITE_CLASS_ENCODER(RGWLifecycleConfiguration)
241
242class RGWLC {
243 CephContext *cct;
244 RGWRados *store;
245 int max_objs;
246 string *obj_names;
247 std::atomic<bool> down_flag = { false };
248 string cookie;
249
250 class LCWorker : public Thread {
251 CephContext *cct;
252 RGWLC *lc;
253 Mutex lock;
254 Cond cond;
255
256 public:
257 LCWorker(CephContext *_cct, RGWLC *_lc) : cct(_cct), lc(_lc), lock("LCWorker") {}
258 void *entry() override;
259 void stop();
260 bool should_work(utime_t& now);
261 int schedule_next_start_time(utime_t& start, utime_t& now);
262 };
263
264 public:
265 LCWorker *worker;
266 RGWLC() : cct(NULL), store(NULL), worker(NULL) {}
267 ~RGWLC() {
268 stop_processor();
269 finalize();
270 }
271
272 void initialize(CephContext *_cct, RGWRados *_store);
273 void finalize();
274
275 int process();
276 int process(int index, int max_secs);
277 bool if_already_run_today(time_t& start_date);
278 int list_lc_progress(const string& marker, uint32_t max_entries, map<string, int> *progress_map);
279 int bucket_lc_prepare(int index);
280 int bucket_lc_process(string& shard_id);
281 int bucket_lc_post(int index, int max_lock_sec, pair<string, int >& entry, int& result);
282 bool going_down();
283 void start_processor();
284 void stop_processor();
285
286 private:
287 int remove_expired_obj(RGWBucketInfo& bucket_info, rgw_obj_key obj_key, bool remove_indeed = true);
288 bool obj_has_expired(double timediff, int days);
289 int handle_multipart_expiration(RGWRados::Bucket *target, const map<string, lc_op>& prefix_map);
290};
291
292
293
294#endif