typedef bi::link_mode<bi::safe_link> link_mode;
+ class ObjectFactory; // Forward declaration
+
class Object
{
private:
uint32_t get_refcnt() const { return lru_refcnt; }
- virtual bool reclaim() = 0;
+ virtual bool reclaim(const ObjectFactory* newobj_fac) = 0;
virtual ~Object() {}
(!(o->lru_flags & FLAG_EVICTING)));
}
- Object* evict_block() {
+ Object* evict_block(const ObjectFactory* newobj_fac) {
uint32_t lane_ix = next_evict_lane();
for (int ix = 0; ix < n_lanes; ++ix,
lane_ix = next_evict_lane()) {
++(o->lru_refcnt);
o->lru_flags |= FLAG_EVICTING;
lane.lock.unlock();
- if (o->reclaim()) {
+ if (o->reclaim(newobj_fac)) {
lane.lock.lock();
--(o->lru_refcnt);
/* assertions that o state has not changed across
Object* insert(ObjectFactory* fac, Edge edge, uint32_t& flags) {
/* use supplied functor to re-use an evicted object, or
* allocate a new one of the descendant type */
- Object* o = evict_block();
+ Object* o = evict_block(fac);
if (o) {
fac->recycle(o); /* recycle existing object */
flags |= FLAG_RECYCLE;
lat.lock->unlock();
return v;
} /* find_latch */
-
+ bool is_same_partition(uint64_t lhs, uint64_t rhs) {
+ return ((lhs % n_part) == (rhs % n_part));
+ }
void insert_latched(T* v, Latch& lat, uint32_t flags) {
(void) lat.p->tr.insert_unique_commit(*v, lat.commit_data);
if (flags & FLAG_UNLOCK)
return dar;
} /* RGWFileHandle::decode_attrs */
- bool RGWFileHandle::reclaim() {
+ bool RGWFileHandle::reclaim(const cohort::lru::ObjectFactory* newobj_fac) {
lsubdout(fs->get_context(), rgw, 17)
<< __func__ << " " << *this
<< dendl;
+ auto factory = dynamic_cast<const RGWFileHandle::Factory*>(newobj_fac);
+ if (factory == nullptr) {
+ return false;
+ }
+ /* make sure the reclaiming object is the same partiton with newobject factory,
+ * then we can recycle the object, and replace with newobject */
+ if (!fs->fh_cache.is_same_partition(factory->fhk.fh_hk.object, fh.fh_hk.object)) {
+ return false;
+ }
/* in the non-delete case, handle may still be in handle table */
if (fh_hook.is_linked()) {
/* in this case, we are being called from a context which holds