Skip to content

Commit

Permalink
ENG-3481: added option to disable flushall in redis (#337)
Browse files Browse the repository at this point in the history
Summary:
Added option to disable flushall in redis

shortened lines

Test Plan:
Modified flushall unit tests to test flag on, flag off
Also yb-ctl sanity check:

./bin/yb-ctl create --tserver_flags "yedis_enable_flush=false"
./bin/yb-ctl setup_redis
./bin/redis-cli
//manually check flushall and exit + destroy

ybd debug --cxx-test redisserver_redisserver-test --gtest_filter TestRedisService.TestFlushDb -n 100
ybd debug --cxx-test redisserver_redisserver-test --gtest_filter TestRedisService.TestFlushAll -n 100

Reviewers: amitanand, bogdan, pritam.damania

Reviewed By: pritam.damania

Subscribers: kannan, karthik, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D4995
  • Loading branch information
vitsai committed Jun 21, 2018
1 parent be5a4fe commit 31563f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/yb/yql/redis/redisserver/redis_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/stringize.hpp>

#include <gflags/gflags.h>

#include "yb/client/client.h"
#include "yb/client/yb_op.h"

Expand All @@ -30,6 +32,8 @@

using namespace std::literals;

DEFINE_bool(yedis_enable_flush, true, "Enables FLUSHDB and FLUSHALL commands in yedis.");

namespace yb {
namespace redisserver {

Expand Down Expand Up @@ -272,7 +276,11 @@ void HandleQuit(LocalCommandData data) {

void HandleFlushDB(LocalCommandData data) {
RedisResponsePB resp;
const Status s = data.client()->TruncateTable(data.table()->id());

const Status s = FLAGS_yedis_enable_flush ?
data.client()->TruncateTable(data.table()->id()) :
STATUS(InvalidArgument, "FLUSHDB and FLUSHALL are not enabled.");

if (s.ok()) {
resp.set_code(RedisResponsePB_RedisStatusCode_OK);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/yb/yql/redis/redisserver/redis_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef scoped_refptr<BatchContext> BatchContextPtr;
struct RedisCommandInfo {
std::string name;
// The following arguments should be passed to this functor:
// Info about it's command.
// Info about its command.
// Index of call in batch.
// Batch context.
std::function<void(const RedisCommandInfo&,
Expand Down
16 changes: 13 additions & 3 deletions src/yb/yql/redis/redisserver/redisserver-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ DECLARE_int32(rpc_max_message_size);
DECLARE_int32(consensus_max_batch_size_bytes);
DECLARE_int32(consensus_rpc_timeout_ms);
DECLARE_int64(max_time_in_queue_ms);
DECLARE_bool(yedis_enable_flush);

DEFINE_uint64(test_redis_max_concurrent_commands, 20,
"Value of redis_max_concurrent_commands for pipeline test");
Expand Down Expand Up @@ -316,7 +317,8 @@ class TestRedisService : public RedisTableTestBase {
std::to_string(expire_val - ttl_sec)}); // ttl of 0 not allowed.
}

void TestFlush(const string& flush_cmd) {
void TestFlush(const string& flush_cmd, const bool allow_flush) {
FLAGS_yedis_enable_flush = allow_flush;
// Populate keys.
const int kKeyCount = 100;
for (int i = 0; i < kKeyCount; i++) {
Expand All @@ -330,6 +332,12 @@ class TestRedisService : public RedisTableTestBase {
}
SyncClient();

if (!allow_flush) {
DoRedisTestExpectError(__LINE__, {flush_cmd});
SyncClient();
return;
}

// Delete all keys in the database and verify keys are gone.
DoRedisTestOk(__LINE__, {flush_cmd});
SyncClient();
Expand Down Expand Up @@ -2703,11 +2711,13 @@ TEST_F(TestRedisService, TestQuit) {
}

TEST_F(TestRedisService, TestFlushAll) {
TestFlush("FLUSHALL");
TestFlush("FLUSHALL", false);
TestFlush("FLUSHALL", true);
}

TEST_F(TestRedisService, TestFlushDb) {
TestFlush("FLUSHDB");
TestFlush("FLUSHDB", false);
TestFlush("FLUSHDB", true);
}

} // namespace redisserver
Expand Down

0 comments on commit 31563f2

Please sign in to comment.