diff --git a/README.md b/README.md index f15d23bd2..d15b22faa 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Pikiwidb is compiled by default in release mode, which does not support debuggin ## Run ```bash -bin/pikiwidb etc/conf/pikiwidb.conf +./bin/pikiwidb ./etc/conf/pikiwidb.conf ``` ## Support module for write your own extensions diff --git a/README_CN.md b/README_CN.md index 30c4c8446..40a3b502d 100644 --- a/README_CN.md +++ b/README_CN.md @@ -38,7 +38,7 @@ PikiwiDB 默认以 release 模式编译,不支持调试。如果需要调试 ## 运行 ```bash -bin/pikiwidb etc/conf/pikiwidb.conf +./bin/pikiwidb ./etc/conf/pikiwidb.conf ``` ## 与 Redis 完全兼容 diff --git a/src/base_cmd.cc b/src/base_cmd.cc index 88a942b3a..4e53d6873 100644 --- a/src/base_cmd.cc +++ b/src/base_cmd.cc @@ -1,9 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ + Built the foundational classes for the design and expansion of commands. +*/ #include "base_cmd.h" @@ -114,3 +116,4 @@ bool BaseCmdGroup::DoInitial(PClient* client) { } } // namespace pikiwidb +/* namespace pikiwidb */ diff --git a/src/base_cmd.h b/src/base_cmd.h index a77fbcbc1..aa857c847 100644 --- a/src/base_cmd.h +++ b/src/base_cmd.h @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined the open commands of PikiwiDB to the outside, the setting of permissions, and other aspects. */ #pragma once diff --git a/src/client.cc b/src/client.cc index 890ec6164..382843062 100644 --- a/src/client.cc +++ b/src/client.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implemented a set of functions for interfacing with the client. */ #include "client.h" diff --git a/src/client.h b/src/client.h index 6cbcb7c8d..3133f7ad4 100644 --- a/src/client.h +++ b/src/client.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of feedback codes, messages, and functions + related to handling client commands. */ #pragma once diff --git a/src/cmd_admin.cc b/src/cmd_admin.cc index 0964bd821..2b54565dc 100644 --- a/src/cmd_admin.cc +++ b/src/cmd_admin.cc @@ -1,8 +1,15 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Many management-level commands are defined here. + + Compared to the external commands at the user level, + the commands defined here are more focused on the overall + management of the PikiwiDB. + */ #include "cmd_admin.h" diff --git a/src/cmd_admin.h b/src/cmd_admin.h index 3c846d19e..68940e89d 100644 --- a/src/cmd_admin.h +++ b/src/cmd_admin.h @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Stores the declarations of management commands. */ #pragma once diff --git a/src/cmd_hash.cc b/src/cmd_hash.cc index b38ef0b41..ccc1a5af3 100644 --- a/src/cmd_hash.cc +++ b/src/cmd_hash.cc @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of functions for operating key-value pairs + in a hash table. */ #include "cmd_hash.h" diff --git a/src/cmd_hash.h b/src/cmd_hash.h index a664208dd..7f854940c 100644 --- a/src/cmd_hash.h +++ b/src/cmd_hash.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Declared a set of functions for operating key-value pairs + in a hash table, which can be understood with reference to the principles of Redis HSET and other commands. */ #pragma once diff --git a/src/cmd_keys.cc b/src/cmd_keys.cc index f8a56b59c..2af5338b7 100644 --- a/src/cmd_keys.cc +++ b/src/cmd_keys.cc @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + This file implements commands that focus on the keys in + key-value pairs, rather than the values. */ #include "cmd_keys.h" diff --git a/src/cmd_keys.h b/src/cmd_keys.h index 0614ae80c..45186d741 100644 --- a/src/cmd_keys.h +++ b/src/cmd_keys.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + This file defines some functions and commands related + to key operations. */ #pragma once diff --git a/src/cmd_kv.cc b/src/cmd_kv.cc index 726bbb19e..16e30d1f4 100644 --- a/src/cmd_kv.cc +++ b/src/cmd_kv.cc @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implemented a set of operation functions and commands + associated with key-value pairs. */ #include "cmd_kv.h" diff --git a/src/cmd_kv.h b/src/cmd_kv.h index dd5e1f4e8..4ea5fab6b 100644 --- a/src/cmd_kv.h +++ b/src/cmd_kv.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of operation functions and commands related + to key-value pairs. */ #pragma once diff --git a/src/cmd_list.cc b/src/cmd_list.cc index 2dab9f304..1f64eaa2b 100644 --- a/src/cmd_list.cc +++ b/src/cmd_list.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implemented a set of operation functions and commands related to lists. */ #include "cmd_list.h" diff --git a/src/cmd_list.h b/src/cmd_list.h index bf4d299c0..3289b64aa 100644 --- a/src/cmd_list.h +++ b/src/cmd_list.h @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of operation functions and commands related to lists. */ #pragma once diff --git a/src/cmd_raft.cc b/src/cmd_raft.cc index dc5d5c378..e91c93405 100644 --- a/src/cmd_raft.cc +++ b/src/cmd_raft.cc @@ -1,8 +1,13 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + A set of instructions and functions related to Raft. + + Defined a set of functions and instructions related to the + implementation of Raft, which is key to the distributed cluster implementation of PikiwiDB. */ #include "cmd_raft.h" diff --git a/src/cmd_raft.h b/src/cmd_raft.h index e9d04c33b..27ae19d16 100644 --- a/src/cmd_raft.h +++ b/src/cmd_raft.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + The declarations of a set of instructions and functions + related to Raft are written here. */ #pragma once diff --git a/src/cmd_set.cc b/src/cmd_set.cc index e1e5a9b26..b4bfd1de1 100644 --- a/src/cmd_set.cc +++ b/src/cmd_set.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + A set of instructions and functions related to set operations. */ #include "cmd_set.h" diff --git a/src/cmd_set.h b/src/cmd_set.h index 446e553d1..b4cdb0450 100644 --- a/src/cmd_set.h +++ b/src/cmd_set.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Declarations of a set of instructions and functions related + to set operations. */ #pragma once diff --git a/src/cmd_table_manager.cc b/src/cmd_table_manager.cc index b9f398319..0647fe35c 100644 --- a/src/cmd_table_manager.cc +++ b/src/cmd_table_manager.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a command table for managing the commands themselves. */ #include "cmd_table_manager.h" diff --git a/src/cmd_table_manager.h b/src/cmd_table_manager.h index 71b434a19..cb6a1199f 100644 --- a/src/cmd_table_manager.h +++ b/src/cmd_table_manager.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a command table, because PikiwiDB needs to manage + commands in an integrated way. */ #pragma once diff --git a/src/cmd_thread_pool.cc b/src/cmd_thread_pool.cc index afc1bb880..46292a8bb 100644 --- a/src/cmd_thread_pool.cc +++ b/src/cmd_thread_pool.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + A thread pool for managing commands has been implemented. */ #include "cmd_thread_pool.h" diff --git a/src/cmd_thread_pool.h b/src/cmd_thread_pool.h index 33a42fda7..69cd06f10 100644 --- a/src/cmd_thread_pool.h +++ b/src/cmd_thread_pool.h @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + A thread pool for managing commands has been defined here. */ #pragma once @@ -21,6 +23,9 @@ namespace pikiwidb { // task interface // inherit this class and implement the Run method // then submit the task to the thread pool +/* + CmdThreadPoolTask +*/ class CmdThreadPoolTask { public: explicit CmdThreadPoolTask(std::shared_ptr client) : client_(std::move(client)) {} diff --git a/src/cmd_thread_pool_worker.cc b/src/cmd_thread_pool_worker.cc index 7de20a520..96a49a013 100644 --- a/src/cmd_thread_pool_worker.cc +++ b/src/cmd_thread_pool_worker.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Retrieve commands from the thread pool and execute them. */ #include "cmd_thread_pool_worker.h" diff --git a/src/cmd_thread_pool_worker.h b/src/cmd_thread_pool_worker.h index 659180ded..4149b0299 100644 --- a/src/cmd_thread_pool_worker.h +++ b/src/cmd_thread_pool_worker.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of functions for retrieving commands from + the thread pool and executing them. */ #pragma once diff --git a/src/cmd_zset.cc b/src/cmd_zset.cc index cd315921f..64452734c 100644 --- a/src/cmd_zset.cc +++ b/src/cmd_zset.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implemented a set of features related to sorted sets. */ #include "cmd_zset.h" diff --git a/src/cmd_zset.h b/src/cmd_zset.h index d1af08410..ed8ee9b31 100644 --- a/src/cmd_zset.h +++ b/src/cmd_zset.h @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of features related to sorted sets. */ #pragma once diff --git a/src/common.cc b/src/common.cc index 1a15abcd9..d206c0dba 100644 --- a/src/common.cc +++ b/src/common.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + A set of general functions designed for other modules of PikiwiDB. */ #include "common.h" diff --git a/src/common.h b/src/common.h index cfc0a1a51..ed7c6b7db 100644 --- a/src/common.h +++ b/src/common.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + A set of general functions defined here may be utilized by + other modules. */ #pragma once @@ -77,58 +80,113 @@ enum class PParseResult : int8_t { PParseResult GetIntUntilCRLF(const char*& ptr, std::size_t nBytes, int& val); +/* + * AtomicString Use a locking mechanism to ensure atomicity of + * read and write operations. + * Based on the std::string + */ class AtomicString { public: + /*------------------------ + * AtomicString() + * Initialize a string instance. + */ AtomicString() = default; + /*------------------------ + * ~AtomicString() + * Destory a string instance. + */ ~AtomicString() = default; + /*------------------------ + * AtomicString (std::string) + * Initialize a string instance. + */ AtomicString(std::string str) { std::lock_guard lock(mutex_); str_ = std::move(str); } + /*------------------------ + * AtomicString (std::string&& str) + * Initialize a string instance. + */ AtomicString(std::string&& str) { std::lock_guard lock(mutex_); str_ = std::move(str); } + /*------------------------ + * AtomicString (const std::string& str) + * Initialize a string instance. + */ AtomicString(const std::string& str) { std::lock_guard lock(mutex_); str_ = str; } + /*------------------------ + * AtomicString (const char* c) + * Initialize a string instance. + */ AtomicString(const char* c) { std::lock_guard lock(mutex_); str_ = std::string(c); }; + /*------------------------ + * AtomicString (const char* c) + * Initialize a string instance. + */ AtomicString& operator=(const std::string& str) { std::lock_guard lock(mutex_); str_ = str; return *this; } + /*------------------------ + * overloaded operator = (std::string&& str) + * Set string data. + */ AtomicString& operator=(std::string&& str) { std::lock_guard lock(mutex_); str_ = std::move(str); return *this; } + /*------------------------ + * overloaded operator std::string() + * Convert AtomicString to std::string + */ operator std::string() { std::shared_lock lock(mutex_); return str_; } - + /*------------------------ + * overloaded operator std::string() + * Convert AtomicString to std::string + */ operator std::string() const { std::shared_lock lock(mutex_); return str_; } - + /*------------------------ + * empty() + * Empty a AtomicString + */ bool empty() const { std::shared_lock lock(mutex_); return str_.empty(); } - + /*------------------------ + * ToString() + * Convert AtomicString to std::string + */ std::string ToString() const { std::shared_lock lock(mutex_); return str_; } private: + /* + * Mutex established to achieve atomicity + * of read and write operations + */ mutable std::shared_mutex mutex_; + /* Store the string */ std::string str_; }; diff --git a/src/config.cc b/src/config.cc index a66f69e43..02e82a2f2 100644 --- a/src/config.cc +++ b/src/config.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Responsible for managing the runtime configuration information of PikiwiDB. */ #include @@ -104,22 +106,22 @@ Status NumberValue::SetValue(const std::string& value) { PConfig::PConfig() { AddBool("daemonize", &CheckYesNo, false, &daemonize); AddString("ip", false, {&ip}); - AddNumberWihLimit("port", false, &port, PORT_LIMIT_MIN, PORT_LIMIT_MAX); + AddNumberWithLimit("port", false, &port, PORT_LIMIT_MIN, PORT_LIMIT_MAX); AddNumber("raft-port-offset", true, &raft_port_offset); AddNumber("timeout", true, &timeout); AddString("db-path", false, {&db_path}); - AddStrinWithFunc("loglevel", &CheckLogLevel, false, {&log_level}); + AddStringWithFunc("loglevel", &CheckLogLevel, false, {&log_level}); AddString("logfile", false, {&log_dir}); - AddNumberWihLimit("databases", false, &databases, 1, DBNUMBER_MAX); + AddNumberWithLimit("databases", false, &databases, 1, DBNUMBER_MAX); AddString("requirepass", true, {&password}); AddNumber("maxclients", true, &max_clients); - AddNumberWihLimit("worker-threads", false, &worker_threads_num, 1, THREAD_MAX); - AddNumberWihLimit("slave-threads", false, &worker_threads_num, 1, THREAD_MAX); + AddNumberWithLimit("worker-threads", false, &worker_threads_num, 1, THREAD_MAX); + AddNumberWithLimit("slave-threads", false, &worker_threads_num, 1, THREAD_MAX); AddNumber("slowlog-log-slower-than", true, &slow_log_time); AddNumber("slowlog-max-len", true, &slow_log_max_len); - AddNumberWihLimit("db-instance-num", true, &db_instance_num, 1, ROCKSDB_INSTANCE_NUMBER_MAX); - AddNumberWihLimit("fast-cmd-threads-num", false, &fast_cmd_threads_num, 1, THREAD_MAX); - AddNumberWihLimit("slow-cmd-threads-num", false, &slow_cmd_threads_num, 1, THREAD_MAX); + AddNumberWithLimit("db-instance-num", true, &db_instance_num, 1, ROCKSDB_INSTANCE_NUMBER_MAX); + AddNumberWithLimit("fast-cmd-threads-num", false, &fast_cmd_threads_num, 1, THREAD_MAX); + AddNumberWithLimit("slow-cmd-threads-num", false, &slow_cmd_threads_num, 1, THREAD_MAX); AddNumber("max-client-response-size", true, &max_client_response_size); AddString("runid", false, {&run_id}); AddNumber("small-compaction-threshold", true, &small_compaction_threshold); diff --git a/src/config.h b/src/config.h index 4a7bf6e30..ad88661de 100644 --- a/src/config.h +++ b/src/config.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Declared a set of functions responsible for managing the + runtime configuration information of PikiwiDB. */ #pragma once @@ -114,94 +117,304 @@ class BoolValue : public BaseValue { using ValuePrt = std::unique_ptr; using ConfigMap = std::unordered_map; +/* + * PConfig holds information about PikiwiDB + * server-side runtime information. + */ class PConfig { public: + /* Some important, globally relevant public interfaces. */ + + /*------------------------ + * PConfig() + * Initialize PikiwiDB's config & RocksDB's config. + */ PConfig(); + + /*------------------------ + * ~PConfig() + * Destroy a PikiwiDB instance. + */ ~PConfig() = default; + + /*------------------------ + * LoadFromFile(const std::string& file_name) + * Load a PikiwiDB config file and store in PConfig + * Check the return to see success or not + */ bool LoadFromFile(const std::string& file_name); + + /*------------------------ + * ConfigFileName() + * Return the name of the configuration file name specified at load time. + */ const std::string& ConfigFileName() const { return config_file_name_; } - void Get(const std::string&, std::vector*) const; - Status Set(std::string, const std::string&, bool force = false); + + /*------------------------ + * Get (const std::string& key, std::vector* values) + * Retrieve the data corresponding to the specified configuration parameter. + * key is the configuration parameter want to retrieve + * values store the result + */ + void Get(const std::string& key, std::vector* values) const; + + /*------------------------ + * Set (std::string key, const std::string& value, bool init_stage) + * Set the data for the specified parameter。 + * key is the configuration parameter want to set, case insensitive + * value is the data want to storexs + * init_stage represents whether the system is in the initialization phase, + * some parameters are not allowed to be modified outside of the initialization phase + */ + Status Set(std::string key, const std::string& value, bool init_stage = false); public: + /* + * Some crucial, globally significant, externally accessible public data. + * Refer to the pikiwidb.conf + */ + + /* + * If the connection times out, then terminate the connection. + * 0 means no timeout limit, otherwise it is the specified number of seconds. + */ std::atomic_uint32_t timeout = 0; - // auth + /* + * Client connect to PikiwiDB server may need password + */ AtomicString password; + + /* + * Slave node connect to Master node may need password(master_auth), + * and their need to keep the master_ip & master_port + */ AtomicString master_auth; AtomicString master_ip; + std::atomic_uint32_t master_port; + + // aliases store the rename command std::map aliases; - std::atomic_uint32_t max_clients = 10000; // 10000 - std::atomic_uint32_t slow_log_time = 1000; // 1000 microseconds - std::atomic_uint32_t slow_log_max_len = 128; // 128 - std::atomic_uint32_t master_port; // replication - AtomicString include_file; // the template config - std::vector modules; // modules + + // The max connection limition + std::atomic_uint32_t max_clients = 10000; + + /* + * Slow log help us to know the command that execute time more + * than slow_log_time (in microseconds, 1000000 microseconds + * is equivalent to 1 second) + * + * slow_log_max_len in current version just consume memory, + * has no practical effect + */ + std::atomic_uint32_t slow_log_time = 1000; + std::atomic_uint32_t slow_log_max_len = 128; + + /* + * include_file & modules in current version not support + * Reference: https://redis.io/docs/latest/operate/oss_and_stack/management/config-file/ + */ + AtomicString include_file; + std::vector modules; + + /* + * PikiwiDB use the thread pool to manage the task, + * categorize them into two types: fast tasks and slow tasks, + * and fast_cmd_threads_num & slow_cmd_threads_num used to set + * the number of threads to handle these task. + * + * In current version, we only use the fast task thread pool. + * + */ std::atomic_int32_t fast_cmd_threads_num = 4; std::atomic_int32_t slow_cmd_threads_num = 4; + + // Limit the maximum number of bytes returned to the client. std::atomic_uint64_t max_client_response_size = 1073741824; + + /* + * Decide when to trigger a small-scale merge operation. + * In default, small_compaction_threshold = 86400 * 7, + * small_compaction_duration_threshold = 86400 * 3. + */ std::atomic_uint64_t small_compaction_threshold = 604800; std::atomic_uint64_t small_compaction_duration_threshold = 259200; + // Decide whether PikiwiDB runs as a daemon process. std::atomic_bool daemonize = false; + + // Which file to store the process id when running? AtomicString pid_file = "./pikiwidb.pid"; + + /* + * For PikiwiDB, ip is the address and the port that + * the server will listen on. + * In default, the full address will be "127.0.0.1:9221" + */ AtomicString ip = "127.0.0.1"; std::atomic_uint16_t port = 9221; + + /* + * The raft protocol need regular communication between nodes. + * We will set the port that will ultimately be used + * for communication to be the port + raft_port_offset + * In default, raft_port_offset = 10 + */ std::atomic_uint16_t raft_port_offset = 10; + + // The path to store the data AtomicString db_path = "./db/"; - AtomicString log_dir = "stdout"; // the log directory, differ from redis + + // The log directory, default print to stdout + AtomicString log_dir = "stdout"; + + /* + * PikiwiDB uses the SPDLOG Library to implement the log module, + * so the log_level is the same as the SPDLOG level. + * Just look at SPDLOG wiki to know more. + */ AtomicString log_level = "warning"; + + /* + * run_id is a SHA1-sized random number that identifies a + * given execution of PikiwiDB. + */ AtomicString run_id; + + // The number of databases. std::atomic databases = 16; + + /* + * For Network I/O threads, in future version, we may delete + * slave_threads_num. + */ std::atomic_uint32_t worker_threads_num = 2; std::atomic_uint32_t slave_threads_num = 2; + + // How many RocksDB Instances will be opened? std::atomic db_instance_num = 3; + + // Use raft protocol? std::atomic_bool use_raft = true; + /* + * PikiwiDB use the RocksDB to store the data, + * and these options below will set to rocksdb::Options, + * Just check the RocksDB document & PConfig::GetRocksDBOptions + * to know more. + */ + std::atomic_uint32_t rocksdb_max_subcompactions = 0; + // default 2 std::atomic_int rocksdb_max_background_jobs = 4; + // default 2 std::atomic rocksdb_max_write_buffer_number = 2; + // default 2 std::atomic_int rocksdb_min_write_buffer_number_to_merge = 2; + // default 64M std::atomic rocksdb_write_buffer_size = 64 << 20; + std::atomic_int rocksdb_level0_file_num_compaction_trigger = 4; std::atomic_int rocksdb_num_levels = 7; std::atomic_bool rocksdb_enable_pipelined_write = false; std::atomic_int rocksdb_level0_slowdown_writes_trigger = 20; std::atomic_int rocksdb_level0_stop_writes_trigger = 36; - std::atomic_uint64_t rocksdb_ttl_second = 604800; // default 86400 * 7 - std::atomic_uint64_t rocksdb_periodic_second = 259200; // default 86400 * 3 + + // 86400 * 7 = 604800 + std::atomic_uint64_t rocksdb_ttl_second = 604800; + + // 86400 * 3 = 259200 + std::atomic_uint64_t rocksdb_periodic_second = 259200; rocksdb::Options GetRocksDBOptions(); rocksdb::BlockBasedTableOptions GetRocksDBBlockBasedTableOptions(); private: + // Some functions and variables set up for internal work. + + /*------------------------ + * AddString (const std::string& key, bool rewritable, * std::vector values_ptr_vector) + * Introduce a new string key-value pair into the + * configuration data layer. + * A key may correspond to multiple values, so we use std::vector + * to store the data. + * rewritable represents whether to overwrite existing settings + * when a key-value pair is duplicated. + */ inline void AddString(const std::string& key, bool rewritable, std::vector values_ptr_vector) { config_map_.emplace(key, std::make_unique(key, nullptr, rewritable, values_ptr_vector)); } - inline void AddStrinWithFunc(const std::string& key, const CheckFunc& checkfunc, bool rewritable, - std::vector values_ptr_vector) { + + /*------------------------ + * AddStringWithFunc (const std::string& key, const CheckFunc& checkfunc, bool rewritable, + std::vector values_ptr_vector) + * Introduce a new string key-value pair into the + * configuration data layer, with a check function. + * key, value, rewritable is the same as AddString. + * The checkfunc is coded by the user, validate the string as needed, + * and the return value should refer to rocksdb::Status. + */ + inline void AddStringWithFunc(const std::string& key, const CheckFunc& checkfunc, bool rewritable, + std::vector values_ptr_vector) { config_map_.emplace(key, std::make_unique(key, checkfunc, rewritable, values_ptr_vector)); } + + /*------------------------ + * AddBool (const std::string& key, const CheckFunc& checkfunc, bool rewritable, + std::atomic* value_ptr) + * Introduce a new string key-value pair into the + * configuration data layer, with a check function. + * key is a string and value_ptr is a point to a bool value. + * checkfunc is the same as AddStrinWithFunc. + * rewritable represents whether to overwrite existing settings + * when a key-value pair is duplicated. + */ inline void AddBool(const std::string& key, const CheckFunc& checkfunc, bool rewritable, std::atomic* value_ptr) { config_map_.emplace(key, std::make_unique(key, checkfunc, rewritable, value_ptr)); } + + /*------------------------ + * AddNumber (const std::string& key, bool rewritable, std::atomic* value_ptr) + * Introduce a new string key-value pair into the + * configuration data layer, with a check function. + * key is a string and value_ptr is a set of numbers. + * rewritable represents whether to overwrite existing settings + * when a key-value pair is duplicated. + */ template inline void AddNumber(const std::string& key, bool rewritable, std::atomic* value_ptr) { config_map_.emplace(key, std::make_unique>(key, nullptr, rewritable, value_ptr)); } + + /*------------------------ + * AddNumberWithLimit (const std::string& key, bool rewritable, std::atomic* value_ptr, T min, T max) + * Introduce a new string key-value pair into the + * configuration data layer, with a check function. + * key is a string and value_ptr is a set of numbers. + * rewritable represents whether to overwrite existing settings + * when a key-value pair is duplicated. + * Please note that this function does not have a checkfunc function, + * as we have replaced it with the upper and lower limits + * of the numbers passed in. + */ template - inline void AddNumberWihLimit(const std::string& key, bool rewritable, std::atomic* value_ptr, T min, T max) { + inline void AddNumberWithLimit(const std::string& key, bool rewritable, std::atomic* value_ptr, T min, T max) { config_map_.emplace(key, std::make_unique>(key, nullptr, rewritable, value_ptr, min, max)); } private: + // The parser to parse the config data ConfigParser parser_; + + // Store the key-value data for config ConfigMap config_map_; + + // The file name of the config std::string config_file_name_; }; } // namespace pikiwidb diff --git a/src/config_parser.cc b/src/config_parser.cc index 9b8aaf8a5..a4caefc6f 100644 --- a/src/config_parser.cc +++ b/src/config_parser.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Responsible for parsing configuration data as required. */ #include "config_parser.h" diff --git a/src/config_parser.h b/src/config_parser.h index a8491e85c..f19b948ae 100644 --- a/src/config_parser.h +++ b/src/config_parser.h @@ -1,8 +1,12 @@ /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * config_parser.h + * Declared a set of functions for parsing configuration data + * as required. + * + * Copyright (c) 2023-present, Qihoo, Inc. All rights reserved. + * + * src/config_parser.h + * */ #pragma once diff --git a/src/crc64.c b/src/crc64.c index 9f0f03779..258add5b4 100644 --- a/src/crc64.c +++ b/src/crc64.c @@ -1,3 +1,7 @@ +/* + The source code is derived from Redis, thanks Redis very much. + */ + /* Redis uses the CRC64 variant with "Jones" coefficients and init value of 0. * * Specification of this CRC64 variant follows: diff --git a/src/db.cc b/src/db.cc index bb4728c09..e736c594e 100644 --- a/src/db.cc +++ b/src/db.cc @@ -1,8 +1,11 @@ +// Copyright (c) 2024-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2024-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Responsible for interfacing with RocksDB to effectively + manage PikiwiDB's data. */ #include "db.h" diff --git a/src/db.h b/src/db.h index 89dbedf12..7326606c2 100644 --- a/src/db.h +++ b/src/db.h @@ -1,8 +1,11 @@ +// Copyright (c) 2024-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2024-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Declared a set of functions responsible for interfacing + with RocksDB. */ #pragma once diff --git a/src/helper.cc b/src/helper.cc index ef33e4124..2d358042a 100644 --- a/src/helper.cc +++ b/src/helper.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of helper functions. */ #include diff --git a/src/helper.h b/src/helper.h index 0c05c37c6..597b1e6ba 100644 --- a/src/helper.h +++ b/src/helper.h @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Declared a set of auxiliary functions. */ #pragma once diff --git a/src/multi.cc b/src/multi.cc deleted file mode 100644 index d0d8a214e..000000000 --- a/src/multi.cc +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#include "multi.h" -#include "client.h" -#include "log.h" -#include "store.h" - -// namespace pikiwidb { -// -// PMulti& PMulti::Instance() { -// static PMulti mt; -// return mt; -// } -// -// void PMulti::Watch(PClient* client, int dbno, const PString& key) { -// if (client->Watch(dbno, key)) { -// Clients& cls = clients_[dbno][key]; -// cls.push_back(std::static_pointer_cast(client->shared_from_this())); -// } -// } -// -// bool PMulti::Multi(PClient* client) { -// if (client->IsFlagOn(kClientFlagMulti)) { -// return false; -// } -// -// client->ClearMulti(); -// client->SetFlag(kClientFlagMulti); -// return true; -// } -// -// bool PMulti::Exec(PClient* client) { return client->Exec(); } -// -// void PMulti::Discard(PClient* client) { -// client->ClearMulti(); -// client->ClearWatch(); -// } -// -// void PMulti::NotifyDirty(int dbno, const PString& key) { -// auto tmpDBIter = clients_.find(dbno); -// if (tmpDBIter == clients_.end()) { -// return; -// } -// -// auto& dbWatchedKeys = tmpDBIter->second; -// auto it = dbWatchedKeys.find(key); -// if (it == dbWatchedKeys.end()) { -// return; -// } -// -// Clients& cls = it->second; -// for (auto itCli(cls.begin()); itCli != cls.end();) { -// auto client(itCli->lock()); -// if (!client) { -// WARN("Erase not exist client when notify dirty key[{}]", key); -// itCli = cls.erase(itCli); -// } else { -// if (client.get() != PClient::Current() && client->NotifyDirty(dbno, key)) { -// WARN("Erase dirty client {} when notify dirty key[{}]", client->GetName(), key); -// itCli = cls.erase(itCli); -// itCli = cls.erase(itCli); -// } else { -// ++itCli; -// } -// } -// } -// -// if (cls.empty()) { -// dbWatchedKeys.erase(it); -// } -// } -// -// void PMulti::NotifyDirtyAll(int dbno) { -// if (dbno == -1) { -// for (auto& db_set : clients_) { -// for (auto& key_clients : db_set.second) { -// std::for_each(key_clients.second.begin(), key_clients.second.end(), [&](const std::weak_ptr& wcli) { -// auto scli = wcli.lock(); -// if (scli) { -// scli->SetFlag(kClientFlagDirty); -// } -// }); -// } -// } -// } else { -// auto it = clients_.find(dbno); -// if (it != clients_.end()) { -// for (auto& key_clients : it->second) { -// std::for_each(key_clients.second.begin(), key_clients.second.end(), [&](const std::weak_ptr& wcli) { -// auto scli = wcli.lock(); -// if (scli) { -// scli->SetFlag(kClientFlagDirty); -// } -// }); -// } -// } -// } -// } -// -//// multi commands -// PError watch(const std::vector& params, UnboundedBuffer* reply) { -// PClient* client = PClient::Current(); -// if (client->IsFlagOn(kClientFlagMulti)) { -// ReplyError(kPErrorWatch, reply); -// return kPErrorWatch; -// } -// -// std::for_each(++params.begin(), params.end(), -// [client](const PString& s) { PMulti::Instance().Watch(client, client->GetCurrentDB(), s); }); -// -// FormatOK(reply); -// return kPErrorOK; -// } -// -// PError unwatch(const std::vector& params, UnboundedBuffer* reply) { -// PClient* client = PClient::Current(); -// client->ClearWatch(); -// FormatOK(reply); -// return kPErrorOK; -// } -// -// PError multi(const std::vector& params, UnboundedBuffer* reply) { -// PClient* client = PClient::Current(); -// if (PMulti::Instance().Multi(client)) { -// FormatOK(reply); -// } else { -// reply->PushData("-ERR MULTI calls can not be nested\r\n"); -// } -// -// return kPErrorOK; -// } -// -// PError exec(const std::vector& params, UnboundedBuffer* reply) { -// PClient* client = PClient::Current(); -// if (!client->IsFlagOn(kClientFlagMulti)) { -// ReplyError(kPErrorNoMulti, reply); -// return kPErrorNoMulti; -// } -// if (!PMulti::Instance().Exec(client)) { -// ReplyError(kPErrorDirtyExec, reply); -// return kPErrorDirtyExec; -// } -// return kPErrorOK; -// } -// -// PError discard(const std::vector& params, UnboundedBuffer* reply) { -// PClient* client = PClient::Current(); -// if (!client->IsFlagOn(kClientFlagMulti)) { -// reply->PushData("-ERR DISCARD without MULTI\r\n"); -// } else { -// PMulti::Instance().Discard(client); -// FormatOK(reply); -// } -// -// return kPErrorOK; -// } -// -// } // namespace pikiwidb diff --git a/src/multi.h b/src/multi.h deleted file mode 100644 index f25423459..000000000 --- a/src/multi.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#pragma once - -#include -#include -#include -#include - -#include "common.h" - -// namespace pikiwidb { -// -// class PClient; -// class PMulti { -// public: -// static PMulti& Instance(); -// -// PMulti(const PMulti&) = delete; -// void operator=(const PMulti&) = delete; -// -// void Watch(PClient* client, int dbno, const PString& key); -// bool Multi(PClient* client); -// bool Exec(PClient* client); -// void Discard(PClient* client); -// -// void NotifyDirty(int dbno, const PString& key); -// void NotifyDirtyAll(int dbno); -// -// private: -// PMulti() {} -// -// using Clients = std::vector >; -// using WatchedClients = std::map >; -// -// WatchedClients clients_; -// }; -// -// } // namespace pikiwidb diff --git a/src/pikiwidb.cc b/src/pikiwidb.cc index 0880549ad..203105e33 100644 --- a/src/pikiwidb.cc +++ b/src/pikiwidb.cc @@ -1,19 +1,23 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ + Stub main() routine for the pikiwidb executable. -// -// PikiwiDB.cc + This does some essential startup tasks for pikiwidb, and then dispatches to the proper FooMain() routine for the + incarnation. + */ #include "pikiwidb.h" +#include #include #include #include #include +#include #include #include @@ -28,9 +32,15 @@ #include "slow_log.h" #include "store.h" +// g_pikiwidb is a global abstraction of the server-side process std::unique_ptr g_pikiwidb; + using namespace pikiwidb; +/* + * set up a handler to be called if the PikiwiDB crashes + * with a fatal signal or exception. + */ static void IntSigHandle(const int sig) { INFO("Catch Signal {}, cleanup...", sig); g_pikiwidb->Stop(); @@ -47,60 +57,97 @@ static void SignalSetup() { const uint32_t PikiwiDB::kRunidSize = 40; static void Usage() { - std::cerr << "Usage: ./pikiwidb-server [/path/to/redis.conf] [options]\n\ - ./pikiwidb-server -v or --version\n\ - ./pikiwidb-server -h or --help\n\ -Examples:\n\ - ./pikiwidb-server (run the server with default conf)\n\ - ./pikiwidb-server /etc/redis/6379.conf\n\ - ./pikiwidb-server --port 7777\n\ - ./pikiwidb-server --port 7777 --slaveof 127.0.0.1 8888\n\ - ./pikiwidb-server /etc/myredis.conf --loglevel verbose\n"; + std::cerr << "pikiwidb is the PikiwiDB server.\n"; + std::cerr << "\n"; + std::cerr << "Usage:\n"; + std::cerr << " pikiwidb [/path/to/pikiwidb.conf] [options]\n"; + std::cerr << "\n"; + std::cerr << "Options:\n"; + std::cerr << " -v, --version output version information, then exit\n"; + std::cerr << " -h, --help output help message\n"; + std::cerr << " -p PORT, --port PORT Set the port listen on\n"; + std::cerr << " -l LEVEL, --loglevel LEVEL Set the log level\n"; + std::cerr << " -s ADDRESS, --slaveof ADDRESS Set the slave address\n"; + std::cerr << "Examples:\n"; + std::cerr << " pikiwidb /path/pikiwidb.conf\n"; + std::cerr << " pikiwidb /path/pikiwidb.conf --loglevel verbose\n"; + std::cerr << " pikiwidb --port 7777\n"; + std::cerr << " pikiwidb --port 7777 --slaveof 127.0.0.1:8888\n"; } -bool PikiwiDB::ParseArgs(int ac, char* av[]) { - for (int i = 0; i < ac; i++) { - if (cfg_file_.empty() && ::access(av[i], R_OK) == 0) { - cfg_file_ = av[i]; - continue; - } else if (strncasecmp(av[i], "-v", 2) == 0 || strncasecmp(av[i], "--version", 9) == 0) { - std::cerr << "PikiwiDB Server version: " << KPIKIWIDB_VERSION << " bits=" << (sizeof(void*) == 8 ? 64 : 32) - << std::endl; - std::cerr << "PikiwiDB Server Build Type: " << KPIKIWIDB_BUILD_TYPE << std::endl; +// Handle the argc & argv +bool PikiwiDB::ParseArgs(int argc, char* argv[]) { + static struct option long_options[] = { + {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, + {"port", required_argument, 0, 'p'}, {"loglevel", required_argument, 0, 'l'}, + {"slaveof", required_argument, 0, 's'}, + }; + // pikiwidb [/path/to/pikiwidb.conf] [options] + if (cfg_file_.empty() && argc > 1 && ::access(argv[1], R_OK) == 0) { + cfg_file_ = argv[1]; + argc = argc - 1; + argv = argv + 1; + } + while (1) { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + int c; + c = getopt_long(argc, argv, "vhp:l:s:", long_options, &option_index); + if (c == -1) { + break; + } + + switch (c) { + case 'v': { + std::cerr << "PikiwiDB Server version: " << KPIKIWIDB_VERSION << " bits=" << (sizeof(void*) == 8 ? 64 : 32) + << std::endl; + std::cerr << "PikiwiDB Server Build Type: " << KPIKIWIDB_BUILD_TYPE << std::endl; #if defined(KPIKIWIDB_BUILD_DATE) - std::cerr << "PikiwiDB Server Build Date: " << KPIKIWIDB_BUILD_DATE << std::endl; + std::cerr << "PikiwiDB Server Build Date: " << KPIKIWIDB_BUILD_DATE << std::endl; #endif #if defined(KPIKIWIDB_GIT_COMMIT_ID) - std::cerr << "PikiwiDB Server Build GIT SHA: " << KPIKIWIDB_GIT_COMMIT_ID << std::endl; + std::cerr << "PikiwiDB Server Build GIT SHA: " << KPIKIWIDB_GIT_COMMIT_ID << std::endl; #endif - exit(0); - } else if (strncasecmp(av[i], "-h", 2) == 0 || strncasecmp(av[i], "--help", 6) == 0) { - Usage(); - exit(0); - } else if (strncasecmp(av[i], "--port", 6) == 0) { - if (++i == ac) { - return false; + exit(0); + break; } - port_ = static_cast(std::atoi(av[i])); - } else if (strncasecmp(av[i], "--loglevel", 10) == 0) { - if (++i == ac) { - return false; + case 'h': { + Usage(); + exit(0); + break; + } + case 'p': { + port_ = static_cast(std::atoi(optarg)); + break; + } + case 'l': { + log_level_ = std::string(optarg); + break; + } + case 's': { + unsigned int optarg_long = static_cast(strlen(optarg)); + char* str = (char*)calloc(optarg_long, sizeof(char*)); + if (str) { + if (sscanf(optarg, "%s:%d", str, &master_port_) != 2) { + ERROR("Invalid slaveof format."); + free(str); + return false; + } + master_ = str; + free(str); + } else { + ERROR("Memory alloc failed."); + } + break; } - log_level_ = std::string(av[i]); - } else if (strncasecmp(av[i], "--slaveof", 9) == 0) { - if (i + 2 >= ac) { + case '?': { + std::cerr << "Unknow option " << std::endl; return false; + break; } - - master_ = std::string(av[++i]); - master_port_ = static_cast(std::atoi(av[++i])); - } else { - std::cerr << "Unknow option " << av[i] << std::endl; - return false; } } - return true; } @@ -241,9 +288,11 @@ static int InitLimit() { static void daemonize() { if (fork()) { - exit(0); /* parent exits */ + // parent exits + exit(0); } - setsid(); /* create a new session */ + // create a new session + setsid(); } static void closeStd() { @@ -257,9 +306,10 @@ static void closeStd() { } } -int main(int ac, char* av[]) { +// Any PikiwiDB server process begins execution here. +int main(int argc, char* argv[]) { g_pikiwidb = std::make_unique(); - if (!g_pikiwidb->ParseArgs(ac - 1, av + 1)) { + if (!g_pikiwidb->ParseArgs(argc, argv)) { Usage(); return -1; } @@ -271,12 +321,6 @@ int main(int ac, char* av[]) { } } - // output logo to console - char logo[512] = ""; - snprintf(logo, sizeof logo - 1, pikiwidbLogo, KPIKIWIDB_VERSION, static_cast(sizeof(void*)) * 8, - static_cast(g_config.port)); - std::cout << logo; - if (g_config.daemonize.load()) { daemonize(); } @@ -291,10 +335,15 @@ int main(int ac, char* av[]) { } if (g_pikiwidb->Init()) { + // output logo to console + char logo[512] = ""; + snprintf(logo, sizeof logo - 1, pikiwidbLogo, KPIKIWIDB_VERSION, static_cast(sizeof(void*)) * 8, + static_cast(g_config.port)); + std::cout << logo; g_pikiwidb->Run(); } - // when process exit, flush log + // When PikiwiDB exit, flush log spdlog::get(logger::Logger::Instance().Name())->flush(); return 0; } diff --git a/src/pikiwidb.h b/src/pikiwidb.h index a9112ba21..67e11cee6 100644 --- a/src/pikiwidb.h +++ b/src/pikiwidb.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Designed a set of functions and variables associated with + the PikiwiDB server. */ #include "cmd_table_manager.h" diff --git a/src/pikiwidb_logo.h b/src/pikiwidb_logo.h index 8d42a9e79..dffc13bf9 100644 --- a/src/pikiwidb_logo.h +++ b/src/pikiwidb_logo.h @@ -1,8 +1,12 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Responsible for defining the text form of the PikiwiDB logo, + the output of this LOGO must be combined with the definition + in practice. */ #pragma once diff --git a/src/proto_parser.cc b/src/proto_parser.cc index f01677c69..7071292d2 100644 --- a/src/proto_parser.cc +++ b/src/proto_parser.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Responsible for interfacing with the Redis client protocol. */ #include diff --git a/src/proto_parser.h b/src/proto_parser.h index 02f81989b..953983905 100644 --- a/src/proto_parser.h +++ b/src/proto_parser.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Responsible for declaring functions and instructions for + handling the Redis client protocol. */ #pragma once diff --git a/src/pubsub.cc b/src/pubsub.cc index ab8bdba9d..a3c81dfa8 100644 --- a/src/pubsub.cc +++ b/src/pubsub.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implement the client's subscription mechanism. */ #include diff --git a/src/pubsub.h b/src/pubsub.h index f2e97356d..4823e94c6 100644 --- a/src/pubsub.h +++ b/src/pubsub.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of functions related to the client's + subscription mechanism. */ #pragma once diff --git a/src/replication.cc b/src/replication.cc index d0a34f71a..97ab08fe9 100644 --- a/src/replication.cc +++ b/src/replication.cc @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Defined a set of functions associated with the master-slave + replication mechanism. */ #include // the child process use stdout for log diff --git a/src/replication.h b/src/replication.h index 9e1e64328..6266a67a7 100644 --- a/src/replication.h +++ b/src/replication.h @@ -1,8 +1,12 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Declared a set of functions related to the master-slave + replication mechanism, note that this is not driven by the + Raft protocol. */ #pragma once diff --git a/src/server_command.cc b/src/server_command.cc deleted file mode 100644 index a7b1df75d..000000000 --- a/src/server_command.cc +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -// #include -// #include -// #include -// #include -// -// #include "client.h" -// #include "config.h" -// #include "delegate.h" -// #include "pikiwidb.h" -// #include "slow_log.h" -// #include "store.h" -// -// namespace pikiwidb { -// -// PError dbsize(const std::vector& params, UnboundedBuffer* reply) { -// FormatInt(static_cast(PSTORE.DBSize()), reply); -// return kPErrorOK; -// } -// -// PError flushdb(const std::vector& params, UnboundedBuffer* reply) { -// PSTORE.dirty_ += PSTORE.DBSize(); -// PSTORE.ClearCurrentDB(); -// Propagate(PSTORE.GetDB(), params); -// -// FormatOK(reply); -// return kPErrorOK; -// } -// -// PError flushall(const std::vector& params, UnboundedBuffer* reply) { -// int currentDB = PSTORE.GetDB(); -// -// DEFER { -// PSTORE.SelectDB(currentDB); -// Propagate(-1, params); -// PSTORE.ResetDB(); -// }; -// -// for (int dbno = 0; true; ++dbno) { -// if (PSTORE.SelectDB(dbno) == -1) { -// break; -// } -// -// PSTORE.dirty_ += PSTORE.DBSize(); -// } -// -// FormatOK(reply); -// return kPErrorOK; -// } -// -// PError bgsave(const std::vector& params, UnboundedBuffer* reply) { -// if (g_qdbPid != -1) { -// FormatBulk("-ERR Background save already in progress", sizeof "-ERR Background save already in progress" - 1, -// reply); -// -// return kPErrorOK; -// } -// -// int ret = fork(); -// if (ret == 0) { -// { -// PDBSaver qdb; -// qdb.Save(g_config.rdbfullname.c_str()); -// } -// _exit(0); -// } else if (ret == -1) { -// FormatSingle("Background saving FAILED", 24, reply); -// } else { -// g_qdbPid = ret; -// FormatSingle("Background saving started", 25, reply); -// } -// -// return kPErrorOK; -// } -// -// PError save(const std::vector& params, UnboundedBuffer* reply) { -// if (g_qdbPid != -1) { -// FormatBulk("-ERR Background save already in progress", sizeof "-ERR Background save already in progress" - 1, -// reply); -// -// return kPErrorOK; -// } -// -// PDBSaver qdb; -// qdb.Save(g_config.rdbfullname.c_str()); -// g_lastPDBSave = time(nullptr); -// -// FormatOK(reply); -// return kPErrorOK; -// } -// -// PError lastsave(const std::vector& params, UnboundedBuffer* reply) { -// FormatInt(g_lastPDBSave, reply); -// return kPErrorOK; -// } -// -// PError client(const std::vector& params, UnboundedBuffer* reply) { -// // getname setname kill list -// PError err = kPErrorOK; -// -// if (params[1].size() == 7 && strncasecmp(params[1].c_str(), "getname", 7) == 0) { -// if (params.size() != 2) { -// ReplyError(err = kPErrorParam, reply); -// } else { -// FormatBulk(PClient::Current()->GetName(), reply); -// } -// } else if (params[1].size() == 7 && strncasecmp(params[1].c_str(), "setname", 7) == 0) { -// if (params.size() != 3) { -// ReplyError(err = kPErrorParam, reply); -// } else { -// PClient::Current()->SetName(params[2]); -// FormatOK(reply); -// } -// } else if (params[1].size() == 4 && strncasecmp(params[1].c_str(), "kill", 4) == 0) { -// // only kill current client -// // PClient::Current()->OnError(); -// FormatOK(reply); -// } else if (params[1].size() == 4 && strncasecmp(params[1].c_str(), "list", 4) == 0) { -// FormatOK(reply); -// } else { -// ReplyError(err = kPErrorParam, reply); -// } -// -// return err; -// } -// -// static int Suicide() { -// int* ptr = nullptr; -// *ptr = 0; -// -// return *ptr; -// } -// -// PError debug(const std::vector& params, UnboundedBuffer* reply) { -// PError err = kPErrorOK; -// -// if (strncasecmp(params[1].c_str(), "segfault", 8) == 0 && params.size() == 2) { -// Suicide(); -// assert(false); -// } else if (strncasecmp(params[1].c_str(), "object", 6) == 0 && params.size() == 3) { -// PObject* obj = nullptr; -// err = PSTORE.GetValue(params[2], obj, false); -// -// if (err != kPErrorOK) { -// ReplyError(err, reply); -// } else { -// // ref count, encoding, idle time -// char buf[512]; -// int len = snprintf(buf, sizeof buf, "ref count:%ld, encoding:%s, idletime:%u", -// 1L, // TODO ? -// EncodingStringInfo(obj->encoding), EstimateIdleTime(obj->lru)); -// FormatBulk(buf, len, reply); -// } -// } else { -// ReplyError(err = kPErrorParam, reply); -// } -// -// return err; -// } -// -// PError shutdown(const std::vector& params, UnboundedBuffer* reply) { -// if (params.size() == 2 && strncasecmp(params[1].c_str(), "save", 4) == 0) { -// PDBSaver qdb; -// qdb.Save(g_config.rdbfullname.c_str()); -// } -// -// if (g_pikiwidb) { -// g_pikiwidb->Stop(); -// } -// -// return kPErrorOK; -// } -// -// PError ping(const std::vector& params, UnboundedBuffer* reply) { -// FormatSingle("PONG", 4, reply); -// return kPErrorOK; -// } -// -// PError echo(const std::vector& params, UnboundedBuffer* reply) { -// FormatBulk(params[1], reply); -// return kPErrorOK; -// } -// -// void OnMemoryInfoCollect(UnboundedBuffer& res) { -// // memory info -// auto minfo = getMemoryInfo(); -// -// char buf[1024]; -// int n = -// snprintf(buf, sizeof buf - 1, -// "# Memory\r\n" -// "used_memory_peak:%lu\r\n" -// "used_memory:%lu\r\n" -// "used_memory_human:%sMB\r\n" -// "used_memory_rss_peak:%lu\r\n" -// "used_memory_rss:%lu\r\n" -// "used_memory_rss_human:%sMB\r\n" -// "used_memory_lock:%lu\r\n" -// "used_memory_swap:%lu\r\n", -// minfo[kVmPeak], minfo[kVmSize], std::to_string(minfo[kVmSize] / 1024.0f / 1024.0f).data(), -// minfo[kVmHWM], minfo[kVmRSS], std::to_string(minfo[kVmRSS] / 1024.0f / 1024.0f).data(), minfo[kVmLck], -// minfo[kVmSwap]); -// -// if (!res.IsEmpty()) { -// res.PushData("\r\n", 2); -// } -// -// res.PushData(buf, n); -// } -// -// void OnServerInfoCollect(UnboundedBuffer& res) { -// char buf[1024]; -// -// // server -// struct utsname name; -// uname(&name); -// int n = snprintf(buf, sizeof buf - 1, -// "# Server\r\n" -// "redis_mode:standalone\r\n" // not cluster node yet -// "os:%s %s %s\r\n" -// "run_id:%s\r\n" -// "hz:%d\r\n" -// "tcp_port:%hu\r\n", -// name.sysname, name.release, name.machine, g_config.runid.data(), g_config.hz, g_config.port); -// -// if (!res.IsEmpty()) { -// res.PushData("\r\n", 2); -// } -// -// res.PushData(buf, n); -// } -// -// void OnClientInfoCollect(UnboundedBuffer& res) { -// char buf[1024]; -// -// size_t nconnected = 0; // TODO -// int n = snprintf(buf, sizeof buf - 1, -// "# Clients\r\n" -// "connected_clients:%lu\r\n" -// "blocked_clients:%lu\r\n", -// nconnected, PSTORE.BlockedSize()); -// -// if (!res.IsEmpty()) { -// res.PushData("\r\n", 2); -// } -// -// res.PushData(buf, n); -// } -// -// PError info(const std::vector& params, UnboundedBuffer* reply) { -// UnboundedBuffer res; -// -// extern Delegate g_infoCollector; -// g_infoCollector(res); -// -// FormatBulk(res.ReadAddr(), res.ReadableSize(), reply); -// return kPErrorOK; -// } -// -// PError monitor(const std::vector& params, UnboundedBuffer* reply) { -// PClient::AddCurrentToMonitor(); -// -// FormatOK(reply); -// return kPErrorOK; -// } -// -// PError auth(const std::vector& params, UnboundedBuffer* reply) { -// if (g_config.CheckPassword(params[1])) { -// PClient::Current()->SetAuth(); -// FormatOK(reply); -// } else { -// ReplyError(kPErrorErrAuth, reply); -// } -// -// return kPErrorOK; -// } -// -// PError slowlog(const std::vector& params, UnboundedBuffer* reply) { -// if (params[1] == "len") { -// FormatInt(static_cast(PSlowLog::Instance().GetLogsCount()), reply); -// } else if (params[1] == "reset") { -// PSlowLog::Instance().ClearLogs(); -// FormatOK(reply); -// } else if (params[1] == "get") { -// const long limit = static_cast(PSlowLog::Instance().GetLogsCount()); -// long realCnt = limit; -// if (params.size() == 3) { -// if (!Strtol(params[2].c_str(), params[2].size(), &realCnt)) { -// ReplyError(kPErrorSyntax, reply); -// return kPErrorSyntax; -// } -// } -// -// if (realCnt > limit) { -// realCnt = limit; -// } -// -// PreFormatMultiBulk(realCnt, reply); -// for (const auto& item : PSlowLog::Instance().GetLogs()) { -// if (realCnt-- == 0) { -// break; -// } -// -// PreFormatMultiBulk(2, reply); -// FormatInt(static_cast(item.used), reply); -// -// PreFormatMultiBulk(static_cast(item.cmds.size()), reply); -// for (const auto& c : item.cmds) { -// FormatBulk(c, reply); -// } -// } -// } else { -// ReplyError(kPErrorSyntax, reply); -// return kPErrorSyntax; -// } -// -// return kPErrorOK; -// } -// -//// Config options get/set -//// -// enum ConfigType { -// kConfigString, -// kConfigBool, -// kConfigInt, -// kConfigInt64, -// }; -// -// struct ConfigInfo { -// ConfigType type; -// bool canModify; -// void* value; -// }; -// -//// TODO sanity check: use function setter -// std::map configOptions = { -// {"bind", {kConfigString, false, &g_config.ip}}, -// {"dbfilename", {kConfigString, true, &g_config.rdbfullname}}, -// {"databases", {kConfigInt, false, &g_config.databases}}, -// {"daemonize", {kConfigBool, false, &g_config.daemonize}}, -// {"hz", {kConfigInt, false, &g_config.hz}}, -// {"logfile", {kConfigString, false, &g_config.logdir}}, -// {"loglevel", {kConfigString, true, &g_config.loglevel}}, -// {"masterauth", {kConfigString, true, &g_config.masterauth}}, -// {"maxclients", {kConfigInt, true, &g_config.maxclients}}, -// {"port", {kConfigInt, false, &g_config.port}}, -// {"requirepass", {kConfigString, true, &g_config.password}}, -// {"rdbchecksum", {kConfigBool, false, &g_config.rdbchecksum}}, -// {"rdbcompression", {kConfigBool, false, &g_config.rdbcompression}}, -// {"slowlog-log-slower-than", {kConfigInt, true, &g_config.slowlogtime}}, -// {"slowlog-max-len", {kConfigInt, true, &g_config.slowlogmaxlen}}, -// {"slaveof", {kConfigString, false, &g_config.masterIp}}, -// {"maxmemory", {kConfigInt64, true, &g_config.maxmemory}}, -// {"maxmemorySamples", {kConfigInt, true, &g_config.maxmemorySamples}}, -// {"maxmemory-noevict", {kConfigBool, true, &g_config.noeviction}}, -// {"backend", {kConfigInt, false, &g_config.backend}}, -// {"backendhz", {kConfigInt, false, &g_config.backendHz}}, -// }; -// -// static std::vector GetConfig(const PString& option) { -// std::vector res; -// std::vector::const_iterator> iters; -// -// if (NotGlobRegex(option.data(), option.size())) { -// auto it = configOptions.find(option); -// if (it == configOptions.end()) { -// return res; -// } -// -// iters.push_back(it); -// } else { -// // try glob match -// for (auto it(configOptions.begin()); it != configOptions.end(); ++it) { -// if (fnmatch(option.c_str(), it->first.c_str(), FNM_NOESCAPE) == 0) { -// iters.push_back(it); -// } -// } -// } -// -// for (const auto& it : iters) { -// res.push_back(it->first); // push option -// -// // push value -// switch (it->second.type) { -// case kConfigBool: -// if (*(bool*)(it->second.value)) { -// res.push_back("true"); -// } else { -// res.push_back("false"); -// } -// break; -// -// case kConfigString: -// res.push_back(*(const PString*)it->second.value); -// break; -// -// case kConfigInt: -// case kConfigInt64: { -// int64_t val = 0; -// if (it->second.type == kConfigInt) { -// val = *(int*)it->second.value; -// } else { -// val = *(int64_t*)it->second.value; -// } -// -// char buf[16] = ""; -// Number2Str(buf, sizeof buf, val); -// res.push_back(buf); -// } -// -// break; -// -// default: -// assert(!!!"invalid type"); -// } -// } -// -// return res; -// } -// -// static PError SetConfig(const PString& option, const PString& value) { -// auto it = configOptions.find(option); -// if (it == configOptions.end()) { -// return kPErrorSyntax; -// } -// -// if (!it->second.canModify) { -// return kPErrorSyntax; -// } -// -// // set option value -// switch (it->second.type) { -// case kConfigBool: -// *(bool*)(it->second.value) = (value == "true"); -// break; -// -// case kConfigString: -// *(PString*)it->second.value = value; -// break; -// -// case kConfigInt: -// case kConfigInt64: { -// long val = 0; -// if (Strtol(value.data(), value.size(), &val)) { -// if (it->second.type == kConfigInt) { -// *(int*)it->second.value = static_cast(val); -// } else { -// *(int64_t*)it->second.value = static_cast(val); -// } -// -// // ugly... process slow log option -// if (option.find("slowlog") == 0) { -// PSlowLog::Instance().SetThreshold(g_config.slowlogtime); -// PSlowLog::Instance().SetLogLimit(static_cast(g_config.slowlogmaxlen)); -// } -// } else { -// return kPErrorSyntax; -// } -// } -// -// break; -// -// default: -// assert(!!!"invalid type"); -// } -// -// return kPErrorOK; -// } -// -// PError config(const std::vector& params, UnboundedBuffer* reply) { -// // at least 3 params -// if (strncasecmp(params[1].c_str(), "get", 3) == 0) { -// auto res = GetConfig(params[2]); -// PreFormatMultiBulk(res.size(), reply); -// for (const auto& e : res) { -// FormatBulk(e, reply); -// } -// } else if (strncasecmp(params[1].c_str(), "set", 3) == 0) { -// if (params.size() != 4) { -// ReplyError(kPErrorParam, reply); -// return kPErrorParam; -// } -// -// auto err = SetConfig(params[2], params[3]); -// if (err == kPErrorOK) { -// FormatOK(reply); -// } else { -// const char* format = "-ERR Invalid argument '%s' for CONFIG SET '%s'\r\n"; -// char info[128]; -// auto len = snprintf(info, sizeof info, format, params[3].data(), params[2].data()); -// -// reply->PushData(info, len); -// } -// -// return err; -// } else { -// ReplyError(kPErrorSyntax, reply); -// return kPErrorSyntax; -// } -// -// return kPErrorOK; -// } -// -// } // namespace pikiwidb diff --git a/src/slow_log.cc b/src/slow_log.cc index 0c251e281..d571cf6af 100644 --- a/src/slow_log.cc +++ b/src/slow_log.cc @@ -1,8 +1,12 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implement the slow log feature. + + The slow log is responsible for recording commands that exceed the threshold time. */ #include diff --git a/src/slow_log.h b/src/slow_log.h index a95327b01..e8abfc09e 100644 --- a/src/slow_log.h +++ b/src/slow_log.h @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Declared a set of features related to the slow log. */ #pragma once diff --git a/src/store.cc b/src/store.cc index 4bbadba87..6f0500091 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implemented a set of functions and instructions for + coordinating external commands and interfacing with RocksDB. */ #include "store.h" diff --git a/src/store.h b/src/store.h index 85f76d051..4383cb392 100644 --- a/src/store.h +++ b/src/store.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Connects external commands and coordinates the operation + of RocksDB. */ #pragma once diff --git a/src/unbounded_buffer.cc b/src/unbounded_buffer.cc index 52bc99c1b..1fb4ac7da 100644 --- a/src/unbounded_buffer.cc +++ b/src/unbounded_buffer.cc @@ -1,8 +1,10 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + Implemented a dynamically expandable buffer. */ #include "unbounded_buffer.h" diff --git a/src/unbounded_buffer.h b/src/unbounded_buffer.h index 46af35767..69a8c315b 100644 --- a/src/unbounded_buffer.h +++ b/src/unbounded_buffer.h @@ -1,8 +1,11 @@ +// Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory + /* - * Copyright (c) 2023-present, OpenAtom Foundation, Inc. All rights reserved. - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + The definition part of the module that supports dynamically + expandable buffer. */ #pragma once