Commit 0597941d authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Implement LHDEL with fallback

parent 2ba03b36
Pipeline #386853 passed with stages
in 22 minutes and 14 seconds
......@@ -88,6 +88,13 @@ RedisEncodedResponse RedisDispatcher::dispatchHDEL(StagingArea &stagingArea, con
return Formatter::integer(count);
}
RedisEncodedResponse RedisDispatcher::dispatchLHDEL(StagingArea &stagingArea, const std::string &key, const VecIterator &start, const VecIterator &end) {
int64_t count = 0;
rocksdb::Status st = store.lhdel(stagingArea, key, start, end, count);
if(!st.ok()) return Formatter::fromStatus(st);
return Formatter::integer(count);
}
RedisEncodedResponse RedisDispatcher::dispatchWrite(StagingArea &stagingArea, RedisRequest &request) {
qdb_assert(request.getCommandType() == CommandType::WRITE);
......@@ -226,10 +233,7 @@ RedisEncodedResponse RedisDispatcher::dispatchWrite(StagingArea &stagingArea, Re
}
case RedisCommand::LHDEL: {
if(request.size() <= 2) return errArgs(request);
int64_t count = 0;
rocksdb::Status st = store.lhdel(stagingArea, request[1], request.begin()+2, request.end(), count);
if(!st.ok()) return Formatter::fromStatus(st);
return Formatter::integer(count);
return dispatchLHDEL(stagingArea, request[1], request.begin()+2, request.end());
}
case RedisCommand::LHMSET: {
if(request.size() <= 4 || (request.size()-2) % 3 != 0) return Formatter::errArgs(request[0]);
......@@ -243,6 +247,15 @@ RedisEncodedResponse RedisDispatcher::dispatchWrite(StagingArea &stagingArea, Re
dispatchHDEL(stagingArea, request[5], request.begin()+2, request.begin()+3);
return resp;
}
case RedisCommand::LHDEL_WITH_FALLBACK: {
if(request.size() != 4) return errArgs(request);
RedisEncodedResponse resp = dispatchLHDEL(stagingArea, request[1], request.begin()+2, request.begin()+3);
if(resp.val != Formatter::integer(1).val) {
return dispatchHDEL(stagingArea, request[3], request.begin()+2, request.begin()+3);
}
return resp;
}
default: {
qdb_throw("internal dispatching error in RedisDispatcher for " << request);
}
......
......@@ -65,7 +65,7 @@ private:
RedisEncodedResponse dispatchLHGET(StagingArea &stagingArea, const std::string &key, const std::string &field, const std::string &hint);
RedisEncodedResponse dispatchLHSET(StagingArea &stagingArea, const std::string &key, const std::string &field, const std::string &hint, const std::string &value);
RedisEncodedResponse dispatchHDEL(StagingArea &stagingArea, const std::string &key, const VecIterator &start, const VecIterator &end);
RedisEncodedResponse dispatchLHDEL(StagingArea &stagingArea, const std::string &key, const VecIterator &start, const VecIterator &end);
};
}
......
......@@ -1119,11 +1119,13 @@ TEST_F(Raft_e2e, LocalityHash) {
ASSERT_REPLY(tunnel(leaderID)->exec("lhget-with-fallback", "mykey", "f9", "fb"), "ZZZ");
ASSERT_REPLY(tunnel(leaderID)->exec("lhget", "mykey", "f9"), "ZZZ");
ASSERT_REPLY(tunnel(leaderID)->exec("lhdel-with-fallback", "mykey", "f9", "fb"), 1);
ASSERT_REPLY(tunnel(leaderID)->exec("lhdel-with-fallback", "mykey", "f9", "fb"), 0);
ASSERT_REPLY(tunnel(leaderID)->exec("lhlen", "mykey"), 3);
ASSERT_REPLY(tunnel(leaderID)->exec("lhget-with-fallback", "mykey", "f9", "fb"), "");
ASSERT_REPLY(tunnel(leaderID)->exec("lhdel-with-fallback", "mykey", "f8", "fb"), 1);
ASSERT_REPLY(tunnel(leaderID)->exec("lhlen", "mykey"), 3);
ASSERT_REPLY(tunnel(leaderID)->exec("hlen", "fb"), 0);
ASSERT_REPLY(tunnel(leaderID)->exec("hget", "fb", "f8"), "");
}
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