From fe8b1c977fb8df5af81ee0368ebd199b6e8ea65f Mon Sep 17 00:00:00 2001 From: xinxin shu Date: Sun, 16 Aug 2015 09:12:56 +0800 Subject: [PATCH] in filestore, OP_SETATTR is implemented in FileStore::_setattrs this funtion will get all attrs of object before setting new attrs merge several OP_SETATTR ops into one OP_SETATTRS in one ceph trasaction, which will reduce counts of getting all attrs Signed-off-by: xinxin shu --- src/osd/ReplicatedPG.cc | 39 +++++++++++++++++++++++++++++++-------- src/osd/ReplicatedPG.h | 5 +++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index c29a2afa706d5..c721c2f75c061 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -3240,13 +3240,15 @@ ReplicatedPG::RepGather *ReplicatedPG::trim_object(const hobject_t &coid) ctx->snapset_obc->obs.oi.version; ctx->snapset_obc->obs.oi.version = ctx->at_version; + map attrs; bl.clear(); ::encode(snapset, bl); - setattr_maybe_cache(ctx->snapset_obc, ctx, t, SS_ATTR, bl); + attrs[SS_ATTR].claim(bl); bl.clear(); ::encode(ctx->snapset_obc->obs.oi, bl); - setattr_maybe_cache(ctx->snapset_obc, ctx, t, OI_ATTR, bl); + attrs[OI_ATTR].claim(bl); + setattrs_maybe_cache(ctx->snapset_obc, ctx, t, attrs); if (pool.info.require_rollback()) { set changing; @@ -6140,11 +6142,13 @@ void ReplicatedPG::finish_ctx(OpContext *ctx, int log_op_type, bool maintain_ssc ctx->snapset_obc->obs.oi.mtime = ctx->mtime; ctx->snapset_obc->obs.oi.local_mtime = now; + map attrs; bufferlist bv(sizeof(ctx->new_obs.oi)); ::encode(ctx->snapset_obc->obs.oi, bv); ctx->op_t->touch(snapoid); - setattr_maybe_cache(ctx->snapset_obc, ctx, ctx->op_t, OI_ATTR, bv); - setattr_maybe_cache(ctx->snapset_obc, ctx, ctx->op_t, SS_ATTR, bss); + attrs[OI_ATTR].claim(bv); + attrs[SS_ATTR].claim(bss); + setattrs_maybe_cache(ctx->snapset_obc, ctx, ctx->op_t, attrs); if (pool.info.require_rollback()) { map > to_set; to_set[SS_ATTR]; @@ -6184,17 +6188,19 @@ void ReplicatedPG::finish_ctx(OpContext *ctx, int log_op_type, bool maintain_ssc dout(10) << " mtime unchanged at " << ctx->new_obs.oi.mtime << dendl; } + map attrs; bufferlist bv(sizeof(ctx->new_obs.oi)); ::encode(ctx->new_obs.oi, bv); - setattr_maybe_cache(ctx->obc, ctx, ctx->op_t, OI_ATTR, bv); + attrs[OI_ATTR].claim(bv); if (soid.snap == CEPH_NOSNAP) { dout(10) << " final snapset " << ctx->new_snapset << " in " << soid << dendl; - setattr_maybe_cache(ctx->obc, ctx, ctx->op_t, SS_ATTR, bss); + attrs[SS_ATTR].claim(bss); } else { dout(10) << " no snapset (this is a clone)" << dendl; } + setattrs_maybe_cache(ctx->obc, ctx, ctx->op_t, attrs); if (pool.info.require_rollback()) { set changing; @@ -10899,8 +10905,10 @@ void ReplicatedPG::hit_set_persist() ::encode(ctx->new_obs.oi, boi); ctx->op_t->append(oid, 0, bl.length(), bl, 0); - setattr_maybe_cache(ctx->obc, ctx, ctx->op_t, OI_ATTR, boi); - setattr_maybe_cache(ctx->obc, ctx, ctx->op_t, SS_ATTR, bss); + map attrs; + attrs[OI_ATTR].claim(boi); + attrs[SS_ATTR].claim(bss); + setattrs_maybe_cache(ctx->obc, ctx, ctx->op_t, attrs); ctx->log.push_back( pg_log_entry_t( pg_log_entry_t::MODIFY, @@ -12258,6 +12266,21 @@ void ReplicatedPG::setattr_maybe_cache( t->setattr(obc->obs.oi.soid, key, val); } +void ReplicatedPG::setattrs_maybe_cache( + ObjectContextRef obc, + OpContext *op, + PGBackend::PGTransaction *t, + map &attrs) +{ + if (pool.info.require_rollback()) { + for (map::iterator it = attrs.begin(); + it != attrs.end(); it++ ) { + op->pending_attrs[obc][it->first] = it->second; + } + } + t->setattrs(obc->obs.oi.soid, attrs); +} + void ReplicatedPG::rmattr_maybe_cache( ObjectContextRef obc, OpContext *op, diff --git a/src/osd/ReplicatedPG.h b/src/osd/ReplicatedPG.h index 4517e68730ebb..06c9b36268f45 100644 --- a/src/osd/ReplicatedPG.h +++ b/src/osd/ReplicatedPG.h @@ -1581,6 +1581,11 @@ public: PGBackend::PGTransaction *t, const string &key, bufferlist &val); + void setattrs_maybe_cache( + ObjectContextRef obc, + OpContext *op, + PGBackend::PGTransaction *t, + map &attrs); void rmattr_maybe_cache( ObjectContextRef obc, OpContext *op, -- 2.47.3