using namespace std;
using namespace librados;
+
+bool LCRule::validate()
+{
+ if (id.length() > MAX_ID_LEN)
+ return false;
+ else if (status.compare("Enabled") != 0 && status.compare("Disabled") != 0)
+ return false;
+ else if (expiration.get_days() <= 0)
+ return false;
+ return true;
+}
+
void RGWLifecycleConfiguration::add_rule(LCRule *rule)
{
string id;
prefix_map[rule->get_prefix()] = rule->get_expiration().get_days();
}
+bool RGWLifecycleConfiguration::check_and_add_rule(LCRule *rule)
+{
+ if (!rule->validate())
+ return false;
+ string id;
+ rule->get_id(id);
+ if (rule_map.find(id) != rule_map.end()) //id shouldn't be the same
+ return false;
+ rule_map.insert(pair<string, LCRule>(id, *rule));
+
+ auto ret = prefix_map.insert(pair<string, int>(rule->get_prefix(), rule->get_expiration().get_days()));
+ //Now prefix shouldn't be the same. When we add noncurrent expiration or other action, prefix may be same.
+ if (!ret.second)
+ return false;
+ return true;
+}
+
+//Rules are conflicted: if one rule's prefix starts with other rule's prefix, and these two rules
+//define same action(now only support expiration days).
+bool RGWLifecycleConfiguration::validate()
+{
+ if (prefix_map.size() < 2)
+ return true;
+ auto next_iter = prefix_map.begin();
+ auto cur_iter = next_iter++;
+ while (next_iter != prefix_map.end()) {
+ string c_pre = cur_iter->first;
+ string n_pre = next_iter->first;
+ if (c_pre.length() > n_pre.length()) {
+ if (c_pre.compare(0, n_pre.length(), n_pre) == 0) {
+ return false;
+ }
+ } else {
+ if (n_pre.compare(0, c_pre.length(), c_pre) == 0) {
+ return false;
+ }
+ }
+ ++next_iter;
+ ++cur_iter;
+ }
+ return true;
+}
+
void *RGWLC::LCWorker::entry() {
do {
utime_t start = ceph_clock_now();
using namespace std;
#define HASH_PRIME 7877
+#define MAX_ID_LEN 255
static string lc_oid_prefix = "lc";
static string lc_index_lock_name = "lc_process";
void set_expiration(LCExpiration*_expiration) {
expiration = *_expiration;
}
+
+ bool validate();
void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
void add_rule(LCRule* rule);
+ bool check_and_add_rule(LCRule* rule);
+
+ bool validate();
+
multimap<string, LCRule>& get_rule_map() { return rule_map; }
map<string, int>& get_prefix_map() { return prefix_map; }
/*
multimap<string, LCRule>::iterator iter;
for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
LCRule& src_rule = iter->second;
- bool rule_ok = true;
-
- if (rule_ok) {
- dest.add_rule(&src_rule);
- }
+ if (!dest.check_and_add_rule(&src_rule))
+ return -EINVAL;
}
-
+ if (!dest.validate())
+ return -EINVAL;
return 0;
}