summaryrefslogtreecommitdiffstats
path: root/src/test/cls_lock
diff options
context:
space:
mode:
authorJ. Eric Ivancich <ivancich@redhat.com>2018-10-01 21:18:39 +0200
committerJ. Eric Ivancich <ivancich@redhat.com>2018-10-24 23:52:37 +0200
commit479c90993cc80b140af010a72ff9a34ecb7b3b32 (patch)
treebc864d4a031a1931d3371679becaa8bd4f4c6575 /src/test/cls_lock
parentrgw: use the same lock when resharding (diff)
downloadceph-479c90993cc80b140af010a72ff9a34ecb7b3b32.tar.xz
ceph-479c90993cc80b140af010a72ff9a34ecb7b3b32.zip
cls: add semantics for cls locks to require renewal without expiring
Add ability to *require* renewal of an existing lock in addition toexisting ability to *allow* renewal of an existing lock. The key difference is that a MUST_RENEW will fail if the lock has expired (where a MAY_RENEW) will succeed. This provides calling code with the ability to verify that a lock is held continually and that it was never lost/expired. Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
Diffstat (limited to 'src/test/cls_lock')
-rw-r--r--src/test/cls_lock/test_cls_lock.cc72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/test/cls_lock/test_cls_lock.cc b/src/test/cls_lock/test_cls_lock.cc
index 0aeed8245e7..b8bc51e01a4 100644
--- a/src/test/cls_lock/test_cls_lock.cc
+++ b/src/test/cls_lock/test_cls_lock.cc
@@ -94,10 +94,10 @@ TEST(ClsLock, TestMultiLocking) {
ASSERT_EQ(-EEXIST, l.lock_exclusive(&ioctx, oid));
/* test idempotency */
- l.set_renew(true);
+ l.set_may_renew(true);
ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid));
- l.set_renew(false);
+ l.set_may_renew(false);
/* test second client */
Lock l2(lock_name);
@@ -204,7 +204,7 @@ TEST(ClsLock, TestMeta) {
/* check new tag */
string new_tag = "new_tag";
l.set_tag(new_tag);
- l.set_renew(true);
+ l.set_may_renew(true);
ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid));
lock_info(&ioctx, oid, lock_name, lockers, NULL, &new_tag);
ASSERT_EQ(1, (int)lockers.size());
@@ -391,3 +391,69 @@ TEST(ClsLock, TestSetCookie) {
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
+
+TEST(ClsLock, TestRenew) {
+ Rados cluster;
+ std::string pool_name = get_temp_pool_name();
+ ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+ IoCtx ioctx;
+ cluster.ioctx_create(pool_name.c_str(), ioctx);
+
+ bufferlist bl;
+
+ string oid1 = "foo1";
+ string lock_name1 = "mylock1";
+
+ ASSERT_EQ(0, ioctx.write(oid1, bl, bl.length(), 0));
+
+ Lock l1(lock_name1);
+ utime_t lock_duration1(5, 0);
+ l1.set_duration(lock_duration1);
+
+ ASSERT_EQ(0, l1.lock_exclusive(&ioctx, oid1));
+ l1.set_may_renew(true);
+ sleep(2);
+ ASSERT_EQ(0, l1.lock_exclusive(&ioctx, oid1));
+ sleep(7);
+ ASSERT_EQ(0, l1.lock_exclusive(&ioctx, oid1)) <<
+ "when a cls_lock is set to may_renew, a relock after expiration "
+ "should still work";
+ ASSERT_EQ(0, l1.unlock(&ioctx, oid1));
+
+ // ***********************************************
+
+ string oid2 = "foo2";
+ string lock_name2 = "mylock2";
+
+ ASSERT_EQ(0, ioctx.write(oid2, bl, bl.length(), 0));
+
+ Lock l2(lock_name2);
+ utime_t lock_duration2(5, 0);
+ l2.set_duration(lock_duration2);
+
+ ASSERT_EQ(0, l2.lock_exclusive(&ioctx, oid2));
+ l2.set_must_renew(true);
+ sleep(2);
+ ASSERT_EQ(0, l2.lock_exclusive(&ioctx, oid2));
+ sleep(7);
+ ASSERT_EQ(-ENOENT, l2.lock_exclusive(&ioctx, oid2)) <<
+ "when a cls_lock is set to must_renew, a relock after expiration "
+ "should fail";
+ ASSERT_EQ(-ENOENT, l2.unlock(&ioctx, oid2));
+
+ // ***********************************************
+
+ string oid3 = "foo3";
+ string lock_name3 = "mylock3";
+
+ ASSERT_EQ(0, ioctx.write(oid3, bl, bl.length(), 0));
+
+ Lock l3(lock_name3);
+ l3.set_duration(utime_t(5, 0));
+ l3.set_must_renew(true);
+
+ ASSERT_EQ(-ENOENT, l3.lock_exclusive(&ioctx, oid3)) <<
+ "unable to create a lock with must_renew";
+
+ ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}