TD-10430 refact osDir.h and daemon module
This commit is contained in:
parent
6c62690911
commit
94eac805b9
|
@ -26,38 +26,112 @@ extern "C" {
|
|||
typedef struct SDnode SDnode;
|
||||
|
||||
typedef struct {
|
||||
int32_t sver;
|
||||
int32_t numOfCores;
|
||||
float numOfThreadsPerCore;
|
||||
float ratioOfQueryCores;
|
||||
int32_t maxShellConns;
|
||||
int32_t shellActivityTimer;
|
||||
int32_t statusInterval;
|
||||
/**
|
||||
* @brief software version of the program.
|
||||
*
|
||||
*/
|
||||
int32_t sver;
|
||||
|
||||
/**
|
||||
* @brief num of CPU cores.
|
||||
*
|
||||
*/
|
||||
int32_t numOfCores;
|
||||
|
||||
/**
|
||||
* @brief number of threads per CPU core.
|
||||
*
|
||||
*/
|
||||
float numOfThreadsPerCore;
|
||||
|
||||
/**
|
||||
* @brief the proportion of total CPU cores available for query processing.
|
||||
*
|
||||
*/
|
||||
float ratioOfQueryCores;
|
||||
|
||||
/**
|
||||
* @brief max number of connections allowed in dnode.
|
||||
*
|
||||
*/
|
||||
int32_t maxShellConns;
|
||||
|
||||
/**
|
||||
* @brief time interval of heart beat from shell to dnode, seconds.
|
||||
*
|
||||
*/
|
||||
int32_t shellActivityTimer;
|
||||
|
||||
/**
|
||||
* @brief time interval of dnode status reporting to mnode, seconds, for cluster only.
|
||||
*
|
||||
*/
|
||||
int32_t statusInterval;
|
||||
|
||||
/**
|
||||
* @brief first port number for the connection (12 continuous UDP/TCP port number are used).
|
||||
*
|
||||
*/
|
||||
uint16_t serverPort;
|
||||
char dataDir[PATH_MAX];
|
||||
char localEp[TSDB_EP_LEN];
|
||||
char localFqdn[TSDB_FQDN_LEN];
|
||||
char firstEp[TSDB_EP_LEN];
|
||||
char timezone[TSDB_TIMEZONE_LEN];
|
||||
char locale[TSDB_LOCALE_LEN];
|
||||
char charset[TSDB_LOCALE_LEN];
|
||||
|
||||
/**
|
||||
* @brief data file's directory.
|
||||
*
|
||||
*/
|
||||
char dataDir[PATH_MAX];
|
||||
|
||||
/**
|
||||
* @brief local endpoint.
|
||||
*
|
||||
*/
|
||||
char localEp[TSDB_EP_LEN];
|
||||
|
||||
/**
|
||||
* @brieflocal fully qualified domain name (FQDN).
|
||||
*
|
||||
*/
|
||||
char localFqdn[TSDB_FQDN_LEN];
|
||||
|
||||
/**
|
||||
* @brief first fully qualified domain name (FQDN) for TDengine system.
|
||||
*
|
||||
*/
|
||||
char firstEp[TSDB_EP_LEN];
|
||||
|
||||
/**
|
||||
* @brief system time zone.
|
||||
*
|
||||
*/
|
||||
char timezone[TSDB_TIMEZONE_LEN];
|
||||
|
||||
/**
|
||||
* @brief system locale.
|
||||
*
|
||||
*/
|
||||
char locale[TSDB_LOCALE_LEN];
|
||||
|
||||
/**
|
||||
* @briefdefault system charset.
|
||||
*
|
||||
*/
|
||||
char charset[TSDB_LOCALE_LEN];
|
||||
} SDnodeOpt;
|
||||
|
||||
/* ------------------------ SDnode ------------------------ */
|
||||
/**
|
||||
* @brief Initialize and start the dnode.
|
||||
*
|
||||
* @param cfgPath Config file path.
|
||||
* @param pOptions Options of the dnode.
|
||||
* @return SDnode* The dnode object.
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void taosRemoveDir(const char *dirname);
|
||||
bool taosDirExist(char *dirname);
|
||||
bool taosMkDir(const char *dirname);
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||
bool taosRealPath(char *dirname, int32_t maxlen);
|
||||
void taosRemoveDir(const char *dirname);
|
||||
int32_t taosDirExist(char *dirname);
|
||||
int32_t taosMkDir(const char *dirname);
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||
int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||
int32_t taosRealPath(char *dirname, int32_t maxlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1679,7 +1679,7 @@ int32_t taosCheckGlobalCfg() {
|
|||
|
||||
taosCheckDataDirCfg();
|
||||
|
||||
if (!taosDirExist(tsTempDir)) {
|
||||
if (taosDirExist(tsTempDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ void dmnSetSignalHandle() {
|
|||
taosSetSignal(SIGBREAK, dmnSigintHandle);
|
||||
}
|
||||
|
||||
int dmnParseOpts(int argc, char const *argv[]) {
|
||||
int dmnParseOption(int argc, char const *argv[]) {
|
||||
tstrncpy(global.configDir, "/etc/taos", PATH_MAX);
|
||||
|
||||
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);
|
||||
} else {
|
||||
printf("'-c' requires a parameter, default:%s\n", configDir);
|
||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-C") == 0) {
|
||||
|
@ -78,11 +78,11 @@ void dmnGenerateGrant() {
|
|||
|
||||
void dmnPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *versionStr = "enterprise";
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
char *versionStr = "community";
|
||||
char *releaseName = "community";
|
||||
#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("gitinfoI: %s\n", gitinfoOfInternal);
|
||||
printf("builuInfo: %s\n", buildinfo);
|
||||
|
@ -164,7 +164,7 @@ int dmnRunDnode() {
|
|||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
if (dmnParseOpts(argc, argv) != 0) {
|
||||
if (dmnParseOption(argc, argv) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,19 +98,19 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOptions) {
|
|||
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));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
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));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
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));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
|
|
@ -21,19 +21,19 @@
|
|||
static int32_t sdbCreateDir() {
|
||||
mDebug("start to create mnode at %s", tsMnodeDir);
|
||||
|
||||
if (!taosMkDir(tsSdb.currDir)) {
|
||||
if (taosMkDir(tsSdb.currDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", tsSdb.currDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.syncDir)) {
|
||||
if (taosMkDir(tsSdb.syncDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", tsSdb.syncDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.tmpDir)) {
|
||||
if (taosMkDir(tsSdb.tmpDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", tsSdb.tmpDir, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -92,7 +92,7 @@ TqMetaStore* tqStoreOpen(const char* path,
|
|||
char name[pathLen+10];
|
||||
|
||||
strcpy(name, path);
|
||||
if(!taosDirExist(name) && !taosMkDir(name)) {
|
||||
if (taosDirExist(name) != 0 && taosMkDir(name) != 0) {
|
||||
ASSERT(false);
|
||||
}
|
||||
strcat(name, "/" TQ_IDX_NAME);
|
||||
|
|
|
@ -136,7 +136,7 @@ void walClose(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));
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
|
|
@ -58,15 +58,15 @@ void taosRemoveDir(const char *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);
|
||||
if (code < 0 && errno == EEXIST) {
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return code == 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
|
||||
|
@ -112,12 +112,12 @@ void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
|
|||
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;
|
||||
if (0 != wordexp(dirname, &full_path, 0)) {
|
||||
printf("failed to expand path:%s since %s", dirname, strerror(errno));
|
||||
wordfree(&full_path);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool taosRealPath(char *dirname, int32_t maxlen) {
|
||||
int32_t taosRealPath(char *dirname, int32_t maxlen) {
|
||||
char tmp[PATH_MAX] = {0};
|
||||
if (realpath(dirname, tmp) != NULL) {
|
||||
strncpy(dirname, tmp, maxlen);
|
||||
}
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -154,7 +154,7 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
|
|||
taosExpandDir(input_value, 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,
|
||||
strerror(errno));
|
||||
return false;
|
||||
|
|
|
@ -371,7 +371,7 @@ void tscSaveSubscriptionProgress(void* sub) {
|
|||
|
||||
char path[256];
|
||||
sprintf(path, "%s/subscribe", tsDataDir);
|
||||
if (!taosMkDir(path)) {
|
||||
if (taosMkDir(path) != 0) {
|
||||
tscError("failed to create subscribe dir: %s", path);
|
||||
}
|
||||
|
||||
|
|
|
@ -252,7 +252,7 @@ int tfsMkdirAt(const char *rname, int level, int id) {
|
|||
char aname[TMPNAME_LEN];
|
||||
|
||||
snprintf(aname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), rname);
|
||||
if (!taosMkDir(aname)) {
|
||||
if (taosMkDir(aname) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue