From d8936304996baa21e2ccd96c034d4f9c06b4ff6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=BF=90=E6=9D=A5?= Date: Tue, 14 Nov 2023 16:47:51 +0800 Subject: [PATCH] clang-format --- .scanignore | 1 + src/observer/common/global_context.cpp | 5 +- src/observer/common/global_context.h | 4 +- src/observer/common/init.cpp | 75 +++++++---------- src/observer/common/init.h | 4 +- src/observer/common/rc.h | 108 ++++++++++++------------- src/observer/common/types.h | 1 - src/observer/main.cpp | 83 ++++++++----------- 8 files changed, 123 insertions(+), 158 deletions(-) create mode 100644 .scanignore diff --git a/.scanignore b/.scanignore new file mode 100644 index 000000000..020c92722 --- /dev/null +++ b/.scanignore @@ -0,0 +1 @@ +docker/bin/starter-code.sh diff --git a/src/observer/common/global_context.cpp b/src/observer/common/global_context.cpp index 4931a746b..da7120188 100644 --- a/src/observer/common/global_context.cpp +++ b/src/observer/common/global_context.cpp @@ -16,7 +16,4 @@ See the Mulan PSL v2 for more details. */ static GlobalContext global_context; -GlobalContext &GlobalContext::instance() -{ - return global_context; -} +GlobalContext &GlobalContext::instance() { return global_context; } diff --git a/src/observer/common/global_context.h b/src/observer/common/global_context.h index 6b5920f74..6cbde4d75 100644 --- a/src/observer/common/global_context.h +++ b/src/observer/common/global_context.h @@ -25,8 +25,8 @@ class TrxKit; struct GlobalContext { BufferPoolManager *buffer_pool_manager_ = nullptr; - DefaultHandler *handler_ = nullptr; - TrxKit *trx_kit_ = nullptr; + DefaultHandler *handler_ = nullptr; + TrxKit *trx_kit_ = nullptr; static GlobalContext &instance(); }; diff --git a/src/observer/common/init.cpp b/src/observer/common/init.cpp index a82666ac5..4d4c1dfdc 100644 --- a/src/observer/common/init.cpp +++ b/src/observer/common/init.cpp @@ -14,7 +14,6 @@ See the Mulan PSL v2 for more details. */ #include "common/init.h" -#include "common/ini_setting.h" #include "common/conf/ini.h" #include "common/lang/string.h" #include "common/log/log.h" @@ -24,38 +23,27 @@ See the Mulan PSL v2 for more details. */ #include "common/os/signal.h" #include "common/seda/init.h" #include "common/seda/stage_factory.h" +#include "global_context.h" #include "session/session.h" #include "session/session_stage.h" -#include "sql/executor/execute_stage.h" -#include "sql/optimizer/optimize_stage.h" -#include "sql/parser/parse_stage.h" -#include "sql/parser/resolve_stage.h" #include "sql/plan_cache/plan_cache_stage.h" -#include "sql/query_cache/query_cache_stage.h" #include "storage/buffer/disk_buffer_pool.h" #include "storage/default/default_handler.h" #include "storage/trx/trx.h" -#include "global_context.h" +using namespace std; using namespace common; bool *&_get_init() { - static bool util_init = false; + static bool util_init = false; static bool *util_init_p = &util_init; return util_init_p; } -bool get_init() -{ - return *_get_init(); -} +bool get_init() { return *_get_init(); } -void set_init(bool value) -{ - *_get_init() = value; - return; -} +void set_init(bool value) { *_get_init() = value; } void sig_handler(int sig) { @@ -63,13 +51,11 @@ void sig_handler(int sig) // Add action to shutdown LOG_INFO("Receive one signal of %d.", sig); - - return; } int init_log(ProcessParam *process_cfg, Ini &properties) { - const std::string &proc_name = process_cfg->get_process_name(); + const string &proc_name = process_cfg->get_process_name(); try { // we had better alloc one lock to do so, but simplify the logic if (g_log) { @@ -78,17 +64,18 @@ int init_log(ProcessParam *process_cfg, Ini &properties) auto log_context_getter = []() { return reinterpret_cast(Session::current_session()); }; - const std::string log_section_name = "LOG"; - std::map log_section = properties.get(log_section_name); + const string log_section_name = "LOG"; + map log_section = properties.get(log_section_name); - std::string log_file_name; + string log_file_name; // get log file name - std::string key = "LOG_FILE_NAME"; - std::map::iterator it = log_section.find(key); + string key = "LOG_FILE_NAME"; + + map::iterator it = log_section.find(key); if (it == log_section.end()) { log_file_name = proc_name + ".log"; - std::cout << "Not set log file name, use default " << log_file_name << std::endl; + cout << "Not set log file name, use default " << log_file_name << endl; } else { log_file_name = it->second; } @@ -96,8 +83,8 @@ int init_log(ProcessParam *process_cfg, Ini &properties) log_file_name = getAboslutPath(log_file_name.c_str()); LOG_LEVEL log_level = LOG_LEVEL_INFO; - key = ("LOG_FILE_LEVEL"); - it = log_section.find(key); + key = ("LOG_FILE_LEVEL"); + it = log_section.find(key); if (it != log_section.end()) { int log = (int)log_level; str_to_val(it->second, log); @@ -105,8 +92,8 @@ int init_log(ProcessParam *process_cfg, Ini &properties) } LOG_LEVEL console_level = LOG_LEVEL_INFO; - key = ("LOG_CONSOLE_LEVEL"); - it = log_section.find(key); + key = ("LOG_CONSOLE_LEVEL"); + it = log_section.find(key); if (it != log_section.end()) { int log = (int)console_level; str_to_val(it->second, log); @@ -117,7 +104,7 @@ int init_log(ProcessParam *process_cfg, Ini &properties) g_log->set_context_getter(log_context_getter); key = ("DefaultLogModules"); - it = log_section.find(key); + it = log_section.find(key); if (it != log_section.end()) { g_log->set_default_module(it->second); } @@ -127,8 +114,8 @@ int init_log(ProcessParam *process_cfg, Ini &properties) } return 0; - } catch (std::exception &e) { - std::cerr << "Failed to init log for " << proc_name << SYS_OUTPUT_FILE_POS << SYS_OUTPUT_ERROR << std::endl; + } catch (exception &e) { + cerr << "Failed to init log for " << proc_name << SYS_OUTPUT_FILE_POS << SYS_OUTPUT_ERROR << endl; return errno; } @@ -142,7 +129,6 @@ void cleanup_log() delete g_log; g_log = nullptr; } - return; } int prepare_init_seda() @@ -157,11 +143,11 @@ int init_global_objects(ProcessParam *process_param, Ini &properties) BufferPoolManager::set_instance(GCTX.buffer_pool_manager_); GCTX.handler_ = new DefaultHandler(); - + DefaultHandler::set_default(GCTX.handler_); int ret = 0; - RC rc = TrxKit::init_global(process_param->trx_kit_name().c_str()); + RC rc = TrxKit::init_global(process_param->trx_kit_name().c_str()); if (rc != RC::SUCCESS) { LOG_ERROR("failed to init trx kit. rc=%s", strrc(rc)); ret = -1; @@ -196,7 +182,6 @@ int uninit_global_objects() int init(ProcessParam *process_param) { if (get_init()) { - return 0; } @@ -207,7 +192,7 @@ int init(ProcessParam *process_param) if (process_param->is_demon()) { rc = daemonize_service(process_param->get_std_out().c_str(), process_param->get_std_err().c_str()); if (rc != 0) { - std::cerr << "Shutdown due to failed to daemon current process!" << std::endl; + cerr << "Shutdown due to failed to daemon current process!" << endl; return rc; } } @@ -220,18 +205,18 @@ int init(ProcessParam *process_param) // Read Configuration files rc = get_properties()->load(process_param->get_conf()); if (rc) { - std::cerr << "Failed to load configuration files" << std::endl; + cerr << "Failed to load configuration files" << endl; return rc; } // Init tracer rc = init_log(process_param, *get_properties()); if (rc) { - std::cerr << "Failed to init Log" << std::endl; + cerr << "Failed to init Log" << endl; return rc; } - std::string conf_data; + string conf_data; get_properties()->to_string(conf_data); LOG_INFO("Output configuration \n%s", conf_data.c_str()); @@ -266,7 +251,7 @@ int init(ProcessParam *process_param) void cleanup_util() { uninit_global_objects(); - + if (nullptr != get_properties()) { delete get_properties(); get_properties() = nullptr; @@ -278,10 +263,6 @@ void cleanup_util() cleanup_log(); set_init(false); - return; } -void cleanup() -{ - cleanup_util(); -} +void cleanup() { cleanup_util(); } diff --git a/src/observer/common/init.h b/src/observer/common/init.h index 2993b238b..466415dbd 100644 --- a/src/observer/common/init.h +++ b/src/observer/common/init.h @@ -14,8 +14,8 @@ See the Mulan PSL v2 for more details. */ #pragma once -#include "common/os/process_param.h" #include "common/conf/ini.h" +#include "common/os/process_param.h" -int init(common::ProcessParam *processParam); +int init(common::ProcessParam *processParam); void cleanup(); diff --git a/src/observer/common/rc.h b/src/observer/common/rc.h index 9acc27651..ab58d9fe3 100644 --- a/src/observer/common/rc.h +++ b/src/observer/common/rc.h @@ -19,60 +19,60 @@ See the Mulan PSL v2 for more details. */ * @enum RC */ -#define DEFINE_RCS \ - DEFINE_RC(SUCCESS) \ - DEFINE_RC(INVALID_ARGUMENT) \ - DEFINE_RC(UNIMPLENMENT) \ - DEFINE_RC(SQL_SYNTAX) \ - DEFINE_RC(INTERNAL) \ - DEFINE_RC(NOMEM) \ - DEFINE_RC(NOTFOUND) \ - DEFINE_RC(EMPTY) \ - DEFINE_RC(BUFFERPOOL_OPEN) \ - DEFINE_RC(BUFFERPOOL_NOBUF) \ - DEFINE_RC(BUFFERPOOL_INVALID_PAGE_NUM) \ - DEFINE_RC(RECORD_OPENNED) \ - DEFINE_RC(RECORD_INVALID_RID) \ - DEFINE_RC(RECORD_INVALID_KEY) \ - DEFINE_RC(RECORD_DUPLICATE_KEY) \ - DEFINE_RC(RECORD_NOMEM) \ - DEFINE_RC(RECORD_EOF) \ - DEFINE_RC(RECORD_NOT_EXIST) \ - DEFINE_RC(RECORD_INVISIBLE) \ - DEFINE_RC(SCHEMA_DB_EXIST) \ - DEFINE_RC(SCHEMA_DB_NOT_EXIST) \ - DEFINE_RC(SCHEMA_DB_NOT_OPENED) \ - DEFINE_RC(SCHEMA_TABLE_NOT_EXIST) \ - DEFINE_RC(SCHEMA_TABLE_EXIST) \ - DEFINE_RC(SCHEMA_FIELD_NOT_EXIST) \ - DEFINE_RC(SCHEMA_FIELD_MISSING) \ - DEFINE_RC(SCHEMA_FIELD_TYPE_MISMATCH) \ - DEFINE_RC(SCHEMA_INDEX_NAME_REPEAT) \ - DEFINE_RC(IOERR_READ) \ - DEFINE_RC(IOERR_WRITE) \ - DEFINE_RC(IOERR_ACCESS) \ - DEFINE_RC(IOERR_OPEN) \ - DEFINE_RC(IOERR_CLOSE) \ - DEFINE_RC(IOERR_SEEK) \ - DEFINE_RC(IOERR_TOO_LONG) \ - DEFINE_RC(IOERR_SYNC) \ - DEFINE_RC(LOCKED_UNLOCK) \ - DEFINE_RC(LOCKED_NEED_WAIT) \ - DEFINE_RC(LOCKED_CONCURRENCY_CONFLICT) \ - DEFINE_RC(FILE_EXIST) \ - DEFINE_RC(FILE_NOT_EXIST) \ - DEFINE_RC(FILE_NAME) \ - DEFINE_RC(FILE_BOUND) \ - DEFINE_RC(FILE_CREATE) \ - DEFINE_RC(FILE_OPEN) \ - DEFINE_RC(FILE_NOT_OPENED) \ - DEFINE_RC(FILE_CLOSE) \ - DEFINE_RC(FILE_REMOVE) \ - DEFINE_RC(FILE_SEEK) \ - DEFINE_RC(FILE_READ) \ - DEFINE_RC(FILE_WRITE) \ - DEFINE_RC(VARIABLE_NOT_EXISTS) \ - DEFINE_RC(VARIABLE_NOT_VALID) \ +#define DEFINE_RCS \ + DEFINE_RC(SUCCESS) \ + DEFINE_RC(INVALID_ARGUMENT) \ + DEFINE_RC(UNIMPLENMENT) \ + DEFINE_RC(SQL_SYNTAX) \ + DEFINE_RC(INTERNAL) \ + DEFINE_RC(NOMEM) \ + DEFINE_RC(NOTFOUND) \ + DEFINE_RC(EMPTY) \ + DEFINE_RC(BUFFERPOOL_OPEN) \ + DEFINE_RC(BUFFERPOOL_NOBUF) \ + DEFINE_RC(BUFFERPOOL_INVALID_PAGE_NUM) \ + DEFINE_RC(RECORD_OPENNED) \ + DEFINE_RC(RECORD_INVALID_RID) \ + DEFINE_RC(RECORD_INVALID_KEY) \ + DEFINE_RC(RECORD_DUPLICATE_KEY) \ + DEFINE_RC(RECORD_NOMEM) \ + DEFINE_RC(RECORD_EOF) \ + DEFINE_RC(RECORD_NOT_EXIST) \ + DEFINE_RC(RECORD_INVISIBLE) \ + DEFINE_RC(SCHEMA_DB_EXIST) \ + DEFINE_RC(SCHEMA_DB_NOT_EXIST) \ + DEFINE_RC(SCHEMA_DB_NOT_OPENED) \ + DEFINE_RC(SCHEMA_TABLE_NOT_EXIST) \ + DEFINE_RC(SCHEMA_TABLE_EXIST) \ + DEFINE_RC(SCHEMA_FIELD_NOT_EXIST) \ + DEFINE_RC(SCHEMA_FIELD_MISSING) \ + DEFINE_RC(SCHEMA_FIELD_TYPE_MISMATCH) \ + DEFINE_RC(SCHEMA_INDEX_NAME_REPEAT) \ + DEFINE_RC(IOERR_READ) \ + DEFINE_RC(IOERR_WRITE) \ + DEFINE_RC(IOERR_ACCESS) \ + DEFINE_RC(IOERR_OPEN) \ + DEFINE_RC(IOERR_CLOSE) \ + DEFINE_RC(IOERR_SEEK) \ + DEFINE_RC(IOERR_TOO_LONG) \ + DEFINE_RC(IOERR_SYNC) \ + DEFINE_RC(LOCKED_UNLOCK) \ + DEFINE_RC(LOCKED_NEED_WAIT) \ + DEFINE_RC(LOCKED_CONCURRENCY_CONFLICT) \ + DEFINE_RC(FILE_EXIST) \ + DEFINE_RC(FILE_NOT_EXIST) \ + DEFINE_RC(FILE_NAME) \ + DEFINE_RC(FILE_BOUND) \ + DEFINE_RC(FILE_CREATE) \ + DEFINE_RC(FILE_OPEN) \ + DEFINE_RC(FILE_NOT_OPENED) \ + DEFINE_RC(FILE_CLOSE) \ + DEFINE_RC(FILE_REMOVE) \ + DEFINE_RC(FILE_SEEK) \ + DEFINE_RC(FILE_READ) \ + DEFINE_RC(FILE_WRITE) \ + DEFINE_RC(VARIABLE_NOT_EXISTS) \ + DEFINE_RC(VARIABLE_NOT_VALID) \ DEFINE_RC(LOGBUF_FULL) enum class RC diff --git a/src/observer/common/types.h b/src/observer/common/types.h index 286064718..b3b6306dd 100644 --- a/src/observer/common/types.h +++ b/src/observer/common/types.h @@ -14,7 +14,6 @@ See the Mulan PSL v2 for more details. */ #pragma once - /// 磁盘文件,包括存放数据的文件和索引(B+-Tree)文件,都按照页来组织 /// 每一页都有一个编号,称为PageNum using PageNum = int32_t; diff --git a/src/observer/main.cpp b/src/observer/main.cpp index a0a7def56..e91edbd50 100644 --- a/src/observer/main.cpp +++ b/src/observer/main.cpp @@ -15,18 +15,19 @@ See the Mulan PSL v2 for more details. */ * Author: Longda Feng */ +#include #include #include -#include -#include "common/init.h" #include "common/ini_setting.h" +#include "common/init.h" +#include "common/lang/string.h" #include "common/os/process.h" #include "common/os/signal.h" -#include "common/lang/string.h" #include "net/server.h" #include "net/server_param.h" +using namespace std; using namespace common; #define NET "NET" @@ -35,59 +36,41 @@ static Server *g_server = nullptr; void usage() { - std::cout << "Useage " << std::endl; - std::cout << "-p: server port. if not specified, the item in the config file will be used" << std::endl; - std::cout << "-f: path of config file." << std::endl; - std::cout << "-s: use unix socket and the argument is socket address" << std::endl; - std::cout << "-P: protocol. {plain(default), mysql, cli}." << std::endl; - std::cout << "-t: transaction model. {vacuous(default), mvcc}." << std::endl; - std::cout << "-n: buffer pool memory size in byte" << std::endl; + cout << "Useage " << endl; + cout << "-p: server port. if not specified, the item in the config file will be used" << endl; + cout << "-f: path of config file." << endl; + cout << "-s: use unix socket and the argument is socket address" << endl; + cout << "-P: protocol. {plain(default), mysql, cli}." << endl; + cout << "-t: transaction model. {vacuous(default), mvcc}." << endl; + cout << "-n: buffer pool memory size in byte" << endl; } void parse_parameter(int argc, char **argv) { - std::string process_name = get_process_name(argv[0]); + string process_name = get_process_name(argv[0]); ProcessParam *process_param = the_process_param(); process_param->init_default(process_name); // Process args - int opt; + int opt; extern char *optarg; while ((opt = getopt(argc, argv, "dp:P:s:t:f:o:e:hn:")) > 0) { switch (opt) { - case 's': - process_param->set_unix_socket_path(optarg); - break; - case 'p': - process_param->set_server_port(atoi(optarg)); - break; - case 'P': - process_param->set_protocol(optarg); - break; - case 'f': - process_param->set_conf(optarg); - break; - case 'o': - process_param->set_std_out(optarg); - break; - case 'e': - process_param->set_std_err(optarg); - break; - case 't': - process_param->set_trx_kit_name(optarg); - break; - case 'n': - process_param->set_buffer_pool_memory_size(atoi(optarg)); - break; + case 's': process_param->set_unix_socket_path(optarg); break; + case 'p': process_param->set_server_port(atoi(optarg)); break; + case 'P': process_param->set_protocol(optarg); break; + case 'f': process_param->set_conf(optarg); break; + case 'o': process_param->set_std_out(optarg); break; + case 'e': process_param->set_std_err(optarg); break; + case 't': process_param->set_trx_kit_name(optarg); break; + case 'n': process_param->set_buffer_pool_memory_size(atoi(optarg)); break; case 'h': usage(); exit(0); return; - default: - std::cout << "Unknown option: " << static_cast(opt) << ", ignored" << std::endl; - break; + default: cout << "Unknown option: " << static_cast(opt) << ", ignored" << endl; break; } } } @@ -98,9 +81,9 @@ Server *init_server() ProcessParam *process_param = the_process_param(); - long listen_addr = INADDR_ANY; + long listen_addr = INADDR_ANY; long max_connection_num = MAX_CONNECTION_NUM_DEFAULT; - int port = PORT_DEFAULT; + int port = PORT_DEFAULT; std::map::iterator it = net_section.find(CLIENT_ADDRESS); if (it != net_section.end()) { @@ -126,20 +109,20 @@ Server *init_server() } ServerParam server_param; - server_param.listen_addr = listen_addr; + server_param.listen_addr = listen_addr; server_param.max_connection_num = max_connection_num; - server_param.port = port; + server_param.port = port; if (0 == strcasecmp(process_param->get_protocol().c_str(), "mysql")) { server_param.protocol = CommunicateProtocol::MYSQL; } else if (0 == strcasecmp(process_param->get_protocol().c_str(), "cli")) { server_param.use_std_io = true; - server_param.protocol = CommunicateProtocol::CLI; + server_param.protocol = CommunicateProtocol::CLI; } else { server_param.protocol = CommunicateProtocol::PLAIN; } if (process_param->get_unix_socket_path().size() > 0 && !server_param.use_std_io) { - server_param.use_unix_socket = true; + server_param.use_unix_socket = true; server_param.unix_socket_path = process_param->get_unix_socket_path(); } @@ -177,7 +160,7 @@ int main(int argc, char **argv) rc = init(the_process_param()); if (rc != STATUS_SUCCESS) { - std::cerr << "Shutdown due to failed to init!" << std::endl; + std::cerr << "Shutdown due to failed to init!" << endl; cleanup(); return rc; } @@ -195,8 +178,12 @@ int main(int argc, char **argv) /** * @mainpage MiniOB - * + * * MiniOB 是 OceanBase 与华中科技大学联合开发的、面向"零"基础同学的数据库入门学习项目。 * - * MiniOB 设计的目标是面向在校学生、数据库从业者、爱好者,或者对基础技术有兴趣的爱好者, 整体代码量少,易于上手并学习, 是一个系统性的数据库学习项目。miniob 设置了一系列由浅入深的题目,以帮助同学们"零"基础入门, 让同学们快速了解数据库并深入学习数据库内核,期望通过相关训练之后,能够熟练掌握数据库内核模块的功能与协同关系, 并能够在使用数据库时,设计出高效的 SQL 。miniob 为了更好的学习数据库实现原理, 对诸多模块都做了简化,比如不考虑并发操作, 安全特性, 复杂的事物管理等功能。 + * MiniOB 设计的目标是面向在校学生、数据库从业者、爱好者,或者对基础技术有兴趣的爱好者, 整体代码量少,易于上手并学习, + * 是一个系统性的数据库学习项目。miniob 设置了一系列由浅入深的题目,以帮助同学们"零"基础入门, + * 让同学们快速了解数据库并深入学习数据库内核,期望通过相关训练之后,能够熟练掌握数据库内核模块的功能与协同关系, + * 并能够在使用数据库时,设计出高效的 SQL 。miniob 为了更好的学习数据库实现原理, + * 对诸多模块都做了简化,比如不考虑并发操作, 安全特性, 复杂的事物管理等功能。 */