Commit 67df5e6a authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Implement user-facing lease-get command, add tests

parent beb2b429
Pipeline #432571 failed with stages
in 78 minutes and 51 seconds
......@@ -313,6 +313,26 @@ RedisEncodedResponse RedisDispatcher::dispatchWrite(StagingArea &stagingArea, Re
return Formatter::err(SSTR("lease held by '" << leaseInfo.getValue() << "', time remaining " << leaseInfo.getDeadline() - timestamp << " ms"));
}
}
case RedisCommand::TIMESTAMPED_LEASE_GET: {
if(request.size() != 3) return Formatter::errArgs("lease_get");
qdb_assert(request[2].size() == 8u);
ClockValue timestamp = binaryStringToUnsignedInt(request[2].c_str());
LeaseInfo leaseInfo;
rocksdb::Status st = store.lease_get(stagingArea, request[1], timestamp, leaseInfo);
if(st.IsNotFound()) {
return Formatter::null();
}
qdb_assert(st.ok());
std::vector<std::string> reply;
reply.emplace_back(SSTR("HOLDER: " << leaseInfo.getValue()));
reply.emplace_back(SSTR("REMAINING: " << leaseInfo.getDeadline() - timestamp << " ms"));
return Formatter::statusVector(reply);
}
default: {
qdb_throw("internal dispatching error in RedisDispatcher for " << request);
}
......
......@@ -574,6 +574,28 @@ TEST_F(Raft_e2e, test_many_redis_commands) {
ASSERT_REPLY(c4.getFuture(), "OK");
ASSERT_REPLY(c5.getFuture(), "3");
ASSERT_REPLY(fut4, "3");
// Test lease commands.
std::future<redisReplyPtr> l0 = tunnel(leaderID)->exec("lease-acquire", "get");
std::future<redisReplyPtr> l1 = tunnel(leaderID)->exec("lease-acquire", "mykey", "holder1", "10000");
std::future<redisReplyPtr> l2 = tunnel(leaderID)->exec("lease-acquire", "mykey", "holder2", "10000");
std::future<redisReplyPtr> l3 = tunnel(leaderID)->exec("lease-acquire", "mykey", "holder1", "10000");
ASSERT_REPLY(l0, "ERR Invalid Argument: WRONGTYPE Operation against a key holding the wrong kind of value");
ASSERT_REPLY(l1, "ACQUIRED");
redisReplyPtr replyL2 = l2.get();
std::string reply = std::string(replyL2->str, replyL2->len);
ASSERT_TRUE(StringUtils::startswith(reply, "ERR lease held by 'holder1', time remaining"));
ASSERT_REPLY(l3, "RENEWED");
std::future<redisReplyPtr> l4 = tunnel(leaderID)->exec("lease-get", "mykey");
std::future<redisReplyPtr> l5 = tunnel(leaderID)->exec("lease-get", "mykey-2");
redisReplyPtr replyL4 = l4.get();
qdb_info(qclient::describeRedisReply(replyL4));
ASSERT_TRUE(StringUtils::startswith(qclient::describeRedisReply(replyL4), "1) HOLDER: holder1\n2) REMAINING: "));
ASSERT_NIL(l5);
}
TEST_F(Raft_e2e, replication_with_trimmed_journal) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment