Skip to content

Commit

Permalink
Merge branch 'unstable' into update-glog-0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksraiden authored Nov 6, 2024
2 parents 21706cf + 4de82cd commit 6af5f2d
Show file tree
Hide file tree
Showing 66 changed files with 861 additions and 609 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:noble
RUN apt update \
&& apt install -y \
git build-essential cmake libtool python3 libssl-dev python3-pip \
wget curl clang-format-14 clang-tidy-14 golang-go ninja-build \
redis-tools vim python3-redis redis-server clang lld mold gdb fish
RUN BUILD_DIR=$(pwd) && git clone https://github.com/jsha/minica /opt/minica \
&& cd /opt/minica && git checkout 96a5c93723cf3d34b50b3e723a9f05cd3765bc67 && go build && cd $BUILD_DIR \
&& echo 'export PATH=/opt/minica:$PATH' >> $HOME/.bashrc
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"build": {
"dockerfile": "Dockerfile"
}
}
5 changes: 5 additions & 0 deletions .github/config/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ extend-exclude = [
".git/",
"src/vendor/",
"tests/gocase/util/slot.go",

# Uses short strings for testing glob matching
"tests/cppunit/string_util_test.cc",
"tests/gocase/unit/keyspace/keyspace_test.go",
"tests/gocase/unit/scan/scan_test.go",
]
ignore-hidden = false

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Check typos
uses: crate-ci/typos@v1.25.0
uses: crate-ci/typos@v1.27.0
with:
config: .github/config/typos.toml

Expand Down Expand Up @@ -258,7 +258,7 @@ jobs:
if: ${{ matrix.sonarcloud }}

- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2
uses: SonarSource/sonarcloud-github-c-cpp@v3
if: ${{ matrix.sonarcloud }}

- name: Build Kvrocks
Expand Down
4 changes: 2 additions & 2 deletions cmake/jsoncons.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ include_guard()
include(cmake/utils.cmake)

FetchContent_DeclareGitHubWithMirror(jsoncons
danielaparker/jsoncons v0.177.0
MD5=393062889321f4f715a9302d8f49acf8
danielaparker/jsoncons v0.178.0
MD5=397410843b7c540e9dcee9b8b0c797a6
)

