summaryrefslogtreecommitdiff
path: root/src/rados.cc
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2012-07-05 13:42:23 -0700
committerYehuda Sadeh <yehuda@inktank.com>2012-07-06 10:15:34 -0700
commitd75100667a539baf47c79d752b787ed5dcb51d7a (patch)
tree1ee5544a6327242bbfc8d820b727e7b8375e6d16 /src/rados.cc
parent16ea64fbdebb7a74e69e80a18d98f35d68b8d9a1 (diff)
downloadceph-d75100667a539baf47c79d752b787ed5dcb51d7a.tar.gz
rados tool: copy object in chunks
Instead of reading the entire object and then writing it, we read it in chunks. Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
Diffstat (limited to 'src/rados.cc')
-rw-r--r--src/rados.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/rados.cc b/src/rados.cc
index 94ca5c1e924..42c0d1d568f 100644
--- a/src/rados.cc
+++ b/src/rados.cc
@@ -173,7 +173,8 @@ static int do_copy(IoCtx& io_ctx, const char *objname, IoCtx& target_ctx, const
librados::ObjectReadOperation read_op;
string start_after;
- read_op.read(0, 0, &outdata, NULL);
+#define COPY_CHUNK_SIZE (4 * 1024 * 1024)
+ read_op.read(0, COPY_CHUNK_SIZE, &outdata, NULL);
map<std::string, bufferlist> attrset;
read_op.getxattrs(&attrset, NULL);
@@ -213,6 +214,20 @@ static int do_copy(IoCtx& io_ctx, const char *objname, IoCtx& target_ctx, const
return ret;
}
+ uint64_t off = 0;
+
+ while (outdata.length() == COPY_CHUNK_SIZE) {
+ off += outdata.length();
+ outdata.clear();
+ ret = io_ctx.read(oid, outdata, COPY_CHUNK_SIZE, off);
+ if (ret < 0)
+ goto err;
+
+ ret = target_ctx.write(target_oid, outdata, outdata.length(), off);
+ if (ret < 0)
+ goto err;
+ }
+
/* iterate through source omap and update target. This is not atomic */
while (omap.size() == OMAP_CHUNK) {
/* now start_after should point at the last entry */
@@ -233,7 +248,6 @@ static int do_copy(IoCtx& io_ctx, const char *objname, IoCtx& target_ctx, const
goto err;
}
-
return 0;
err: