creationTime type from time_t to double.
1. rgw/d4n: Change score calculation
2. rgw/d4n: Update creationTime calculation to include decimal value
3. rgw/d4n: changes for converting string value to
time_point, when creationTime type changed to double.
Co-authored-by: Pritha Srivastava <prsrivas@redhat.com>
Updated bucket::list to convert from string to time_point
Signed-off-by: Samarah <samarah.uriarte@ibm.com>
Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
return -EINVAL;
}
} else if (ret == -ENOENT) {
- ldpp_dout(dpp, 0) << "ObjectDirectory::" << __func__ << "(): Object does not exist." << dendl;
+ ldpp_dout(dpp, 10) << "ObjectDirectory::" << __func__ << "(): Object does not exist." << dendl;
} else {
ldpp_dout(dpp, 0) << "ObjectDirectory::" << __func__ << "(): ERROR: ret=" << ret << dendl;
}
}
}
-int LFUDAPolicy::init(CephContext *cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver *_driver) {
+int LFUDAPolicy::init(CephContext* cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver* _driver) {
response<int, int, int, int> resp;
static auto obj_callback = [this](
- const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool dirty, uint64_t size,
- time_t creationTime, const rgw_user user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
+ const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
+ double creationTime, const rgw_user user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
const rgw_obj_key& obj_key, optional_yield y, std::string& restore_val) {
- update_dirty_object(dpp, key, version, dirty, size, creationTime, user, etag, bucket_name, bucket_id, obj_key, RefCount::NOOP, y, restore_val);
+ update_dirty_object(dpp, key, version, deleteMarker, size, creationTime, user, etag, bucket_name, bucket_id, obj_key, RefCount::NOOP, y, restore_val);
};
static auto block_callback = [this](
return victim;
}
-int LFUDAPolicy::exist_key(std::string key) {
+int LFUDAPolicy::exist_key(const std::string& key) {
const std::lock_guard l(lfuda_lock);
if (entries_map.count(key) != 0) {
return true;
weightSum += ((localWeight < 0) ? 0 : localWeight);
}
-void LFUDAPolicy::update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size, time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id, const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val)
+void LFUDAPolicy::update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size, double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id, const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val)
{
using handle_type = boost::heap::fibonacci_heap<LFUDAObjEntry*, boost::heap::compare<ObjectComparator<LFUDAObjEntry>>>::handle_type;
State state{State::INIT};
} //end-while true
}
-int LRUPolicy::exist_key(std::string key)
+int LRUPolicy::exist_key(const std::string& key)
{
const std::lock_guard l(lru_lock);
if (entries_map.count(key) != 0) {
entries_map.emplace(key, e);
}
-void LRUPolicy::update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size, time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
+void LRUPolicy::update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size, double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val)
{
const std::lock_guard l(lru_lock);
std::string version;
bool delete_marker;
uint64_t size;
- time_t creationTime;
+ double creationTime;
rgw_user user;
std::string etag;
std::string bucket_name;
rgw_obj_key obj_key;
ObjEntry() = default;
ObjEntry(const std::string& key, const std::string& version, bool delete_marker, uint64_t size,
- time_t creationTime, rgw_user user, const std::string& etag,
+ double creationTime, const rgw_user& user, const std::string& etag,
const std::string& bucket_name, const std::string& bucket_id, const rgw_obj_key& obj_key) : key(key), version(version), delete_marker(delete_marker), size(size),
creationTime(creationTime), user(user), etag(etag),
bucket_name(bucket_name), bucket_id(bucket_id), obj_key(obj_key) {}
virtual ~CachePolicy() = default;
virtual int init(CephContext* cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver* _driver) = 0;
- virtual int exist_key(std::string key) = 0;
+ virtual int exist_key(const std::string& key) = 0;
virtual int eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y) = 0;
virtual bool update_refcount_if_key_exists(const DoutPrefixProvider* dpp, const std::string& key, uint8_t op, optional_yield y) = 0;
virtual void update(const DoutPrefixProvider* dpp, const std::string& key, uint64_t offset, uint64_t len, const std::string& version, bool dirty, uint8_t op, optional_yield y, std::string& restore_val=empty) = 0;
virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
- time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
+ double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) = 0;
virtual bool erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) = 0;
virtual bool erase_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) = 0;
handle_type handle;
LFUDAObjEntry(const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
- time_t creationTime, rgw_user user, const std::string& etag,
+ double creationTime, const rgw_user& user, const std::string& etag,
const std::string& bucket_name, const std::string& bucket_id, const rgw_obj_key& obj_key) : ObjEntry(key, version, deleteMarker, size,
creationTime, user, etag, bucket_name, bucket_id, obj_key) {}
}
virtual int init(CephContext *cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver *_driver);
- virtual int exist_key(std::string key) override;
+ virtual int exist_key(const std::string& key) override;
virtual int eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y) override;
virtual bool update_refcount_if_key_exists(const DoutPrefixProvider* dpp, const std::string& key, uint8_t op, optional_yield y) override;
virtual void update(const DoutPrefixProvider* dpp, const std::string& key, uint64_t offset, uint64_t len, const std::string& version, bool dirty, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
virtual bool _erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y);
void save_y(optional_yield y) { this->y = y; }
virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
- time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
+ double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
virtual bool erase_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override;
virtual bool invalidate_dirty_object(const DoutPrefixProvider* dpp, const std::string& key) override;
LRUPolicy(rgw::cache::CacheDriver* cacheDriver) : cacheDriver{cacheDriver} {}
virtual int init(CephContext* cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver* _driver) { return 0; }
- virtual int exist_key(std::string key) override;
+ virtual int exist_key(const std::string& key) override;
virtual int eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y) override;
virtual bool update_refcount_if_key_exists(const DoutPrefixProvider* dpp, const std::string& key, uint8_t op, optional_yield y) override { return false; }
virtual void update(const DoutPrefixProvider* dpp, const std::string& key, uint64_t offset, uint64_t len, const std::string& version, bool dirty, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
- virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
- time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
- const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
+ virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
+ double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
+ const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
virtual bool erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override;
virtual bool erase_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override;
virtual bool invalidate_dirty_object(const DoutPrefixProvider* dpp, const std::string& key) override { return false; }
entry.meta.storage_class = "CACHE";
entry.meta.size = block.cacheObj.size;
entry.meta.accounted_size = block.cacheObj.size;
- struct std::tm tm;
- std::istringstream ss(block.cacheObj.creationTime);
- ss >> std::get_time(&tm, "%H:%M:%S");
- std::time_t creationTime = mktime(&tm);
- entry.meta.mtime = ceph::real_clock::from_time_t(creationTime);
+ try {
+ double time = std::stod(block.cacheObj.creationTime);
+ entry.meta.mtime = ceph::real_clock::from_double(time);
+ } catch (const std::exception& e) {
+ ldpp_dout(dpp, 0) << "D4NFilterBucket::" << __func__ << " Invalid value of time: " << block.cacheObj.creationTime << dendl;
+ }
entry.meta.etag = block.cacheObj.etag;
entry.meta.owner = block.cacheObj.user_id;
entry.meta.owner_display_name = block.cacheObj.display_name;
} else {
dest_mtime = real_clock::now();
}
- creationTime = ceph::real_clock::to_time_t(dest_mtime);
+ creationTime = ceph::real_clock::to_double(dest_mtime);
dest_object->set_mtime(dest_mtime);
dest_object->set_obj_size(this->get_size());
dest_object->set_accounted_size(this->get_accounted_size());
ldpp_dout(dpp, 0) << "D4NFilterObject::" << __func__ << "(): BlockDirectory set method failed for head object, ret=" << ret << dendl;
return ret;
}
- auto creationTime = ceph::real_clock::to_time_t(this->get_mtime());
+ auto creationTime = ceph::real_clock::to_double(this->get_mtime());
ldpp_dout(dpp, 0) << "D4NFilterObject::" << __func__ << "(): key=" << key << dendl;
std::string objEtag = "";
driver->get_policy_driver()->get_cache_policy()->update_dirty_object(dpp, key, version, true, this->get_accounted_size(), creationTime, std::get<rgw_user>(this->get_bucket()->get_owner()), objEtag, this->get_bucket()->get_name(), this->get_bucket()->get_bucket_id(), this->get_key(), rgw::d4n::RefCount::NOOP, y);
rgw::d4n::CacheObj object = rgw::d4n::CacheObj{
.objName = objName,
.bucketName = this->get_bucket()->get_bucket_id(),
- .creationTime = std::to_string(ceph::real_clock::to_time_t(this->get_mtime())),
+ .creationTime = std::to_string(ceph::real_clock::to_double(this->get_mtime())),
.dirty = dirty,
.hostsList = { dpp->get_cct()->_conf->rgw_d4n_l1_datacache_address },
.etag = etag,
object_version = this->get_object_version();
}
auto mtime = this->get_mtime();
- auto score = ceph::real_clock::to_time_t(mtime);
- ldpp_dout(dpp, 10) << "D4NFilterObject::" << __func__ << "(): Score of object name: "<< this->get_name() << " version: " << object_version << " is: " << std::setprecision(std::numeric_limits<double>::max_digits10) << score << ret << dendl;
+ auto score = ceph::real_clock::to_double(mtime);
+ ldpp_dout(dpp, 10) << "D4NFilterObject::" << __func__ << "(): Score of object name: "<< this->get_name() << " version: " << object_version << " is: " << score << ret << dendl;
rgw::d4n::ObjectDirectory* objDir = this->driver->get_obj_dir();
ret = objDir->zadd(dpp, &object, score, object_version, y);
if (ret < 0) {
rgw::d4n::CacheObj version_object = rgw::d4n::CacheObj{
.objName = objName,
.bucketName = this->get_bucket()->get_bucket_id(),
- .creationTime = std::to_string(ceph::real_clock::to_time_t(this->get_mtime())),
+ .creationTime = std::to_string(ceph::real_clock::to_double(this->get_mtime())),
.dirty = dirty,
.etag = etag,
.size = this->get_accounted_size(),
block.cacheObj.objName = source->get_key().get_oid();
block.cacheObj.bucketName = source->get_bucket()->get_bucket_id();
std::stringstream s;
- block.cacheObj.creationTime = std::to_string(ceph::real_clock::to_time_t(source->get_mtime()));
+ block.cacheObj.creationTime = std::to_string(ceph::real_clock::to_double(source->get_mtime()));
bool dirty = block.cacheObj.dirty = false; //Reading from the backend, data is clean
block.version = version;
return ret;
}
if (dirty) {
- auto creationTime = ceph::real_clock::to_time_t(object->get_mtime());
+ auto creationTime = ceph::real_clock::to_double(object->get_mtime());
ldpp_dout(dpp, 20) << "D4NFilterWriter::" << __func__ << "(): key=" << key << dendl;
ldpp_dout(dpp, 20) << "D4NFilterWriter::" << __func__ << "(): obj->get_key()=" << obj->get_key() << dendl;
driver->get_policy_driver()->get_cache_policy()->update_dirty_object(dpp, key, version, false, accounted_size, creationTime, std::get<rgw_user>(obj->get_bucket()->get_owner()), objEtag, obj->get_bucket()->get_name(), obj->get_bucket()->get_bucket_id(), obj->get_key(), rgw::d4n::RefCount::NOOP, y);