Skip to content

Commit 9b64d68

Browse files
rgw/d4n: implementation of load_obj_state() and exists()
for D4NFilterObject. Signed-off-by: Pritha Srivastava <[email protected]>
1 parent 0e9f895 commit 9b64d68

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/rgw/driver/d4n/rgw_sal_d4n.cc

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,31 @@ int D4NFilterObject::copy_object(const ACLOwner& owner,
799799
return 0;
800800
}
801801

802+
int D4NFilterObject::load_obj_state(const DoutPrefixProvider *dpp, optional_yield y,
803+
bool follow_olh)
804+
{
805+
if (load_from_store) {
806+
return next->load_obj_state(dpp, y, follow_olh);
807+
}
808+
bool has_instance = false;
809+
if (!this->get_instance().empty()) {
810+
has_instance = true;
811+
}
812+
int ret = get_obj_attrs_from_cache(dpp, y);
813+
if (ret) {
814+
/* clearing instance if not present in object before
815+
calling get_obj_attrs_from_cache as it incorrectly
816+
causes delete obj to be invoked for an instance
817+
even though a simple delete request has been issued
818+
(after load_obj_state is invoked) */
819+
if (!has_instance) {
820+
this->clear_instance();
821+
}
822+
return 0;
823+
}
824+
return next->load_obj_state(dpp, y, follow_olh);
825+
}
826+
802827
int D4NFilterObject::set_obj_attrs(const DoutPrefixProvider* dpp, Attrs* setattrs,
803828
Attrs* delattrs, optional_yield y, uint32_t flags)
804829
{
@@ -915,7 +940,9 @@ int D4NFilterObject::get_obj_attrs_from_cache(const DoutPrefixProvider* dpp, opt
915940
}
916941
}//end-if
917942
}//end-for
918-
this->set_instance(instance); //set this only after setting object state else it won't take effect
943+
if (!instance.empty()) {
944+
this->set_instance(instance); //set this only after setting object state else it won't take effect
945+
}
919946
attrs.erase(RGW_CACHE_ATTR_MTIME);
920947
attrs.erase(RGW_CACHE_ATTR_OBJECT_SIZE);
921948
attrs.erase(RGW_CACHE_ATTR_ACCOUNTED_SIZE);
@@ -1412,6 +1439,7 @@ bool D4NFilterObject::check_head_exists_in_cache_get_oid(const DoutPrefixProvide
14121439
}
14131440
std::string key = head_oid_in_cache;
14141441
this->driver->get_policy_driver()->get_cache_policy()->update(dpp, key, 0, 0, version, block.cacheObj.dirty, rgw::d4n::RefCount::DECR, y);
1442+
this->exists_in_cache = true;
14151443
} else {
14161444
found_in_cache = false;
14171445
}
@@ -2948,6 +2976,9 @@ int D4NFilterWriter::complete(size_t accounted_size, const std::string& etag,
29482976
ldpp_dout(dpp, 0) << "D4NFilterWriter::" << __func__ << "(): writing to backend store failed, ret=" << ret << dendl;
29492977
return ret;
29502978
}
2979+
/* we want to always load latest object state from store
2980+
to avoid reading stale state in case of object overwrites. */
2981+
object->set_load_obj_from_store(true);
29512982
object->load_obj_state(dpp, y);
29522983
attrs = object->get_attrs();
29532984
object->set_attrs_from_obj_state(dpp, y, attrs, dirty);
@@ -3025,6 +3056,9 @@ int D4NFilterMultipartUpload::complete(const DoutPrefixProvider *dpp,
30253056

30263057
//Cache only the head object for multipart objects
30273058
D4NFilterObject* d4n_target_obj = dynamic_cast<D4NFilterObject*>(target_obj);
3059+
/* we want to always load latest object state from store
3060+
to avoid reading stale state in case of object overwrites. */
3061+
d4n_target_obj->set_load_obj_from_store(true);
30283062
d4n_target_obj->load_obj_state(dpp, y);
30293063
rgw::sal::Attrs attrs = d4n_target_obj->get_attrs();
30303064
d4n_target_obj->set_attrs_from_obj_state(dpp, y, attrs);

src/rgw/driver/d4n/rgw_sal_d4n.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class D4NFilterObject : public FilterObject {
134134
rgw::sal::Bucket* dest_bucket{nullptr}; //for copy-object
135135
bool multipart{false};
136136
bool delete_marker{false};
137+
bool exists_in_cache{false};
138+
bool load_from_store{false};
137139

138140
public:
139141
struct D4NFilterReadOp : FilterReadOp {
@@ -245,6 +247,8 @@ class D4NFilterObject : public FilterObject {
245247
optional_yield y) override;
246248

247249
virtual const std::string &get_name() const override { return next->get_name(); }
250+
virtual int load_obj_state(const DoutPrefixProvider *dpp, optional_yield y,
251+
bool follow_olh = true) override;
248252
virtual int set_obj_attrs(const DoutPrefixProvider* dpp, Attrs* setattrs,
249253
Attrs* delattrs, optional_yield y, uint32_t flags) override;
250254
virtual int get_obj_attrs(optional_yield y, const DoutPrefixProvider* dpp,
@@ -277,6 +281,9 @@ class D4NFilterObject : public FilterObject {
277281
int set_attr_crypt_parts(const DoutPrefixProvider* dpp, optional_yield y, rgw::sal::Attrs& attrs);
278282
int create_delete_marker(const DoutPrefixProvider* dpp, optional_yield y);
279283
bool is_delete_marker() { return delete_marker; }
284+
bool exists(void) override { if (exists_in_cache) { return true;} return next->exists(); };
285+
bool load_obj_from_store() { return load_from_store; }
286+
void set_load_obj_from_store(bool load_from_store) { this->load_from_store = load_from_store; }
280287
};
281288

282289
class D4NFilterWriter : public FilterWriter {

0 commit comments

Comments
 (0)