Merge pull request #4937 from majianpeng/replicated-misc-fix

ReplicatedPG: small bugs and clean up

Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2015-07-06 01:20:30 +08:00
commit 9c81dafd47
2 changed files with 18 additions and 23 deletions

View File

@ -4211,8 +4211,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
} else {
t->write(soid, op.extent.offset, op.extent.length, osd_op.indata, op.flags);
}
write_update_size_and_usage(ctx->delta_stats, oi, ctx->modified_ranges,
op.extent.offset, op.extent.length, true);
maybe_create_new_object(ctx);
if (op.extent.offset == 0 && op.extent.length >= oi.size)
obs.oi.set_data_digest(osd_op.indata.crc32c(-1));
@ -4220,19 +4219,22 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
obs.oi.set_data_digest(osd_op.indata.crc32c(obs.oi.data_digest));
else
obs.oi.clear_data_digest();
write_update_size_and_usage(ctx->delta_stats, oi, ctx->modified_ranges,
op.extent.offset, op.extent.length, true);
}
break;
case CEPH_OSD_OP_WRITEFULL:
++ctx->num_write;
{ // write full object
tracepoint(osd, do_osd_op_pre_writefull, soid.oid.name.c_str(), soid.snap.val, oi.size, op.extent.offset, op.extent.length);
tracepoint(osd, do_osd_op_pre_writefull, soid.oid.name.c_str(), soid.snap.val, oi.size, 0, op.extent.length);
if (op.extent.length != osd_op.indata.length()) {
result = -EINVAL;
break;
}
result = check_offset_and_length(op.extent.offset, op.extent.length, cct->_conf->osd_max_object_size);
result = check_offset_and_length(0, op.extent.length, cct->_conf->osd_max_object_size);
if (result < 0)
break;
@ -4248,7 +4250,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
}
}
ctx->mod_desc.create();
t->append(soid, op.extent.offset, op.extent.length, osd_op.indata, op.flags);
t->append(soid, 0, op.extent.length, osd_op.indata, op.flags);
if (obs.exists) {
map<string, bufferlist> to_set = ctx->obc->attr_cache;
map<string, boost::optional<bufferlist> > &overlay =
@ -4267,25 +4269,16 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
}
} else {
ctx->mod_desc.mark_unrollbackable();
if (obs.exists) {
t->truncate(soid, 0);
t->write(soid, 0, op.extent.length, osd_op.indata, op.flags);
if (obs.exists && op.extent.length < oi.size) {
t->truncate(soid, op.extent.length);
}
t->write(soid, op.extent.offset, op.extent.length, osd_op.indata, op.flags);
}
maybe_create_new_object(ctx);
obs.oi.set_data_digest(osd_op.indata.crc32c(-1));
interval_set<uint64_t> ch;
if (oi.size > 0)
ch.insert(0, oi.size);
ctx->modified_ranges.union_of(ch);
if (op.extent.length + op.extent.offset != oi.size) {
ctx->delta_stats.num_bytes -= oi.size;
oi.size = op.extent.length + op.extent.offset;
ctx->delta_stats.num_bytes += oi.size;
}
ctx->delta_stats.num_wr++;
ctx->delta_stats.num_wr_kb += SHIFT_ROUND_UP(op.extent.length, 10);
write_update_size_and_usage(ctx->delta_stats, oi, ctx->modified_ranges,
0, op.extent.length, true, op.extent.length != oi.size ? true : false);
}
break;
@ -5525,15 +5518,16 @@ void ReplicatedPG::make_writeable(OpContext *ctx)
void ReplicatedPG::write_update_size_and_usage(object_stat_sum_t& delta_stats, object_info_t& oi,
interval_set<uint64_t>& modified, uint64_t offset,
uint64_t length, bool count_bytes)
uint64_t length, bool count_bytes, bool force_changesize)
{
interval_set<uint64_t> ch;
if (length)
ch.insert(offset, length);
modified.union_of(ch);
if (length && (offset + length > oi.size)) {
if (force_changesize || offset + length > oi.size) {
uint64_t new_size = offset + length;
delta_stats.num_bytes += new_size - oi.size;
delta_stats.num_bytes -= oi.size;
delta_stats.num_bytes += new_size;
oi.size = new_size;
}
delta_stats.num_wr++;

View File

@ -1162,7 +1162,8 @@ protected:
void write_update_size_and_usage(object_stat_sum_t& stats, object_info_t& oi,
interval_set<uint64_t>& modified, uint64_t offset,
uint64_t length, bool count_bytes);
uint64_t length, bool count_bytes,
bool force_changesize=false);
void add_interval_usage(interval_set<uint64_t>& s, object_stat_sum_t& st);
/**