test/tier: add test for cache_pin

Signed-off-by: Zhiqiang Wang <zhiqiang.wang@intel.com>
This commit is contained in:
Zhiqiang Wang 2015-04-15 22:40:47 +08:00 committed by Sage Weil
parent 36b2d3d7bc
commit 59d0de7c54

View File

@ -2543,6 +2543,157 @@ TEST_F(LibRadosTwoPoolsPP, ProxyRead) {
cluster.wait_for_latest_osdmap();
}
TEST_F(LibRadosTwoPoolsPP, CachePin) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("bar", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("baz", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("bam", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name +
"\", \"force_nonempty\": \"--force-nonempty\" }",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier cache-mode\", \"pool\": \"" + cache_pool_name +
"\", \"mode\": \"writeback\"}",
inbl, NULL, NULL));
// wait for maps to settle
cluster.wait_for_latest_osdmap();
// read, trigger promote
{
bufferlist bl;
ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ(1, ioctx.read("bar", bl, 1, 0));
ASSERT_EQ(1, ioctx.read("baz", bl, 1, 0));
ASSERT_EQ(1, ioctx.read("bam", bl, 1, 0));
}
// verify the objects are present in the cache tier
{
NObjectIterator it = cache_ioctx.nobjects_begin();
ASSERT_TRUE(it != cache_ioctx.nobjects_end());
for (uint32_t i = 0; i < 4; i++) {
ASSERT_TRUE(it->get_oid() == string("foo") ||
it->get_oid() == string("bar") ||
it->get_oid() == string("baz") ||
it->get_oid() == string("bam"));
++it;
}
ASSERT_TRUE(it == cache_ioctx.nobjects_end());
}
// pin objects
{
ObjectWriteOperation op;
op.cache_pin();
librados::AioCompletion *completion = cluster.aio_create_completion();
ASSERT_EQ(0, cache_ioctx.aio_operate("foo", completion, &op));
completion->wait_for_safe();
ASSERT_EQ(0, completion->get_return_value());
completion->release();
}
{
ObjectWriteOperation op;
op.cache_pin();
librados::AioCompletion *completion = cluster.aio_create_completion();
ASSERT_EQ(0, cache_ioctx.aio_operate("baz", completion, &op));
completion->wait_for_safe();
ASSERT_EQ(0, completion->get_return_value());
completion->release();
}
// enable agent
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "hit_set_count", 2),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "hit_set_period", 600),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "hit_set_type", "bloom"),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "min_read_recency_for_promote", 1),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "target_max_objects", 1),
inbl, NULL, NULL));
sleep(10);
// Verify the pinned object 'foo' is not flushed/evicted
uint32_t count = 0;
while (true) {
bufferlist bl;
ASSERT_EQ(1, ioctx.read("baz", bl, 1, 0));
count = 0;
NObjectIterator it = cache_ioctx.nobjects_begin();
while (it != cache_ioctx.nobjects_end()) {
ASSERT_TRUE(it->get_oid() == string("foo") ||
it->get_oid() == string("bar") ||
it->get_oid() == string("baz") ||
it->get_oid() == string("bam"));
++count;
++it;
}
if (count == 2) {
ASSERT_TRUE(it->get_oid() == string("foo") ||
it->get_oid() == string("baz"));
break;
}
sleep(1);
}
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
// wait for maps to settle before next test
cluster.wait_for_latest_osdmap();
}
class LibRadosTwoPoolsECPP : public RadosTestECPP
{
public:
@ -4722,6 +4873,157 @@ TEST_F(LibRadosTwoPoolsECPP, ProxyRead) {
cluster.wait_for_latest_osdmap();
}
TEST_F(LibRadosTwoPoolsECPP, CachePin) {
// create object
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("foo", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("bar", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("baz", &op));
}
{
bufferlist bl;
bl.append("hi there");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("bam", &op));
}
// configure cache
bufferlist inbl;
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name +
"\", \"force_nonempty\": \"--force-nonempty\" }",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name +
"\", \"overlaypool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier cache-mode\", \"pool\": \"" + cache_pool_name +
"\", \"mode\": \"writeback\"}",
inbl, NULL, NULL));
// wait for maps to settle
cluster.wait_for_latest_osdmap();
// read, trigger promote
{
bufferlist bl;
ASSERT_EQ(1, ioctx.read("foo", bl, 1, 0));
ASSERT_EQ(1, ioctx.read("bar", bl, 1, 0));
ASSERT_EQ(1, ioctx.read("baz", bl, 1, 0));
ASSERT_EQ(1, ioctx.read("bam", bl, 1, 0));
}
// verify the objects are present in the cache tier
{
NObjectIterator it = cache_ioctx.nobjects_begin();
ASSERT_TRUE(it != cache_ioctx.nobjects_end());
for (uint32_t i = 0; i < 4; i++) {
ASSERT_TRUE(it->get_oid() == string("foo") ||
it->get_oid() == string("bar") ||
it->get_oid() == string("baz") ||
it->get_oid() == string("bam"));
++it;
}
ASSERT_TRUE(it == cache_ioctx.nobjects_end());
}
// pin objects
{
ObjectWriteOperation op;
op.cache_pin();
librados::AioCompletion *completion = cluster.aio_create_completion();
ASSERT_EQ(0, cache_ioctx.aio_operate("foo", completion, &op));
completion->wait_for_safe();
ASSERT_EQ(0, completion->get_return_value());
completion->release();
}
{
ObjectWriteOperation op;
op.cache_pin();
librados::AioCompletion *completion = cluster.aio_create_completion();
ASSERT_EQ(0, cache_ioctx.aio_operate("baz", completion, &op));
completion->wait_for_safe();
ASSERT_EQ(0, completion->get_return_value());
completion->release();
}
// enable agent
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "hit_set_count", 2),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "hit_set_period", 600),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "hit_set_type", "bloom"),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "min_read_recency_for_promote", 1),
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
set_pool_str(cache_pool_name, "target_max_objects", 1),
inbl, NULL, NULL));
sleep(10);
// Verify the pinned object 'foo' is not flushed/evicted
uint32_t count = 0;
while (true) {
bufferlist bl;
ASSERT_EQ(1, ioctx.read("baz", bl, 1, 0));
count = 0;
NObjectIterator it = cache_ioctx.nobjects_begin();
while (it != cache_ioctx.nobjects_end()) {
ASSERT_TRUE(it->get_oid() == string("foo") ||
it->get_oid() == string("bar") ||
it->get_oid() == string("baz") ||
it->get_oid() == string("bam"));
++count;
++it;
}
if (count == 2) {
ASSERT_TRUE(it->get_oid() == string("foo") ||
it->get_oid() == string("baz"));
break;
}
sleep(1);
}
// tear down tiers
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name +
"\"}",
inbl, NULL, NULL));
ASSERT_EQ(0, cluster.mon_command(
"{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name +
"\", \"tierpool\": \"" + cache_pool_name + "\"}",
inbl, NULL, NULL));
// wait for maps to settle before next test
cluster.wait_for_latest_osdmap();
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);