@@ -27,21 +27,15 @@ const char* LC_STATUS[] = {
27
27
using namespace std ;
28
28
using namespace librados ;
29
29
30
- bool LCRule::validate ()
30
+ bool LCRule::valid ()
31
31
{
32
32
if (id.length () > MAX_ID_LEN) {
33
33
return false ;
34
34
}
35
35
else if (expiration.empty () && noncur_expiration.empty () && mp_expiration.empty () && !dm_expiration) {
36
36
return false ;
37
37
}
38
- else if (!expiration.empty () && expiration.get_days () <= 0 ) {
39
- return false ;
40
- }
41
- else if (!noncur_expiration.empty () && noncur_expiration.get_days () <=0 ) {
42
- return false ;
43
- }
44
- else if (!mp_expiration.empty () && mp_expiration.get_days () <= 0 ) {
38
+ else if (!expiration.valid () || !noncur_expiration.valid () || !mp_expiration.valid ()) {
45
39
return false ;
46
40
}
47
41
return true ;
@@ -60,13 +54,16 @@ bool RGWLifecycleConfiguration::_add_rule(LCRule *rule)
60
54
if (rule->get_status ().compare (" Enabled" ) == 0 ) {
61
55
op.status = true ;
62
56
}
63
- if (! rule->get_expiration ().empty ()) {
57
+ if (rule->get_expiration ().has_days ()) {
64
58
op.expiration = rule->get_expiration ().get_days ();
65
59
}
66
- if (!rule->get_noncur_expiration ().empty ()) {
60
+ if (rule->get_expiration ().has_date ()) {
61
+ op.expiration_date = ceph::from_iso_8601 (rule->get_expiration ().get_date ());
62
+ }
63
+ if (rule->get_noncur_expiration ().has_days ()) {
67
64
op.noncur_expiration = rule->get_noncur_expiration ().get_days ();
68
65
}
69
- if (! rule->get_mp_expiration ().empty ()) {
66
+ if (rule->get_mp_expiration ().has_days ()) {
70
67
op.mp_expiration = rule->get_mp_expiration ().get_days ();
71
68
}
72
69
op.dm_expiration = rule->get_dm_expiration ();
@@ -76,7 +73,7 @@ bool RGWLifecycleConfiguration::_add_rule(LCRule *rule)
76
73
77
74
int RGWLifecycleConfiguration::check_and_add_rule (LCRule *rule)
78
75
{
79
- if (!rule->validate ()) {
76
+ if (!rule->valid ()) {
80
77
return -EINVAL;
81
78
}
82
79
string id;
@@ -92,9 +89,22 @@ int RGWLifecycleConfiguration::check_and_add_rule(LCRule *rule)
92
89
return 0 ;
93
90
}
94
91
92
+ bool RGWLifecycleConfiguration::has_same_action (const lc_op& first, const lc_op& second) {
93
+ if ((first.expiration > 0 || first.expiration_date != boost::none) &&
94
+ (second.expiration > 0 || second.expiration_date != boost::none)) {
95
+ return true ;
96
+ } else if (first.noncur_expiration > 0 && second.noncur_expiration > 0 ) {
97
+ return true ;
98
+ } else if (first.mp_expiration > 0 && second.mp_expiration > 0 ) {
99
+ return true ;
100
+ } else {
101
+ return false ;
102
+ }
103
+ }
104
+
95
105
// Rules are conflicted: if one rule's prefix starts with other rule's prefix, and these two rules
96
106
// define same action.
97
- bool RGWLifecycleConfiguration::validate ()
107
+ bool RGWLifecycleConfiguration::valid ()
98
108
{
99
109
if (prefix_map.size () < 2 ) {
100
110
return true ;
@@ -107,9 +117,7 @@ bool RGWLifecycleConfiguration::validate()
107
117
string c_pre = cur_iter->first ;
108
118
string n_pre = next_iter->first ;
109
119
if (n_pre.compare (0 , c_pre.length (), c_pre) == 0 ) {
110
- if ((cur_iter->second .expiration > 0 && next_iter->second .expiration > 0 ) ||
111
- (cur_iter->second .noncur_expiration > 0 && next_iter->second .noncur_expiration > 0 ) ||
112
- (cur_iter->second .mp_expiration > 0 && next_iter->second .mp_expiration > 0 )) {
120
+ if (has_same_action (cur_iter->second , next_iter->second )) {
113
121
return false ;
114
122
} else {
115
123
++next_iter;
@@ -346,7 +354,12 @@ int RGWLC::bucket_lc_process(string& shard_id)
346
354
list_op.params .list_versions = bucket_info.versioned ();
347
355
if (!bucket_info.versioned ()) {
348
356
for (auto prefix_iter = prefix_map.begin (); prefix_iter != prefix_map.end (); ++prefix_iter) {
349
- if (!prefix_iter->second .status || prefix_iter->second .expiration <=0 ) {
357
+ if (!prefix_iter->second .status ||
358
+ (prefix_iter->second .expiration <=0 && prefix_iter->second .expiration_date == boost::none)) {
359
+ continue ;
360
+ }
361
+ if (prefix_iter->second .expiration_date != boost::none &&
362
+ ceph_clock_now () < ceph::real_clock::to_time_t (*prefix_iter->second .expiration_date )) {
350
363
continue ;
351
364
}
352
365
list_op.params .prefix = prefix_iter->first ;
@@ -361,17 +374,22 @@ int RGWLC::bucket_lc_process(string& shard_id)
361
374
ldout (cct, 0 ) << " ERROR: store->list_objects():" <<dendl;
362
375
return ret;
363
376
}
364
-
377
+
365
378
utime_t now = ceph_clock_now ();
366
-
379
+ bool is_expired;
367
380
for (auto obj_iter = objs.begin (); obj_iter != objs.end (); ++obj_iter) {
368
381
rgw_obj_key key (obj_iter->key );
369
382
370
383
if (!key.ns .empty ()) {
371
384
continue ;
372
385
}
373
-
374
- if (obj_has_expired (now - ceph::real_clock::to_time_t (obj_iter->meta .mtime ), prefix_iter->second .expiration )) {
386
+ if (prefix_iter->second .expiration_date != boost::none) {
387
+ // we have checked it before
388
+ is_expired = true ;
389
+ } else {
390
+ is_expired = obj_has_expired (now - ceph::real_clock::to_time_t (obj_iter->meta .mtime ), prefix_iter->second .expiration );
391
+ }
392
+ if (is_expired) {
375
393
RGWObjectCtx rctx (store);
376
394
rgw_obj obj (bucket_info.bucket , key);
377
395
RGWObjState *state;
@@ -396,6 +414,7 @@ int RGWLC::bucket_lc_process(string& shard_id)
396
414
rgw_obj_key pre_marker;
397
415
for (auto prefix_iter = prefix_map.begin (); prefix_iter != prefix_map.end (); ++prefix_iter) {
398
416
if (!prefix_iter->second .status || (prefix_iter->second .expiration <= 0
417
+ && prefix_iter->second .expiration_date == boost::none
399
418
&& prefix_iter->second .noncur_expiration <= 0 && !prefix_iter->second .dm_expiration )) {
400
419
continue ;
401
420
}
@@ -427,10 +446,13 @@ int RGWLC::bucket_lc_process(string& shard_id)
427
446
bool remove_indeed = true ;
428
447
int expiration;
429
448
bool skip_expiration;
449
+ bool is_expired;
430
450
for (auto obj_iter = objs.begin (); obj_iter != objs.end (); ++obj_iter) {
431
451
skip_expiration = false ;
452
+ is_expired = false ;
432
453
if (obj_iter->is_current ()) {
433
- if (prefix_iter->second .expiration <= 0 && !prefix_iter->second .dm_expiration ) {
454
+ if (prefix_iter->second .expiration <= 0 && prefix_iter->second .expiration_date == boost::none
455
+ && !prefix_iter->second .dm_expiration ) {
434
456
continue ;
435
457
}
436
458
if (obj_iter->is_delete_marker ()) {
@@ -450,8 +472,14 @@ int RGWLC::bucket_lc_process(string& shard_id)
450
472
}
451
473
mtime = obj_iter->meta .mtime ;
452
474
expiration = prefix_iter->second .expiration ;
453
- if (!skip_expiration && expiration <= 0 ) {
475
+ if (!skip_expiration && expiration <= 0 && prefix_iter-> second . expiration_date == boost::none ) {
454
476
continue ;
477
+ } else if (!skip_expiration) {
478
+ if (expiration > 0 ) {
479
+ is_expired = obj_has_expired (now - ceph::real_clock::to_time_t (mtime), expiration);
480
+ } else {
481
+ is_expired = now >= ceph::real_clock::to_time_t (*prefix_iter->second .expiration_date );
482
+ }
455
483
}
456
484
} else {
457
485
if (prefix_iter->second .noncur_expiration <=0 ) {
@@ -460,8 +488,9 @@ int RGWLC::bucket_lc_process(string& shard_id)
460
488
remove_indeed = true ;
461
489
mtime = (obj_iter == objs.begin ())?pre_obj.meta .mtime :(obj_iter - 1 )->meta .mtime ;
462
490
expiration = prefix_iter->second .noncur_expiration ;
491
+ is_expired = obj_has_expired (now - ceph::real_clock::to_time_t (mtime), expiration);
463
492
}
464
- if (skip_expiration || obj_has_expired (now - ceph::real_clock::to_time_t (mtime), expiration) ) {
493
+ if (skip_expiration || is_expired ) {
465
494
if (obj_iter->is_visible ()) {
466
495
RGWObjectCtx rctx (store);
467
496
rgw_obj obj (bucket_info.bucket , obj_iter->key );
0 commit comments