Commit 3ca898f8 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Implement convenience command deque-clear

parent 30cb6097
Pipeline #950071 passed with stages
in 38 minutes and 4 seconds
# Changelog
All notable changes to this project will be documented in this file.
## Unreleased
- Add convenience command ``DEQUE-CLEAR``.
## 0.3.8 (2019-05-27)
- Prevent elections from hanging on the TCP timeout when one of the member hosts
is dropping packets, which could bring down an otherwise healthy cluster.
......
......@@ -92,6 +92,7 @@ struct cmdMapInit {
redis_cmd_map["deque_push_back"] = {RedisCommand::DEQUE_PUSH_BACK, CommandType::WRITE};
redis_cmd_map["deque_pop_back"] = {RedisCommand::DEQUE_POP_BACK, CommandType::WRITE};
redis_cmd_map["deque_trim_front"] = {RedisCommand::DEQUE_TRIM_FRONT, CommandType::WRITE};
redis_cmd_map["deque_clear"] = {RedisCommand::DEQUE_CLEAR, CommandType::WRITE};
redis_cmd_map["config_set"] = {RedisCommand::CONFIG_SET, CommandType::WRITE};
redis_cmd_map["lhset"] = {RedisCommand::LHSET, CommandType::WRITE};
redis_cmd_map["lhdel"] = {RedisCommand::LHDEL, CommandType::WRITE};
......
......@@ -93,6 +93,7 @@ enum class RedisCommand {
DEQUE_TRIM_FRONT,
DEQUE_LEN,
DEQUE_SCAN_BACK,
DEQUE_CLEAR,
RAW_SCAN,
RAW_SCAN_TOMBSTONES,
......
......@@ -300,6 +300,13 @@ RedisEncodedResponse RedisDispatcher::dispatchWrite(StagingArea &stagingArea, Re
if(!st.ok()) return Formatter::fromStatus(st);
return Formatter::integer(itemsRemoved);
}
case RedisCommand::DEQUE_CLEAR: {
if(request.size() != 2) return errArgs(request);
int64_t itemsRemoved;
rocksdb::Status st = store.dequeTrimFront(stagingArea, request[1], "0", itemsRemoved);
if(!st.ok()) return Formatter::fromStatus(st);
return Formatter::integer(itemsRemoved);
}
case RedisCommand::CONFIG_SET: {
if(request.size() != 3) return errArgs(request);
rocksdb::Status st = store.configSet(stagingArea, request[1], request[2]);
......
......@@ -842,6 +842,17 @@ TEST_F(Raft_e2e, DequeTrimming) {
ASSERT_REPLY(tunnel(leaderID)->exec("del", "dq", "test"), 2);
}
TEST_F(Raft_e2e, DequeClear) {
spinup(0); spinup(1); spinup(2);
RETRY_ASSERT_TRUE(checkStateConsensus(0, 1, 2));
int leaderID = getServerID(state(0)->getSnapshot()->leader);
ASSERT_REPLY(tunnel(leaderID)->exec("deque-push-back", "dq", "1", "2", "3", "4"), 4);
ASSERT_REPLY(tunnel(leaderID)->exec("deque-clear", "dq"), 4);
ASSERT_REPLY(tunnel(leaderID)->exec("deque-len", "dq"), 0);
ASSERT_REPLY(tunnel(leaderID)->exec("set", "dq", "abc"), "OK");
}
TEST_F(Raft_e2e, replication_with_trimmed_journal) {
spinup(0); spinup(1);
RETRY_ASSERT_TRUE(checkStateConsensus(0, 1));
......
Markdown is supported
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