TD-10430 refact osDir.h and daemon module

This commit is contained in:
Shengliang Guan 2021-11-23 19:54:17 +08:00
parent 6c62690911
commit 94eac805b9
12 changed files with 125 additions and 51 deletions

View File

@ -26,20 +26,94 @@ extern "C" {
typedef struct SDnode SDnode; typedef struct SDnode SDnode;
typedef struct { typedef struct {
/**
* @brief software version of the program.
*
*/
int32_t sver; int32_t sver;
/**
* @brief num of CPU cores.
*
*/
int32_t numOfCores; int32_t numOfCores;
/**
* @brief number of threads per CPU core.
*
*/
float numOfThreadsPerCore; float numOfThreadsPerCore;
/**
* @brief the proportion of total CPU cores available for query processing.
*
*/
float ratioOfQueryCores; float ratioOfQueryCores;
/**
* @brief max number of connections allowed in dnode.
*
*/
int32_t maxShellConns; int32_t maxShellConns;
/**
* @brief time interval of heart beat from shell to dnode, seconds.
*
*/
int32_t shellActivityTimer; int32_t shellActivityTimer;
/**
* @brief time interval of dnode status reporting to mnode, seconds, for cluster only.
*
*/
int32_t statusInterval; int32_t statusInterval;
/**
* @brief first port number for the connection (12 continuous UDP/TCP port number are used).
*
*/
uint16_t serverPort; uint16_t serverPort;
/**
* @brief data file's directory.
*
*/
char dataDir[PATH_MAX]; char dataDir[PATH_MAX];
/**
* @brief local endpoint.
*
*/
char localEp[TSDB_EP_LEN]; char localEp[TSDB_EP_LEN];
/**
* @brieflocal fully qualified domain name (FQDN).
*
*/
char localFqdn[TSDB_FQDN_LEN]; char localFqdn[TSDB_FQDN_LEN];
/**
* @brief first fully qualified domain name (FQDN) for TDengine system.
*
*/
char firstEp[TSDB_EP_LEN]; char firstEp[TSDB_EP_LEN];
/**
* @brief system time zone.
*
*/
char timezone[TSDB_TIMEZONE_LEN]; char timezone[TSDB_TIMEZONE_LEN];
/**
* @brief system locale.
*
*/
char locale[TSDB_LOCALE_LEN]; char locale[TSDB_LOCALE_LEN];
/**
* @briefdefault system charset.
*
*/
char charset[TSDB_LOCALE_LEN]; char charset[TSDB_LOCALE_LEN];
} SDnodeOpt; } SDnodeOpt;
@ -47,17 +121,17 @@ typedef struct {
/** /**
* @brief Initialize and start the dnode. * @brief Initialize and start the dnode.
* *
* @param cfgPath Config file path. * @param pOptions Options of the dnode.
* @return SDnode* The dnode object. * @return SDnode* The dnode object.
*/ */
SDnode *dndInit(SDnodeOpt *pOptions); SDnode *dndInit(SDnodeOpt *pOptions);
/** /**
* @brief Stop and cleanup dnode. * @brief Stop and cleanup the dnode.
* *
* @param pDnd The dnode object to close. * @param pDnode The dnode object to close.
*/ */
void dndCleanup(SDnode *pDnd); void dndCleanup(SDnode *pDnode);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -21,11 +21,11 @@ extern "C" {
#endif #endif
void taosRemoveDir(const char *dirname); void taosRemoveDir(const char *dirname);
bool taosDirExist(char *dirname); int32_t taosDirExist(char *dirname);
bool taosMkDir(const char *dirname); int32_t taosMkDir(const char *dirname);
void taosRemoveOldFiles(char *dirname, int32_t keepDays); void taosRemoveOldFiles(char *dirname, int32_t keepDays);
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen); int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen);
bool taosRealPath(char *dirname, int32_t maxlen); int32_t taosRealPath(char *dirname, int32_t maxlen);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1679,7 +1679,7 @@ int32_t taosCheckGlobalCfg() {
taosCheckDataDirCfg(); taosCheckDataDirCfg();
if (!taosDirExist(tsTempDir)) { if (taosDirExist(tsTempDir) != 0) {
return -1; return -1;
} }

View File

@ -40,7 +40,7 @@ void dmnSetSignalHandle() {
taosSetSignal(SIGBREAK, dmnSigintHandle); taosSetSignal(SIGBREAK, dmnSigintHandle);
} }
int dmnParseOpts(int argc, char const *argv[]) { int dmnParseOption(int argc, char const *argv[]) {
tstrncpy(global.configDir, "/etc/taos", PATH_MAX); tstrncpy(global.configDir, "/etc/taos", PATH_MAX);
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
@ -52,7 +52,7 @@ int dmnParseOpts(int argc, char const *argv[]) {
} }
tstrncpy(global.configDir, argv[i], PATH_MAX); tstrncpy(global.configDir, argv[i], PATH_MAX);
} else { } else {
printf("'-c' requires a parameter, default:%s\n", configDir); printf("'-c' requires a parameter, default is %s\n", configDir);
return -1; return -1;
} }
} else if (strcmp(argv[i], "-C") == 0) { } else if (strcmp(argv[i], "-C") == 0) {
@ -78,11 +78,11 @@ void dmnGenerateGrant() {
void dmnPrintVersion() { void dmnPrintVersion() {
#ifdef TD_ENTERPRISE #ifdef TD_ENTERPRISE
char *versionStr = "enterprise"; char *releaseName = "enterprise";
#else #else
char *versionStr = "community"; char *releaseName = "community";
#endif #endif
printf("%s version: %s compatible_version: %s\n", versionStr, version, compatible_version); printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
printf("gitinfo: %s\n", gitinfo); printf("gitinfo: %s\n", gitinfo);
printf("gitinfoI: %s\n", gitinfoOfInternal); printf("gitinfoI: %s\n", gitinfoOfInternal);
printf("builuInfo: %s\n", buildinfo); printf("builuInfo: %s\n", buildinfo);
@ -164,7 +164,7 @@ int dmnRunDnode() {
} }
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
if (dmnParseOpts(argc, argv) != 0) { if (dmnParseOption(argc, argv) != 0) {
return -1; return -1;
} }

View File

@ -98,19 +98,19 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOptions) {
return -1; return -1;
} }
if (!taosMkDir(pDnode->dir.dnode)) { if (taosMkDir(pDnode->dir.dnode) != 0) {
dError("failed to create dir:%s since %s", pDnode->dir.dnode, strerror(errno)); dError("failed to create dir:%s since %s", pDnode->dir.dnode, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
if (!taosMkDir(pDnode->dir.mnode)) { if (taosMkDir(pDnode->dir.mnode) != 0) {
dError("failed to create dir:%s since %s", pDnode->dir.mnode, strerror(errno)); dError("failed to create dir:%s since %s", pDnode->dir.mnode, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }
if (!taosMkDir(pDnode->dir.vnodes)) { if (taosMkDir(pDnode->dir.vnodes) != 0) {
dError("failed to create dir:%s since %s", pDnode->dir.vnodes, strerror(errno)); dError("failed to create dir:%s since %s", pDnode->dir.vnodes, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;

View File

@ -21,19 +21,19 @@
static int32_t sdbCreateDir() { static int32_t sdbCreateDir() {
mDebug("start to create mnode at %s", tsMnodeDir); mDebug("start to create mnode at %s", tsMnodeDir);
if (!taosMkDir(tsSdb.currDir)) { if (taosMkDir(tsSdb.currDir) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
mError("failed to create dir:%s since %s", tsSdb.currDir, terrstr()); mError("failed to create dir:%s since %s", tsSdb.currDir, terrstr());
return -1; return -1;
} }
if (!taosMkDir(tsSdb.syncDir)) { if (taosMkDir(tsSdb.syncDir) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
mError("failed to create dir:%s since %s", tsSdb.syncDir, terrstr()); mError("failed to create dir:%s since %s", tsSdb.syncDir, terrstr());
return -1; return -1;
} }
if (!taosMkDir(tsSdb.tmpDir)) { if (taosMkDir(tsSdb.tmpDir) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
mError("failed to create dir:%s since %s", tsSdb.tmpDir, terrstr()); mError("failed to create dir:%s since %s", tsSdb.tmpDir, terrstr());
return -1; return -1;

View File

@ -92,7 +92,7 @@ TqMetaStore* tqStoreOpen(const char* path,
char name[pathLen+10]; char name[pathLen+10];
strcpy(name, path); strcpy(name, path);
if(!taosDirExist(name) && !taosMkDir(name)) { if (taosDirExist(name) != 0 && taosMkDir(name) != 0) {
ASSERT(false); ASSERT(false);
} }
strcat(name, "/" TQ_IDX_NAME); strcat(name, "/" TQ_IDX_NAME);

View File

@ -136,7 +136,7 @@ void walClose(SWal *pWal) {
} }
static int32_t walInitObj(SWal *pWal) { static int32_t walInitObj(SWal *pWal) {
if (!taosMkDir(pWal->path)) { if (taosMkDir(pWal->path) != 0) {
wError("vgId:%d, path:%s, failed to create directory since %s", pWal->vgId, pWal->path, strerror(errno)); wError("vgId:%d, path:%s, failed to create directory since %s", pWal->vgId, pWal->path, strerror(errno));
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} }

View File

@ -58,15 +58,15 @@ void taosRemoveDir(const char *dirname) {
printf("dir:%s is removed\n", dirname); printf("dir:%s is removed\n", dirname);
} }
bool taosDirExist(char *dirname) { return access(dirname, F_OK) == 0; } int32_t taosDirExist(char *dirname) { return access(dirname, F_OK); }
bool taosMkDir(const char *dirname) { int32_t taosMkDir(const char *dirname) {
int32_t code = mkdir(dirname, 0755); int32_t code = mkdir(dirname, 0755);
if (code < 0 && errno == EEXIST) { if (code < 0 && errno == EEXIST) {
return true; return 0;
} }
return code == 0; return code;
} }
void taosRemoveOldFiles(char *dirname, int32_t keepDays) { void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
@ -112,12 +112,12 @@ void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
rmdir(dirname); rmdir(dirname);
} }
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen) { int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen) {
wordexp_t full_path; wordexp_t full_path;
if (0 != wordexp(dirname, &full_path, 0)) { if (0 != wordexp(dirname, &full_path, 0)) {
printf("failed to expand path:%s since %s", dirname, strerror(errno)); printf("failed to expand path:%s since %s", dirname, strerror(errno));
wordfree(&full_path); wordfree(&full_path);
return false; return -1;
} }
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
@ -126,16 +126,16 @@ bool taosExpandDir(char *dirname, char *outname, int32_t maxlen) {
wordfree(&full_path); wordfree(&full_path);
return true; return 0;
} }
bool taosRealPath(char *dirname, int32_t maxlen) { int32_t taosRealPath(char *dirname, int32_t maxlen) {
char tmp[PATH_MAX] = {0}; char tmp[PATH_MAX] = {0};
if (realpath(dirname, tmp) != NULL) { if (realpath(dirname, tmp) != NULL) {
strncpy(dirname, tmp, maxlen); strncpy(dirname, tmp, maxlen);
} }
return true; return 0;
} }
#endif #endif

View File

@ -154,7 +154,7 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
taosExpandDir(input_value, option, cfg->ptrLength); taosExpandDir(input_value, option, cfg->ptrLength);
taosRealPath(option, cfg->ptrLength); taosRealPath(option, cfg->ptrLength);
if (!taosMkDir(option)) { if (taosMkDir(option) != 0) {
uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value, uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value,
strerror(errno)); strerror(errno));
return false; return false;

View File

@ -371,7 +371,7 @@ void tscSaveSubscriptionProgress(void* sub) {
char path[256]; char path[256];
sprintf(path, "%s/subscribe", tsDataDir); sprintf(path, "%s/subscribe", tsDataDir);
if (!taosMkDir(path)) { if (taosMkDir(path) != 0) {
tscError("failed to create subscribe dir: %s", path); tscError("failed to create subscribe dir: %s", path);
} }

View File

@ -252,7 +252,7 @@ int tfsMkdirAt(const char *rname, int level, int id) {
char aname[TMPNAME_LEN]; char aname[TMPNAME_LEN];
snprintf(aname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), rname); snprintf(aname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), rname);
if (!taosMkDir(aname)) { if (taosMkDir(aname) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
} }