rados: add 'tmap-to-omap' command

Explicitly convert tmap object data to omap keys.  Removes the old tmap
content at the same time.

Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2013-10-01 17:19:24 -07:00
parent 20974dc052
commit 84c028674a
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#!/bin/sh -ex
expect_false()
{
set -x
if "$@"; then return 1; else return 0; fi
}
pool="pool-$$"
rados mkpool $pool
rados -p $pool tmap set foo key1 value1
rados -p $pool tmap set foo key2 value2
rados -p $pool tmap set foo key2 value2
rados -p $pool tmap dump foo | grep key1
rados -p $pool tmap dump foo | grep key2
rados -p $pool tmap-to-omap foo
expect_false rados -p $pool tmap dump foo
expect_false rados -p $pool tmap dump foo
rados -p $pool listomapkeys foo | grep key1
rados -p $pool listomapkeys foo | grep key2
rados -p $pool getomapval foo key1 | grep value1
rados -p $pool getomapval foo key2 | grep value2
rados rmpool $pool $pool --yes-i-really-really-mean-it
echo OK

View File

@ -98,6 +98,7 @@ void usage(ostream& out)
" rmomapkey <obj-name> <key>\n"
" getomapheader <obj-name>\n"
" setomapheader <obj-name> <val>\n"
" tmap-to-omap <obj-name> convert tmap keys/values to omap\n"
" listwatchers <obj-name> list the watchers of this object\n"
"\n"
"IMPORT AND EXPORT\n"
@ -1848,6 +1849,50 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
}
}
else if (strcmp(nargs[0], "tmap-to-omap") == 0) {
if (!pool_name || nargs.size() < 2)
usage_exit();
string oid(nargs[1]);
bufferlist bl;
int r = io_ctx.tmap_get(oid, bl);
if (r < 0) {
ret = r;
cerr << "error reading tmap " << pool_name << "/" << oid
<< ": " << cpp_strerror(ret) << std::endl;
goto out;
}
bufferlist hdr;
map<string, bufferlist> kv;
bufferlist::iterator p = bl.begin();
try {
::decode(hdr, p);
::decode(kv, p);
}
catch (buffer::error& e) {
cerr << "error decoding tmap " << pool_name << "/" << oid << std::endl;
ret = -EINVAL;
goto out;
}
if (!p.end()) {
cerr << "error decoding tmap (stray trailing data) in " << pool_name << "/" << oid << std::endl;
ret = -EINVAL;
goto out;
}
librados::ObjectWriteOperation wr;
wr.omap_set_header(hdr);
wr.omap_set(kv);
wr.truncate(0); // delete the old tmap data
r = io_ctx.operate(oid, &wr);
if (r < 0) {
ret = r;
cerr << "error writing tmap data as omap on " << pool_name << "/" << oid
<< ": " << cpp_strerror(ret) << std::endl;
goto out;
}
ret = 0;
}
else if (strcmp(nargs[0], "mkpool") == 0) {
int auid = 0;
__u8 crush_rule = 0;