Skip to content

Commit

Permalink
feat(.*): improve code readable #11
Browse files Browse the repository at this point in the history
[summary]
1. NULL-->nullptr
2. namespace "DBHandler"-->"handler"
3. class TianmuHandler-->ha_tianmu
4. sdb-->tianmu
5. functions in ha_my_tianmu.cpp all renamed with prefix "ha_my_tianmu_xxx"
  • Loading branch information
hustjieke committed Oct 19, 2022
1 parent 89826cb commit 022b743
Show file tree
Hide file tree
Showing 161 changed files with 1,017 additions and 1,017 deletions.
8 changes: 4 additions & 4 deletions sql/sql_cmd_ddl_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ bool Sql_cmd_create_table::execute(THD *thd) {
else if (thd->is_strict_mode())
thd->push_internal_handler(&strict_handler);

int sdb_res = 0, free_join_from_sdb = 0, optimize_after_sdb = 0;
int tianmu_res = 0, free_join_from_tianmu = 0, optimize_after_tianmu = 0;
Query_result * result_tianmu = dynamic_cast<Query_result *>(result);
if (Tianmu::DBHandler::Tianmu_Handle_Query(thd, query_expression, result_tianmu, 0, sdb_res, optimize_after_sdb,
free_join_from_sdb, (int)true) == Tianmu::DBHandler::Query_route_to::TO_MYSQL)
if (Tianmu::handler::ha_my_tianmu_query(thd, query_expression, result_tianmu, 0, tianmu_res, optimize_after_tianmu,
free_join_from_tianmu, (int)true) == Tianmu::handler::Query_route_to::TO_MYSQL)
res = populate_table(thd, lex);
else
res = sdb_res;
res = tianmu_res;

// Count the number of statements offloaded to a secondary storage engine.
if (using_secondary_storage_engine() && lex->unit->is_executed())
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@ bool Sql_cmd_insert_values::execute_inner(THD *thd) {
if (!has_error ||
thd->get_transaction()->cannot_safely_rollback(Transaction_ctx::STMT)) {
bool tianmu_engine = insert_table->s->db_type() ? insert_table->s->db_type()->db_type == DB_TYPE_TIANMU: false;
bool tianmu_engier_insert_delayed = tianmu_engine ? Tianmu::DBHandler::Tianmu_Get_Insert_Delayed_Flag(thd): false;
if (!tianmu_engier_insert_delayed && mysql_bin_log.is_open()) {
bool if_tianmu_engine_insert_delayed = tianmu_engine ? Tianmu::handler::ha_my_tianmu_get_insert_delayed_flag(thd): false;
if (!if_tianmu_engine_insert_delayed && mysql_bin_log.is_open()) {
int errcode = 0;
if (!has_error) {
/*
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool Sql_cmd_load_table::execute_inner(THD *thd,
return true;
}
// TIANMU UPGRADE BEGIN
if (!Tianmu::DBHandler::Tianmu_Load(thd, &m_exchange, table_list,
if (!Tianmu::handler::ha_my_tianmu_load(thd, &m_exchange, table_list,
(void *)&lf_info)) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ bool Sql_cmd_dml::execute(THD *thd) {

// if is select operation, route to Tianmu
if (lex->sql_command == SQLCOM_SELECT) {
int sdb_res = 0, free_join_from_sdb = 0, optimize_after_sdb = 0;
if (Tianmu::DBHandler::Tianmu_Handle_Query(thd, unit, result, 0, sdb_res, optimize_after_sdb,
free_join_from_sdb) != Tianmu::DBHandler::Query_route_to::TO_MYSQL) {
if (sdb_res) goto err; else goto clean;
int tianmu_res = 0, free_join_from_tianmu = 0, optimize_after_tianmu = 0;
if (Tianmu::handler::ha_my_tianmu_query(thd, unit, result, 0, tianmu_res, optimize_after_tianmu,
free_join_from_tianmu) != Tianmu::handler::Query_route_to::TO_MYSQL) {
if (tianmu_res) goto err; else goto clean;
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/base/core/posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ posix_thread::~posix_thread() { assert(!_valid); }

void posix_thread::join() {
assert(_valid);
pthread_join(_pthread, NULL);
pthread_join(_pthread, nullptr);
_valid = false;
}

Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/base/core/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class file_desc {
return size_t(r);
}
void timerfd_settime(int flags, const itimerspec &its) {
auto r = ::timerfd_settime(_fd, flags, &its, NULL);
auto r = ::timerfd_settime(_fd, flags, &its, nullptr);
throw_system_error_on(r == -1, "timerfd_settime");
}

Expand Down
12 changes: 6 additions & 6 deletions storage/tianmu/base/core/reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ reactor::signals::signals() : _pending_signals(0) {}
reactor::signals::~signals() {
sigset_t mask;
sigfillset(&mask);
::pthread_sigmask(SIG_BLOCK, &mask, NULL);
::pthread_sigmask(SIG_BLOCK, &mask, nullptr);
}

reactor::signals::signal_handler::signal_handler(int signo, std::function<void()> &&handler)
Expand All @@ -158,7 +158,7 @@ reactor::signals::signal_handler::signal_handler(int signo, std::function<void()
auto r = ::sigaction(signo, &sa, nullptr);
throw_system_error_on(r == -1);
auto mask = make_sigset_mask(signo);
r = ::pthread_sigmask(SIG_UNBLOCK, &mask, NULL);
r = ::pthread_sigmask(SIG_UNBLOCK, &mask, nullptr);
throw_pthread_error(r);
}

Expand Down Expand Up @@ -221,7 +221,7 @@ static decltype(auto) install_signal_handler_stack() {
throw_system_error_on(r == -1);
return defer([mem = std::move(mem), prev_stack]() mutable {
try {
auto r = sigaltstack(&prev_stack, NULL);
auto r = sigaltstack(&prev_stack, nullptr);
throw_system_error_on(r == -1);
} catch (...) {
mem.release(); // We failed to restore previous stack, must leak it.
Expand Down Expand Up @@ -309,7 +309,7 @@ reactor::reactor(unsigned id)
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, alarm_signal());
r = ::pthread_sigmask(SIG_BLOCK, &mask, NULL);
r = ::pthread_sigmask(SIG_BLOCK, &mask, nullptr);
assert(r == 0);
struct sigevent sev;
sev.sigev_notify = SIGEV_THREAD_ID;
Expand Down Expand Up @@ -786,7 +786,7 @@ void reactor::enable_timer(steady_clock_type::time_point when) {
itimerspec its;
its.it_interval = to_timespec(when);
its.it_value = to_timespec(when);
auto ret = timer_settime(_steady_clock_timer, TIMER_ABSTIME, &its, NULL);
auto ret = timer_settime(_steady_clock_timer, TIMER_ABSTIME, &its, nullptr);
throw_system_error_on(ret == -1);
}

Expand Down Expand Up @@ -2142,7 +2142,7 @@ void smp::configure(const options &opt) {
for (auto sig : {SIGSEGV}) {
sigdelset(&mask, sig);
}
auto r = ::pthread_sigmask(SIG_BLOCK, &mask, NULL);
auto r = ::pthread_sigmask(SIG_BLOCK, &mask, nullptr);
throw_pthread_error(r);
allocate_reactor(i);
_reactors[i] = &engine();
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/base/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ using intmax_t = __int64;
#if FMT_HAS_FEATURE(cxx_nullptr) || (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600
#define FMT_NULL nullptr
#else
#define FMT_NULL NULL
#define FMT_NULL nullptr
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/common/txt_data_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ uint TxtDataFormat::StaticExtrnalSize(CT attrt, uint precision, int scale, const
return 23;
else if (attrt == CT::FLOAT)
return 15;
if (col == NULL)
if (col == nullptr)
return precision;
else
return precision / col->collation->mbmaxlen; // at creation, the charlen was multiplicated by
Expand Down
4 changes: 2 additions & 2 deletions storage/tianmu/compress/data_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class DataStream {
pos = pos_;
}

DataStream() : buf(NULL) { Reset(0, 0, 0); }
DataStream(char *buf_, uint len_, uint pos_ = 0) : buf(NULL) { Reset(buf_, len_, pos_); }
DataStream() : buf(nullptr) { Reset(0, 0, 0); }
DataStream(char *buf_, uint len_, uint pos_ = 0) : buf(nullptr) { Reset(buf_, len_, pos_); }
virtual ~DataStream() {}
char *GetBuf() { return (char *)buf; }
uint GetPos() { return pos; }
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/compress/inc_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class IncAlloc {
struct Block {
void *mem;
uint size;
Block() : mem(NULL), size(0) {}
Block() : mem(nullptr), size(0) {}
Block(void *m, uint s) : mem(m), size(s) {}
};

Expand Down
14 changes: 7 additions & 7 deletions storage/tianmu/compress/inc_wgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ const uint IncWGraph::MatchLenCoder::c2[] = {120, 128};
const uint IncWGraph::MatchLenCoder::c3[] = {102, 119, 128};

IncWGraph::IncWGraph() : memory() {
dump = NULL;
ROOT = NIL = START = NULL;
mask = NULL;
coder = NULL;
reclen = NULL;
records = NULL;
dump = nullptr;
ROOT = NIL = START = nullptr;
mask = nullptr;
coder = nullptr;
reclen = nullptr;
records = nullptr;
}

void IncWGraph::Init() {
nfinals = 0;
matchlen_cost = esc_cost = 0;
// mask = &_mask_; // uncomment if masking should be used
mask = NULL;
mask = nullptr;

// create ROOT and NIL nodes (and START)
memory.alloc(ROOT);
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/compress/num_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ inline CprsErr NumDecompress(T *dest, char *src, uint len, uint nrec, uint64_t m

template <class T>
NumCompressor<T>::NumCompressor(bool copy_only) : copy_only(copy_only) {
dump = NULL;
dump = nullptr;

// Create filters
filters.reserve(NFILTERS);
Expand Down
20 changes: 10 additions & 10 deletions storage/tianmu/compress/ppm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
namespace Tianmu {
namespace compress {

FILE *PPM::dump = NULL;
FILE *PPM::dump = nullptr;
bool PPM::printstat = false;

PPM::PPM(const Symb *data, int dlen, ModelType mt, PPMParam param, uchar method) {
if ((data == NULL) || (dlen <= 0) || (mt == ModelType::ModelNull)) return;
if ((data == nullptr) || (dlen <= 0) || (mt == ModelType::ModelNull)) return;

switch (mt) {
case ModelType::ModelSufTree:
Expand Down Expand Up @@ -60,11 +60,11 @@ CprsErr PPM::CompressArith(char *dest, int &dlen, Symb *src, int slen) {
dlen = slen + 1;
return CprsErr::CPRS_SUCCESS;
}
WordGraph *wg = NULL;
WordGraph *wg = nullptr;
try {
wg = dynamic_cast<WordGraph *>(model.get());
} catch (...) {
wg = NULL;
wg = nullptr;
}
if (wg) ASSERT(wg->insatend == false, "should be 'wg->insatend == false'");

Expand Down Expand Up @@ -167,11 +167,11 @@ CprsErr PPM::DecompressArith(Symb *dest, int dlen, char *src, int slen) {
//}
// if(method != 1) return CprsErr::CPRS_ERR_VER;

WordGraph *wg = NULL;
WordGraph *wg = nullptr;
try {
wg = dynamic_cast<WordGraph *>(model.get());
} catch (...) {
wg = NULL;
wg = nullptr;
}
if (wg) ASSERT(wg->insatend == false, "should be 'wg->insatend == false'");

Expand Down Expand Up @@ -246,11 +246,11 @@ CprsErr PPM::Compress(char *dest, int &dlen, Symb *src, int slen) {
if (dlen < 1) return CprsErr::CPRS_ERR_BUF;
dest[0] = 2; // compression method: with RangeCoder

WordGraph *wg = NULL;
WordGraph *wg = nullptr;
try {
wg = dynamic_cast<WordGraph *>(model.get());
} catch (...) {
wg = NULL;
wg = nullptr;
}

if (wg) ASSERT(wg->insatend, "'wg->insatend' should be true");
Expand Down Expand Up @@ -310,11 +310,11 @@ CprsErr PPM::Decompress(Symb *dest, int dlen, char *src, int slen) {
return DecompressArith(dest, dlen, src, slen);
if (method != 2) return CprsErr::CPRS_ERR_VER;

WordGraph *wg = NULL;
WordGraph *wg = nullptr;
try {
wg = dynamic_cast<WordGraph *>(model.get());
} catch (...) {
wg = NULL;
wg = nullptr;
}

if (wg) ASSERT(wg->insatend, "'wg->insatend' should be true");
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/compress/ppm.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PPM {
static FILE *dump;
static bool printstat;

// if data=NULL or dlen=0, the model will be null - compression will simply
// if data=nullptr or dlen=0, the model will be null - compression will simply
// copy the data; 'method' - which version of compression will be used in
// Compress/Decompress
PPM(const Symb *data, int dlen, ModelType mt, PPMParam param = PPMParam(), uchar method = 2);
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/compress/ppm_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PPMModel {
// file for making logs during compression or decompression
FILE *logfile;

PPMModel() : logfile(NULL) {}
PPMModel() : logfile(nullptr) {}
virtual ~PPMModel() {}
};

Expand Down
4 changes: 2 additions & 2 deletions storage/tianmu/compress/text_compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ CprsErr TextCompressor::DecompressCopy(char *dest, int dlen, char *src, [[maybe_
//---------------------------------------------------------------------------------------------------------

CprsErr TextCompressor::CompressPlain(char *dest, int &dlen, char *src, int slen, int ver, int lev) {
if ((dest == NULL) || (src == NULL) || (dlen <= 0) || (slen <= 0)) return CprsErr::CPRS_ERR_PAR;
if ((dest == nullptr) || (src == nullptr) || (dlen <= 0) || (slen <= 0)) return CprsErr::CPRS_ERR_PAR;
if ((ver < 0) || (ver > 2) || (lev < 1) || (lev > 9)) return CprsErr::CPRS_ERR_VER;

if (ver == 0) return CompressCopy(dest, dlen, src, slen);
Expand Down Expand Up @@ -172,7 +172,7 @@ CprsErr TextCompressor::CompressPlain(char *dest, int &dlen, char *src, int slen
}

CprsErr TextCompressor::DecompressPlain(char *dest, int dlen, char *src, int slen) {
if ((dest == NULL) || (src == NULL) || (dlen <= 0) || (slen <= 0)) return CprsErr::CPRS_ERR_PAR;
if ((dest == nullptr) || (src == nullptr) || (dlen <= 0) || (slen <= 0)) return CprsErr::CPRS_ERR_PAR;
if (slen < 2) return CprsErr::CPRS_ERR_BUF;

char ver = src[0], lev = (ver > 0) ? src[1] : 1;
Expand Down
8 changes: 4 additions & 4 deletions storage/tianmu/compress/word_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ WordGraph::WordGraph(const Symb *data_, int dlen_, bool insatend_) {
}

void WordGraph::Init() {
data = NULL;
data = nullptr;
dlen = -1;
// NIL = 0; ROOT = 1;
// nleaves = 0;
Expand All @@ -64,7 +64,7 @@ void WordGraph::Init() {
// iscreating = false;
// for(int i = 0; i < 256; i++)
// nodes[NIL].child[i] = ROOT;
// lens = NULL;
// lens = nullptr;
}

void WordGraph::Create() {
Expand Down Expand Up @@ -284,7 +284,7 @@ void WordGraph::Clear() {
finals.clear();
edges.clear();
nodes.clear();
data = NULL;
data = nullptr;
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -729,7 +729,7 @@ void WordGraph::Move(PEdge e) {
}

void WordGraph::MakeLog(PNode stt, PEdge e) {
if (logfile == NULL) return;
if (logfile == nullptr) return;
// if(e != ENIL) {
// std::fprintf(logfile, "F\n"); // forward transition
// return;
Expand Down
6 changes: 3 additions & 3 deletions storage/tianmu/core/aggregation_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void AggregationAlgorithm::Aggregate(bool just_distinct, int64_t &limit, int64_t
continue;
}
if ((!just_distinct && cur_a.mode != common::ColOperation::GROUP_BY) || // aggregation
(just_distinct && cur_a.alias == NULL)) { // special case: hidden column for DISTINCT
(just_distinct && cur_a.alias == nullptr)) { // special case: hidden column for DISTINCT
bool already_added = false;
for (uint j = 0; j < i; j++) {
if (*(t->GetAttrP(j)) == cur_a) {
Expand Down Expand Up @@ -178,7 +178,7 @@ void AggregationAlgorithm::Aggregate(bool just_distinct, int64_t &limit, int64_t
}

if (all_done_in_one_row) {
for (uint i = 0; i < t->NumOfAttrs(); i++) { // left as uninitialized (NULL or 0)
for (uint i = 0; i < t->NumOfAttrs(); i++) { // left as uninitialized (nullptr or 0)
t->GetAttrP(i)->page_size = 1;
t->GetAttrP(i)->CreateBuffer(1);
}
Expand Down Expand Up @@ -263,7 +263,7 @@ void AggregationAlgorithm::MultiDimensionalGroupByScan(GroupByWrapper &gbw, int6
mit.Rewind(); // aggregated rows will be massively omitted packrow by
// packrow
rewind_needed = true;
for (uint i = 0; i < t->NumOfAttrs(); i++) { // left as uninitialized (NULL or 0)
for (uint i = 0; i < t->NumOfAttrs(); i++) { // left as uninitialized (nullptr or 0)
if (t->GetAttrP(i)->mode == common::ColOperation::DELAYED) {
MIDummyIterator m(1);
t->GetAttrP(i)->term.vc->LockSourcePacks(m);
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/aggregator_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void AggregatorGroupConcat::PutAggregatedValue(unsigned char *buf, const types::
types::BString AggregatorGroupConcat::GetValueT(unsigned char *buf) {
auto it = lenmap.find(buf);
if (it == lenmap.end()) {
// cases that grouping value is NULL
// cases that grouping value is nullptr
return types::BString();
}

Expand Down
Loading

0 comments on commit 022b743

Please sign in to comment.