7 #include <include/types.h>
9 #include "common/debug.h"
11 #include "include/types.h"
12 #include "include/rados/librados.hpp"
13 #include "common/Mutex.h"
14 #include "common/Cond.h"
15 #include "common/iso_8601.h"
16 #include "common/Thread.h"
17 #include "rgw_common.h"
18 #include "rgw_rados.h"
19 #include "rgw_multi.h"
20 #include "cls/rgw/cls_rgw_types.h"
24 #define HASH_PRIME 7877
25 #define MAX_ID_LEN 255
26 static string lc_oid_prefix
= "lc";
27 static string lc_index_lock_name
= "lc_process";
29 extern const char* LC_STATUS
[];
42 //At present only current object has expiration date
48 void encode(bufferlist
& bl
) const {
49 ENCODE_START(3, 2, bl
);
54 void decode(bufferlist::iterator
& bl
) {
55 DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl
);
62 void dump(Formatter
*f
) const;
63 // static void generate_test_instances(list<ACLOwner*>& o);
64 void set_days(const string
& _days
) { days
= _days
; }
65 string
get_days_str() const {
68 int get_days() const {return atoi(days
.c_str()); }
69 bool has_days() const {
72 void set_date(const string
& _date
) { date
= _date
; }
73 string
get_date() const {
76 bool has_date() const {
80 return days
.empty() && date
.empty();
83 if (!days
.empty() && !date
.empty()) {
85 } else if (!days
.empty() && get_days() <= 0) {
88 //We've checked date in xml parsing
92 WRITE_CLASS_ENCODER(LCExpiration
)
100 LCExpiration expiration
;
101 LCExpiration noncur_expiration
;
102 LCExpiration mp_expiration
;
103 bool dm_expiration
= false;
110 bool get_id(string
& _id
) {
115 string
& get_status() {
119 string
& get_prefix() {
123 LCExpiration
& get_expiration() {
127 LCExpiration
& get_noncur_expiration() {
128 return noncur_expiration
;
131 LCExpiration
& get_mp_expiration() {
132 return mp_expiration
;
135 bool get_dm_expiration() {
136 return dm_expiration
;
139 void set_id(string
*_id
) {
143 void set_prefix(string
*_prefix
) {
147 void set_status(string
*_status
) {
151 void set_expiration(LCExpiration
*_expiration
) {
152 expiration
= *_expiration
;
155 void set_noncur_expiration(LCExpiration
*_noncur_expiration
) {
156 noncur_expiration
= *_noncur_expiration
;
159 void set_mp_expiration(LCExpiration
* _mp_expiration
) {
160 mp_expiration
= *_mp_expiration
;
163 void set_dm_expiration(bool _dm_expiration
) {
164 dm_expiration
= _dm_expiration
;
169 void encode(bufferlist
& bl
) const {
170 ENCODE_START(4, 1, bl
);
172 ::encode(prefix
, bl
);
173 ::encode(status
, bl
);
174 ::encode(expiration
, bl
);
175 ::encode(noncur_expiration
, bl
);
176 ::encode(mp_expiration
, bl
);
177 ::encode(dm_expiration
, bl
);
180 void decode(bufferlist::iterator
& bl
) {
181 DECODE_START_LEGACY_COMPAT_LEN(4, 1, 1, bl
);
183 ::decode(prefix
, bl
);
184 ::decode(status
, bl
);
185 ::decode(expiration
, bl
);
187 ::decode(noncur_expiration
, bl
);
190 ::decode(mp_expiration
, bl
);
193 ::decode(dm_expiration
, bl
);
199 WRITE_CLASS_ENCODER(LCRule
)
206 int noncur_expiration
;
208 boost::optional
<ceph::real_time
> expiration_date
;
210 lc_op() : status(false), dm_expiration(false), expiration(0), noncur_expiration(0), mp_expiration(0) {}
214 class RGWLifecycleConfiguration
218 map
<string
, lc_op
> prefix_map
;
219 multimap
<string
, LCRule
> rule_map
;
220 bool _add_rule(LCRule
*rule
);
221 bool has_same_action(const lc_op
& first
, const lc_op
& second
);
223 RGWLifecycleConfiguration(CephContext
*_cct
) : cct(_cct
) {}
224 RGWLifecycleConfiguration() : cct(NULL
) {}
226 void set_ctx(CephContext
*ctx
) {
230 virtual ~RGWLifecycleConfiguration() {}
232 // int get_perm(string& id, int perm_mask);
233 // int get_group_perm(ACLGroupTypeEnum group, int perm_mask);
234 void encode(bufferlist
& bl
) const {
235 ENCODE_START(1, 1, bl
);
236 ::encode(rule_map
, bl
);
239 void decode(bufferlist::iterator
& bl
) {
240 DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl
);
241 ::decode(rule_map
, bl
);
242 multimap
<string
, LCRule
>::iterator iter
;
243 for (iter
= rule_map
.begin(); iter
!= rule_map
.end(); ++iter
) {
244 LCRule
& rule
= iter
->second
;
249 void dump(Formatter
*f
) const;
250 // static void generate_test_instances(list<RGWAccessControlList*>& o);
252 void add_rule(LCRule
* rule
);
254 int check_and_add_rule(LCRule
* rule
);
258 multimap
<string
, LCRule
>& get_rule_map() { return rule_map
; }
259 map
<string
, lc_op
>& get_prefix_map() { return prefix_map
; }
261 void create_default(string id, string name) {
263 grant.set_canon(id, name, RGW_PERM_FULL_CONTROL);
268 WRITE_CLASS_ENCODER(RGWLifecycleConfiguration
)
274 string
*obj_names
{nullptr};
275 std::atomic
<bool> down_flag
= { false };
278 class LCWorker
: public Thread
{
285 LCWorker(CephContext
*_cct
, RGWLC
*_lc
) : cct(_cct
), lc(_lc
), lock("LCWorker") {}
286 void *entry() override
;
288 bool should_work(utime_t
& now
);
289 int schedule_next_start_time(utime_t
& start
, utime_t
& now
);
294 RGWLC() : cct(NULL
), store(NULL
), worker(NULL
) {}
300 void initialize(CephContext
*_cct
, RGWRados
*_store
);
304 int process(int index
, int max_secs
);
305 bool if_already_run_today(time_t& start_date
);
306 int list_lc_progress(const string
& marker
, uint32_t max_entries
, map
<string
, int> *progress_map
);
307 int bucket_lc_prepare(int index
);
308 int bucket_lc_process(string
& shard_id
);
309 int bucket_lc_post(int index
, int max_lock_sec
, pair
<string
, int >& entry
, int& result
);
311 void start_processor();
312 void stop_processor();
315 int remove_expired_obj(RGWBucketInfo
& bucket_info
, rgw_obj_key obj_key
, bool remove_indeed
= true);
316 bool obj_has_expired(double timediff
, int days
);
317 int handle_multipart_expiration(RGWRados::Bucket
*target
, const map
<string
, lc_op
>& prefix_map
);