Skip to content

Commit

Permalink
Merge pull request #9698 from LiumxNL/fix-clones-flush-evict
Browse files Browse the repository at this point in the history
rados: add option to include clones when doing flush or evict

Reviewed-by: Sage Weil <sage@redhat.com>
  • Loading branch information
tchaikov committed Jul 11, 2016
2 parents e9e3a23 + 383177b commit 90a18d8
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 29 deletions.
31 changes: 31 additions & 0 deletions qa/workunits/rados/test_cache_pool.sh
Expand Up @@ -127,6 +127,37 @@ expect_false rados -p base cache-flush-evict-all
rados -p cache cache-try-flush-evict-all
rados -p cache ls - | wc -l | grep 0

# cache flush/evit when clone objects exist
rados -p base put testclone /etc/passwd
rados -p cache ls - | wc -l | grep 1
ceph osd pool mksnap base snap
rados -p base put testclone /etc/hosts
rados -p cache cache-flush-evict-all
rados -p cache ls - | wc -l | grep 0

ceph osd tier cache-mode cache forward --yes-i-really-mean-it
rados -p base -s snap get testclone testclone.txt
diff -q testclone.txt /etc/passwd
rados -p base get testclone testclone.txt
diff -q testclone.txt /etc/hosts

# test --with-clones option
ceph osd tier cache-mode cache writeback
rados -p base put testclone2 /etc/passwd
rados -p cache ls - | wc -l | grep 1
ceph osd pool mksnap base snap1
rados -p base put testclone2 /etc/hosts
expect_false rados -p cache cache-flush testclone2
rados -p cache cache-flush testclone2 --with-clones
expect_false rados -p cache cache-evict testclone2
rados -p cache cache-evict testclone2 --with-clones
rados -p cache ls - | wc -l | grep 0

rados -p base -s snap1 get testclone2 testclone2.txt
diff -q testclone2.txt /etc/passwd
rados -p base get testclone2 testclone2.txt
diff -q testclone2.txt /etc/hosts

# cleanup
ceph osd tier remove-overlay base
ceph osd tier remove base cache
Expand Down
173 changes: 144 additions & 29 deletions src/tools/rados/rados.cc
Expand Up @@ -220,6 +220,8 @@ void usage(ostream& out)
" --read-percent percent of operations that are read\n"
" --target-throughput target throughput (in bytes)\n"
" --run-length total time (in seconds)\n"
"CACHE POOLS OPTIONS:\n"
" --with-clones include clones when doing flush or evict\n"
;
}

Expand Down Expand Up @@ -1190,22 +1192,59 @@ static int do_cache_flush_evict_all(IoCtx& io_ctx, bool blocking)
io_ctx.locator_set_key(string());
}
io_ctx.set_namespace(i->get_nspace());
if (blocking)
r = do_cache_flush(io_ctx, i->get_oid());
else
r = do_cache_try_flush(io_ctx, i->get_oid());
snap_set_t ls;
io_ctx.snap_set_read(LIBRADOS_SNAP_DIR);
r = io_ctx.list_snaps(i->get_oid(), &ls);
if (r < 0) {
cerr << "failed to flush " << i->get_nspace() << "/" << i->get_oid() << ": "
<< cpp_strerror(r) << std::endl;
++errors;
continue;
cerr << "error listing snap shots " << i->get_nspace() << "/" << i->get_oid() << ": "
<< cpp_strerror(r) << std::endl;
++errors;
continue;
}
r = do_cache_evict(io_ctx, i->get_oid());
if (r < 0) {
cerr << "failed to evict " << i->get_nspace() << "/" << i->get_oid() << ": "
<< cpp_strerror(r) << std::endl;
++errors;
continue;
std::vector<clone_info_t>::iterator ci = ls.clones.begin();
// no snapshots
if (ci == ls.clones.end()) {
io_ctx.snap_set_read(CEPH_NOSNAP);
if (blocking)
r = do_cache_flush(io_ctx, i->get_oid());
else
r = do_cache_try_flush(io_ctx, i->get_oid());
if (r < 0) {
cerr << "failed to flush " << i->get_nspace() << "/" << i->get_oid() << ": "
<< cpp_strerror(r) << std::endl;
++errors;
continue;
}
r = do_cache_evict(io_ctx, i->get_oid());
if (r < 0) {
cerr << "failed to evict " << i->get_nspace() << "/" << i->get_oid() << ": "
<< cpp_strerror(r) << std::endl;
++errors;
continue;
}
} else {
// has snapshots
for (std::vector<clone_info_t>::iterator ci = ls.clones.begin();
ci != ls.clones.end(); ++ci) {
io_ctx.snap_set_read(ci->cloneid);
if (blocking)
r = do_cache_flush(io_ctx, i->get_oid());
else
r = do_cache_try_flush(io_ctx, i->get_oid());
if (r < 0) {
cerr << "failed to flush " << i->get_nspace() << "/" << i->get_oid() << ": "
<< cpp_strerror(r) << std::endl;
++errors;
break;
}
r = do_cache_evict(io_ctx, i->get_oid());
if (r < 0) {
cerr << "failed to evict " << i->get_nspace() << "/" << i->get_oid() << ": "
<< cpp_strerror(r) << std::endl;
++errors;
break;
}
}
}
}
}
Expand Down Expand Up @@ -1512,6 +1551,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
bool cleanup = true;
bool no_verify = false;
bool use_striper = false;
bool with_clones = false;
const char *snapname = NULL;
snap_t snapid = CEPH_NOSNAP;
std::map<std::string, std::string>::const_iterator i;
Expand Down Expand Up @@ -1719,6 +1759,10 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
if (i != opts.end()) {
bench_write_dest |= static_cast<int>(OP_WRITE_DEST_XATTR);
}
i = opts.find("with-clones");
if (i != opts.end()) {
with_clones = true;
}

