@@ -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+
802827int 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);
0 commit comments