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"
23 #define HASH_PRIME 7877
24 #define MAX_ID_LEN 255
25 static string lc_oid_prefix
= "lc";
26 static string lc_index_lock_name
= "lc_process";
28 extern const char* LC_STATUS
[];
45 void encode(bufferlist
& bl
) const {
46 ENCODE_START(2, 2, bl
);
50 void decode(bufferlist::iterator
& bl
) {
51 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
55 void dump(Formatter
*f
) const;
56 // static void generate_test_instances(list<ACLOwner*>& o);
57 void set_days(const string
& _days
) { days
= _days
; }
58 string
get_days_str() const{
61 int get_days() {return atoi(days
.c_str()); }
66 WRITE_CLASS_ENCODER(LCExpiration
)
74 LCExpiration expiration
;
75 LCExpiration noncur_expiration
;
76 LCExpiration mp_expiration
;
84 bool get_id(string
& _id
) {
89 string
& get_status() {
93 string
& get_prefix() {
97 LCExpiration
& get_expiration() {
101 LCExpiration
& get_noncur_expiration() {
102 return noncur_expiration
;
105 LCExpiration
& get_mp_expiration() {
106 return mp_expiration
;
109 bool get_dm_expiration() {
110 return dm_expiration
;
113 void set_id(string
*_id
) {
117 void set_prefix(string
*_prefix
) {
121 void set_status(string
*_status
) {
125 void set_expiration(LCExpiration
*_expiration
) {
126 expiration
= *_expiration
;
129 void set_noncur_expiration(LCExpiration
*_noncur_expiration
) {
130 noncur_expiration
= *_noncur_expiration
;
133 void set_mp_expiration(LCExpiration
* _mp_expiration
) {
134 mp_expiration
= *_mp_expiration
;
137 void set_dm_expiration(bool _dm_expiration
) {
138 dm_expiration
= _dm_expiration
;
143 void encode(bufferlist
& bl
) const {
144 ENCODE_START(4, 1, bl
);
146 ::encode(prefix
, bl
);
147 ::encode(status
, bl
);
148 ::encode(expiration
, bl
);
149 ::encode(noncur_expiration
, bl
);
150 ::encode(mp_expiration
, bl
);
151 ::encode(dm_expiration
, bl
);
154 void decode(bufferlist::iterator
& bl
) {
155 DECODE_START_LEGACY_COMPAT_LEN(4, 1, 1, bl
);
157 ::decode(prefix
, bl
);
158 ::decode(status
, bl
);
159 ::decode(expiration
, bl
);
161 ::decode(noncur_expiration
, bl
);
164 ::decode(mp_expiration
, bl
);
167 ::decode(dm_expiration
, bl
);
173 WRITE_CLASS_ENCODER(LCRule
)
180 int noncur_expiration
;
183 lc_op() : status(false), dm_expiration(false), expiration(0), noncur_expiration(0), mp_expiration(0) {}
187 class RGWLifecycleConfiguration
191 map
<string
, lc_op
> prefix_map
;
192 multimap
<string
, LCRule
> rule_map
;
193 bool _add_rule(LCRule
*rule
);
195 RGWLifecycleConfiguration(CephContext
*_cct
) : cct(_cct
) {}
196 RGWLifecycleConfiguration() : cct(NULL
) {}
198 void set_ctx(CephContext
*ctx
) {
202 virtual ~RGWLifecycleConfiguration() {}
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
);
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
;
221 void dump(Formatter
*f
) const;
222 // static void generate_test_instances(list<RGWAccessControlList*>& o);
224 void add_rule(LCRule
* rule
);
226 int check_and_add_rule(LCRule
* rule
);
230 multimap
<string
, LCRule
>& get_rule_map() { return rule_map
; }
231 map
<string
, lc_op
>& get_prefix_map() { return prefix_map
; }
233 void create_default(string id, string name) {
235 grant.set_canon(id, name, RGW_PERM_FULL_CONTROL);
240 WRITE_CLASS_ENCODER(RGWLifecycleConfiguration
)
247 std::atomic
<bool> down_flag
= { false };
250 class LCWorker
: public Thread
{
257 LCWorker(CephContext
*_cct
, RGWLC
*_lc
) : cct(_cct
), lc(_lc
), lock("LCWorker") {}
258 void *entry() override
;
260 bool should_work(utime_t
& now
);
261 int schedule_next_start_time(utime_t
& start
, utime_t
& now
);
266 RGWLC() : cct(NULL
), store(NULL
), worker(NULL
) {}
272 void initialize(CephContext
*_cct
, RGWRados
*_store
);
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
);
283 void start_processor();
284 void stop_processor();
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
);