From a36ee8c2076eb1bcdbb69c24f4ce9c63c5928540 Mon Sep 17 00:00:00 2001 From: Ying He Date: Wed, 16 Aug 2017 07:47:35 +0800 Subject: [PATCH] * messages/MOSDOp: a fix of encode_payload If we set config ms_dump_on_send,the function encode may run twice. Then data will double of normal data. Signed-off-by: Ying He --- src/messages/MOSDOp.h | 15 ++++++++++----- src/messages/MOSDOpReply.h | 14 ++++++++++---- src/messages/MOSDSubOp.h | 12 +++++++++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/messages/MOSDOp.h b/src/messages/MOSDOp.h index 80c6ecf77687..de19e879bc30 100755 --- a/src/messages/MOSDOp.h +++ b/src/messages/MOSDOp.h @@ -59,7 +59,7 @@ private: vector snaps; uint64_t features; - + bool bdata_encode; osd_reqid_t reqid; // reqid explicitly set by sender public: @@ -169,7 +169,8 @@ public: MOSDOp() : MOSDFastDispatchOp(CEPH_MSG_OSD_OP, HEAD_VERSION, COMPAT_VERSION), partial_decode_needed(true), - final_decode_needed(true) { } + final_decode_needed(true), + bdata_encode(false) { } MOSDOp(int inc, long tid, const hobject_t& ho, spg_t& _pgid, epoch_t _osdmap_epoch, int _flags, uint64_t feat) @@ -180,7 +181,8 @@ public: pgid(_pgid), partial_decode_needed(false), final_decode_needed(false), - features(feat) { + features(feat), + bdata_encode(false) { set_tid(tid); // also put the client_inc in reqid.inc, so that get_reqid() can @@ -244,8 +246,10 @@ public: // marshalling void encode_payload(uint64_t features) override { - - OSDOp::merge_osd_op_vector_in_data(ops, data); + if( false == bdata_encode ) { + OSDOp::merge_osd_op_vector_in_data(ops, data); + bdata_encode = true; + } if ((features & CEPH_FEATURE_OBJECTLOCATOR) == 0) { // here is the old structure we are encoding to: // @@ -560,6 +564,7 @@ struct ceph_osd_request_head { void clear_buffers() override { OSDOp::clear_data(ops); + bdata_encode = false; } const char *get_type_name() const override { return "osd_op"; } diff --git a/src/messages/MOSDOpReply.h b/src/messages/MOSDOpReply.h index 19502a5602b2..69f0856e097c 100644 --- a/src/messages/MOSDOpReply.h +++ b/src/messages/MOSDOpReply.h @@ -38,6 +38,7 @@ class MOSDOpReply : public Message { object_t oid; pg_t pgid; vector ops; + bool bdata_encode; int64_t flags = 0; errorcode32_t result; eversion_t bad_replay_version; @@ -104,6 +105,7 @@ public: } void claim_ops(vector& o) { o.swap(ops); + bdata_encode = false; } /** @@ -125,13 +127,15 @@ public: public: MOSDOpReply() - : Message(CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION) { + : Message(CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION), + bdata_encode(false) { do_redirect = false; } MOSDOpReply(const MOSDOp *req, int r, epoch_t e, int acktype, bool ignore_out_data) : Message(CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION), - oid(req->hobj.oid), pgid(req->pgid.pgid), ops(req->ops) { + oid(req->hobj.oid), pgid(req->pgid.pgid), ops(req->ops), + bdata_encode(false) { set_tid(req->get_tid()); result = r; @@ -154,8 +158,10 @@ private: public: void encode_payload(uint64_t features) override { - - OSDOp::merge_osd_op_vector_out_data(ops, data); + if(false == bdata_encode) { + OSDOp::merge_osd_op_vector_out_data(ops, data); + bdata_encode = true; + } if ((features & CEPH_FEATURE_PGID64) == 0) { header.version = 1; diff --git a/src/messages/MOSDSubOp.h b/src/messages/MOSDSubOp.h index 4fd3a522fd32..524aa3867027 100644 --- a/src/messages/MOSDSubOp.h +++ b/src/messages/MOSDSubOp.h @@ -72,6 +72,7 @@ public: map> clone_subsets; bool first = false, complete = false; + bool bdata_encode; interval_set data_included; ObjectRecoveryInfo recovery_info; @@ -198,7 +199,10 @@ public: for (unsigned i = 0; i < ops.size(); i++) { ops[i].op.payload_len = ops[i].indata.length(); ::encode(ops[i].op, payload); - data.append(ops[i].indata); + if(false == bdata_encode) { + data.append(ops[i].indata); + bdata_encode = true; + } } ::encode(mtime, payload); //encode a false here for backward compatiable @@ -245,7 +249,8 @@ public: } MOSDSubOp() - : MOSDFastDispatchOp(MSG_OSD_SUBOP, HEAD_VERSION, COMPAT_VERSION) { } + : MOSDFastDispatchOp(MSG_OSD_SUBOP, HEAD_VERSION, COMPAT_VERSION), + bdata_encode(false) { } MOSDSubOp(osd_reqid_t r, pg_shard_t from, spg_t p, const hobject_t& po, int aw, epoch_t mape, ceph_tid_t rtid, eversion_t v) @@ -258,7 +263,8 @@ public: acks_wanted(aw), old_exists(false), old_size(0), version(v), - first(false), complete(false) { + first(false), complete(false), + bdata_encode(false) { memset(&peer_stat, 0, sizeof(peer_stat)); set_tid(rtid); } -- 2.47.3