From 6c8f60f6a6c3e8e22889140c52554fd9ab4b0612 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 13 Dec 2011 15:03:36 -0800 Subject: [PATCH] osd: simplify creation logic in do_osd_ops Drop the maybe_created variable, and track exists over the course of the transaction. Fixes: #1825 Signed-off-by: Sage Weil Signed-off-by: Greg Farnum --- src/osd/ReplicatedPG.cc | 63 +++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index a05de1ebbe2d7..cf9a02fa5abc6 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -1210,8 +1210,6 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops, ObjectState& obs = ctx->new_obs; object_info_t& oi = obs.oi; - bool maybe_created = false; - const hobject_t& soid = oi.soid; ObjectStore::Transaction& t = ctx->op_t; @@ -1616,7 +1614,10 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops, } write_update_size_and_usage(ctx->delta_stats, oi, ssc->snapset, ctx->modified_ranges, op.extent.offset, op.extent.length, true); - maybe_created = true; + if (!obs.exists) { + ctx->delta_stats.num_objects++; + obs.exists = true; + } } break; @@ -1624,10 +1625,12 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops, { // write full object bufferlist nbl; bp.copy(op.extent.length, nbl); - if (obs.exists) + if (obs.exists) { t.truncate(coll, soid, 0); - else - maybe_created = true; + } else { + ctx->delta_stats.num_objects++; + obs.exists = true; + } t.write(coll, soid, op.extent.offset, op.extent.length, nbl); interval_set ch; if (oi.size > 0) @@ -1664,26 +1667,29 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops, } break; case CEPH_OSD_OP_CREATE: - { // zero + { int flags = le32_to_cpu(op.flags); - if (obs.exists && (flags & CEPH_OSD_OP_FLAG_EXCL)) + if (obs.exists && (flags & CEPH_OSD_OP_FLAG_EXCL)) { result = -EEXIST; /* this is an exclusive create */ - else { - t.touch(coll, soid); - maybe_created = true; - } - if (osd_op.data.length()) { - bufferlist::iterator p = osd_op.data.begin(); - string category; - ::decode(category, p); - if (category.size()) { - if (obs.exists) { - if (obs.oi.category != category) - result = -EEXIST; - } else { - obs.oi.category = category; + } else { + if (osd_op.data.length()) { + bufferlist::iterator p = osd_op.data.begin(); + string category; + ::decode(category, p); + if (category.size()) { + if (obs.exists) { + if (obs.oi.category != category) + result = -EEXIST; // category cannot be reset + } else { + obs.oi.category = category; + } } - } + } + if (result >= 0 && !obs.exists) { + t.touch(coll, soid); + ctx->delta_stats.num_objects++; + obs.exists = true; + } } } break; @@ -1742,7 +1748,8 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops, { if (!obs.exists) { t.touch(coll, obs.oi.soid); - maybe_created = true; + ctx->delta_stats.num_objects++; + obs.exists = true; } if (op.clonerange.src_offset + op.clonerange.length > src_obc->obs.oi.size) { dout(10) << " clonerange source " << osd_op.soid << " " @@ -1809,7 +1816,8 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops, { if (!obs.exists) { t.touch(coll, soid); - maybe_created = true; + ctx->delta_stats.num_objects++; + obs.exists = true; } string aname; bp.copy(op.xattr.name_len, aname); @@ -2060,11 +2068,6 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops, result = -EOPNOTSUPP; } - if (!obs.exists && maybe_created) { - ctx->delta_stats.num_objects++; - obs.exists = true; - } - if (result < 0 && (op.flags & CEPH_OSD_OP_FLAG_FAILOK)) result = 0; -- 2.39.5