Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
hnwyllmm committed Nov 14, 2023
1 parent 98707ed commit d893630
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 158 deletions.
1 change: 1 addition & 0 deletions .scanignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker/bin/starter-code.sh
5 changes: 1 addition & 4 deletions src/observer/common/global_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
4 changes: 2 additions & 2 deletions src/observer/common/global_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
75 changes: 28 additions & 47 deletions src/observer/common/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,52 +23,39 @@ 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)
{
// Signal handler will be add in the next step.
// 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) {
Expand All @@ -78,35 +64,36 @@ int init_log(ProcessParam *process_cfg, Ini &properties)

auto log_context_getter = []() { return reinterpret_cast<intptr_t>(Session::current_session()); };

const std::string log_section_name = "LOG";
std::map<std::string, std::string> log_section = properties.get(log_section_name);
const string log_section_name = "LOG";
map<string, string> 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<std::string, std::string>::iterator it = log_section.find(key);
string key = "LOG_FILE_NAME";

map<string, string>::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;
}

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);
log_level = (LOG_LEVEL)log;
}

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);
Expand All @@ -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);
}
Expand All @@ -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;
}

Expand All @@ -142,7 +129,6 @@ void cleanup_log()
delete g_log;
g_log = nullptr;
}
return;
}

int prepare_init_seda()
Expand All @@ -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;
Expand Down Expand Up @@ -196,7 +182,6 @@ int uninit_global_objects()
int init(ProcessParam *process_param)
{
if (get_init()) {

return 0;
}

Expand All @@ -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;
}
}
Expand All @@ -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());

Expand Down Expand Up @@ -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;
Expand All @@ -278,10 +263,6 @@ void cleanup_util()
cleanup_log();

set_init(false);
return;
}

void cleanup()
{
cleanup_util();
}
void cleanup() { cleanup_util(); }
4 changes: 2 additions & 2 deletions src/observer/common/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
108 changes: 54 additions & 54 deletions src/observer/common/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/observer/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the Mulan PSL v2 for more details. */

#pragma once


/// 磁盘文件,包括存放数据的文件和索引(B+-Tree)文件,都按照页来组织
/// 每一页都有一个编号,称为PageNum
using PageNum = int32_t;
Expand Down
Loading

0 comments on commit d893630

Please sign in to comment.