Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #195

Merged
merged 9 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion benchmark/bplus_tree_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ See the Mulan PSL v2 for more details. */

#include "storage/index/bplus_tree.h"
#include "storage/default/disk_buffer_pool.h"
#include "rc.h"
#include "common/log/log.h"
#include "integer_generator.h"

Expand Down
1 change: 0 additions & 1 deletion benchmark/record_manager_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ See the Mulan PSL v2 for more details. */
#include "storage/default/disk_buffer_pool.h"
#include "storage/common/condition_filter.h"
#include "storage/trx/vacuous_trx.h"
#include "rc.h"
#include "common/log/log.h"
#include "integer_generator.h"

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function do_init
git checkout release-2.1.12-stable && \
mkdir -p build && \
cd build && \
cmake .. -DEVENT__DISABLE_OPENSSL=ON && \
cmake .. -DEVENT__DISABLE_OPENSSL=ON -DEVENT__LIBRARY_TYPE=BOTH && \
make -j4 && \
make install

Expand Down
25 changes: 3 additions & 22 deletions deps/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@

PROJECT(common)
MESSAGE("Begin to build " ${PROJECT_NAME})
MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR})
MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR})

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/..)
#find_file() 只会找一个文件
#AUX_SOURCE_DIRECTORY(. SRC_LIST)
#FOREACH(F ${SRC_LIST})
# MESSAGE(${F})
#ENDFOREACH(F)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/deps)

FILE(GLOB_RECURSE ALL_SRC *.cpp)
FOREACH(F ${ALL_SRC})
SET(SRC_LIST ${SRC_LIST} ${F})
MESSAGE("Use " ${F})
ENDFOREACH(F)


#SHARED,动态库
#STATIC,静态库
ADD_LIBRARY(common STATIC ${ALL_SRC} )

# 编译静态库时,自动会把同名的动态库给删除, 因此需要临时设置一下
SET_TARGET_PROPERTIES(common PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# 设置版本号 VERSION指代动态库版本,SOVERSION指代API版本

SET(MAIJOR_VER 1)
SET(MINOR_VER 0)
SET(PATCH_VER 0)
SET(OTHER_VER 1)
ADD_DEFINITIONS(-DMAIJOR_VER=${MAIJOR_VER} -DMINOR_VER=${MINOR_VER} -DPATCH_VER=${PATCH_VER} -DOTHER_VER=${OTHER_VER})

SET_TARGET_PROPERTIES(common PROPERTIES VERSION ${MAIJOR_VER}.${MINOR_VER}.${PATCH_VER} SOVERSION ${MAIJOR_VER})

SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../lib)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
# Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制
# TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类
# 类型分为RUNTIME/LIBRARY/ARCHIVE, prog
Expand All @@ -50,6 +31,6 @@ FILE(GLOB_RECURSE ALL_HEADER *.h)
FOREACH(F ${ALL_HEADER})
file(RELATIVE_PATH RELAPATH_HEADER ${PROJECT_SOURCE_DIR} ${F}) # 获取相对路径
get_filename_component(headDir ${RELAPATH_HEADER} DIRECTORY)
MESSAGE("Install " ${RELAPATH_HEADER} " to " ${CMAKE_INSTALL_PREFIX} "/" ${PROJECT_NAME} "/include/" ${headDir})
MESSAGE("Install " ${RELAPATH_HEADER} " to " ${CMAKE_INSTALL_PREFIX} "/" common "/include/" ${headDir})
INSTALL(FILES ${RELAPATH_HEADER} DESTINATION include/${headDir})
ENDFOREACH(F)
30 changes: 1 addition & 29 deletions deps/common/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ See the Mulan PSL v2 for more details. */
#include <sys/types.h>
#include <unistd.h>

