You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by tw...@apache.org on 2023/04/14 15:26:49 UTC
[incubator-kvrocks] branch unstable updated: Check function names in readability-identifier-naming (#1390)
This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 5db4fadf Check function names in readability-identifier-naming (#1390)
5db4fadf is described below
commit 5db4fadff232176c4945bc521696edbd6ee39bc7
Author: Twice <tw...@gmail.com>
AuthorDate: Fri Apr 14 23:26:41 2023 +0800
Check function names in readability-identifier-naming (#1390)
---
.clang-tidy | 2 +
src/cluster/redis_slot.cc | 4 +-
src/cluster/redis_slot.h | 2 +-
src/cluster/replication.cc | 14 ++--
src/commands/cmd_bit.cc | 6 +-
src/commands/cmd_script.cc | 4 +-
src/common/io_util.cc | 4 +-
src/common/io_util.h | 2 +-
src/common/rand.cc | 30 ++++---
src/common/rand.h | 4 +-
src/common/string_util.cc | 24 +++---
src/config/config.cc | 34 ++++----
src/config/config_type.h | 8 +-
src/main.cc | 58 +++++++-------
src/storage/event_listener.cc | 18 ++---
src/storage/scripting.cc | 168 +++++++++++++++++++--------------------
src/storage/scripting.h | 64 +++++++--------
src/types/geohash.cc | 122 ++++++++++++++--------------
src/types/geohash.h | 20 ++---
src/types/redis_bitmap_string.cc | 10 +--
src/types/redis_geo.cc | 6 +-
utils/kvrocks2redis/main.cc | 32 ++++----
utils/kvrocks2redis/sync.cc | 2 +-
23 files changed, 322 insertions(+), 316 deletions(-)
diff --git a/.clang-tidy b/.clang-tidy
index 18a654d0..15f31b6c 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -48,3 +48,5 @@ CheckOptions:
value: UPPER_CASE
- key: readability-identifier-naming.NamespaceCase
value: lower_case
+ - key: readability-identifier-naming.FunctionCase
+ value: CamelCase
diff --git a/src/cluster/redis_slot.cc b/src/cluster/redis_slot.cc
index b5487d6e..62787789 100644
--- a/src/cluster/redis_slot.cc
+++ b/src/cluster/redis_slot.cc
@@ -47,7 +47,7 @@ static const uint16_t crc16tab[256] = {
0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74,
0x2e93, 0x3eb2, 0x0ed1, 0x1ef0};
-uint16_t crc16(const char *buf, int len) {
+uint16_t Crc16(const char *buf, int len) {
int i = 0;
uint16_t crc = 0;
for (i = 0; i < len; i++) crc = (crc << 8) ^ crc16tab[((crc >> 8) ^ *buf++) & 0x00FF];
@@ -60,7 +60,7 @@ uint16_t GetSlotIdFromKey(const std::string &key) {
tag = key;
}
- auto crc = crc16(tag.data(), static_cast<int>(tag.size()));
+ auto crc = Crc16(tag.data(), static_cast<int>(tag.size()));
return static_cast<int>(crc & HASH_SLOTS_MASK);
}
diff --git a/src/cluster/redis_slot.h b/src/cluster/redis_slot.h
index 4354597c..5e55d124 100644
--- a/src/cluster/redis_slot.h
+++ b/src/cluster/redis_slot.h
@@ -26,6 +26,6 @@ constexpr const uint16_t HASH_SLOTS_MASK = 0x3fff;
constexpr const uint16_t HASH_SLOTS_SIZE = HASH_SLOTS_MASK + 1; // 16384
constexpr const uint16_t HASH_SLOTS_MAX_ITERATIONS = 50;
-uint16_t crc16(const char *buf, int len);
+uint16_t Crc16(const char *buf, int len);
uint16_t GetSlotIdFromKey(const std::string &key);
std::string GetTagFromKey(const std::string &key);
diff --git a/src/cluster/replication.cc b/src/cluster/replication.cc
index 0219d9da..68bceebc 100644
--- a/src/cluster/replication.cc
+++ b/src/cluster/replication.cc
@@ -156,7 +156,7 @@ void FeedSlaveThread::loop() {
}
}
-void send_string(bufferevent *bev, const std::string &data) {
+void SendString(bufferevent *bev, const std::string &data) {
auto output = bufferevent_get_output(bev);
evbuffer_add(output, data.c_str(), data.length());
}
@@ -372,7 +372,7 @@ void ReplicationThread::run() {
ReplicationThread::CBState ReplicationThread::authWriteCB(bufferevent *bev, void *ctx) {
auto self = static_cast<ReplicationThread *>(ctx);
- send_string(bev, redis::MultiBulkString({"AUTH", self->srv_->GetConfig()->masterauth}));
+ SendString(bev, redis::MultiBulkString({"AUTH", self->srv_->GetConfig()->masterauth}));
LOG(INFO) << "[replication] Auth request was sent, waiting for response";
self->repl_state_.store(kReplSendAuth, std::memory_order_relaxed);
return CBState::NEXT;
@@ -392,7 +392,7 @@ ReplicationThread::CBState ReplicationThread::authReadCB(bufferevent *bev, void
}
ReplicationThread::CBState ReplicationThread::checkDBNameWriteCB(bufferevent *bev, void *ctx) {
- send_string(bev, redis::MultiBulkString({"_db_name"}));
+ SendString(bev, redis::MultiBulkString({"_db_name"}));
auto self = static_cast<ReplicationThread *>(ctx);
self->repl_state_.store(kReplCheckDBName, std::memory_order_relaxed);
LOG(INFO) << "[replication] Check db name request was sent, waiting for response";
@@ -433,7 +433,7 @@ ReplicationThread::CBState ReplicationThread::replConfWriteCB(bufferevent *bev,
data_to_send.emplace_back("ip-address");
data_to_send.emplace_back(config->replica_announce_ip);
}
- send_string(bev, redis::MultiBulkString(data_to_send));
+ SendString(bev, redis::MultiBulkString(data_to_send));
self->repl_state_.store(kReplReplConf, std::memory_order_relaxed);
LOG(INFO) << "[replication] replconf request was sent, waiting for response";
return CBState::NEXT;
@@ -492,11 +492,11 @@ ReplicationThread::CBState ReplicationThread::tryPSyncWriteCB(bufferevent *bev,
// Also use old PSYNC if replica can't find replication id from WAL and DB.
if (!self->srv_->GetConfig()->use_rsid_psync || self->next_try_old_psync_ || replid.length() != kReplIdLength) {
self->next_try_old_psync_ = false; // Reset next_try_old_psync_
- send_string(bev, redis::MultiBulkString({"PSYNC", std::to_string(next_seq)}));
+ SendString(bev, redis::MultiBulkString({"PSYNC", std::to_string(next_seq)}));
LOG(INFO) << "[replication] Try to use psync, next seq: " << next_seq;
} else {
// NEW PSYNC "Unique Replication Sequence ID": replication id and sequence id
- send_string(bev, redis::MultiBulkString({"PSYNC", replid, std::to_string(next_seq)}));
+ SendString(bev, redis::MultiBulkString({"PSYNC", replid, std::to_string(next_seq)}));
LOG(INFO) << "[replication] Try to use new psync, current unique replication sequence id: " << replid << ":"
<< cur_seq;
}
@@ -588,7 +588,7 @@ ReplicationThread::CBState ReplicationThread::incrementBatchLoopCB(bufferevent *
}
ReplicationThread::CBState ReplicationThread::fullSyncWriteCB(bufferevent *bev, void *ctx) {
- send_string(bev, redis::MultiBulkString({"_fetch_meta"}));
+ SendString(bev, redis::MultiBulkString({"_fetch_meta"}));
auto self = static_cast<ReplicationThread *>(ctx);
self->repl_state_.store(kReplFetchMeta, std::memory_order_relaxed);
LOG(INFO) << "[replication] Start syncing data with fullsync";
diff --git a/src/commands/cmd_bit.cc b/src/commands/cmd_bit.cc
index a9b612a7..a56d5ac4 100644
--- a/src/commands/cmd_bit.cc
+++ b/src/commands/cmd_bit.cc
@@ -25,7 +25,7 @@
namespace redis {
-Status getBitOffsetFromArgument(const std::string &arg, uint32_t *offset) {
+Status GetBitOffsetFromArgument(const std::string &arg, uint32_t *offset) {
auto parse_result = ParseInt<uint32_t>(arg, 10);
if (!parse_result) {
return parse_result.ToStatus();
@@ -38,7 +38,7 @@ Status getBitOffsetFromArgument(const std::string &arg, uint32_t *offset) {
class CommandGetBit : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
- Status s = getBitOffsetFromArgument(args[2], &offset_);
+ Status s = GetBitOffsetFromArgument(args[2], &offset_);
if (!s.IsOK()) return s;
return Commander::Parse(args);
@@ -61,7 +61,7 @@ class CommandGetBit : public Commander {
class CommandSetBit : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
- Status s = getBitOffsetFromArgument(args[2], &offset_);
+ Status s = GetBitOffsetFromArgument(args[2], &offset_);
if (!s.IsOK()) return s;
if (args[3] == "0") {
diff --git a/src/commands/cmd_script.cc b/src/commands/cmd_script.cc
index 0f2e89c8..6194129d 100644
--- a/src/commands/cmd_script.cc
+++ b/src/commands/cmd_script.cc
@@ -42,7 +42,7 @@ class CommandEvalImpl : public Commander {
return {Status::NotOK, "Number of keys can't be negative"};
}
- return lua::evalGenericCommand(
+ return lua::EvalGenericCommand(
conn, args_[1], std::vector<std::string>(args_.begin() + 3, args_.begin() + 3 + numkeys),
std::vector<std::string>(args_.begin() + 3 + numkeys, args_.end()), evalsha, output, read_only);
}
@@ -90,7 +90,7 @@ class CommandScript : public Commander {
}
} else if (args_.size() == 3 && subcommand_ == "load") {
std::string sha;
- auto s = lua::createFunction(svr, args_[2], &sha, svr->Lua(), true);
+ auto s = lua::CreateFunction(svr, args_[2], &sha, svr->Lua(), true);
if (!s.IsOK()) {
return s;
}
diff --git a/src/common/io_util.cc b/src/common/io_util.cc
index d3fe62fe..ec8d877f 100644
--- a/src/common/io_util.cc
+++ b/src/common/io_util.cc
@@ -125,7 +125,7 @@ StatusOr<int> SockConnect(const std::string &host, uint32_t port, int conn_timeo
continue;
}
- auto retmask = util::aeWait(*cfd, AE_WRITABLE, conn_timeout);
+ auto retmask = util::AeWait(*cfd, AE_WRITABLE, conn_timeout);
if ((retmask & AE_WRITABLE) == 0 || (retmask & AE_ERROR) != 0 || (retmask & AE_HUP) != 0) {
return Status::FromErrno();
}
@@ -293,7 +293,7 @@ bool IsPortInUse(uint32_t port) {
/* Wait for milliseconds until the given file descriptor becomes
* writable/readable/exception */
-int aeWait(int fd, int mask, int timeout) {
+int AeWait(int fd, int mask, int timeout) {
pollfd pfd;
int retmask = 0;
diff --git a/src/common/io_util.h b/src/common/io_util.h
index f3ef8bf2..7b47fa09 100644
--- a/src/common/io_util.h
+++ b/src/common/io_util.h
@@ -38,7 +38,7 @@ int GetPeerAddr(int fd, std::string *addr, uint32_t *port);
int GetLocalPort(int fd);
bool IsPortInUse(uint32_t port);
-int aeWait(int fd, int mask, int milliseconds);
+int AeWait(int fd, int mask, int milliseconds);
Status Write(int fd, const std::string &data);
Status Pwrite(int fd, const std::string &data, off_t offset);
diff --git a/src/common/rand.cc b/src/common/rand.cc
index 8ba434a9..2cc74618 100644
--- a/src/common/rand.cc
+++ b/src/common/rand.cc
@@ -50,6 +50,8 @@
#include <stdint.h>
+namespace redis_rand_impl {
+
constexpr const int N = 16;
constexpr const int MASK = ((1 << (N - 1)) + (1 << (N - 1)) - 1);
template <typename T>
@@ -105,22 +107,11 @@ constexpr void SEED(const T x0, const T x1, const T x2) {
}
template <typename T>
-constexpr T HI_BIT(const T x) {
+constexpr T HiBit(const T x) {
return (1L << (2 * N - 1));
}
-static void next();
-
-int32_t redisLrand48() {
- next();
- return static_cast<int32_t>(x[2] << (N - 1)) + static_cast<int32_t>(x[1] >> 1);
-}
-
-void redisSrand48(int32_t seedval) {
- SEED(X0, static_cast<uint32_t>(LOW(seedval)), static_cast<uint32_t>(HIGH(seedval)));
-}
-
-static void next() {
+static void Next() {
uint32_t p[2], q[2], r[2], carry0 = 0, carry1 = 0;
MUL(a[0], x[0], p);
@@ -133,3 +124,16 @@ static void next() {
x[1] = LOW(p[1] + r[0]);
x[0] = LOW(p[0]);
}
+
+} // namespace redis_rand_impl
+
+int32_t RedisLrand48() {
+ using namespace redis_rand_impl;
+ Next();
+ return static_cast<int32_t>(x[2] << (N - 1)) + static_cast<int32_t>(x[1] >> 1);
+}
+
+void RedisSrand48(int32_t seedval) {
+ using namespace redis_rand_impl;
+ SEED(X0, static_cast<uint32_t>(LOW(seedval)), static_cast<uint32_t>(HIGH(seedval)));
+}
diff --git a/src/common/rand.h b/src/common/rand.h
index 311ce3ad..eb05c684 100644
--- a/src/common/rand.h
+++ b/src/common/rand.h
@@ -36,7 +36,7 @@
#include <stdint.h>
-int32_t redisLrand48();
-void redisSrand48(int32_t seedval);
+int32_t RedisLrand48();
+void RedisSrand48(int32_t seedval);
constexpr const int32_t REDIS_LRAND48_MAX = INT32_MAX;
diff --git a/src/common/string_util.cc b/src/common/string_util.cc
index 7883a154..95443db1 100644
--- a/src/common/string_util.cc
+++ b/src/common/string_util.cc
@@ -223,21 +223,21 @@ std::string StringToHex(const std::string &input) {
return output;
}
-constexpr unsigned long long expTo1024(unsigned n) { return 1ULL << (n * 10); }
+constexpr unsigned long long ExpTo1024(unsigned n) { return 1ULL << (n * 10); }
std::string BytesToHuman(uint64_t n) {
- if (n < expTo1024(1)) {
+ if (n < ExpTo1024(1)) {
return fmt::format("{}B", n);
- } else if (n < expTo1024(2)) {
- return fmt::format("{:.2f}K", static_cast<double>(n) / expTo1024(1));
- } else if (n < expTo1024(3)) {
- return fmt::format("{:.2f}M", static_cast<double>(n) / expTo1024(2));
- } else if (n < expTo1024(4)) {
- return fmt::format("{:.2f}G", static_cast<double>(n) / expTo1024(3));
- } else if (n < expTo1024(5)) {
- return fmt::format("{:.2f}T", static_cast<double>(n) / expTo1024(4));
- } else if (n < expTo1024(6)) {
- return fmt::format("{:.2f}P", static_cast<double>(n) / expTo1024(5));
+ } else if (n < ExpTo1024(2)) {
+ return fmt::format("{:.2f}K", static_cast<double>(n) / ExpTo1024(1));
+ } else if (n < ExpTo1024(3)) {
+ return fmt::format("{:.2f}M", static_cast<double>(n) / ExpTo1024(2));
+ } else if (n < ExpTo1024(4)) {
+ return fmt::format("{:.2f}G", static_cast<double>(n) / ExpTo1024(3));
+ } else if (n < ExpTo1024(5)) {
+ return fmt::format("{:.2f}T", static_cast<double>(n) / ExpTo1024(4));
+ } else if (n < ExpTo1024(6)) {
+ return fmt::format("{:.2f}P", static_cast<double>(n) / ExpTo1024(5));
} else {
return fmt::format("{}B", n);
}
diff --git a/src/config/config.cc b/src/config/config.cc
index 173f519d..3e3c2866 100644
--- a/src/config/config.cc
+++ b/src/config/config.cc
@@ -62,12 +62,12 @@ ConfigEnum log_levels[] = {{"info", google::INFO},
{"fatal", google::FATAL},
{nullptr, 0}};
-std::string trimRocksDBPrefix(std::string s) {
+std::string TrimRocksDbPrefix(std::string s) {
if (strncasecmp(s.data(), "rocksdb.", 8) != 0) return s;
return s.substr(8, s.size() - 8);
}
-int configEnumGetValue(ConfigEnum *ce, const char *name) {
+int ConfigEnumGetValue(ConfigEnum *ce, const char *name) {
while (ce->name != nullptr) {
if (strcasecmp(ce->name, name) == 0) return ce->val;
ce++;
@@ -75,7 +75,7 @@ int configEnumGetValue(ConfigEnum *ce, const char *name) {
return INT_MIN;
}
-const char *configEnumGetName(ConfigEnum *ce, int val) {
+const char *ConfigEnumGetName(ConfigEnum *ce, int val) {
while (ce->name != nullptr) {
if (ce->val == val) return ce->name;
ce++;
@@ -319,11 +319,11 @@ void Config::initFieldValidator() {
void Config::initFieldCallback() {
auto set_db_option_cb = [](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK(); // srv is nullptr when load config from file
- return srv->storage->SetDBOption(trimRocksDBPrefix(k), v);
+ return srv->storage->SetDBOption(TrimRocksDbPrefix(k), v);
};
auto set_cf_option_cb = [](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK(); // srv is nullptr when load config from file
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), v);
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), v);
};
#ifdef ENABLE_OPENSSL
auto set_tls_option = [](Server *srv, const std::string &k, const std::string &v) {
@@ -492,31 +492,31 @@ void Config::initFieldCallback() {
{"rocksdb.target_file_size_base",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k),
std::to_string(rocks_db.target_file_size_base * MiB));
}},
{"rocksdb.write_buffer_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k),
std::to_string(rocks_db.write_buffer_size * MiB));
}},
{"rocksdb.disable_auto_compactions",
[](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
std::string disable_auto_compactions = v == "yes" ? "true" : "false";
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), disable_auto_compactions);
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), disable_auto_compactions);
}},
{"rocksdb.max_total_wal_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
- return srv->storage->SetDBOption(trimRocksDBPrefix(k), std::to_string(rocks_db.max_total_wal_size * MiB));
+ return srv->storage->SetDBOption(TrimRocksDbPrefix(k), std::to_string(rocks_db.max_total_wal_size * MiB));
}},
{"rocksdb.enable_blob_files",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
std::string enable_blob_files = rocks_db.enable_blob_files ? "true" : "false";
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), enable_blob_files);
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), enable_blob_files);
}},
{"rocksdb.min_blob_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
@@ -524,7 +524,7 @@ void Config::initFieldCallback() {
if (!rocks_db.enable_blob_files) {
return {Status::NotOK, errBlobDbNotEnabled};
}
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), v);
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), v);
}},
{"rocksdb.blob_file_size",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
@@ -532,7 +532,7 @@ void Config::initFieldCallback() {
if (!rocks_db.enable_blob_files) {
return {Status::NotOK, errBlobDbNotEnabled};
}
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k),
std::to_string(rocks_db.blob_file_size));
}},
{"rocksdb.enable_blob_garbage_collection",
@@ -542,7 +542,7 @@ void Config::initFieldCallback() {
return {Status::NotOK, errBlobDbNotEnabled};
}
std::string enable_blob_garbage_collection = v == "yes" ? "true" : "false";
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), enable_blob_garbage_collection);
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), enable_blob_garbage_collection);
}},
{"rocksdb.blob_garbage_collection_age_cutoff",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
@@ -561,13 +561,13 @@ void Config::initFieldCallback() {
}
double cutoff = val / 100.0;
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), std::to_string(cutoff));
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), std::to_string(cutoff));
}},
{"rocksdb.level_compaction_dynamic_level_bytes",
[](Server *srv, const std::string &k, const std::string &v) -> Status {
if (!srv) return Status::OK();
std::string level_compaction_dynamic_level_bytes = v == "yes" ? "true" : "false";
- return srv->storage->SetDBOption(trimRocksDBPrefix(k), level_compaction_dynamic_level_bytes);
+ return srv->storage->SetDBOption(TrimRocksDbPrefix(k), level_compaction_dynamic_level_bytes);
}},
{"rocksdb.max_bytes_for_level_base",
[this](Server *srv, const std::string &k, const std::string &v) -> Status {
@@ -575,7 +575,7 @@ void Config::initFieldCallback() {
if (!rocks_db.level_compaction_dynamic_level_bytes) {
return {Status::NotOK, errLevelCompactionDynamicLevelBytesNotSet};
}
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k),
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k),
std::to_string(rocks_db.max_bytes_for_level_base));
}},
{"rocksdb.max_bytes_for_level_multiplier",
@@ -584,7 +584,7 @@ void Config::initFieldCallback() {
if (!rocks_db.level_compaction_dynamic_level_bytes) {
return {Status::NotOK, errLevelCompactionDynamicLevelBytesNotSet};
}
- return srv->storage->SetOptionForAllColumnFamilies(trimRocksDBPrefix(k), v);
+ return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), v);
}},
{"rocksdb.max_open_files", set_db_option_cb},
{"rocksdb.stats_dump_period_sec", set_db_option_cb},
diff --git a/src/config/config_type.h b/src/config/config_type.h
index 84167893..12e78a6d 100644
--- a/src/config/config_type.h
+++ b/src/config/config_type.h
@@ -53,8 +53,8 @@ struct ConfigEnum {
enum ConfigType { SingleConfig, MultiConfig };
-int configEnumGetValue(ConfigEnum *ce, const char *name);
-const char *configEnumGetName(ConfigEnum *ce, int val);
+int ConfigEnumGetValue(ConfigEnum *ce, const char *name);
+const char *ConfigEnumGetName(ConfigEnum *ce, int val);
class ConfigField {
public:
@@ -188,13 +188,13 @@ class EnumField : public ConfigField {
public:
EnumField(int *receiver, ConfigEnum *enums, int e) : receiver_(receiver), enums_(enums) { *receiver_ = e; }
~EnumField() override = default;
- std::string ToString() override { return configEnumGetName(enums_, *receiver_); }
+ std::string ToString() override { return ConfigEnumGetName(enums_, *receiver_); }
Status ToNumber(int64_t *n) override {
*n = *receiver_;
return Status::OK();
}
Status Set(const std::string &v) override {
- int e = configEnumGetValue(enums_, v.c_str());
+ int e = ConfigEnumGetValue(enums_, v.c_str());
if (e == INT_MIN) {
return {Status::NotOK, "invalid enum option"};
}
diff --git a/src/main.cc b/src/main.cc
index bebdc06f..77d49aeb 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -57,14 +57,14 @@ Server *srv = nullptr;
Server *GetServer() { return srv; }
-extern "C" void signalHandler(int sig) {
+extern "C" void SignalHandler(int sig) {
if (srv && !srv->IsStopped()) {
LOG(INFO) << "Bye Bye";
srv->Stop();
}
}
-std::ostream &printVersion(std::ostream &os) {
+std::ostream &PrintVersion(std::ostream &os) {
os << "kvrocks ";
if (VERSION != "unstable") {
@@ -80,10 +80,10 @@ std::ostream &printVersion(std::ostream &os) {
return os;
}
-extern "C" void segvHandler(int sig, siginfo_t *info, void *secret) {
+extern "C" void SegvHandler(int sig, siginfo_t *info, void *secret) {
void *trace[100];
- LOG(ERROR) << "======= Ooops! " << printVersion << " got signal: " << strsignal(sig) << " (" << sig << ") =======";
+ LOG(ERROR) << "======= Ooops! " << PrintVersion << " got signal: " << strsignal(sig) << " (" << sig << ") =======";
int trace_size = backtrace(trace, sizeof(trace) / sizeof(void *));
char **messages = backtrace_symbols(trace, trace_size);
@@ -118,14 +118,14 @@ extern "C" void segvHandler(int sig, siginfo_t *info, void *secret) {
kill(getpid(), sig);
}
-void setupSigSegvAction() {
+void SetupSigSegvAction() {
struct sigaction act;
sigemptyset(&act.sa_mask);
/* When the SA_SIGINFO flag is set in sa_flags then sa_sigaction
* is used. Otherwise, sa_handler is used */
act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
- act.sa_sigaction = segvHandler;
+ act.sa_sigaction = SegvHandler;
sigaction(SIGSEGV, &act, nullptr);
sigaction(SIGBUS, &act, nullptr);
sigaction(SIGFPE, &act, nullptr);
@@ -133,7 +133,7 @@ void setupSigSegvAction() {
sigaction(SIGABRT, &act, nullptr);
act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
- act.sa_handler = signalHandler;
+ act.sa_handler = SignalHandler;
sigaction(SIGTERM, &act, nullptr);
sigaction(SIGINT, &act, nullptr);
}
@@ -142,7 +142,7 @@ struct NewOpt {
friend auto &operator<<(std::ostream &os, NewOpt) { return os << std::string(4, ' ') << std::setw(32); }
} new_opt;
-static void printUsage(const char *program) {
+static void PrintUsage(const char *program) {
std::cout << program << " implements the Redis protocol based on rocksdb" << std::endl
<< "Usage:" << std::endl
<< std::left << new_opt << "-c, --config <filename>"
@@ -155,7 +155,7 @@ static void printUsage(const char *program) {
<< "overwrite specific config option <config-key> to <config-value>" << std::endl;
}
-static CLIOptions parseCommandLineOptions(int argc, char **argv) {
+static CLIOptions ParseCommandLineOptions(int argc, char **argv) {
using namespace std::string_view_literals;
CLIOptions opts;
@@ -163,16 +163,16 @@ static CLIOptions parseCommandLineOptions(int argc, char **argv) {
if ((argv[i] == "-c"sv || argv[i] == "--config"sv) && i + 1 < argc) {
opts.conf_file = argv[++i];
} else if (argv[i] == "-v"sv || argv[i] == "--version"sv) {
- std::cout << printVersion << std::endl;
+ std::cout << PrintVersion << std::endl;
std::exit(0);
} else if (argv[i] == "-h"sv || argv[i] == "--help"sv) {
- printUsage(*argv);
+ PrintUsage(*argv);
std::exit(0);
} else if (std::string_view(argv[i], 2) == "--" && std::string_view(argv[i]).size() > 2 && i + 1 < argc) {
auto key = std::string_view(argv[i] + 2);
opts.cli_options.emplace_back(key, argv[++i]);
} else {
- printUsage(*argv);
+ PrintUsage(*argv);
std::exit(1);
}
}
@@ -180,7 +180,7 @@ static CLIOptions parseCommandLineOptions(int argc, char **argv) {
return opts;
}
-static void initGoogleLog(const Config *config) {
+static void InitGoogleLog(const Config *config) {
FLAGS_minloglevel = config->log_level;
FLAGS_max_log_size = 100;
FLAGS_logbufsecs = 0;
@@ -199,7 +199,7 @@ static void initGoogleLog(const Config *config) {
}
}
-bool supervisedUpstart() {
+bool SupervisedUpstart() {
const char *upstart_job = getenv("UPSTART_JOB");
if (!upstart_job) {
LOG(WARNING) << "upstart supervision requested, but UPSTART_JOB not found";
@@ -211,7 +211,7 @@ bool supervisedUpstart() {
return true;
}
-bool supervisedSystemd() {
+bool SupervisedSystemd() {
const char *notify_socket = getenv("NOTIFY_SOCKET");
if (!notify_socket) {
LOG(WARNING) << "systemd supervision requested, but NOTIFY_SOCKET not found";
@@ -256,7 +256,7 @@ bool supervisedSystemd() {
return true;
}
-bool isSupervisedMode(int mode) {
+bool IsSupervisedMode(int mode) {
if (mode == kSupervisedAutoDetect) {
const char *upstart_job = getenv("UPSTART_JOB");
const char *notify_socket = getenv("NOTIFY_SOCKET");
@@ -267,14 +267,14 @@ bool isSupervisedMode(int mode) {
}
}
if (mode == kSupervisedUpStart) {
- return supervisedUpstart();
+ return SupervisedUpstart();
} else if (mode == kSupervisedSystemd) {
- return supervisedSystemd();
+ return SupervisedSystemd();
}
return false;
}
-static Status createPidFile(const std::string &path) {
+static Status CreatePidFile(const std::string &path) {
auto fd = UniqueFD(open(path.data(), O_RDWR | O_CREAT, 0660));
if (!fd) {
return Status::FromErrno();
@@ -289,9 +289,9 @@ static Status createPidFile(const std::string &path) {
return Status::OK();
}
-static void removePidFile(const std::string &path) { std::remove(path.data()); }
+static void RemovePidFile(const std::string &path) { std::remove(path.data()); }
-static void daemonize() {
+static void Daemonize() {
pid_t pid = fork();
if (pid < 0) {
LOG(ERROR) << "Failed to fork the process, err: " << strerror(errno);
@@ -315,9 +315,9 @@ int main(int argc, char *argv[]) {
evthread_use_pthreads();
signal(SIGPIPE, SIG_IGN);
- setupSigSegvAction();
+ SetupSigSegvAction();
- auto opts = parseCommandLineOptions(argc, argv);
+ auto opts = ParseCommandLineOptions(argc, argv);
Config config;
Status s = config.Load(opts);
@@ -326,8 +326,8 @@ int main(int argc, char *argv[]) {
return 1;
}
- initGoogleLog(&config);
- LOG(INFO) << printVersion;
+ InitGoogleLog(&config);
+ LOG(INFO) << PrintVersion;
// Tricky: We don't expect that different instances running on the same port,
// but the server use REUSE_PORT to support the multi listeners. So we connect
// the listen port to check if the port has already listened or not.
@@ -340,14 +340,14 @@ int main(int argc, char *argv[]) {
}
}
}
- bool is_supervised = isSupervisedMode(config.supervised_mode);
- if (config.daemonize && !is_supervised) daemonize();
- s = createPidFile(config.pidfile);
+ bool is_supervised = IsSupervisedMode(config.supervised_mode);
+ if (config.daemonize && !is_supervised) Daemonize();
+ s = CreatePidFile(config.pidfile);
if (!s.IsOK()) {
LOG(ERROR) << "Failed to create pidfile: " << s.Msg();
return 1;
}
- auto pidfile_exit = MakeScopeExit([&config] { removePidFile(config.pidfile); });
+ auto pidfile_exit = MakeScopeExit([&config] { RemovePidFile(config.pidfile); });
#ifdef ENABLE_OPENSSL
// initialize OpenSSL
diff --git a/src/storage/event_listener.cc b/src/storage/event_listener.cc
index c4333c14..fa9b7c0a 100644
--- a/src/storage/event_listener.cc
+++ b/src/storage/event_listener.cc
@@ -24,7 +24,7 @@
#include <string>
#include <vector>
-std::string fileCreatedReason2String(const rocksdb::TableFileCreationReason reason) {
+std::string FileCreatedReason2String(const rocksdb::TableFileCreationReason reason) {
std::vector<std::string> file_created_reason = {"flush", "compaction", "recovery", "misc"};
if (static_cast<size_t>(reason) < file_created_reason.size()) {
return file_created_reason[static_cast<size_t>(reason)];
@@ -32,7 +32,7 @@ std::string fileCreatedReason2String(const rocksdb::TableFileCreationReason reas
return "unknown";
}
-std::string stallConditionType2String(const rocksdb::WriteStallCondition type) {
+std::string StallConditionType2String(const rocksdb::WriteStallCondition type) {
std::vector<std::string> stall_condition_strings = {"normal", "delay", "stop"};
if (static_cast<size_t>(type) < stall_condition_strings.size()) {
return stall_condition_strings[static_cast<size_t>(type)];
@@ -40,7 +40,7 @@ std::string stallConditionType2String(const rocksdb::WriteStallCondition type) {
return "unknown";
}
-std::string compressType2String(const rocksdb::CompressionType type) {
+std::string CompressType2String(const rocksdb::CompressionType type) {
std::map<rocksdb::CompressionType, std::string> compression_type_string_map = {
{rocksdb::kNoCompression, "no"},
{rocksdb::kSnappyCompression, "snappy"},
@@ -59,7 +59,7 @@ std::string compressType2String(const rocksdb::CompressionType type) {
return iter->second;
}
-bool isDiskQuotaExceeded(const rocksdb::Status &bg_error) {
+bool IsDiskQuotaExceeded(const rocksdb::Status &bg_error) {
// EDQUOT: Disk quota exceeded (POSIX.1-2001)
std::string exceeded_quota_str = "Disk quota exceeded";
std::string err_msg = bg_error.ToString();
@@ -70,7 +70,7 @@ bool isDiskQuotaExceeded(const rocksdb::Status &bg_error) {
void EventListener::OnCompactionCompleted(rocksdb::DB *db, const rocksdb::CompactionJobInfo &ci) {
LOG(INFO) << "[event_listener/compaction_completed] column family: " << ci.cf_name
<< ", compaction reason: " << static_cast<int>(ci.compaction_reason)
- << ", output compression type: " << compressType2String(ci.compression)
+ << ", output compression type: " << CompressType2String(ci.compression)
<< ", base input level(files): " << ci.base_input_level << "(" << ci.input_files.size() << ")"
<< ", output level(files): " << ci.output_level << "(" << ci.output_files.size() << ")"
<< ", input bytes: " << ci.stats.total_input_bytes << ", output bytes:" << ci.stats.total_output_bytes
@@ -115,7 +115,7 @@ void EventListener::OnBackgroundError(rocksdb::BackgroundErrorReason reason, roc
// Should not arrive here
break;
}
- if ((bg_error->IsNoSpace() || isDiskQuotaExceeded(*bg_error)) &&
+ if ((bg_error->IsNoSpace() || IsDiskQuotaExceeded(*bg_error)) &&
bg_error->severity() < rocksdb::Status::kFatalError) {
storage_->SetDBInRetryableIOError(true);
}
@@ -130,12 +130,12 @@ void EventListener::OnTableFileDeleted(const rocksdb::TableFileDeletionInfo &inf
void EventListener::OnStallConditionsChanged(const rocksdb::WriteStallInfo &info) {
LOG(WARNING) << "[event_listener/stall_cond_changed] column family: " << info.cf_name
- << " write stall condition was changed, from " << stallConditionType2String(info.condition.prev)
- << " to " << stallConditionType2String(info.condition.cur);
+ << " write stall condition was changed, from " << StallConditionType2String(info.condition.prev)
+ << " to " << StallConditionType2String(info.condition.cur);
}
void EventListener::OnTableFileCreated(const rocksdb::TableFileCreationInfo &info) {
LOG(INFO) << "[event_listener/table_file_created] column family: " << info.cf_name
<< ", file path: " << info.file_path << ", file size: " << info.file_size << ", job id: " << info.job_id
- << ", reason: " << fileCreatedReason2String(info.reason) << ", status: " << info.status.ToString();
+ << ", reason: " << FileCreatedReason2String(info.reason) << ", status: " << info.status.ToString();
}
diff --git a/src/storage/scripting.cc b/src/storage/scripting.cc
index 1cfa36d7..83a53264 100644
--- a/src/storage/scripting.cc
+++ b/src/storage/scripting.cc
@@ -53,10 +53,10 @@ namespace lua {
lua_State *CreateState(bool read_only) {
lua_State *lua = lua_open();
- loadLibraries(lua);
- removeUnsupportedFunctions(lua);
- loadFuncs(lua, read_only);
- enableGlobalsProtection(lua);
+ LoadLibraries(lua);
+ RemoveUnsupportedFunctions(lua);
+ LoadFuncs(lua, read_only);
+ EnableGlobalsProtection(lua);
return lua;
}
@@ -65,22 +65,22 @@ void DestroyState(lua_State *lua) {
lua_close(lua);
}
-void loadFuncs(lua_State *lua, bool read_only) {
+void LoadFuncs(lua_State *lua, bool read_only) {
lua_newtable(lua);
/* redis.call */
lua_pushstring(lua, "call");
- lua_pushcfunction(lua, redisCallCommand);
+ lua_pushcfunction(lua, RedisCallCommand);
lua_settable(lua, -3);
/* redis.pcall */
lua_pushstring(lua, "pcall");
- lua_pushcfunction(lua, redisPCallCommand);
+ lua_pushcfunction(lua, RedisPCallCommand);
lua_settable(lua, -3);
/* redis.log and log levels. */
lua_pushstring(lua, "log");
- lua_pushcfunction(lua, redisLogCommand);
+ lua_pushcfunction(lua, RedisLogCommand);
lua_settable(lua, -3);
lua_pushstring(lua, "LOG_DEBUG");
@@ -101,15 +101,15 @@ void loadFuncs(lua_State *lua, bool read_only) {
/* redis.sha1hex */
lua_pushstring(lua, "sha1hex");
- lua_pushcfunction(lua, redisSha1hexCommand);
+ lua_pushcfunction(lua, RedisSha1hexCommand);
lua_settable(lua, -3);
/* redis.error_reply and redis.status_reply */
lua_pushstring(lua, "error_reply");
- lua_pushcfunction(lua, redisErrorReplyCommand);
+ lua_pushcfunction(lua, RedisErrorReplyCommand);
lua_settable(lua, -3);
lua_pushstring(lua, "status_reply");
- lua_pushcfunction(lua, redisStatusReplyCommand);
+ lua_pushcfunction(lua, RedisStatusReplyCommand);
lua_settable(lua, -3);
/* redis.read_only */
@@ -123,11 +123,11 @@ void loadFuncs(lua_State *lua, bool read_only) {
lua_getglobal(lua, "math");
lua_pushstring(lua, "random");
- lua_pushcfunction(lua, redisMathRandom);
+ lua_pushcfunction(lua, RedisMathRandom);
lua_settable(lua, -3);
lua_pushstring(lua, "randomseed");
- lua_pushcfunction(lua, redisMathRandomSeed);
+ lua_pushcfunction(lua, RedisMathRandomSeed);
lua_settable(lua, -3);
lua_setglobal(lua, "math");
@@ -162,7 +162,7 @@ void loadFuncs(lua_State *lua, bool read_only) {
lua_pcall(lua, 0, 0, 0);
}
-int redisLogCommand(lua_State *lua) {
+int RedisLogCommand(lua_State *lua) {
int argc = lua_gettop(lua);
if (argc < 2) {
@@ -203,7 +203,7 @@ int redisLogCommand(lua_State *lua) {
return 0;
}
-Status evalGenericCommand(redis::Connection *conn, const std::string &body_or_sha, const std::vector<std::string> &keys,
+Status EvalGenericCommand(redis::Connection *conn, const std::string &body_or_sha, const std::vector<std::string> &keys,
const std::vector<std::string> &argv, bool evalsha, std::string *output, bool read_only) {
Server *srv = conn->GetServer();
@@ -241,7 +241,7 @@ Status evalGenericCommand(redis::Connection *conn, const std::string &body_or_sh
}
std::string sha = funcname + 2;
- auto s = createFunction(srv, body, &sha, lua, false);
+ auto s = CreateFunction(srv, body, &sha, lua, false);
if (!s.IsOK()) {
lua_pop(lua, 1); /* remove the error handler from the stack. */
return s;
@@ -252,15 +252,15 @@ Status evalGenericCommand(redis::Connection *conn, const std::string &body_or_sh
/* Populate the argv and keys table accordingly to the arguments that
* EVAL received. */
- setGlobalArray(lua, "KEYS", keys);
- setGlobalArray(lua, "ARGV", argv);
+ SetGlobalArray(lua, "KEYS", keys);
+ SetGlobalArray(lua, "ARGV", argv);
if (lua_pcall(lua, 0, 1, -2)) {
auto msg = fmt::format("ERR running script (call to {}): {}", funcname, lua_tostring(lua, -1));
*output = redis::Error(msg);
lua_pop(lua, 2);
} else {
- *output = replyToRedisReply(lua);
+ *output = ReplyToRedisReply(lua);
lua_pop(lua, 2);
}
@@ -288,13 +288,13 @@ Status evalGenericCommand(redis::Connection *conn, const std::string &body_or_sh
return Status::OK();
}
-int redisCallCommand(lua_State *lua) { return redisGenericCommand(lua, 1); }
+int RedisCallCommand(lua_State *lua) { return RedisGenericCommand(lua, 1); }
-int redisPCallCommand(lua_State *lua) { return redisGenericCommand(lua, 0); }
+int RedisPCallCommand(lua_State *lua) { return RedisGenericCommand(lua, 0); }
// TODO: we do not want to repeat same logic as Connection::ExecuteCommands,
// so the function need to be refactored
-int redisGenericCommand(lua_State *lua, int raise_error) {
+int RedisGenericCommand(lua_State *lua, int raise_error) {
lua_getglobal(lua, "redis");
lua_getfield(lua, -1, "read_only");
int read_only = lua_toboolean(lua, -1);
@@ -302,8 +302,8 @@ int redisGenericCommand(lua_State *lua, int raise_error) {
int argc = lua_gettop(lua);
if (argc == 0) {
- pushError(lua, "Please specify at least one argument for redis.call()");
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, "Please specify at least one argument for redis.call()");
+ return raise_error ? RaiseError(lua) : 1;
}
std::vector<std::string> args;
@@ -315,8 +315,8 @@ int redisGenericCommand(lua_State *lua, int raise_error) {
size_t obj_len = 0;
const char *obj_s = lua_tolstring(lua, j, &obj_len);
if (obj_s == nullptr) {
- pushError(lua, "Lua redis() command arguments must be strings or integers");
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, "Lua redis() command arguments must be strings or integers");
+ return raise_error ? RaiseError(lua) : 1;
}
args.emplace_back(obj_s, obj_len);
}
@@ -325,14 +325,14 @@ int redisGenericCommand(lua_State *lua, int raise_error) {
auto commands = redis::GetCommands();
auto cmd_iter = commands->find(util::ToLower(args[0]));
if (cmd_iter == commands->end()) {
- pushError(lua, "Unknown Redis command called from Lua script");
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, "Unknown Redis command called from Lua script");
+ return raise_error ? RaiseError(lua) : 1;
}
auto redis_cmd = cmd_iter->second;
if (read_only && !(redis_cmd->flags & redis::kCmdReadOnly)) {
- pushError(lua, "Write commands are not allowed from read-only scripts");
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, "Write commands are not allowed from read-only scripts");
+ return raise_error ? RaiseError(lua) : 1;
}
auto cmd = redis_cmd->factory();
@@ -341,13 +341,13 @@ int redisGenericCommand(lua_State *lua, int raise_error) {
int arity = cmd->GetAttributes()->arity;
if (((arity > 0 && argc != arity) || (arity < 0 && argc < -arity))) {
- pushError(lua, "Wrong number of args calling Redis command From Lua script");
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, "Wrong number of args calling Redis command From Lua script");
+ return raise_error ? RaiseError(lua) : 1;
}
auto attributes = cmd->GetAttributes();
if (attributes->flags & redis::kCmdNoScript) {
- pushError(lua, "This Redis command is not allowed from scripts");
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, "This Redis command is not allowed from scripts");
+ return raise_error ? RaiseError(lua) : 1;
}
std::string cmd_name = util::ToLower(args[0]);
@@ -358,28 +358,28 @@ int redisGenericCommand(lua_State *lua, int raise_error) {
if (config->cluster_enabled) {
auto s = srv->cluster->CanExecByMySelf(attributes, args, conn);
if (!s.IsOK()) {
- pushError(lua, s.Msg().c_str());
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, s.Msg().c_str());
+ return raise_error ? RaiseError(lua) : 1;
}
}
if (config->slave_readonly && srv->IsSlave() && attributes->IsWrite()) {
- pushError(lua, "READONLY You can't write against a read only slave.");
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, "READONLY You can't write against a read only slave.");
+ return raise_error ? RaiseError(lua) : 1;
}
if (!config->slave_serve_stale_data && srv->IsSlave() && cmd_name != "info" && cmd_name != "slaveof" &&
srv->GetReplicationState() != kReplConnected) {
- pushError(lua,
+ PushError(lua,
"MASTERDOWN Link with MASTER is down "
"and slave-serve-stale-data is set to 'no'.");
- return raise_error ? raiseError(lua) : 1;
+ return raise_error ? RaiseError(lua) : 1;
}
auto s = cmd->Parse(args);
if (!s) {
- pushError(lua, s.Msg().data());
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, s.Msg().data());
+ return raise_error ? RaiseError(lua) : 1;
}
srv->stats.IncrCalls(cmd_name);
@@ -394,22 +394,22 @@ int redisGenericCommand(lua_State *lua, int raise_error) {
srv->stats.IncrLatency(static_cast<uint64_t>(duration), cmd_name);
srv->FeedMonitorConns(conn, args);
if (!s) {
- pushError(lua, s.Msg().data());
- return raise_error ? raiseError(lua) : 1;
+ PushError(lua, s.Msg().data());
+ return raise_error ? RaiseError(lua) : 1;
}
- redisProtocolToLuaType(lua, output.data());
+ RedisProtocolToLuaType(lua, output.data());
return 1;
}
-void removeUnsupportedFunctions(lua_State *lua) {
+void RemoveUnsupportedFunctions(lua_State *lua) {
lua_pushnil(lua);
lua_setglobal(lua, "loadfile");
lua_pushnil(lua);
lua_setglobal(lua, "dofile");
}
-void enableGlobalsProtection(lua_State *lua) {
+void EnableGlobalsProtection(lua_State *lua) {
const char *code =
"local dbg=debug\n"
"local mt = {}\n"
@@ -435,7 +435,7 @@ void enableGlobalsProtection(lua_State *lua) {
lua_pcall(lua, 0, 0, 0);
}
-void loadLibraries(lua_State *lua) {
+void LoadLibraries(lua_State *lua) {
auto load_lib = [](lua_State *lua, const char *libname, lua_CFunction func) {
lua_pushcfunction(lua, func);
lua_pushstring(lua, libname);
@@ -460,9 +460,9 @@ void loadLibraries(lua_State *lua) {
* return redis.error_reply("ERR Some Error")
* return redis.status_reply("ERR Some Error")
*/
-int redisReturnSingleFieldTable(lua_State *lua, const char *field) {
+int RedisReturnSingleFieldTable(lua_State *lua, const char *field) {
if (lua_gettop(lua) != 1 || lua_type(lua, -1) != LUA_TSTRING) {
- pushError(lua, "wrong number or type of arguments");
+ PushError(lua, "wrong number or type of arguments");
return 1;
}
@@ -474,14 +474,14 @@ int redisReturnSingleFieldTable(lua_State *lua, const char *field) {
}
/* redis.error_reply() */
-int redisErrorReplyCommand(lua_State *lua) { return redisReturnSingleFieldTable(lua, "err"); }
+int RedisErrorReplyCommand(lua_State *lua) { return RedisReturnSingleFieldTable(lua, "err"); }
/* redis.status_reply() */
-int redisStatusReplyCommand(lua_State *lua) { return redisReturnSingleFieldTable(lua, "ok"); }
+int RedisStatusReplyCommand(lua_State *lua) { return RedisReturnSingleFieldTable(lua, "ok"); }
/* This adds redis.sha1hex(string) to Lua scripts using the same hashing
* function used for sha1ing lua scripts. */
-int redisSha1hexCommand(lua_State *lua) {
+int RedisSha1hexCommand(lua_State *lua) {
int argc = lua_gettop(lua);
if (argc != 1) {
@@ -546,52 +546,52 @@ void SHA1Hex(char *digest, const char *script, size_t len) {
* error string.
*/
-const char *redisProtocolToLuaType(lua_State *lua, const char *reply) {
+const char *RedisProtocolToLuaType(lua_State *lua, const char *reply) {
const char *p = reply;
switch (*p) {
case ':':
- p = redisProtocolToLuaType_Int(lua, reply);
+ p = RedisProtocolToLuaTypeInt(lua, reply);
break;
case '$':
- p = redisProtocolToLuaType_Bulk(lua, reply);
+ p = RedisProtocolToLuaTypeBulk(lua, reply);
break;
case '+':
- p = redisProtocolToLuaType_Status(lua, reply);
+ p = RedisProtocolToLuaTypeStatus(lua, reply);
break;
case '-':
- p = redisProtocolToLuaType_Error(lua, reply);
+ p = RedisProtocolToLuaTypeError(lua, reply);
break;
case '*':
- p = redisProtocolToLuaType_Aggregate(lua, reply, *p);
+ p = RedisProtocolToLuaTypeAggregate(lua, reply, *p);
break;
case '%':
- p = redisProtocolToLuaType_Aggregate(lua, reply, *p);
+ p = RedisProtocolToLuaTypeAggregate(lua, reply, *p);
break;
case '~':
- p = redisProtocolToLuaType_Aggregate(lua, reply, *p);
+ p = RedisProtocolToLuaTypeAggregate(lua, reply, *p);
break;
case '_':
- p = redisProtocolToLuaType_Null(lua, reply);
+ p = RedisProtocolToLuaTypeNull(lua, reply);
break;
case '#':
- p = redisProtocolToLuaType_Bool(lua, reply, p[1]);
+ p = RedisProtocolToLuaTypeBool(lua, reply, p[1]);
break;
case ',':
- p = redisProtocolToLuaType_Double(lua, reply);
+ p = RedisProtocolToLuaTypeDouble(lua, reply);
break;
}
return p;
}
-const char *redisProtocolToLuaType_Int(lua_State *lua, const char *reply) {
+const char *RedisProtocolToLuaTypeInt(lua_State *lua, const char *reply) {
const char *p = strchr(reply + 1, '\r');
auto value = ParseInt<int64_t>(std::string(reply + 1, p - reply - 1), 10).ValueOr(0);
lua_pushnumber(lua, static_cast<lua_Number>(value));
return p + 2;
}
-const char *redisProtocolToLuaType_Bulk(lua_State *lua, const char *reply) {
+const char *RedisProtocolToLuaTypeBulk(lua_State *lua, const char *reply) {
const char *p = strchr(reply + 1, '\r');
auto bulklen = ParseInt<int64_t>(std::string(reply + 1, p - reply - 1), 10).ValueOr(0);
@@ -604,7 +604,7 @@ const char *redisProtocolToLuaType_Bulk(lua_State *lua, const char *reply) {
}
}
-const char *redisProtocolToLuaType_Status(lua_State *lua, const char *reply) {
+const char *RedisProtocolToLuaTypeStatus(lua_State *lua, const char *reply) {
const char *p = strchr(reply + 1, '\r');
lua_newtable(lua);
@@ -614,7 +614,7 @@ const char *redisProtocolToLuaType_Status(lua_State *lua, const char *reply) {
return p + 2;
}
-const char *redisProtocolToLuaType_Error(lua_State *lua, const char *reply) {
+const char *RedisProtocolToLuaTypeError(lua_State *lua, const char *reply) {
const char *p = strchr(reply + 1, '\r');
lua_newtable(lua);
@@ -624,7 +624,7 @@ const char *redisProtocolToLuaType_Error(lua_State *lua, const char *reply) {
return p + 2;
}
-const char *redisProtocolToLuaType_Aggregate(lua_State *lua, const char *reply, int atype) {
+const char *RedisProtocolToLuaTypeAggregate(lua_State *lua, const char *reply, int atype) {
const char *p = strchr(reply + 1, '\r');
int64_t mbulklen = ParseInt<int64_t>(std::string(reply + 1, p - reply - 1), 10).ValueOr(0);
int j = 0;
@@ -637,25 +637,25 @@ const char *redisProtocolToLuaType_Aggregate(lua_State *lua, const char *reply,
lua_newtable(lua);
for (j = 0; j < mbulklen; j++) {
lua_pushnumber(lua, j + 1);
- p = redisProtocolToLuaType(lua, p);
+ p = RedisProtocolToLuaType(lua, p);
lua_settable(lua, -3);
}
return p;
}
-const char *redisProtocolToLuaType_Null(lua_State *lua, const char *reply) {
+const char *RedisProtocolToLuaTypeNull(lua_State *lua, const char *reply) {
const char *p = strchr(reply + 1, '\r');
lua_pushnil(lua);
return p + 2;
}
-const char *redisProtocolToLuaType_Bool(lua_State *lua, const char *reply, int tf) {
+const char *RedisProtocolToLuaTypeBool(lua_State *lua, const char *reply, int tf) {
const char *p = strchr(reply + 1, '\r');
lua_pushboolean(lua, tf == 't');
return p + 2;
}
-const char *redisProtocolToLuaType_Double(lua_State *lua, const char *reply) {
+const char *RedisProtocolToLuaTypeDouble(lua_State *lua, const char *reply) {
const char *p = strchr(reply + 1, '\r');
char buf[MAX_LONG_DOUBLE_CHARS + 1];
size_t len = p - reply - 1;
@@ -681,7 +681,7 @@ const char *redisProtocolToLuaType_Double(lua_State *lua, const char *reply) {
* with a single "err" field set to the error string. Note that this
* table is never a valid reply by proper commands, since the returned
* tables are otherwise always indexed by integers, never by strings. */
-void pushError(lua_State *lua, const char *err) {
+void PushError(lua_State *lua, const char *err) {
lua_newtable(lua);
lua_pushstring(lua, "err");
lua_pushstring(lua, err);
@@ -689,7 +689,7 @@ void pushError(lua_State *lua, const char *err) {
}
// this function does not pop any element on the stack
-std::string replyToRedisReply(lua_State *lua) {
+std::string ReplyToRedisReply(lua_State *lua) {
std::string output;
const char *obj_s = nullptr;
size_t obj_len = 0;
@@ -743,7 +743,7 @@ std::string replyToRedisReply(lua_State *lua) {
break;
}
mbulklen++;
- output += replyToRedisReply(lua);
+ output += ReplyToRedisReply(lua);
lua_pop(lua, 1);
}
output = redis::MultiLen(mbulklen) + output;
@@ -759,7 +759,7 @@ std::string replyToRedisReply(lua_State *lua) {
* by the non-error-trapping version of redis.pcall(), which is redis.call(),
* this function will raise the Lua error so that the execution of the
* script will be halted. */
-[[noreturn]] int raiseError(lua_State *lua) {
+[[noreturn]] int RaiseError(lua_State *lua) {
lua_pushstring(lua, "err");
lua_gettable(lua, -2);
lua_error(lua);
@@ -772,7 +772,7 @@ std::string replyToRedisReply(lua_State *lua) {
*
* The array is sorted using table.sort itself, and assuming all the
* list elements are strings. */
-void sortArray(lua_State *lua) {
+void SortArray(lua_State *lua) {
/* Initial Stack: array */
lua_getglobal(lua, "table");
lua_pushstring(lua, "sort");
@@ -797,7 +797,7 @@ void sortArray(lua_State *lua) {
lua_pop(lua, 1); /* Stack: array (sorted) */
}
-void setGlobalArray(lua_State *lua, const std::string &var, const std::vector<std::string> &elems) {
+void SetGlobalArray(lua_State *lua, const std::string &var, const std::vector<std::string> &elems) {
lua_newtable(lua);
for (size_t i = 0; i < elems.size(); i++) {
lua_pushlstring(lua, elems[i].c_str(), elems[i].size());
@@ -816,10 +816,10 @@ void setGlobalArray(lua_State *lua, const std::string &var, const std::vector<st
/* The following implementation is the one shipped with Lua itself but with
* rand() replaced by redisLrand48(). */
-int redisMathRandom(lua_State *lua) {
+int RedisMathRandom(lua_State *lua) {
/* the `%' avoids the (rare) case of r==1, and is needed also because on
some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
- lua_Number r = (lua_Number)(redisLrand48() % REDIS_LRAND48_MAX) / (lua_Number)REDIS_LRAND48_MAX;
+ lua_Number r = (lua_Number)(RedisLrand48() % REDIS_LRAND48_MAX) / (lua_Number)REDIS_LRAND48_MAX;
switch (lua_gettop(lua)) { /* check number of arguments */
case 0: { /* no arguments */
lua_pushnumber(lua, r); /* Number between 0 and 1 */
@@ -844,8 +844,8 @@ int redisMathRandom(lua_State *lua) {
return 1;
}
-int redisMathRandomSeed(lua_State *lua) {
- redisSrand48(luaL_checkint(lua, 1));
+int RedisMathRandomSeed(lua_State *lua) {
+ RedisSrand48(luaL_checkint(lua, 1));
return 0;
}
@@ -870,7 +870,7 @@ int redisMathRandomSeed(lua_State *lua) {
*
* If 'c' is not NULL, on error the client is informed with an appropriate
* error describing the nature of the problem and the Lua interpreter error. */
-Status createFunction(Server *srv, const std::string &body, std::string *sha, lua_State *lua, bool need_to_store) {
+Status CreateFunction(Server *srv, const std::string &body, std::string *sha, lua_State *lua, bool need_to_store) {
char funcname[2 + 40 + 1] = REDIS_LUA_FUNC_SHA_PREFIX;
if (sha->empty()) {
diff --git a/src/storage/scripting.h b/src/storage/scripting.h
index fbb51816..41b75e54 100644
--- a/src/storage/scripting.h
+++ b/src/storage/scripting.h
@@ -34,46 +34,46 @@ namespace lua {
lua_State *CreateState(bool read_only = false);
void DestroyState(lua_State *lua);
-void loadFuncs(lua_State *lua, bool read_only = false);
-void loadLibraries(lua_State *lua);
-void removeUnsupportedFunctions(lua_State *lua);
-void enableGlobalsProtection(lua_State *lua);
-
-int redisCallCommand(lua_State *lua);
-int redisPCallCommand(lua_State *lua);
-int redisGenericCommand(lua_State *lua, int raise_error);
-int redisSha1hexCommand(lua_State *lua);
-int redisStatusReplyCommand(lua_State *lua);
-int redisErrorReplyCommand(lua_State *lua);
-int redisLogCommand(lua_State *lua);
-
-Status createFunction(Server *srv, const std::string &body, std::string *sha, lua_State *lua, bool need_to_store);
-
-Status evalGenericCommand(redis::Connection *conn, const std::string &body_or_sha, const std::vector<std::string> &keys,
+void LoadFuncs(lua_State *lua, bool read_only = false);
+void LoadLibraries(lua_State *lua);
+void RemoveUnsupportedFunctions(lua_State *lua);
+void EnableGlobalsProtection(lua_State *lua);
+
+int RedisCallCommand(lua_State *lua);
+int RedisPCallCommand(lua_State *lua);
+int RedisGenericCommand(lua_State *lua, int raise_error);
+int RedisSha1hexCommand(lua_State *lua);
+int RedisStatusReplyCommand(lua_State *lua);
+int RedisErrorReplyCommand(lua_State *lua);
+int RedisLogCommand(lua_State *lua);
+
+Status CreateFunction(Server *srv, const std::string &body, std::string *sha, lua_State *lua, bool need_to_store);
+
+Status EvalGenericCommand(redis::Connection *conn, const std::string &body_or_sha, const std::vector<std::string> &keys,
const std::vector<std::string> &argv, bool evalsha, std::string *output,
bool read_only = false);
-const char *redisProtocolToLuaType(lua_State *lua, const char *reply);
-const char *redisProtocolToLuaType_Int(lua_State *lua, const char *reply);
-const char *redisProtocolToLuaType_Bulk(lua_State *lua, const char *reply);
-const char *redisProtocolToLuaType_Status(lua_State *lua, const char *reply);
-const char *redisProtocolToLuaType_Error(lua_State *lua, const char *reply);
-const char *redisProtocolToLuaType_Aggregate(lua_State *lua, const char *reply, int atype);
-const char *redisProtocolToLuaType_Null(lua_State *lua, const char *reply);
-const char *redisProtocolToLuaType_Bool(lua_State *lua, const char *reply, int tf);
-const char *redisProtocolToLuaType_Double(lua_State *lua, const char *reply);
+const char *RedisProtocolToLuaType(lua_State *lua, const char *reply);
+const char *RedisProtocolToLuaTypeInt(lua_State *lua, const char *reply);
+const char *RedisProtocolToLuaTypeBulk(lua_State *lua, const char *reply);
+const char *RedisProtocolToLuaTypeStatus(lua_State *lua, const char *reply);
+const char *RedisProtocolToLuaTypeError(lua_State *lua, const char *reply);
+const char *RedisProtocolToLuaTypeAggregate(lua_State *lua, const char *reply, int atype);
+const char *RedisProtocolToLuaTypeNull(lua_State *lua, const char *reply);
+const char *RedisProtocolToLuaTypeBool(lua_State *lua, const char *reply, int tf);
+const char *RedisProtocolToLuaTypeDouble(lua_State *lua, const char *reply);
-std::string replyToRedisReply(lua_State *lua);
+std::string ReplyToRedisReply(lua_State *lua);
-void pushError(lua_State *lua, const char *err);
-[[noreturn]] int raiseError(lua_State *lua);
+void PushError(lua_State *lua, const char *err);
+[[noreturn]] int RaiseError(lua_State *lua);
-void sortArray(lua_State *lua);
-void setGlobalArray(lua_State *lua, const std::string &var, const std::vector<std::string> &elems);
+void SortArray(lua_State *lua);
+void SetGlobalArray(lua_State *lua, const std::string &var, const std::vector<std::string> &elems);
void SHA1Hex(char *digest, const char *script, size_t len);
-int redisMathRandom(lua_State *l);
-int redisMathRandomSeed(lua_State *l);
+int RedisMathRandom(lua_State *l);
+int RedisMathRandomSeed(lua_State *l);
} // namespace lua
diff --git a/src/types/geohash.cc b/src/types/geohash.cc
index b5ac26d5..3199df76 100644
--- a/src/types/geohash.cc
+++ b/src/types/geohash.cc
@@ -49,8 +49,8 @@ const double EARTH_RADIUS_IN_METERS = 6372797.560856;
const double MERCATOR_MAX = 20037726.37;
// const double MERCATOR_MIN = -20037726.37;
-static inline double deg_rad(double ang) { return ang * D_R; }
-static inline double rad_deg(double ang) { return ang / D_R; }
+static inline double DegRad(double ang) { return ang * D_R; }
+static inline double RadDeg(double ang) { return ang / D_R; }
/**
* Hashing works like this:
@@ -71,7 +71,7 @@ static inline double rad_deg(double ang) { return ang / D_R; }
* x and y must initially be less than 2**32 (65536).
* From: https://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
*/
-static inline uint64_t interleave64(uint32_t xlo, uint32_t ylo) {
+static inline uint64_t Interleave64(uint32_t xlo, uint32_t ylo) {
static const uint64_t B[] = {0x5555555555555555ULL, 0x3333333333333333ULL, 0x0F0F0F0F0F0F0F0FULL,
0x00FF00FF00FF00FFULL, 0x0000FFFF0000FFFFULL};
static const unsigned int S[] = {1, 2, 4, 8, 16};
@@ -100,7 +100,7 @@ static inline uint64_t interleave64(uint32_t xlo, uint32_t ylo) {
/* reverse the interleave process
* derived from http://stackoverflow.com/questions/4909263
*/
-static inline uint64_t deinterleave64(uint64_t interleaved) {
+static inline uint64_t Deinterleave64(uint64_t interleaved) {
static const uint64_t B[] = {0x5555555555555555ULL, 0x3333333333333333ULL, 0x0F0F0F0F0F0F0F0FULL,
0x00FF00FF00FF00FFULL, 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL};
static const unsigned int S[] = {0, 1, 2, 4, 8, 16};
@@ -129,7 +129,7 @@ static inline uint64_t deinterleave64(uint64_t interleaved) {
return x | (y << 32);
}
-void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) {
+void GeohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) {
/* These are constraints from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
/* We can't geocode at the north/south pole. */
long_range->max = GEO_LONG_MAX;
@@ -138,7 +138,7 @@ void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) {
lat_range->min = GEO_LAT_MIN;
}
-int geohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range, double longitude, double latitude,
+int GeohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range, double longitude, double latitude,
uint8_t step, GeoHashBits *hash) {
/* Check basic arguments sanity. */
if (!hash || step > 32 || step == 0 || RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0;
@@ -162,21 +162,21 @@ int geohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range,
/* convert to fixed point based on the step size */
lat_offset *= static_cast<double>(1ULL << step);
long_offset *= static_cast<double>(1ULL << step);
- hash->bits = interleave64(static_cast<uint32_t>(lat_offset), static_cast<uint32_t>(long_offset));
+ hash->bits = Interleave64(static_cast<uint32_t>(lat_offset), static_cast<uint32_t>(long_offset));
return 1;
}
-int geohashEncodeType(double longitude, double latitude, uint8_t step, GeoHashBits *hash) {
+int GeohashEncodeType(double longitude, double latitude, uint8_t step, GeoHashBits *hash) {
GeoHashRange r[2] = {{0}};
- geohashGetCoordRange(&r[0], &r[1]);
- return geohashEncode(&r[0], &r[1], longitude, latitude, step, hash);
+ GeohashGetCoordRange(&r[0], &r[1]);
+ return GeohashEncode(&r[0], &r[1], longitude, latitude, step, hash);
}
-int geohashEncodeWGS84(double longitude, double latitude, uint8_t step, GeoHashBits *hash) {
- return geohashEncodeType(longitude, latitude, step, hash);
+int GeohashEncodeWGS84(double longitude, double latitude, uint8_t step, GeoHashBits *hash) {
+ return GeohashEncodeType(longitude, latitude, step, hash);
}
-int geohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range, const GeoHashBits &hash,
+int GeohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range, const GeoHashBits &hash,
GeoHashArea *area) {
if (HASHISZERO(hash) || !area || RANGEISZERO(lat_range) || RANGEISZERO(long_range)) {
return 0;
@@ -184,7 +184,7 @@ int geohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range,
area->hash = hash;
uint8_t step = hash.step;
- uint64_t hash_sep = deinterleave64(hash.bits); /* hash = [LAT][LONG] */
+ uint64_t hash_sep = Deinterleave64(hash.bits); /* hash = [LAT][LONG] */
double lat_scale = lat_range.max - lat_range.min;
double long_scale = long_range.max - long_range.min;
@@ -203,15 +203,15 @@ int geohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range,
return 1;
}
-int geohashDecodeType(const GeoHashBits &hash, GeoHashArea *area) {
+int GeohashDecodeType(const GeoHashBits &hash, GeoHashArea *area) {
GeoHashRange r[2] = {{0}};
- geohashGetCoordRange(&r[0], &r[1]);
- return geohashDecode(r[0], r[1], hash, area);
+ GeohashGetCoordRange(&r[0], &r[1]);
+ return GeohashDecode(r[0], r[1], hash, area);
}
-int geohashDecodeWGS84(const GeoHashBits &hash, GeoHashArea *area) { return geohashDecodeType(hash, area); }
+int GeohashDecodeWGS84(const GeoHashBits &hash, GeoHashArea *area) { return GeohashDecodeType(hash, area); }
-int geohashDecodeAreaToLongLat(const GeoHashArea *area, double *xy) {
+int GeohashDecodeAreaToLongLat(const GeoHashArea *area, double *xy) {
if (!xy) return 0;
xy[0] = (area->longitude.min + area->longitude.max) / 2;
if (xy[0] > GEO_LONG_MAX) xy[0] = GEO_LONG_MAX;
@@ -222,15 +222,15 @@ int geohashDecodeAreaToLongLat(const GeoHashArea *area, double *xy) {
return 1;
}
-int geohashDecodeToLongLatType(const GeoHashBits &hash, double *xy) {
+int GeohashDecodeToLongLatType(const GeoHashBits &hash, double *xy) {
GeoHashArea area = {{0}};
- if (!xy || !geohashDecodeType(hash, &area)) return 0;
- return geohashDecodeAreaToLongLat(&area, xy);
+ if (!xy || !GeohashDecodeType(hash, &area)) return 0;
+ return GeohashDecodeAreaToLongLat(&area, xy);
}
-int geohashDecodeToLongLatWGS84(const GeoHashBits &hash, double *xy) { return geohashDecodeToLongLatType(hash, xy); }
+int GeohashDecodeToLongLatWGS84(const GeoHashBits &hash, double *xy) { return GeohashDecodeToLongLatType(hash, xy); }
-static void geohash_move_x(GeoHashBits *hash, int8_t d) {
+static void GeohashMoveX(GeoHashBits *hash, int8_t d) {
if (d == 0) return;
uint64_t x = hash->bits & 0xaaaaaaaaaaaaaaaaULL;
@@ -249,7 +249,7 @@ static void geohash_move_x(GeoHashBits *hash, int8_t d) {
hash->bits = (x | y);
}
-static void geohash_move_y(GeoHashBits *hash, int8_t d) {
+static void GeohashMoveY(GeoHashBits *hash, int8_t d) {
if (d == 0) return;
uint64_t x = hash->bits & 0xaaaaaaaaaaaaaaaaULL;
@@ -266,7 +266,7 @@ static void geohash_move_y(GeoHashBits *hash, int8_t d) {
hash->bits = (x | y);
}
-void geohashNeighbors(const GeoHashBits *hash, GeoHashNeighbors *neighbors) {
+void GeohashNeighbors(const GeoHashBits *hash, GeoHashNeighbors *neighbors) {
neighbors->east = *hash;
neighbors->west = *hash;
neighbors->north = *hash;
@@ -276,29 +276,29 @@ void geohashNeighbors(const GeoHashBits *hash, GeoHashNeighbors *neighbors) {
neighbors->north_east = *hash;
neighbors->north_west = *hash;
- geohash_move_x(&neighbors->east, 1);
- geohash_move_y(&neighbors->east, 0);
+ GeohashMoveX(&neighbors->east, 1);
+ GeohashMoveY(&neighbors->east, 0);
- geohash_move_x(&neighbors->west, -1);
- geohash_move_y(&neighbors->west, 0);
+ GeohashMoveX(&neighbors->west, -1);
+ GeohashMoveY(&neighbors->west, 0);
- geohash_move_x(&neighbors->south, 0);
- geohash_move_y(&neighbors->south, -1);
+ GeohashMoveX(&neighbors->south, 0);
+ GeohashMoveY(&neighbors->south, -1);
- geohash_move_x(&neighbors->north, 0);
- geohash_move_y(&neighbors->north, 1);
+ GeohashMoveX(&neighbors->north, 0);
+ GeohashMoveY(&neighbors->north, 1);
- geohash_move_x(&neighbors->north_west, -1);
- geohash_move_y(&neighbors->north_west, 1);
+ GeohashMoveX(&neighbors->north_west, -1);
+ GeohashMoveY(&neighbors->north_west, 1);
- geohash_move_x(&neighbors->north_east, 1);
- geohash_move_y(&neighbors->north_east, 1);
+ GeohashMoveX(&neighbors->north_east, 1);
+ GeohashMoveY(&neighbors->north_east, 1);
- geohash_move_x(&neighbors->south_east, 1);
- geohash_move_y(&neighbors->south_east, -1);
+ GeohashMoveX(&neighbors->south_east, 1);
+ GeohashMoveY(&neighbors->south_east, -1);
- geohash_move_x(&neighbors->south_west, -1);
- geohash_move_y(&neighbors->south_west, -1);
+ GeohashMoveX(&neighbors->south_west, -1);
+ GeohashMoveY(&neighbors->south_west, -1);
}
/* This function is used in order to estimate the step (bits precision)
@@ -347,10 +347,10 @@ uint8_t GeoHashHelper::EstimateStepsByRadius(double range_meters, double lat) {
int GeoHashHelper::BoundingBox(double longitude, double latitude, double radius_meters, double *bounds) {
if (!bounds) return 0;
- bounds[0] = longitude - rad_deg(radius_meters / EARTH_RADIUS_IN_METERS / cos(deg_rad(latitude)));
- bounds[2] = longitude + rad_deg(radius_meters / EARTH_RADIUS_IN_METERS / cos(deg_rad(latitude)));
- bounds[1] = latitude - rad_deg(radius_meters / EARTH_RADIUS_IN_METERS);
- bounds[3] = latitude + rad_deg(radius_meters / EARTH_RADIUS_IN_METERS);
+ bounds[0] = longitude - RadDeg(radius_meters / EARTH_RADIUS_IN_METERS / cos(DegRad(latitude)));
+ bounds[2] = longitude + RadDeg(radius_meters / EARTH_RADIUS_IN_METERS / cos(DegRad(latitude)));
+ bounds[1] = latitude - RadDeg(radius_meters / EARTH_RADIUS_IN_METERS);
+ bounds[3] = latitude + RadDeg(radius_meters / EARTH_RADIUS_IN_METERS);
return 1;
}
@@ -373,10 +373,10 @@ GeoHashRadius GeoHashHelper::GetAreasByRadius(double longitude, double latitude,
int steps = EstimateStepsByRadius(radius_meters, latitude);
- geohashGetCoordRange(&long_range, &lat_range);
- geohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash);
- geohashNeighbors(&hash, &neighbors);
- geohashDecode(long_range, lat_range, hash, &area);
+ GeohashGetCoordRange(&long_range, &lat_range);
+ GeohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash);
+ GeohashNeighbors(&hash, &neighbors);
+ GeohashDecode(long_range, lat_range, hash, &area);
/* Check if the step is enough at the limits of the covered area.
* Sometimes when the search area is near an edge of the
@@ -387,10 +387,10 @@ GeoHashRadius GeoHashHelper::GetAreasByRadius(double longitude, double latitude,
{
GeoHashArea north, south, east, west;
- geohashDecode(long_range, lat_range, neighbors.north, &north);
- geohashDecode(long_range, lat_range, neighbors.south, &south);
- geohashDecode(long_range, lat_range, neighbors.east, &east);
- geohashDecode(long_range, lat_range, neighbors.west, &west);
+ GeohashDecode(long_range, lat_range, neighbors.north, &north);
+ GeohashDecode(long_range, lat_range, neighbors.south, &south);
+ GeohashDecode(long_range, lat_range, neighbors.east, &east);
+ GeohashDecode(long_range, lat_range, neighbors.west, &west);
if (GetDistance(longitude, latitude, longitude, north.latitude.max) < radius_meters) decrease_step = 1;
if (GetDistance(longitude, latitude, longitude, south.latitude.min) < radius_meters) decrease_step = 1;
@@ -400,9 +400,9 @@ GeoHashRadius GeoHashHelper::GetAreasByRadius(double longitude, double latitude,
if (steps > 1 && decrease_step) {
steps--;
- geohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash);
- geohashNeighbors(&hash, &neighbors);
- geohashDecode(long_range, lat_range, hash, &area);
+ GeohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash);
+ GeohashNeighbors(&hash, &neighbors);
+ GeohashDecode(long_range, lat_range, hash, &area);
}
/* Exclude the search areas that are useless. */
@@ -447,10 +447,10 @@ GeoHashFix52Bits GeoHashHelper::Align52Bits(const GeoHashBits &hash) {
/* Calculate distance using haversin great circle distance formula. */
double GeoHashHelper::GetDistance(double lon1d, double lat1d, double lon2d, double lat2d) {
double lat1r = NAN, lon1r = NAN, lat2r = NAN, lon2r = NAN, u = NAN, v = NAN;
- lat1r = deg_rad(lat1d);
- lon1r = deg_rad(lon1d);
- lat2r = deg_rad(lat2d);
- lon2r = deg_rad(lon2d);
+ lat1r = DegRad(lat1d);
+ lon1r = DegRad(lon1d);
+ lat2r = DegRad(lat2d);
+ lon2r = DegRad(lon2d);
u = sin((lat2r - lat1r) / 2);
v = sin((lon2r - lon1r) / 2);
return 2.0 * EARTH_RADIUS_IN_METERS * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v));
diff --git a/src/types/geohash.h b/src/types/geohash.h
index 6c18ae7b..092eca19 100644
--- a/src/types/geohash.h
+++ b/src/types/geohash.h
@@ -106,18 +106,18 @@ inline constexpr bool GISNOTZERO(const GeoHashBits &s) { return (s.bits || s.ste
* 0:success
* -1:failed
*/
-void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range);
-int geohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range, double longitude, double latitude,
+void GeohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range);
+int GeohashEncode(const GeoHashRange *long_range, const GeoHashRange *lat_range, double longitude, double latitude,
uint8_t step, GeoHashBits *hash);
-int geohashEncodeType(double longitude, double latitude, uint8_t step, GeoHashBits *hash);
-int geohashEncodeWGS84(double longitude, double latitude, uint8_t step, GeoHashBits *hash);
-int geohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range, const GeoHashBits &hash,
+int GeohashEncodeType(double longitude, double latitude, uint8_t step, GeoHashBits *hash);
+int GeohashEncodeWGS84(double longitude, double latitude, uint8_t step, GeoHashBits *hash);
+int GeohashDecode(const GeoHashRange &long_range, const GeoHashRange &lat_range, const GeoHashBits &hash,
GeoHashArea *area);
-int geohashDecodeType(const GeoHashBits &hash, GeoHashArea *area);
-int geohashDecodeAreaToLongLat(const GeoHashArea *area, double *xy);
-int geohashDecodeToLongLatType(const GeoHashBits &hash, double *xy);
-int geohashDecodeToLongLatWGS84(const GeoHashBits &hash, double *xy);
-void geohashNeighbors(const GeoHashBits *hash, GeoHashNeighbors *neighbors);
+int GeohashDecodeType(const GeoHashBits &hash, GeoHashArea *area);
+int GeohashDecodeAreaToLongLat(const GeoHashArea *area, double *xy);
+int GeohashDecodeToLongLatType(const GeoHashBits &hash, double *xy);
+int GeohashDecodeToLongLatWGS84(const GeoHashBits &hash, double *xy);
+void GeohashNeighbors(const GeoHashBits *hash, GeoHashNeighbors *neighbors);
class GeoHashHelper {
public:
diff --git a/src/types/redis_bitmap_string.cc b/src/types/redis_bitmap_string.cc
index 45646b2b..38a0c8f3 100644
--- a/src/types/redis_bitmap_string.cc
+++ b/src/types/redis_bitmap_string.cc
@@ -144,7 +144,7 @@ size_t BitmapString::RawPopcount(const uint8_t *p, int64_t count) {
}
template <typename T = void>
-inline int clzllWithEndian(uint64_t x) {
+inline int ClzllWithEndian(uint64_t x) {
if constexpr (IsLittleEndian()) {
return __builtin_clzll(__builtin_bswap64(x));
} else if constexpr (IsBigEndian()) {
@@ -171,7 +171,7 @@ int64_t BitmapString::RawBitpos(const uint8_t *c, int64_t count, bool bit) {
for (; count >= 8; c += 8, count -= 8) {
uint64_t x = *reinterpret_cast<const uint64_t *>(c);
if (x != 0) {
- return res + clzllWithEndian(x);
+ return res + ClzllWithEndian(x);
}
res += 64;
}
@@ -179,7 +179,7 @@ int64_t BitmapString::RawBitpos(const uint8_t *c, int64_t count, bool bit) {
if (count > 0) {
uint64_t v = 0;
__builtin_memcpy(&v, c, count);
- res += v == 0 ? count * 8 : clzllWithEndian(v);
+ res += v == 0 ? count * 8 : ClzllWithEndian(v);
}
if (res == ct * 8) {
@@ -189,7 +189,7 @@ int64_t BitmapString::RawBitpos(const uint8_t *c, int64_t count, bool bit) {
for (; count >= 8; c += 8, count -= 8) {
uint64_t x = *reinterpret_cast<const uint64_t *>(c);
if (x != (uint64_t)-1) {
- return res + clzllWithEndian(~x);
+ return res + ClzllWithEndian(~x);
}
res += 64;
}
@@ -197,7 +197,7 @@ int64_t BitmapString::RawBitpos(const uint8_t *c, int64_t count, bool bit) {
if (count > 0) {
uint64_t v = -1;
__builtin_memcpy(&v, c, count);
- res += v == (uint64_t)-1 ? count * 8 : clzllWithEndian(~v);
+ res += v == (uint64_t)-1 ? count * 8 : ClzllWithEndian(~v);
}
}
diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc
index f438195f..83db8b0d 100644
--- a/src/types/redis_geo.cc
+++ b/src/types/redis_geo.cc
@@ -29,7 +29,7 @@ rocksdb::Status Geo::Add(const Slice &user_key, std::vector<GeoPoint> *geo_point
for (const auto &geo_point : *geo_points) {
/* Turn the coordinates into the score of the element. */
GeoHashBits hash;
- geohashEncodeWGS84(geo_point.longitude, geo_point.latitude, GEO_STEP_MAX, &hash);
+ GeohashEncodeWGS84(geo_point.longitude, geo_point.latitude, GEO_STEP_MAX, &hash);
GeoHashFix52Bits bits = GeoHashHelper::Align52Bits(hash);
member_scores.emplace_back(MemberScore{geo_point.member, static_cast<double>(bits)});
}
@@ -184,7 +184,7 @@ std::string Geo::EncodeGeoHash(double longitude, double latitude) {
r[0].max = 180;
r[1].min = -90;
r[1].max = 90;
- geohashEncode(&r[0], &r[1], longitude, latitude, 26, &hash);
+ GeohashEncode(&r[0], &r[1], longitude, latitude, 26, &hash);
std::string geo_hash;
for (int i = 0; i < 11; i++) {
@@ -204,7 +204,7 @@ std::string Geo::EncodeGeoHash(double longitude, double latitude) {
int Geo::decodeGeoHash(double bits, double *xy) {
GeoHashBits hash = {(uint64_t)bits, GEO_STEP_MAX};
- return geohashDecodeToLongLatWGS84(hash, xy);
+ return GeohashDecodeToLongLatWGS84(hash, xy);
}
/* Search all eight neighbors + self geohash box */
diff --git a/utils/kvrocks2redis/main.cc b/utils/kvrocks2redis/main.cc
index be9d02a1..1bd1c33b 100644
--- a/utils/kvrocks2redis/main.cc
+++ b/utils/kvrocks2redis/main.cc
@@ -44,18 +44,18 @@ struct Options {
bool show_usage = false;
};
-extern "C" void signal_handler(int sig) {
+extern "C" void SignalHandler(int sig) {
if (hup_handler) hup_handler();
}
-static void usage(const char *program) {
+static void Usage(const char *program) {
std::cout << program << " sync kvrocks to redis\n"
<< "\t-c config file, default is " << kDefaultConfPath << "\n"
<< "\t-h help\n";
exit(0);
}
-static Options parseCommandLineOptions(int argc, char **argv) {
+static Options ParseCommandLineOptions(int argc, char **argv) {
int ch = 0;
Options opts;
while ((ch = ::getopt(argc, argv, "c:h")) != -1) {
@@ -69,20 +69,20 @@ static Options parseCommandLineOptions(int argc, char **argv) {
break;
}
default:
- usage(argv[0]);
+ Usage(argv[0]);
}
}
return opts;
}
-static void initGoogleLog(const kvrocks2redis::Config *config) {
+static void InitGoogleLog(const kvrocks2redis::Config *config) {
FLAGS_minloglevel = config->loglevel;
FLAGS_max_log_size = 100;
FLAGS_logbufsecs = 0;
FLAGS_log_dir = config->output_dir;
}
-static Status createPidFile(const std::string &path) {
+static Status CreatePidFile(const std::string &path) {
int fd = open(path.data(), O_RDWR | O_CREAT | O_EXCL, 0660);
if (fd < 0) {
return {Status::NotOK, strerror(errno)};
@@ -98,9 +98,9 @@ static Status createPidFile(const std::string &path) {
return Status::OK();
}
-static void removePidFile(const std::string &path) { std::remove(path.data()); }
+static void RemovePidFile(const std::string &path) { std::remove(path.data()); }
-static void daemonize() {
+static void Daemonize() {
pid_t pid = fork();
if (pid < 0) {
LOG(ERROR) << "Failed to fork the process. Error: " << strerror(errno);
@@ -127,12 +127,12 @@ int main(int argc, char *argv[]) {
evthread_use_pthreads();
signal(SIGPIPE, SIG_IGN);
- signal(SIGINT, signal_handler);
- signal(SIGTERM, signal_handler);
+ signal(SIGINT, SignalHandler);
+ signal(SIGTERM, SignalHandler);
std::cout << "Version: " << VERSION << " @" << GIT_COMMIT << std::endl;
- auto opts = parseCommandLineOptions(argc, argv);
- if (opts.show_usage) usage(argv[0]);
+ auto opts = ParseCommandLineOptions(argc, argv);
+ if (opts.show_usage) Usage(argv[0]);
std::string config_file_path = std::move(opts.conf_file);
kvrocks2redis::Config config;
@@ -142,11 +142,11 @@ int main(int argc, char *argv[]) {
exit(1);
}
- initGoogleLog(&config);
+ InitGoogleLog(&config);
- if (config.daemonize) daemonize();
+ if (config.daemonize) Daemonize();
- s = createPidFile(config.pidfile);
+ s = CreatePidFile(config.pidfile);
if (!s.IsOK()) {
LOG(ERROR) << "Failed to create pidfile '" << config.pidfile << "': " << s.Msg();
exit(1);
@@ -176,6 +176,6 @@ int main(int argc, char *argv[]) {
};
sync.Start();
- removePidFile(config.pidfile);
+ RemovePidFile(config.pidfile);
return 0;
}
diff --git a/utils/kvrocks2redis/sync.cc b/utils/kvrocks2redis/sync.cc
index 90ac5124..c142b942 100644
--- a/utils/kvrocks2redis/sync.cc
+++ b/utils/kvrocks2redis/sync.cc
@@ -34,7 +34,7 @@
#include "io_util.h"
#include "server/redis_reply.h"
-void send_string_to_event(bufferevent *bev, const std::string &data) {
+void SendStringToEvent(bufferevent *bev, const std::string &data) {
auto output = bufferevent_get_output(bev);
evbuffer_add(output, data.c_str(), data.length());
}