// open rados
ret = rados.init_with_context(g_ceph_context);
Expand Down Expand Up @@ -3151,31 +3195,100 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
if (!pool_name || nargs.size() < 2)
usage_exit();
string oid(nargs[1]);
ret = do_cache_flush(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
if (with_clones) {
snap_set_t ls;
io_ctx.snap_set_read(LIBRADOS_SNAP_DIR);
ret = io_ctx.list_snaps(oid, &ls);
if (ret < 0) {
cerr << "error listing snapshots " << pool_name << "/" << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
for (std::vector<clone_info_t>::iterator ci = ls.clones.begin();
ci != ls.clones.end(); ++ci) {
if (snapid != CEPH_NOSNAP && ci->cloneid > snapid)
break;
io_ctx.snap_set_read(ci->cloneid);
ret = do_cache_flush(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
}
} else {
ret = do_cache_flush(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
}
} else if (strcmp(nargs[0], "cache-try-flush") == 0) {
if (!pool_name || nargs.size() < 2)
usage_exit();
string oid(nargs[1]);
ret = do_cache_try_flush(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-try-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
if (with_clones) {
snap_set_t ls;
io_ctx.snap_set_read(LIBRADOS_SNAP_DIR);
ret = io_ctx.list_snaps(oid, &ls);
if (ret < 0) {
cerr << "error listing snapshots " << pool_name << "/" << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
for (std::vector<clone_info_t>::iterator ci = ls.clones.begin();
ci != ls.clones.end(); ++ci) {
if (snapid != CEPH_NOSNAP && ci->cloneid > snapid)
break;
io_ctx.snap_set_read(ci->cloneid);
ret = do_cache_try_flush(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
}
} else {
ret = do_cache_try_flush(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
}
} else if (strcmp(nargs[0], "cache-evict") == 0) {
if (!pool_name || nargs.size() < 2)
usage_exit();
string oid(nargs[1]);
ret = do_cache_evict(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-evict " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
if (with_clones) {
snap_set_t ls;
io_ctx.snap_set_read(LIBRADOS_SNAP_DIR);
ret = io_ctx.list_snaps(oid, &ls);
if (ret < 0) {
cerr << "error listing snapshots " << pool_name << "/" << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
for (std::vector<clone_info_t>::iterator ci = ls.clones.begin();
ci != ls.clones.end(); ++ci) {
if (snapid != CEPH_NOSNAP && ci->cloneid > snapid)
break;
io_ctx.snap_set_read(ci->cloneid);
ret = do_cache_evict(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
}
} else {
ret = do_cache_evict(io_ctx, oid);
if (ret < 0) {
cerr << "error from cache-flush " << oid << ": "
<< cpp_strerror(ret) << std::endl;
goto out;
}
}
} else if (strcmp(nargs[0], "cache-flush-evict-all") == 0) {
if (!pool_name)
Expand Down Expand Up @@ -3418,6 +3531,8 @@ int main(int argc, const char **argv)
opts["write-dest-obj"] = "true";
} else if (ceph_argparse_flag(args, i, "--write-xattr", (char*)NULL)) {
opts["write-dest-xattr"] = "true";
} else if (ceph_argparse_flag(args, i, "--with-clones", (char*)NULL)) {
opts["with-clones"] = "true";
} else {
if (val[0] == '-')
usage_exit();
Expand Down

0 comments on commit 90a18d8

Please sign in to comment.