#include "common/version.h"
namespace common {

#ifndef gettid
Expand All @@ -35,14 +34,8 @@ namespace common {

#endif

inline const std::string &theSwVersion()
enum
{
static const std::string swVersion(VERSION_STR);

return swVersion;
}

enum {
// General Error Codes
STATUS_SUCCESS = 0, //!< Success status should be zero,
STATUS_INVALID_PARAM, //!< Invalid parameter
Expand All @@ -55,32 +48,11 @@ enum {

STATUS_UNKNOW_ERROR,
STATUS_LAST_ERR //!< last error code

};

const unsigned int ONE_KILO = 1024;
const unsigned int ONE_MILLION = ONE_KILO * ONE_KILO;
const unsigned int ONE_GIGA = ONE_MILLION * ONE_KILO;
const unsigned int FILENAME_LENGTH_MAX = 256; // the max filename length

static const char FILE_PATH_SPLIT = '/';
static const char FILE_PATH_SPLIT_STR[] = "/";

/*
* Define types
*
*/
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned int u32_t;
typedef unsigned long long u64_t;

typedef char s8_t;
typedef short s16_t;
typedef int s32_t;
typedef long long s64_t;

#define LOCAL_HOST "localhost"
#define EPSILON (1E-6)

} // namespace common
10 changes: 5 additions & 5 deletions deps/common/io/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ int readFromFile(const std::string &fileName, char *&outputData, size_t &fileSiz
return 0;
}

int writeToFile(const std::string &fileName, const char *data, u32_t dataSize, const char *openMode)
int writeToFile(const std::string &fileName, const char *data, uint32_t dataSize, const char *openMode)
{
FILE *file = fopen(fileName.c_str(), openMode);
if (file == NULL) {
std::cerr << "Failed to open file " << fileName << SYS_OUTPUT_FILE_POS << SYS_OUTPUT_ERROR << std::endl;
return -1;
}

u32_t leftSize = dataSize;
uint32_t leftSize = dataSize;
const char *buffer = data;
while (leftSize > 0) {
int writeCount = fwrite(buffer, 1, leftSize, file);
Expand All @@ -106,7 +106,7 @@ int writeToFile(const std::string &fileName, const char *data, u32_t dataSize, c
return 0;
}

int getFileLines(const std::string &fileName, u64_t &lineNum)
int getFileLines(const std::string &fileName, uint64_t &lineNum)
{
lineNum = 0;

Expand All @@ -130,7 +130,7 @@ int getFileLines(const std::string &fileName, u64_t &lineNum)
return 0;
}

int getFileNum(u64_t &fileNum, const std::string &path, const std::string &pattern, bool recursive)
int getFileNum(int64_t &fileNum, const std::string &path, const std::string &pattern, bool recursive)
{
try {
DIR *dirp = NULL;
Expand Down Expand Up @@ -327,7 +327,7 @@ int touch(const std::string &path)
return 0;
}

int getFileSize(const char *filePath, u64_t &fileLen)
int getFileSize(const char *filePath, int64_t &fileLen)
{
if (filePath == NULL || *filePath == '\0') {
std::cerr << "invalid filepath" << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions deps/common/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ namespace common {
*/
int readFromFile(const std::string &fileName, char *&data, size_t &fileSize);

int writeToFile(const std::string &fileName, const char *data, u32_t dataSize, const char *openMode);
int writeToFile(const std::string &fileName, const char *data, uint32_t dataSize, const char *openMode);

/**
* return the line number which line.strip() isn't empty
*/
int getFileLines(const std::string &fileName, u64_t &lineNum);
int getFileLines(const std::string &fileName, uint64_t &lineNum);

/** Get file list from the dir
* don't care ".", "..", ".****" hidden files
Expand All @@ -47,15 +47,15 @@ int getFileLines(const std::string &fileName, u64_t &lineNum);
*/
int getFileList(
std::vector<std::string> &fileList, const std::string &path, const std::string &pattern, bool recursive);
int getFileNum(u64_t &fileNum, const std::string &path, const std::string &pattern, bool recursive);
int getFileNum(uint64_t &fileNum, const std::string &path, const std::string &pattern, bool recursive);
int getDirList(std::vector<std::string> &dirList, const std::string &path, const std::string &pattern);

int touch(const std::string &fileName);

/**
* get file size
*/
int getFileSize(const char *filePath, u64_t &fileLen);
int getFileSize(const char *filePath, uint64_t &fileLen);

/**
* @brief 一次性写入所有指定数据
Expand Down
2 changes: 1 addition & 1 deletion deps/common/io/roll_select_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RollSelectDir : public SelectDir {
std::string mBaseDir;
std::vector<std::string> mSubdirs;
pthread_mutex_t mMutex;
u32_t mPos;
uint32_t mPos;
};

} // namespace common
Expand Down
9 changes: 7 additions & 2 deletions deps/common/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ See the Mulan PSL v2 for more details. */

namespace common {

const unsigned int ONE_KILO = 1024;
const unsigned int ONE_MILLION = ONE_KILO * ONE_KILO;
const unsigned int ONE_GIGA = ONE_MILLION * ONE_KILO;
const unsigned int FILENAME_LENGTH_MAX = 256; // the max filename length

const int LOG_STATUS_OK = 0;
const int LOG_STATUS_ERR = 1;
const int LOG_MAX_LINE = 100000;
Expand Down Expand Up @@ -182,7 +187,7 @@ extern Log *g_log;
p->tm_min, \
p->tm_sec, \
usec, \
(u32_t)getpid(), \
(int32_t)getpid(), \
gettid(), \
common::g_log->context_id()); \
common::g_log->rotate(p->tm_year + 1900, p->tm_mon + 1, p->tm_mday); \
Expand All @@ -194,7 +199,7 @@ extern Log *g_log;
(common::g_log)->prefix_msg(level), \
__FUNCTION__, \
__FILE_NAME__, \
(u32_t)__LINE__ \
(int32_t)__LINE__ \
); \
}

Expand Down
Loading
Loading