提交 546d3e84 编写于 作者: S Shengliang Guan

daemon config

上级 da1351e3
...@@ -99,6 +99,8 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU ...@@ -99,6 +99,8 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
void taosCleanupCfg(); void taosCleanupCfg();
void taosCfgDynamicOptions(const char *option, const char *value); void taosCfgDynamicOptions(const char *option, const char *value);
struct SConfig *taosGetCfg();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -32,8 +32,6 @@ typedef struct { ...@@ -32,8 +32,6 @@ typedef struct {
uint16_t numOfCommitThreads; uint16_t numOfCommitThreads;
bool enableTelem; bool enableTelem;
bool printAuth; bool printAuth;
int32_t rpcTimer;
int32_t rpcMaxTime;
} SDnodeEnvCfg; } SDnodeEnvCfg;
/** /**
......
...@@ -95,7 +95,7 @@ int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal); ...@@ -95,7 +95,7 @@ int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal);
const char *cfgStypeStr(ECfgSrcType type); const char *cfgStypeStr(ECfgSrcType type);
const char *cfgDtypeStr(ECfgDataType type); const char *cfgDtypeStr(ECfgDataType type);
void cfgDumpCfg(SConfig *pCfg, bool tsc); void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -170,6 +170,10 @@ static void taosPrintDataDirCfg() { ...@@ -170,6 +170,10 @@ static void taosPrintDataDirCfg() {
} }
} }
struct SConfig *taosGetCfg() {
return tsCfg;
}
static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) {
char cfgDir[PATH_MAX] = {0}; char cfgDir[PATH_MAX] = {0};
char cfgFile[PATH_MAX + 100] = {0}; char cfgFile[PATH_MAX + 100] = {0};
...@@ -332,6 +336,11 @@ static void taosSetClientCfg(SConfig *pCfg) { ...@@ -332,6 +336,11 @@ static void taosSetClientCfg(SConfig *pCfg) {
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
osSetTimezone(pItem->str);
uDebug("timezone format changed from %s to %s", pItem->str, osTimezone());
cfgSetItem(pCfg, "timezone", osTimezone(), pItem->stype);
taosGetSystemInfo(); taosGetSystemInfo();
if (tsNumOfCores <= 0) { if (tsNumOfCores <= 0) {
tsNumOfCores = 1; tsNumOfCores = 1;
...@@ -408,7 +417,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU ...@@ -408,7 +417,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
taosSetServerCfg(tsCfg); taosSetServerCfg(tsCfg);
} }
cfgDumpCfg(tsCfg, tsc); cfgDumpCfg(tsCfg, tsc, false);
return 0; return 0;
} }
...@@ -429,4 +438,4 @@ void taosCfgDynamicOptions(const char *option, const char *value) { ...@@ -429,4 +438,4 @@ void taosCfgDynamicOptions(const char *option, const char *value) {
taosResetLog(); taosResetLog();
// taosPrintCfg(); // taosPrintCfg();
} }
} }
\ No newline at end of file
...@@ -28,15 +28,10 @@ ...@@ -28,15 +28,10 @@
extern "C" { extern "C" {
#endif #endif
int32_t dmnAddLogCfg(SConfig *pCfg); SDnodeEnvCfg dmnGetEnvCfg();
int32_t dmnInitLog(const char *cfgDir, const char *envFile, const char *apolloUrl); SDnodeObjCfg dmnGetObjCfg();
int32_t dmnLoadCfg(SConfig *pConfig, const char *inputCfgDir, const char *envFile, const char *apolloUrl);
SConfig *dmnReadCfg(const char *cfgDir, const char *envFile, const char *apolloUrl); void dmnDumpCfg();
SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg);
SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg);
void dmnDumpCfg(SConfig *pCfg);
void dmnPrintVersion(); void dmnPrintVersion();
void dmnGenerateGrant(); void dmnGenerateGrant();
......
...@@ -15,131 +15,10 @@ ...@@ -15,131 +15,10 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dmnInt.h" #include "dmnInt.h"
#include "tconfig.h"
static int32_t dmnCheckDirCfg(SConfig *pCfg) { SDnodeEnvCfg dmnGetEnvCfg() {
SConfig *pCfg = taosGetCfg();
return 0;
}
static int32_t dmnAddDnodeCfg(SConfig *pCfg) {
if (dmnAddEpCfg(pCfg) != 0) return -1;
if (dmnAddDirCfg(pCfg) != 0) return -1;
if (dmnAddVersionCfg(pCfg) != 0) return -1;
if (cfgAddTimezone(pCfg, "timezone", "") != 0) return -1;
if (cfgAddLocale(pCfg, "locale", "") != 0) return -1;
if (cfgAddCharset(pCfg, "charset", "") != 0) return -1;
if (cfgAddInt32(pCfg, "numOfCores", 2, 1, 100000) != 0) return -1;
if (cfgAddInt32(pCfg, "numOfCommitThreads", 4, 1, 1000) != 0) return -1;
if (cfgAddBool(pCfg, "telemetryReporting", 0) != 0) return -1;
if (cfgAddBool(pCfg, "enableCoreFile", 0) != 0) return -1;
if (cfgAddInt32(pCfg, "supportVnodes", 256, 0, 65536) != 0) return -1;
if (cfgAddInt32(pCfg, "statusInterval", 1, 1, 30) != 0) return -1;
if (cfgAddFloat(pCfg, "numOfThreadsPerCore", 1, 0, 10) != 0) return -1;
if (cfgAddFloat(pCfg, "ratioOfQueryCores", 1, 0, 5) != 0) return -1;
if (cfgAddInt32(pCfg, "maxShellConns", 50000, 10, 50000000) != 0) return -1;
if (cfgAddInt32(pCfg, "shellActivityTimer", 3, 1, 120) != 0) return -1;
if (cfgAddInt32(pCfg, "rpcTimer", 300, 100, 3000) != 0) return -1;
if (cfgAddInt32(pCfg, "rpcMaxTime", 600, 100, 7200) != 0) return -1;
return 0;
}
static void dmnSetDnodeCfg(SConfig *pCfg) {
SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
osSetTimezone(pItem->str);
uDebug("timezone format changed from %s to %s", pItem->str, osTimezone());
cfgSetItem(pCfg, "timezone", osTimezone(), pItem->stype);
}
static int32_t dmnCheckCfg(SConfig *pCfg) {
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
taosSetCoreDump(enableCore);
dmnSetDnodeCfg(pCfg);
if (dmnCheckDirCfg(pCfg) != 0) {
return -1;
}
taosGetSystemInfo();
if (tsNumOfCores <= 0) {
tsNumOfCores = 1;
}
if (tsQueryBufferSize >= 0) {
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
}
return 0;
}
SConfig *dmnReadCfg(const char *cfgDir, const char *envFile, const char *apolloUrl) {
SConfig *pCfg = cfgInit();
if (pCfg == NULL) return NULL;
if (dmnAddLogCfg(pCfg) != 0) {
uError("failed to add log cfg since %s", terrstr());
cfgCleanup(pCfg);
return NULL;
}
if (dmnAddDnodeCfg(pCfg) != 0) {
uError("failed to init dnode cfg since %s", terrstr());
cfgCleanup(pCfg);
return NULL;
}
if (dmnLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
uError("failed to load cfg since %s", terrstr());
cfgCleanup(pCfg);
return NULL;
}
if (dmnCheckCfg(pCfg) != 0) {
uError("failed to check cfg since %s", terrstr());
cfgCleanup(pCfg);
return NULL;
}
cfgDumpCfg(pCfg);
return pCfg;
}
void dmnDumpCfg(SConfig *pCfg) {
printf("taos global config:\n");
printf("==================================\n");
SConfigItem *pItem = cfgIterate(pCfg, NULL);
while (pItem != NULL) {
switch (pItem->dtype) {
case CFG_DTYPE_BOOL:
printf("cfg:%s, value:%u src:%s\n", pItem->name, pItem->bval, cfgStypeStr(pItem->stype));
break;
case CFG_DTYPE_INT32:
printf("cfg:%s, value:%d src:%s\n", pItem->name, pItem->i32, cfgStypeStr(pItem->stype));
break;
case CFG_DTYPE_INT64:
printf("cfg:%s, value:%" PRId64 " src:%s\n", pItem->name, pItem->i64, cfgStypeStr(pItem->stype));
break;
case CFG_DTYPE_FLOAT:
printf("cfg:%s, value:%f src:%s\n", pItem->name, pItem->fval, cfgStypeStr(pItem->stype));
break;
case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR:
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE:
printf("cfg:%s, value:%s src:%s\n", pItem->name, pItem->str, cfgStypeStr(pItem->stype));
break;
}
pItem = cfgIterate(pCfg, pItem);
}
}
SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg) {
SDnodeEnvCfg envCfg = {0}; SDnodeEnvCfg envCfg = {0};
const char *vstr = cfgGetItem(pCfg, "version")->str; const char *vstr = cfgGetItem(pCfg, "version")->str;
...@@ -147,27 +26,24 @@ SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg) { ...@@ -147,27 +26,24 @@ SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg) {
envCfg.numOfCores = cfgGetItem(pCfg, "numOfCores")->i32; envCfg.numOfCores = cfgGetItem(pCfg, "numOfCores")->i32;
envCfg.numOfCommitThreads = (uint16_t)cfgGetItem(pCfg, "numOfCommitThreads")->i32; envCfg.numOfCommitThreads = (uint16_t)cfgGetItem(pCfg, "numOfCommitThreads")->i32;
envCfg.enableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; envCfg.enableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval;
envCfg.rpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32;
envCfg.rpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32;
return envCfg; return envCfg;
} }
SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg) { SDnodeObjCfg dmnGetObjCfg() {
SConfig *pCfg = taosGetCfg();
SDnodeObjCfg objCfg = {0}; SDnodeObjCfg objCfg = {0};
objCfg.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; objCfg.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
// objCfg.statusInterval = cfgGetItem(pCfg, "statusInterval")->i32;
// objCfg.numOfThreadsPerCore = cfgGetItem(pCfg, "numOfThreadsPerCore")->fval;
// objCfg.ratioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval;
// objCfg.maxShellConns = cfgGetItem(pCfg, "maxShellConns")->i32;
// objCfg.shellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32;
tstrncpy(objCfg.dataDir, cfgGetItem(pCfg, "dataDir")->str, sizeof(objCfg.dataDir)); tstrncpy(objCfg.dataDir, cfgGetItem(pCfg, "dataDir")->str, sizeof(objCfg.dataDir));
tstrncpy(objCfg.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp)); tstrncpy(objCfg.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp));
tstrncpy(objCfg.secondEp, cfgGetItem(pCfg, "secondEp")->str, sizeof(objCfg.firstEp)); tstrncpy(objCfg.secondEp, cfgGetItem(pCfg, "secondEp")->str, sizeof(objCfg.firstEp));
objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn)); tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn));
snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort); snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort);
return objCfg; return objCfg;
}
void dmnDumpCfg() {
SConfig *pCfg = taosGetCfg();
cfgDumpCfg(pCfg, 0, 1);
} }
\ No newline at end of file
...@@ -72,14 +72,14 @@ static int32_t dmnParseOption(int32_t argc, char const *argv[]) { ...@@ -72,14 +72,14 @@ static int32_t dmnParseOption(int32_t argc, char const *argv[]) {
return 0; return 0;
} }
int32_t dmnRunDnode(SConfig *pCfg) { int32_t dmnRunDnode() {
SDnodeEnvCfg envCfg = dmnGetEnvCfg(pCfg); SDnodeEnvCfg envCfg = dmnGetEnvCfg();
if (dndInit(&envCfg) != 0) { if (dndInit(&envCfg) != 0) {
uInfo("Failed to start TDengine, please check the log"); uInfo("Failed to start TDengine, please check the log");
return -1; return -1;
} }
SDnodeObjCfg objCfg = dmnGetObjCfg(pCfg); SDnodeObjCfg objCfg = dmnGetObjCfg();
SDnode *pDnode = dndCreate(&objCfg); SDnode *pDnode = dndCreate(&objCfg);
if (pDnode == NULL) { if (pDnode == NULL) {
uInfo("Failed to start TDengine, please check the log"); uInfo("Failed to start TDengine, please check the log");
...@@ -113,23 +113,23 @@ int main(int argc, char const *argv[]) { ...@@ -113,23 +113,23 @@ int main(int argc, char const *argv[]) {
return 0; return 0;
} }
if (dmnInitLog(configDir, dmn.envFile, dmn.apolloUrl) != 0) { if (taosCreateLog("taosdlog", 1, configDir, dmn.envFile, dmn.apolloUrl, 1) != 0) {
uInfo("Failed to start TDengine since read config error");
return -1; return -1;
} }
SConfig *pCfg = dmnReadCfg(configDir, dmn.envFile, dmn.apolloUrl); if (taosInitCfg(configDir, dmn.envFile, dmn.apolloUrl, 1) != 0) {
if (pCfg == NULL) {
uInfo("Failed to start TDengine since read config error"); uInfo("Failed to start TDengine since read config error");
return -1; return -1;
} }
if (dmn.dumpConfig) { if (dmn.dumpConfig) {
dmnDumpCfg(pCfg); dmnDumpCfg();
cfgCleanup(pCfg); taosCleanupCfg();
return 0; return 0;
} }
int32_t code = dmnRunDnode(pCfg); int32_t code = dmnRunDnode();
cfgCleanup(pCfg); taosCleanupCfg();
return code; return code;
} }
...@@ -43,8 +43,6 @@ void Testbase::Init(const char* path, int16_t port) { ...@@ -43,8 +43,6 @@ void Testbase::Init(const char* path, int16_t port) {
SDnodeEnvCfg cfg = {0}; SDnodeEnvCfg cfg = {0};
cfg.numOfCommitThreads = 1; cfg.numOfCommitThreads = 1;
cfg.numOfCores = 1; cfg.numOfCores = 1;
cfg.rpcMaxTime = 600;
cfg.rpcTimer = 300;
dndInit(&cfg); dndInit(&cfg);
char fqdn[] = "localhost"; char fqdn[] = "localhost";
......
...@@ -475,9 +475,16 @@ const char *cfgDtypeStr(ECfgDataType type) { ...@@ -475,9 +475,16 @@ const char *cfgDtypeStr(ECfgDataType type) {
} }
} }
void cfgDumpCfg(SConfig *pCfg, bool tsc) { void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
uInfo(" global config"); if (dump) {
uInfo("================================================================="); printf(" global config");
printf("\n");
printf("=================================================================");
printf("\n");
} else {
uInfo(" global config");
uInfo("=================================================================");
}
char src[CFG_SRC_PRINT_LEN + 1] = {0}; char src[CFG_SRC_PRINT_LEN + 1] = {0};
char name[CFG_NAME_PRINT_LEN + 1] = {0}; char name[CFG_NAME_PRINT_LEN + 1] = {0};
...@@ -497,111 +504,62 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc) { ...@@ -497,111 +504,62 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc) {
switch (pItem->dtype) { switch (pItem->dtype) {
case CFG_DTYPE_BOOL: case CFG_DTYPE_BOOL:
uInfo("%s %s %u", src, name, pItem->bval); if (dump) {
printf("%s %s %u", src, name, pItem->bval);
printf("\n");
} else {
uInfo("%s %s %u", src, name, pItem->bval);
}
break; break;
case CFG_DTYPE_INT32: case CFG_DTYPE_INT32:
uInfo("%s %s %d", src, name, pItem->i32); if (dump) {
printf("%s %s %d", src, name, pItem->i32);
printf("\n");
} else {
uInfo("%s %s %d", src, name, pItem->i32);
}
break; break;
case CFG_DTYPE_INT64: case CFG_DTYPE_INT64:
uInfo("%s %s %" PRId64, src, name, pItem->i64); if (dump) {
printf("%s %s %" PRId64, src, name, pItem->i64);
printf("\n");
} else {
uInfo("%s %s %" PRId64, src, name, pItem->i64);
}
break; break;
case CFG_DTYPE_FLOAT: case CFG_DTYPE_FLOAT:
uInfo("%s %s %f", src, name, pItem->fval); if (dump) {
printf("%s %s %f", src, name, pItem->fval);
printf("\n");
} else {
uInfo("%s %s %f", src, name, pItem->fval);
}
break; break;
case CFG_DTYPE_STRING: case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR: case CFG_DTYPE_DIR:
case CFG_DTYPE_LOCALE: case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET: case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE: case CFG_DTYPE_TIMEZONE:
uInfo("%s %s %s", src, name, pItem->str); if (dump) {
printf("%s %s %s", src, name, pItem->str);
printf("\n");
} else {
uInfo("%s %s %s", src, name, pItem->str);
}
break; break;
} }
pItem = cfgIterate(pCfg, pItem); pItem = cfgIterate(pCfg, pItem);
} }
uInfo("================================================================="); if (dump) {
printf("=================================================================");
printf("\n");
} else {
uInfo("=================================================================");
}
} }
#if 0
// int32_t cfgCheck(SConfig *pCfg) {
// SConfigItem *pItem = NULL;
// pItem = cfgGetItem(pCfg, "serverPort");
// if (pItem != NULL) {
// tsServerPort = (uint16_t)pItem->i32;
// }
// pItem = cfgGetItem(pCfg, "firstEp");
// if (pItem != NULL) {
// tstrncpy(tsFirst, pItem->str, TSDB_EP_LEN);
// }
// snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort);
// uInfo("localEp is: %s", tsLocalEp);
// SEp ep = {0};
// if (tsFirst[0] == 0) {
// strcpy(tsFirst, tsLocalEp);
// } else {
// taosGetFqdnPortFromEp(tsFirst, &ep);
// snprintf(tsFirst, TSDB_EP_LEN, "%s:%u", ep.fqdn, ep.port);
// }
// pItem = cfgGetItem(pCfg, "secondEp");
// if (pItem != NULL) {
// tstrncpy(tsSecond, pItem->str, TSDB_EP_LEN);
// }
// if (tsSecond[0] == 0) {
// strcpy(tsSecond, tsLocalEp);
// } else {
// taosGetFqdnPortFromEp(tsSecond, &ep);
// snprintf(tsSecond, TSDB_EP_LEN, "%s:%u", ep.fqdn, ep.port);
// }
// pItem = cfgGetItem(pCfg, "dataDir");
// if (pItem != NULL) {
// tstrncpy(osDataDir(), pItem->str, PATH_MAX);
// }
// if (tsDiskCfgNum <= 0) {
// taosAddDataDir(0, osDataDir(), 0, 1);
// tsDiskCfgNum = 1;
// uTrace("dataDir:%s, level:0 primary:1 is configured by default", osDataDir());
// }
// if (taosDirExist(osTempDir()) != 0) {
// return -1;
// }
// taosGetSystemInfo();
// tsSetLocale();
// // SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
// // if (cfg_timezone && cfg_timezone->cfgStatus == TAOS_CFG_CSTATUS_FILE) {
// tsSetTimeZone();
// // }
// pItem = cfgGetItem(pCfg, "numOfCores");
// if (pItem != NULL) {
// tsNumOfCores = pItem->i32;
// }
// if (tsNumOfCores <= 0) {
// tsNumOfCores = 1;
// }
// if (tsQueryBufferSize >= 0) {
// tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
// }
// cfgPrintCfg(pCfg);
// return 0;
// }
#endif
int32_t cfgLoadFromEnvVar(SConfig *pConfig) { int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
uInfo("load from global env variables"); uInfo("load from global env variables");
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册