Skip to content

Commit

Permalink
rbd-mirror: Add sparse read for sync image
Browse files Browse the repository at this point in the history
Currently, the image sync do full read, and we shall add sparse read
to let the sync more efficiently.

Feature: http://tracker.ceph.com/issues/16780
Signed-off-by: tianqing <tianqing@unitedstack.com>
  • Loading branch information
tianqing committed Sep 7, 2016
1 parent f8abb62 commit 8b6db5c
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/tools/rbd_mirror/image_sync/ObjectCopyRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ void ObjectCopyRequest<I>::send_read_object() {

bool read_required = false;
librados::ObjectReadOperation op;
std::map<uint64_t, uint64_t> extents;
bufferlist xbl;
for (auto &sync_op : sync_ops) {
switch (std::get<0>(sync_op)) {
case SYNC_OP_TYPE_WRITE:
Expand All @@ -113,8 +115,15 @@ void ObjectCopyRequest<I>::send_read_object() {

dout(20) << ": read op: " << std::get<1>(sync_op) << "~"
<< std::get<2>(sync_op) << dendl;
op.read(std::get<1>(sync_op), std::get<2>(sync_op),
&std::get<3>(sync_op), nullptr);
op.sparse_read(std::get<1>(sync_op), std::get<2>(sync_op), &extents,
&xbl, nullptr);
for(auto& kv : extents){
// print the extents
dout(20) << "extents: ["<< kv.first << ", " << kv.second << "]" << dendl;
}
// put it into bl
::encode(extents, std::get<3>(sync_op));
::encode(xbl, std::get<3>(sync_op));
break;
default:
break;
Expand Down Expand Up @@ -175,12 +184,26 @@ void ObjectCopyRequest<I>::send_write_object() {
assert(!sync_ops.empty());

librados::ObjectWriteOperation op;
bufferlist::iterator it;
std::map<uint64_t, uint64_t> extents;
bufferlist databl;
uint64_t len = 0;
uint64_t begin = 0;
for (auto &sync_op : sync_ops) {
switch (std::get<0>(sync_op)) {
case SYNC_OP_TYPE_WRITE:
it = std::get<3>(sync_op).begin();
::decode(extents, it);
::decode(databl, it);
for(auto &it : extents){
bufferlist tmpbl;
len = it.second - it.first;
tmpbl.copy_in(begin, len, databl);
op.writesame(it.first, it.second, tmpbl);
begin += len;
}
dout(20) << ": write op: " << std::get<1>(sync_op) << "~"
<< std::get<3>(sync_op).length() << dendl;
op.write(std::get<1>(sync_op), std::get<3>(sync_op));
<< databl.length() << dendl;
break;
case SYNC_OP_TYPE_TRUNC:
dout(20) << ": trunc op: " << std::get<1>(sync_op) << dendl;
Expand Down

0 comments on commit 8b6db5c

Please sign in to comment.