FetchContent_MakeAvailableWithArgs(jsoncons
Expand Down
4 changes: 2 additions & 2 deletions cmake/rocksdb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ endif()
include(cmake/utils.cmake)

FetchContent_DeclareGitHubWithMirror(rocksdb
facebook/rocksdb v9.3.1
MD5=129235c789a963c004290d27d09ca48a
facebook/rocksdb v9.7.4
MD5=9a08feb50e017006146bcff37059096f
)

FetchContent_GetProperties(jemalloc)
Expand Down
4 changes: 2 additions & 2 deletions cmake/tbb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ include_guard()
include(cmake/utils.cmake)

FetchContent_DeclareGitHubWithMirror(tbb
oneapi-src/oneTBB v2021.13.0
MD5=2dd9b7cfa5de5bb3add2f7392e0c9bab
oneapi-src/oneTBB v2022.0.0
MD5=7eaeff0ddec85182afb60f2232fae2af
)

FetchContent_MakeAvailableWithArgs(tbb
Expand Down
19 changes: 10 additions & 9 deletions src/cluster/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ Status Cluster::SetNodeId(const std::string &node_id) {
}

// Set replication relationship
if (myself_) return SetMasterSlaveRepl();

return Status::OK();
return SetMasterSlaveRepl();
}

// The reason why the new version MUST be +1 of current version is that,
Expand Down Expand Up @@ -204,11 +202,8 @@ Status Cluster::SetClusterNodes(const std::string &nodes_str, int64_t version, b
}

// Set replication relationship
if (myself_) {
s = SetMasterSlaveRepl();
if (!s.IsOK()) {
return s.Prefixed("failed to set master-replica replication");
}
if (auto s = SetMasterSlaveRepl(); !s.IsOK()) {
return s.Prefixed("failed to set master-replica replication");
}

// Clear data of migrated slots
Expand All @@ -234,7 +229,13 @@ Status Cluster::SetClusterNodes(const std::string &nodes_str, int64_t version, b
Status Cluster::SetMasterSlaveRepl() {
if (!srv_) return Status::OK();

if (!myself_) return Status::OK();
// If the node is not in the cluster topology, remove the master replication if it's a replica.
if (!myself_) {
if (auto s = srv_->RemoveMaster(); !s.IsOK()) {
return s.Prefixed("failed to remove master");
}
return Status::OK();
}

if (myself_->role == kClusterMaster) {
// Master mode
Expand Down
2 changes: 1 addition & 1 deletion src/cluster/replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Status FeedSlaveThread::Start() {
sigaddset(&mask, SIGHUP);
sigaddset(&mask, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &mask, &omask);
auto s = util::SockSend(conn_->GetFD(), redis::SimpleString("OK"), conn_->GetBufferEvent());
auto s = util::SockSend(conn_->GetFD(), redis::RESP_OK, conn_->GetBufferEvent());
if (!s.IsOK()) {
LOG(ERROR) << "failed to send OK response to the replica: " << s.Msg();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/cluster/sync_migrate_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void SyncMigrateContext::TimerCB(int, [[maybe_unused]] int16_t events) {

void SyncMigrateContext::OnWrite(bufferevent *bev) {
if (migrate_result_) {
conn_->Reply(redis::SimpleString("OK"));
conn_->Reply(redis::RESP_OK);
} else {
conn_->Reply(redis::Error(migrate_result_));
}
Expand Down
11 changes: 10 additions & 1 deletion src/commands/blocking_commander.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include "commander.h"
#include "common/lock_manager.h"
#include "event_util.h"
#include "server/redis_connection.h"

Expand All @@ -44,6 +45,10 @@ class BlockingCommander : public Commander,
// in other words, returning true indicates ending the blocking
virtual bool OnBlockingWrite() = 0;

// GetLocks() locks the keys of the BlockingCommander with MultiLockGuard.
// When OnWrite() is triggered, BlockingCommander needs to relock the keys.
virtual MultiLockGuard GetLocks() = 0;

// to start the blocking process
// usually put to the end of the Execute method
Status StartBlocking(int64_t timeout, std::string *output) {
Expand All @@ -63,7 +68,11 @@ class BlockingCommander : public Commander,
}

void OnWrite(bufferevent *bev) {
bool done = OnBlockingWrite();
bool done{false};
{
auto guard = GetLocks();
done = OnBlockingWrite();
}

if (!done) {
// The connection may be waked up but can't pop from the datatype.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_bloom_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CommandBFReserve : public Commander {
auto s = bloomfilter_db.Reserve(ctx, args_[1], capacity_, error_rate_, expansion_);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
return Status::OK();
}

Expand Down
29 changes: 14 additions & 15 deletions src/commands/cmd_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ class CommandCluster : public Commander {
// TODO: support multiple slot ranges
Status s = srv->cluster->ImportSlotRange(conn, slot_ranges_[0], state_);
if (s.IsOK()) {
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
} else {
return s;
}
} else if (subcommand_ == "reset") {
Status s = srv->cluster->Reset();
if (s.IsOK()) {
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
} else {
return s;
}
Expand Down Expand Up @@ -258,23 +258,23 @@ class CommandClusterX : public Commander {
Status s = srv->cluster->SetClusterNodes(nodes_str_, set_version_, force_);
if (s.IsOK()) {
need_persist_nodes_info = true;
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
} else {
return s;
}
} else if (subcommand_ == "setnodeid") {
Status s = srv->cluster->SetNodeId(args_[2]);
if (s.IsOK()) {
need_persist_nodes_info = true;
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
} else {
return s;
}
} else if (subcommand_ == "setslot") {
Status s = srv->cluster->SetSlotRanges(slot_ranges_, args_[4], set_version_);
if (s.IsOK()) {
need_persist_nodes_info = true;
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
} else {
return s;
}
Expand All @@ -293,7 +293,7 @@ class CommandClusterX : public Commander {
if (sync_migrate_) {
return {Status::BlockingCmd};
}
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
} else {
return s;
}
Expand Down Expand Up @@ -331,7 +331,7 @@ class CommandReadOnly : public Commander {
public:
Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] Server *srv, Connection *conn,
std::string *output) override {
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
conn->EnableFlag(redis::Connection::kReadOnly);
return Status::OK();
}
Expand All @@ -341,7 +341,7 @@ class CommandReadWrite : public Commander {
public:
Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] Server *srv, Connection *conn,
std::string *output) override {
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
conn->DisableFlag(redis::Connection::kReadOnly);
return Status::OK();
}
Expand All @@ -352,16 +352,15 @@ class CommandAsking : public Commander {
Status Execute([[maybe_unused]] engine::Context &ctx, [[maybe_unused]] Server *srv, Connection *conn,
std::string *output) override {
conn->EnableFlag(redis::Connection::kAsking);
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
return Status::OK();
}
};

REDIS_REGISTER_COMMANDS(Cluster,
MakeCmdAttr<CommandCluster>("cluster", -2, "cluster no-script", NO_KEY, GenerateClusterFlag),
MakeCmdAttr<CommandClusterX>("clusterx", -2, "cluster no-script", NO_KEY, GenerateClusterFlag),
MakeCmdAttr<CommandReadOnly>("readonly", 1, "cluster no-multi", NO_KEY),
MakeCmdAttr<CommandReadWrite>("readwrite", 1, "cluster no-multi", NO_KEY),
MakeCmdAttr<CommandAsking>("asking", 1, "cluster", NO_KEY), )
REDIS_REGISTER_COMMANDS(Cluster, MakeCmdAttr<CommandCluster>("cluster", -2, "no-script", NO_KEY, GenerateClusterFlag),
MakeCmdAttr<CommandClusterX>("clusterx", -2, "no-script", NO_KEY, GenerateClusterFlag),
MakeCmdAttr<CommandReadOnly>("readonly", 1, "no-multi", NO_KEY),
MakeCmdAttr<CommandReadWrite>("readwrite", 1, "no-multi", NO_KEY),
MakeCmdAttr<CommandAsking>("asking", 1, "", NO_KEY), )

} // namespace redis
11 changes: 6 additions & 5 deletions src/commands/cmd_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct CommandFunction : Commander {
auto s = lua::FunctionDelete(ctx, srv, libname);
if (!s) return s;

*output = SimpleString("OK");
*output = RESP_OK;
return Status::OK();
} else {
return {Status::NotOK, "no such subcommand"};
Expand Down Expand Up @@ -109,9 +109,10 @@ uint64_t GenerateFunctionFlags(uint64_t flags, const std::vector<std::string> &a
return flags;
}

REDIS_REGISTER_COMMANDS(
Function, MakeCmdAttr<CommandFunction>("function", -2, "exclusive no-script", NO_KEY, GenerateFunctionFlags),
MakeCmdAttr<CommandFCall<>>("fcall", -3, "exclusive write no-script", GetScriptEvalKeyRange),
MakeCmdAttr<CommandFCall<true>>("fcall_ro", -3, "read-only ro-script no-script", GetScriptEvalKeyRange));
REDIS_REGISTER_COMMANDS(Function,
MakeCmdAttr<CommandFunction>("function", -2, "exclusive no-script", NO_KEY,
GenerateFunctionFlags),
MakeCmdAttr<CommandFCall<>>("fcall", -3, "exclusive write no-script", GetScriptEvalKeyRange),
MakeCmdAttr<CommandFCall<true>>("fcall_ro", -3, "read-only no-script", GetScriptEvalKeyRange));

} // namespace redis
2 changes: 1 addition & 1 deletion src/commands/cmd_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class CommandHMSet : public Commander {
if (GetAttributes()->name == "hset") {
*output = redis::Integer(ret);
} else {
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
}
return Status::OK();
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_hll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CommandPfMerge final : public Commander {
if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
}
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
return Status::OK();
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/commands/cmd_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CommandJsonSet : public Commander {
auto s = json.Set(ctx, args_[1], args_[2], args_[3]);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};

*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
return Status::OK();
}
};
Expand Down Expand Up @@ -337,7 +337,7 @@ class CommandJsonMerge : public Commander {
if (!result) {
*output = conn->NilString();
} else {
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
}

return Status::OK();
Expand Down Expand Up @@ -648,7 +648,7 @@ class CommandJsonMSet : public Commander {

if (auto s = json.MSet(ctx, user_keys, paths, values); !s.ok()) return {Status::RedisExecErr, s.ToString()};

*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
return Status::OK();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cmd_key.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class CommandRename : public Commander {
auto s = redis.Copy(ctx, ns_key, new_ns_key, false, true, &res);
if (!s.ok()) return {Status::RedisExecErr, s.ToString()};
if (res == Database::CopyResult::KEY_NOT_EXIST) return {Status::RedisExecErr, "no such key"};
*output = redis::SimpleString("OK");
*output = redis::RESP_OK;
return Status::OK();
}
};
Expand Down
Loading

0 comments on commit 6af5f2d

Please sign in to comment.