#include "common/common_init.h"
#include "common/Cond.h"
#include "test/librados/test.h"
+#include "test/librados/TestCase.h"
#include "json_spirit/json_spirit.h"
#include "osd/HitSet.h"
using std::ostringstream;
using std::string;
-TEST(LibRadosTier, Dirty) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
+typedef RadosTestPP LibRadosTierPP;
+
+class LibRadosTwoPoolsPP : public RadosTestPP
+{
+public:
+ LibRadosTwoPoolsPP() {};
+ virtual ~LibRadosTwoPoolsPP() {};
+protected:
+ static void SetUpTestCase() {
+ pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster));
+ cache_pool_name = get_temp_pool_name();
+ ASSERT_EQ(0, s_cluster.pool_create(cache_pool_name.c_str()));
+ }
+ static void TearDownTestCase() {
+ ASSERT_EQ(0, s_cluster.pool_delete(cache_pool_name.c_str()));
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, s_cluster));
+ }
+ static std::string cache_pool_name;
+
+ virtual void SetUp() {
+ RadosTestPP::SetUp();
+ ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
+ cache_ioctx.set_namespace(ns);
+ }
+ virtual void TearDown() {
+ RadosTestPP::TearDown();
+ cleanup_default_namespace(cache_ioctx);
+ cache_ioctx.close();
+ }
+ librados::IoCtx cache_ioctx;
+};
+
+std::string LibRadosTwoPoolsPP::cache_pool_name;
+TEST_F(LibRadosTierPP, Dirty) {
{
ObjectWriteOperation op;
op.undirty();
ASSERT_TRUE(dirty);
ASSERT_EQ(0, r);
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosTier, Overlay) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, Overlay) {
// create objects
{
bufferlist bl;
bl.append("base");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
// by default, the overlay sends us to cache pool
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
{
ObjectReadOperation op;
op.read(0, 1, &bl, NULL);
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_OVERLAY, NULL));
completion->wait_for_safe();
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, Promote) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, Promote) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
// read, trigger a promote
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
}
// read, trigger a whiteout
{
bufferlist bl;
- ASSERT_EQ(-ENOENT, base_ioctx.read("bar", bl, 1, 0));
- ASSERT_EQ(-ENOENT, base_ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(-ENOENT, ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(-ENOENT, ioctx.read("bar", bl, 1, 0));
}
// verify the object is present in the cache tier
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, PromoteSnap) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, PromoteSnap) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bar", &op));
+ ASSERT_EQ(0, ioctx.operate("bar", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("baz", &op));
+ ASSERT_EQ(0, ioctx.operate("baz", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bam", &op));
+ ASSERT_EQ(0, ioctx.operate("bam", &op));
}
// create a snapshot, clone
vector<uint64_t> my_snaps(1);
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_create(&my_snaps[0]));
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_create(&my_snaps[0]));
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
my_snaps));
{
bufferlist bl;
bl.append("ciao!");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
bl.append("ciao!");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bar", &op));
+ ASSERT_EQ(0, ioctx.operate("bar", &op));
}
{
ObjectWriteOperation op;
op.remove();
- ASSERT_EQ(0, base_ioctx.operate("baz", &op));
+ ASSERT_EQ(0, ioctx.operate("baz", &op));
}
{
bufferlist bl;
bl.append("ciao!");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bam", &op));
+ ASSERT_EQ(0, ioctx.operate("bam", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
// read, trigger a promote on the head
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("bam", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("bam", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
// read foo snap
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('h', bl[0]);
}
// read bar snap
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("bar", bl, 1, 0));
ASSERT_EQ('h', bl[0]);
}
// read baz snap
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("baz", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("baz", bl, 1, 0));
ASSERT_EQ('h', bl[0]);
}
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
// read foo
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
// read bar
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("bar", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
// read baz
{
bufferlist bl;
- ASSERT_EQ(-ENOENT, base_ioctx.read("baz", bl, 1, 0));
+ ASSERT_EQ(-ENOENT, ioctx.read("baz", bl, 1, 0));
}
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, PromoteSnapTrimRace) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, PromoteSnapTrimRace) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// create a snapshot, clone
vector<uint64_t> my_snaps(1);
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_create(&my_snaps[0]));
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_create(&my_snaps[0]));
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
my_snaps));
{
bufferlist bl;
bl.append("ciao!");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
cluster.wait_for_latest_osdmap();
// delete the snap
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_remove(my_snaps[0]));
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_remove(my_snaps[0]));
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
// read foo snap
{
bufferlist bl;
- ASSERT_EQ(-ENOENT, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(-ENOENT, ioctx.read("foo", bl, 1, 0));
}
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- // cluster.pool_delete(cache_pool_name.c_str());
- //ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, Whiteout) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, Whiteout) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
cluster.wait_for_latest_osdmap();
// create some whiteouts, verify they behave
- ASSERT_EQ(0, base_ioctx.remove("foo"));
+ ASSERT_EQ(0, ioctx.remove("foo"));
- ASSERT_EQ(-ENOENT, base_ioctx.remove("bar"));
- ASSERT_EQ(-ENOENT, base_ioctx.remove("bar"));
+ ASSERT_EQ(-ENOENT, ioctx.remove("bar"));
+ ASSERT_EQ(-ENOENT, ioctx.remove("bar"));
// verify the whiteouts are there in the cache tier
{
ASSERT_TRUE(it == cache_ioctx.objects_end());
}
- ASSERT_EQ(-ENOENT, base_ioctx.remove("foo"));
+ ASSERT_EQ(-ENOENT, ioctx.remove("foo"));
// recreate an object and verify we can read it
{
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('h', bl[0]);
}
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, Evict) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, Evict) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
// read, trigger a promote
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
}
// read, trigger a whiteout, and a dirty object
{
bufferlist bl;
- ASSERT_EQ(-ENOENT, base_ioctx.read("bar", bl, 1, 0));
- ASSERT_EQ(-ENOENT, base_ioctx.read("bar", bl, 1, 0));
- ASSERT_EQ(0, base_ioctx.write("bar", bl, bl.length(), 0));
+ ASSERT_EQ(-ENOENT, ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(-ENOENT, ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(0, ioctx.write("bar", bl, bl.length(), 0));
}
// verify the object is present in the cache tier
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, EvictSnap) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, EvictSnap) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bar", &op));
+ ASSERT_EQ(0, ioctx.operate("bar", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("baz", &op));
+ ASSERT_EQ(0, ioctx.operate("baz", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bam", &op));
+ ASSERT_EQ(0, ioctx.operate("bam", &op));
}
// create a snapshot, clone
vector<uint64_t> my_snaps(1);
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_create(&my_snaps[0]));
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_create(&my_snaps[0]));
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
my_snaps));
{
bufferlist bl;
bl.append("ciao!");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
bl.append("ciao!");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bar", &op));
+ ASSERT_EQ(0, ioctx.operate("bar", &op));
}
{
ObjectWriteOperation op;
op.remove();
- ASSERT_EQ(0, base_ioctx.operate("baz", &op));
+ ASSERT_EQ(0, ioctx.operate("baz", &op));
}
{
bufferlist bl;
bl.append("ciao!");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("bam", &op));
+ ASSERT_EQ(0, ioctx.operate("bam", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
// read, trigger a promote on the head
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("bam", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("bam", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
}
// read foo snap
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('h', bl[0]);
}
ObjectReadOperation op;
op.cache_evict();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
ObjectReadOperation op;
op.read(1, 0, &bl, NULL);
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
completion->release();
}
// head is still there...
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
bufferlist bl;
ObjectReadOperation op;
op.read(1, 0, &bl, NULL);
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
}
// promote head + snap of bar
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("bar", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("bar", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("bar", bl, 1, 0));
ASSERT_EQ('h', bl[0]);
}
// evict bar head (fail)
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
ObjectReadOperation op;
op.cache_evict();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"bar", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
}
// evict bar snap
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
{
ObjectReadOperation op;
op.cache_evict();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"bar", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
completion->release();
}
// ...and then head
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
bufferlist bl;
ObjectReadOperation op;
op.read(1, 0, &bl, NULL);
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"bar", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
ObjectReadOperation op;
op.cache_evict();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"bar", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, TryFlush) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, TryFlush) {
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// verify the object is present in the cache tier
// verify the object is NOT present in the base tier
{
- ObjectIterator it = base_ioctx.objects_begin();
- ASSERT_TRUE(it == base_ioctx.objects_end());
+ ObjectIterator it = ioctx.objects_begin();
+ ASSERT_TRUE(it == ioctx.objects_end());
}
// verify dirty
// verify in base tier
{
- ObjectIterator it = base_ioctx.objects_begin();
- ASSERT_TRUE(it != base_ioctx.objects_end());
+ ObjectIterator it = ioctx.objects_begin();
+ ASSERT_TRUE(it != ioctx.objects_end());
ASSERT_TRUE(it->first == string("foo"));
++it;
- ASSERT_TRUE(it == base_ioctx.objects_end());
+ ASSERT_TRUE(it == ioctx.objects_end());
}
// evict it
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, Flush) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, Flush) {
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// verify the object is present in the cache tier
// verify the object is NOT present in the base tier
{
- ObjectIterator it = base_ioctx.objects_begin();
- ASSERT_TRUE(it == base_ioctx.objects_end());
+ ObjectIterator it = ioctx.objects_begin();
+ ASSERT_TRUE(it == ioctx.objects_end());
}
// verify dirty
// verify in base tier
{
- ObjectIterator it = base_ioctx.objects_begin();
- ASSERT_TRUE(it != base_ioctx.objects_end());
+ ObjectIterator it = ioctx.objects_begin();
+ ASSERT_TRUE(it != ioctx.objects_end());
ASSERT_TRUE(it->first == string("foo"));
++it;
- ASSERT_TRUE(it == base_ioctx.objects_end());
+ ASSERT_TRUE(it == ioctx.objects_end());
}
// evict it
{
ObjectWriteOperation op;
op.remove();
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// flush whiteout
}
// or base tier
{
- ObjectIterator it = base_ioctx.objects_begin();
- ASSERT_TRUE(it == base_ioctx.objects_end());
+ ObjectIterator it = ioctx.objects_begin();
+ ASSERT_TRUE(it == ioctx.objects_end());
}
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, FlushSnap) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, FlushSnap) {
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
bl.append("a");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// create a snapshot, clone
vector<uint64_t> my_snaps(1);
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_create(&my_snaps[0]));
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_create(&my_snaps[0]));
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
my_snaps));
{
bufferlist bl;
bl.append("b");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// and another
my_snaps.resize(2);
my_snaps[1] = my_snaps[0];
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_create(&my_snaps[0]));
- ASSERT_EQ(0, base_ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_create(&my_snaps[0]));
+ ASSERT_EQ(0, ioctx.selfmanaged_snap_set_write_ctx(my_snaps[0],
my_snaps));
{
bufferlist bl;
bl.append("c");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// verify the object is present in the cache tier
// verify the object is NOT present in the base tier
{
- ObjectIterator it = base_ioctx.objects_begin();
- ASSERT_TRUE(it == base_ioctx.objects_end());
+ ObjectIterator it = ioctx.objects_begin();
+ ASSERT_TRUE(it == ioctx.objects_end());
}
// flush on head (should fail)
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
ObjectReadOperation op;
op.cache_flush();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
completion->release();
}
// flush on recent snap (should fail)
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
{
ObjectReadOperation op;
op.cache_flush();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
completion->release();
}
// flush on oldest snap
- base_ioctx.snap_set_read(my_snaps[1]);
+ ioctx.snap_set_read(my_snaps[1]);
{
ObjectReadOperation op;
op.cache_flush();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
completion->release();
}
// flush on next oldest snap
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
{
ObjectReadOperation op;
op.cache_flush();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
completion->release();
}
// flush on head
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
ObjectReadOperation op;
op.cache_flush();
librados::AioCompletion *completion = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion, &op,
librados::OPERATION_IGNORE_CACHE, NULL));
completion->wait_for_safe();
}
// verify i can read the snaps from the cache pool
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('b', bl[0]);
}
- base_ioctx.snap_set_read(my_snaps[1]);
+ ioctx.snap_set_read(my_snaps[1]);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('a', bl[0]);
}
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
cluster.wait_for_latest_osdmap();
// verify i can read the snaps from the base pool
- base_ioctx.snap_set_read(librados::SNAP_HEAD);
+ ioctx.snap_set_read(librados::SNAP_HEAD);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('c', bl[0]);
}
- base_ioctx.snap_set_read(my_snaps[0]);
+ ioctx.snap_set_read(my_snaps[0]);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('b', bl[0]);
}
- base_ioctx.snap_set_read(my_snaps[1]);
+ ioctx.snap_set_read(my_snaps[1]);
{
bufferlist bl;
- ASSERT_EQ(1, base_ioctx.read("foo", bl, 1, 0));
+ ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ('a', bl[0]);
}
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, FlushWriteRaces) {
+TEST_F(LibRadosTierPP, FlushWriteRaces) {
Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
+ std::string pool_name = get_temp_pool_name();
+ std::string cache_pool_name = pool_name + "-cache";
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
IoCtx cache_ioctx;
ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
+ IoCtx ioctx;
+ ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
{
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// flush + write
ObjectWriteOperation op2;
op2.write_full(bl);
librados::AioCompletion *completion2 = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate(
+ ASSERT_EQ(0, ioctx.aio_operate(
"foo", completion2, &op2, 0));
completion->wait_for_safe();
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// try-flush + write
ObjectWriteOperation op2;
op2.write_full(bl);
librados::AioCompletion *completion2 = cluster.aio_create_completion();
- ASSERT_EQ(0, base_ioctx.aio_operate("foo", completion2, &op2, 0));
+ ASSERT_EQ(0, ioctx.aio_operate("foo", completion2, &op2, 0));
completion->wait_for_safe();
completion2->wait_for_safe();
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, FlushTryFlushRaces) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, FlushTryFlushRaces) {
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// flush + flush
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// flush + try-flush
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// try-flush + flush
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// try-flush + try-flush
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
test_lock.Unlock();
}
-TEST(LibRadosTier, TryFlushReadRace) {
- Rados cluster;
- std::string base_pool_name = get_temp_pool_name();
- std::string cache_pool_name = base_pool_name + "-cache";
- ASSERT_EQ("", create_one_pool_pp(base_pool_name, cluster));
- ASSERT_EQ(0, cluster.pool_create(cache_pool_name.c_str()));
- IoCtx cache_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(cache_pool_name.c_str(), cache_ioctx));
- IoCtx base_ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(base_pool_name.c_str(), base_ioctx));
-
+TEST_F(LibRadosTwoPoolsPP, TryFlushReadRace) {
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier add\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
bl.append(bp);
ObjectWriteOperation op;
op.write_full(bl);
- ASSERT_EQ(0, base_ioctx.operate("foo", &op));
+ ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// start a continuous stream of reads
- read_ioctx = &base_ioctx;
+ read_ioctx = &ioctx;
test_lock.Lock();
for (int i = 0; i < max_reads; ++i) {
start_flush_read();
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
- "{\"prefix\": \"osd tier remove\", \"pool\": \"" + base_pool_name +
+ "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
-
- base_ioctx.close();
- cache_ioctx.close();
-
- cluster.pool_delete(cache_pool_name.c_str());
- ASSERT_EQ(0, destroy_one_pool_pp(base_pool_name, cluster));
}
-TEST(LibRadosTier, HitSetNone) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
-
+TEST_F(LibRadosTierPP, HitSetNone) {
{
list< pair<time_t,time_t> > ls;
AioCompletion *c = librados::Rados::aio_create_completion();
ASSERT_EQ(-ENOENT, c->get_return_value());
c->release();
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
string set_pool_str(string pool, string var, string val)
+ stringify(val) + string("\"}");
}
-TEST(LibRadosTier, HitSetRead) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
-
+TEST_F(LibRadosTierPP, HitSetRead) {
// enable hitset tracking for this pool
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(set_pool_str(pool_name, "hit_set_count", 2),
// wait for maps to settle
cluster.wait_for_latest_osdmap();
+ ioctx.set_namespace("");
+
// keep reading until we see our object appear in the HitSet
utime_t start = ceph_clock_now(NULL);
utime_t hard_stop = start + utime_t(600, 0);
sleep(1);
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
static int _get_pg_num(Rados& cluster, string pool_name)
}
-TEST(LibRadosTier, HitSetWrite) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
-
+TEST_F(LibRadosTierPP, HitSetWrite) {
int num_pg = _get_pg_num(cluster, pool_name);
assert(num_pg > 0);
// wait for maps to settle
cluster.wait_for_latest_osdmap();
+ ioctx.set_namespace("");
+
// do a bunch of writes
for (int i=0; i<1000; ++i) {
bufferlist bl;
}
ASSERT_TRUE(found);
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
-TEST(LibRadosTier, HitSetTrim) {
- Rados cluster;
- std::string pool_name = get_temp_pool_name();
- ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
- IoCtx ioctx;
- ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
-
+TEST_F(LibRadosTierPP, HitSetTrim) {
unsigned count = 3;
unsigned period = 3;
// wait for maps to settle
cluster.wait_for_latest_osdmap();
+ ioctx.set_namespace("");
+
// do a bunch of writes and make sure the hitsets rotate
utime_t start = ceph_clock_now(NULL);
utime_t hard_stop = start + utime_t(count * period * 12, 0);
sleep(1);
}
-
- ioctx.close();
- ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}