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/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"
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
[];
46 void encode(bufferlist
& bl
) const {
47 ENCODE_START(2, 2, bl
);
51 void decode(bufferlist::iterator
& bl
) {
52 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
56 void dump(Formatter
*f
) const;
57 // static void generate_test_instances(list<ACLOwner*>& o);
58 void set_days(const string
& _days
) { days
= _days
; }
59 int get_days() {return atoi(days
.c_str()); }
64 WRITE_CLASS_ENCODER(LCExpiration
)
72 LCExpiration expiration
;
73 LCExpiration noncur_expiration
;
74 LCExpiration mp_expiration
;
81 bool get_id(string
& _id
) {
86 string
& get_status() {
90 string
& get_prefix() {
94 LCExpiration
& get_expiration() {
98 LCExpiration
& get_noncur_expiration() {
99 return noncur_expiration
;
102 LCExpiration
& get_mp_expiration() {
103 return mp_expiration
;
106 void set_id(string
*_id
) {
110 void set_prefix(string
*_prefix
) {
114 void set_status(string
*_status
) {
118 void set_expiration(LCExpiration
*_expiration
) {
119 expiration
= *_expiration
;
122 void set_noncur_expiration(LCExpiration
*_noncur_expiration
) {
123 noncur_expiration
= *_noncur_expiration
;
126 void set_mp_expiration(LCExpiration
* _mp_expiration
) {
127 mp_expiration
= *_mp_expiration
;
132 void encode(bufferlist
& bl
) const {
133 ENCODE_START(3, 1, bl
);
135 ::encode(prefix
, bl
);
136 ::encode(status
, bl
);
137 ::encode(expiration
, bl
);
138 ::encode(noncur_expiration
, bl
);
139 ::encode(mp_expiration
, bl
);
142 void decode(bufferlist::iterator
& bl
) {
143 DECODE_START_LEGACY_COMPAT_LEN(3, 1, 1, bl
);
145 ::decode(prefix
, bl
);
146 ::decode(status
, bl
);
147 ::decode(expiration
, bl
);
149 ::decode(noncur_expiration
, bl
);
152 ::decode(mp_expiration
, bl
);
158 WRITE_CLASS_ENCODER(LCRule
)
164 int noncur_expiration
;
167 lc_op() : status(false), expiration(0), noncur_expiration(0), mp_expiration(0) {}
171 class RGWLifecycleConfiguration
175 map
<string
, lc_op
> prefix_map
;
176 multimap
<string
, LCRule
> rule_map
;
177 bool _add_rule(LCRule
*rule
);
179 RGWLifecycleConfiguration(CephContext
*_cct
) : cct(_cct
) {}
180 RGWLifecycleConfiguration() : cct(NULL
) {}
182 void set_ctx(CephContext
*ctx
) {
186 virtual ~RGWLifecycleConfiguration() {}
188 // int get_perm(string& id, int perm_mask);
189 // int get_group_perm(ACLGroupTypeEnum group, int perm_mask);
190 void encode(bufferlist
& bl
) const {
191 ENCODE_START(1, 1, bl
);
192 ::encode(rule_map
, bl
);
195 void decode(bufferlist::iterator
& bl
) {
196 DECODE_START_LEGACY_COMPAT_LEN(1, 1, 1, bl
);
197 ::decode(rule_map
, bl
);
198 multimap
<string
, LCRule
>::iterator iter
;
199 for (iter
= rule_map
.begin(); iter
!= rule_map
.end(); ++iter
) {
200 LCRule
& rule
= iter
->second
;
205 void dump(Formatter
*f
) const;
206 // static void generate_test_instances(list<RGWAccessControlList*>& o);
208 void add_rule(LCRule
* rule
);
210 int check_and_add_rule(LCRule
* rule
);
214 multimap
<string
, LCRule
>& get_rule_map() { return rule_map
; }
215 map
<string
, lc_op
>& get_prefix_map() { return prefix_map
; }
217 void create_default(string id, string name) {
219 grant.set_canon(id, name, RGW_PERM_FULL_CONTROL);
224 WRITE_CLASS_ENCODER(RGWLifecycleConfiguration
)
231 std::atomic
<bool> down_flag
= { false };
234 class LCWorker
: public Thread
{
241 LCWorker(CephContext
*_cct
, RGWLC
*_lc
) : cct(_cct
), lc(_lc
), lock("LCWorker") {}
242 void *entry() override
;
244 bool should_work(utime_t
& now
);
245 int schedule_next_start_time(utime_t
& start
, utime_t
& now
);
250 RGWLC() : cct(NULL
), store(NULL
), worker(NULL
) {}
256 void initialize(CephContext
*_cct
, RGWRados
*_store
);
260 int process(int index
, int max_secs
);
261 bool if_already_run_today(time_t& start_date
);
262 int list_lc_progress(const string
& marker
, uint32_t max_entries
, map
<string
, int> *progress_map
);
263 int bucket_lc_prepare(int index
);
264 int bucket_lc_process(string
& shard_id
);
265 int bucket_lc_post(int index
, int max_lock_sec
, pair
<string
, int >& entry
, int& result
);
267 void start_processor();
268 void stop_processor();
271 int remove_expired_obj(RGWBucketInfo
& bucket_info
, rgw_obj_key obj_key
, bool remove_indeed
= true);
272 bool obj_has_expired(double timediff
, int days
);
273 int handle_multipart_expiration(RGWRados::Bucket
*target
, const map
<string
, lc_op
>& prefix_map
);