Skip to content

Commit 0e9f895

Browse files
samarahupritha-srivastava
authored andcommitted
rgw/d4n: squashing commits related to changing
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 <[email protected]> Updated bucket::list to convert from string to time_point Signed-off-by: Samarah <[email protected]> Signed-off-by: Pritha Srivastava <[email protected]>
1 parent 6e03c49 commit 0e9f895

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

src/rgw/driver/d4n/d4n_directory.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ int ObjectDirectory::update_field(const DoutPrefixProvider* dpp, CacheObj* objec
508508
return -EINVAL;
509509
}
510510
} else if (ret == -ENOENT) {
511-
ldpp_dout(dpp, 0) << "ObjectDirectory::" << __func__ << "(): Object does not exist." << dendl;
511+
ldpp_dout(dpp, 10) << "ObjectDirectory::" << __func__ << "(): Object does not exist." << dendl;
512512
} else {
513513
ldpp_dout(dpp, 0) << "ObjectDirectory::" << __func__ << "(): ERROR: ret=" << ret << dendl;
514514
}

src/rgw/driver/d4n/d4n_policy.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ static inline void redis_exec(std::shared_ptr<connection> conn,
4949
}
5050
}
5151

52-
int LFUDAPolicy::init(CephContext *cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver *_driver) {
52+
int LFUDAPolicy::init(CephContext* cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver* _driver) {
5353
response<int, int, int, int> resp;
5454
static auto obj_callback = [this](
55-
const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool dirty, uint64_t size,
56-
time_t creationTime, const rgw_user user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
55+
const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
56+
double creationTime, const rgw_user user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
5757
const rgw_obj_key& obj_key, optional_yield y, std::string& restore_val) {
58-
update_dirty_object(dpp, key, version, dirty, size, creationTime, user, etag, bucket_name, bucket_id, obj_key, RefCount::NOOP, y, restore_val);
58+
update_dirty_object(dpp, key, version, deleteMarker, size, creationTime, user, etag, bucket_name, bucket_id, obj_key, RefCount::NOOP, y, restore_val);
5959
};
6060

6161
static auto block_callback = [this](
@@ -310,7 +310,7 @@ CacheBlock* LFUDAPolicy::get_victim_block(const DoutPrefixProvider* dpp, optiona
310310
return victim;
311311
}
312312

313-
int LFUDAPolicy::exist_key(std::string key) {
313+
int LFUDAPolicy::exist_key(const std::string& key) {
314314
const std::lock_guard l(lfuda_lock);
315315
if (entries_map.count(key) != 0) {
316316
return true;
@@ -480,7 +480,7 @@ void LFUDAPolicy::update(const DoutPrefixProvider* dpp, const std::string& key,
480480
weightSum += ((localWeight < 0) ? 0 : localWeight);
481481
}
482482

483-
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)
483+
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)
484484
{
485485
using handle_type = boost::heap::fibonacci_heap<LFUDAObjEntry*, boost::heap::compare<ObjectComparator<LFUDAObjEntry>>>::handle_type;
486486
State state{State::INIT};
@@ -969,7 +969,7 @@ void LFUDAPolicy::cleaning(const DoutPrefixProvider* dpp)
969969
} //end-while true
970970
}
971971

972-
int LRUPolicy::exist_key(std::string key)
972+
int LRUPolicy::exist_key(const std::string& key)
973973
{
974974
const std::lock_guard l(lru_lock);
975975
if (entries_map.count(key) != 0) {
@@ -1008,7 +1008,7 @@ void LRUPolicy::update(const DoutPrefixProvider* dpp, const std::string& key, ui
10081008
entries_map.emplace(key, e);
10091009
}
10101010

1011-
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,
1011+
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,
10121012
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val)
10131013
{
10141014
const std::lock_guard l(lru_lock);

src/rgw/driver/d4n/d4n_policy.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ class CachePolicy {
5454
std::string version;
5555
bool delete_marker;
5656
uint64_t size;
57-
time_t creationTime;
57+
double creationTime;
5858
rgw_user user;
5959
std::string etag;
6060
std::string bucket_name;
6161
std::string bucket_id;
6262
rgw_obj_key obj_key;
6363
ObjEntry() = default;
6464
ObjEntry(const std::string& key, const std::string& version, bool delete_marker, uint64_t size,
65-
time_t creationTime, rgw_user user, const std::string& etag,
65+
double creationTime, const rgw_user& user, const std::string& etag,
6666
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),
6767
creationTime(creationTime), user(user), etag(etag),
6868
bucket_name(bucket_name), bucket_id(bucket_id), obj_key(obj_key) {}
@@ -73,12 +73,12 @@ class CachePolicy {
7373
virtual ~CachePolicy() = default;
7474

7575
virtual int init(CephContext* cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver* _driver) = 0;
76-
virtual int exist_key(std::string key) = 0;
76+
virtual int exist_key(const std::string& key) = 0;
7777
virtual int eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y) = 0;
7878
virtual bool update_refcount_if_key_exists(const DoutPrefixProvider* dpp, const std::string& key, uint8_t op, optional_yield y) = 0;
7979
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;
8080
virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
81-
time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
81+
double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
8282
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) = 0;
8383
virtual bool erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) = 0;
8484
virtual bool erase_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) = 0;
@@ -132,7 +132,7 @@ class LFUDAPolicy : public CachePolicy {
132132
handle_type handle;
133133

134134
LFUDAObjEntry(const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
135-
time_t creationTime, rgw_user user, const std::string& etag,
135+
double creationTime, const rgw_user& user, const std::string& etag,
136136
const std::string& bucket_name, const std::string& bucket_id, const rgw_obj_key& obj_key) : ObjEntry(key, version, deleteMarker, size,
137137
creationTime, user, etag, bucket_name, bucket_id, obj_key) {}
138138

@@ -201,15 +201,15 @@ class LFUDAPolicy : public CachePolicy {
201201
}
202202

203203
virtual int init(CephContext *cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver *_driver);
204-
virtual int exist_key(std::string key) override;
204+
virtual int exist_key(const std::string& key) override;
205205
virtual int eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y) override;
206206
virtual bool update_refcount_if_key_exists(const DoutPrefixProvider* dpp, const std::string& key, uint8_t op, optional_yield y) override;
207207
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;
208208
virtual bool erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override;
209209
virtual bool _erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y);
210210
void save_y(optional_yield y) { this->y = y; }
211211
virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
212-
time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
212+
double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
213213
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
214214
virtual bool erase_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override;
215215
virtual bool invalidate_dirty_object(const DoutPrefixProvider* dpp, const std::string& key) override;
@@ -239,13 +239,13 @@ class LRUPolicy : public CachePolicy {
239239
LRUPolicy(rgw::cache::CacheDriver* cacheDriver) : cacheDriver{cacheDriver} {}
240240

241241
virtual int init(CephContext* cct, const DoutPrefixProvider* dpp, asio::io_context& io_context, rgw::sal::Driver* _driver) { return 0; }
242-
virtual int exist_key(std::string key) override;
242+
virtual int exist_key(const std::string& key) override;
243243
virtual int eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y) override;
244244
virtual bool update_refcount_if_key_exists(const DoutPrefixProvider* dpp, const std::string& key, uint8_t op, optional_yield y) override { return false; }
245245
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;
246-
virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
247-
time_t creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
248-
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
246+
virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size,
247+
double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id,
248+
const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) override;
249249
virtual bool erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override;
250250
virtual bool erase_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override;
251251
virtual bool invalidate_dirty_object(const DoutPrefixProvider* dpp, const std::string& key) override { return false; }

src/rgw/driver/d4n/rgw_sal_d4n.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,12 @@ int D4NFilterBucket::list(const DoutPrefixProvider* dpp, ListParams& params, int
478478
entry.meta.storage_class = "CACHE";
479479
entry.meta.size = block.cacheObj.size;
480480
entry.meta.accounted_size = block.cacheObj.size;
481-
struct std::tm tm;
482-
std::istringstream ss(block.cacheObj.creationTime);
483-
ss >> std::get_time(&tm, "%H:%M:%S");
484-
std::time_t creationTime = mktime(&tm);
485-
entry.meta.mtime = ceph::real_clock::from_time_t(creationTime);
481+
try {
482+
double time = std::stod(block.cacheObj.creationTime);
483+
entry.meta.mtime = ceph::real_clock::from_double(time);
484+
} catch (const std::exception& e) {
485+
ldpp_dout(dpp, 0) << "D4NFilterBucket::" << __func__ << " Invalid value of time: " << block.cacheObj.creationTime << dendl;
486+
}
486487
entry.meta.etag = block.cacheObj.etag;
487488
entry.meta.owner = block.cacheObj.user_id;
488489
entry.meta.owner_display_name = block.cacheObj.display_name;
@@ -740,7 +741,7 @@ int D4NFilterObject::copy_object(const ACLOwner& owner,
740741
} else {
741742
dest_mtime = real_clock::now();
742743
}
743-
creationTime = ceph::real_clock::to_time_t(dest_mtime);
744+
creationTime = ceph::real_clock::to_double(dest_mtime);
744745
dest_object->set_mtime(dest_mtime);
745746
dest_object->set_obj_size(this->get_size());
746747
dest_object->set_accounted_size(this->get_accounted_size());
@@ -1062,7 +1063,7 @@ int D4NFilterObject::create_delete_marker(const DoutPrefixProvider* dpp, optiona
10621063
ldpp_dout(dpp, 0) << "D4NFilterObject::" << __func__ << "(): BlockDirectory set method failed for head object, ret=" << ret << dendl;
10631064
return ret;
10641065
}
1065-
auto creationTime = ceph::real_clock::to_time_t(this->get_mtime());
1066+
auto creationTime = ceph::real_clock::to_double(this->get_mtime());
10661067
ldpp_dout(dpp, 0) << "D4NFilterObject::" << __func__ << "(): key=" << key << dendl;
10671068
std::string objEtag = "";
10681069
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);
@@ -1129,7 +1130,7 @@ int D4NFilterObject::set_head_obj_dir_entry(const DoutPrefixProvider* dpp, std::
11291130
rgw::d4n::CacheObj object = rgw::d4n::CacheObj{
11301131
.objName = objName,
11311132
.bucketName = this->get_bucket()->get_bucket_id(),
1132-
.creationTime = std::to_string(ceph::real_clock::to_time_t(this->get_mtime())),
1133+
.creationTime = std::to_string(ceph::real_clock::to_double(this->get_mtime())),
11331134
.dirty = dirty,
11341135
.hostsList = { dpp->get_cct()->_conf->rgw_d4n_l1_datacache_address },
11351136
.etag = etag,
@@ -1174,8 +1175,8 @@ int D4NFilterObject::set_head_obj_dir_entry(const DoutPrefixProvider* dpp, std::
11741175
object_version = this->get_object_version();
11751176
}
11761177
auto mtime = this->get_mtime();
1177-
auto score = ceph::real_clock::to_time_t(mtime);
1178-
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;
1178+
auto score = ceph::real_clock::to_double(mtime);
1179+
ldpp_dout(dpp, 10) << "D4NFilterObject::" << __func__ << "(): Score of object name: "<< this->get_name() << " version: " << object_version << " is: " << score << ret << dendl;
11791180
rgw::d4n::ObjectDirectory* objDir = this->driver->get_obj_dir();
11801181
ret = objDir->zadd(dpp, &object, score, object_version, y);
11811182
if (ret < 0) {
@@ -1253,7 +1254,7 @@ int D4NFilterObject::set_head_obj_dir_entry(const DoutPrefixProvider* dpp, std::
12531254
rgw::d4n::CacheObj version_object = rgw::d4n::CacheObj{
12541255
.objName = objName,
12551256
.bucketName = this->get_bucket()->get_bucket_id(),
1256-
.creationTime = std::to_string(ceph::real_clock::to_time_t(this->get_mtime())),
1257+
.creationTime = std::to_string(ceph::real_clock::to_double(this->get_mtime())),
12571258
.dirty = dirty,
12581259
.etag = etag,
12591260
.size = this->get_accounted_size(),
@@ -2262,7 +2263,7 @@ int D4NFilterObject::D4NFilterReadOp::D4NFilterGetCB::handle_data(bufferlist& bl
22622263
block.cacheObj.objName = source->get_key().get_oid();
22632264
block.cacheObj.bucketName = source->get_bucket()->get_bucket_id();
22642265
std::stringstream s;
2265-
block.cacheObj.creationTime = std::to_string(ceph::real_clock::to_time_t(source->get_mtime()));
2266+
block.cacheObj.creationTime = std::to_string(ceph::real_clock::to_double(source->get_mtime()));
22662267
bool dirty = block.cacheObj.dirty = false; //Reading from the backend, data is clean
22672268
block.version = version;
22682269

@@ -2984,7 +2985,7 @@ int D4NFilterWriter::complete(size_t accounted_size, const std::string& etag,
29842985
return ret;
29852986
}
29862987
if (dirty) {
2987-
auto creationTime = ceph::real_clock::to_time_t(object->get_mtime());
2988+
auto creationTime = ceph::real_clock::to_double(object->get_mtime());
29882989
ldpp_dout(dpp, 20) << "D4NFilterWriter::" << __func__ << "(): key=" << key << dendl;
29892990
ldpp_dout(dpp, 20) << "D4NFilterWriter::" << __func__ << "(): obj->get_key()=" << obj->get_key() << dendl;
29902991
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);

0 commit comments

Comments
 (0)