refact config
This commit is contained in:
parent
2fcf9dc638
commit
4278439666
|
@ -20,24 +20,39 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tcfg.h"
|
||||
#include "tdef.h"
|
||||
|
||||
// cluster
|
||||
extern int32_t tsVersion;
|
||||
extern int32_t tsStatusInterval;
|
||||
extern bool tsEnableTelemetryReporting;
|
||||
|
||||
// common
|
||||
extern int32_t tsCompressMsgSize;
|
||||
extern int32_t tsCompressColData;
|
||||
extern int32_t tsMaxNumOfDistinctResults;
|
||||
extern int tsCompatibleModel; // 2.0 compatible model
|
||||
extern int8_t tsEnableSlaveQuery;
|
||||
extern int8_t tsEnableAdjustMaster;
|
||||
extern int8_t tsPrintAuth;
|
||||
extern int64_t tsTickPerDay[3];
|
||||
extern int32_t tsRpcTimer;
|
||||
extern int32_t tsRpcMaxTime;
|
||||
extern bool tsRpcForceTcp; // all commands go to tcp protocol if this is enabled
|
||||
extern int32_t tsMaxConnections;
|
||||
extern int32_t tsMaxShellConns;
|
||||
extern int32_t tsShellActivityTimer;
|
||||
extern int32_t tsMaxTmrCtrl;
|
||||
extern float tsNumOfThreadsPerCore;
|
||||
extern int32_t tsNumOfCommitThreads;
|
||||
extern float tsRatioOfQueryCores;
|
||||
extern int32_t tsCompressMsgSize;
|
||||
extern int32_t tsCompressColData;
|
||||
extern int32_t tsMaxNumOfDistinctResults;
|
||||
extern int32_t tsCompatibleModel;
|
||||
extern bool tsEnableSlaveQuery;
|
||||
extern bool tsPrintAuth;
|
||||
extern int64_t tsTickPerDay[3];
|
||||
|
||||
// query buffer management
|
||||
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
|
||||
extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node
|
||||
extern int32_t tsRetrieveBlockingModel; // retrieve threads will be blocked
|
||||
extern int8_t tsKeepOriginalColumnName;
|
||||
extern int8_t tsDeadLockKillQuery;
|
||||
extern bool tsRetrieveBlockingModel; // retrieve threads will be blocked
|
||||
extern bool tsKeepOriginalColumnName;
|
||||
extern bool tsDeadLockKillQuery;
|
||||
|
||||
// client
|
||||
extern int32_t tsMaxWildCardsLen;
|
||||
|
@ -52,13 +67,32 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the
|
|||
extern int32_t tsProjectExecInterval;
|
||||
extern int64_t tsMaxRetentWindow;
|
||||
|
||||
// build info
|
||||
extern char version[];
|
||||
extern char compatible_version[];
|
||||
extern char gitinfo[];
|
||||
extern char gitinfoOfInternal[];
|
||||
extern char buildinfo[];
|
||||
|
||||
// lossy
|
||||
extern char tsLossyColumns[];
|
||||
extern double tsFPrecision;
|
||||
extern double tsDPrecision;
|
||||
extern uint32_t tsMaxRange;
|
||||
extern uint32_t tsCurRange;
|
||||
extern char tsCompressor[];
|
||||
|
||||
// tfs
|
||||
extern int32_t tsDiskCfgNum;
|
||||
extern SDiskCfg tsDiskCfg[];
|
||||
|
||||
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||
|
||||
int32_t taosCfgDynamicOptions(char *msg);
|
||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
|
||||
void taosAddDataDir(int index, char *v1, int level, int primary);
|
||||
void taosReadDataDirCfg(char *v1, char *v2, char *v3);
|
||||
void taosPrintDataDirCfg();
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||
const char *apolloUrl, bool tsc);
|
||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, bool tsc);
|
||||
void taosCleanupCfg();
|
||||
void taosCfgDynamicOptions(const char *option, const char *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -53,11 +53,12 @@ void dndCleanup();
|
|||
/* ------------------------ SDnode ----------------------- */
|
||||
typedef struct {
|
||||
int32_t numOfSupportVnodes;
|
||||
int32_t statusInterval;
|
||||
float numOfThreadsPerCore;
|
||||
float ratioOfQueryCores;
|
||||
int32_t maxShellConns;
|
||||
int32_t shellActivityTimer;
|
||||
// int32_t statusInterval;
|
||||
// float numOfThreadsPerCore;
|
||||
// float ratioOfQueryCores;
|
||||
// int32_t maxShellConns;
|
||||
// int32_t shellActivityTimer;
|
||||
|
||||
uint16_t serverPort;
|
||||
char dataDir[TSDB_FILENAME_LEN];
|
||||
char localEp[TSDB_EP_LEN];
|
||||
|
|
|
@ -47,6 +47,7 @@ void osSetLogReservedSpace(float sizeInGB);
|
|||
void osSetTempReservedSpace(float sizeInGB);
|
||||
void osSetDataReservedSpace(float sizeInGB);
|
||||
void osSetTimezone(const char *timezone);
|
||||
bool osSetEnableCore(bool enable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ typedef enum {
|
|||
typedef struct SConfigItem {
|
||||
ECfgSrcType stype;
|
||||
ECfgDataType dtype;
|
||||
bool tsc;
|
||||
char *name;
|
||||
union {
|
||||
bool bval;
|
||||
|
@ -82,13 +83,12 @@ void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter);
|
|||
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name);
|
||||
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype);
|
||||
|
||||
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal);
|
||||
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval);
|
||||
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval);
|
||||
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, double minval, double maxval);
|
||||
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal);
|
||||
int32_t cfgAddIpStr(SConfig *pCfg, const char *name, const char *defaultVa);
|
||||
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal);
|
||||
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal, bool tsc);
|
||||
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, bool tsc);
|
||||
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, bool tsc);
|
||||
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, double minval, double maxval, bool tsc);
|
||||
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc);
|
||||
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc);
|
||||
int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal);
|
||||
int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal);
|
||||
int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal);
|
||||
|
@ -96,7 +96,7 @@ int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal);
|
|||
const char *cfgStypeStr(ECfgSrcType type);
|
||||
const char *cfgDtypeStr(ECfgDataType type);
|
||||
|
||||
void cfgDumpCfg(SConfig *pCfg);
|
||||
void cfgDumpCfg(SConfig *pCfg, bool tsc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -8,7 +8,7 @@ target_include_directories(
|
|||
target_link_libraries(
|
||||
taos
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport parser planner catalog scheduler function qcom config
|
||||
PRIVATE os util common transport parser planner catalog scheduler function qcom
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
|
|
|
@ -32,7 +32,7 @@ extern "C" {
|
|||
#include "tmsgtype.h"
|
||||
#include "trpc.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "tconfig.h"
|
||||
|
||||
#define CHECK_CODE_GOTO(expr, label) \
|
||||
do { \
|
||||
|
|
|
@ -17,153 +17,6 @@
|
|||
#include "clientInt.h"
|
||||
#include "ulog.h"
|
||||
|
||||
// todo refact
|
||||
SConfig *tscCfg;
|
||||
|
||||
static int32_t tscLoadCfg(SConfig *pConfig, const char *inputCfgDir, const char *envFile, const char *apolloUrl) {
|
||||
char cfgDir[PATH_MAX] = {0};
|
||||
char cfgFile[PATH_MAX + 100] = {0};
|
||||
|
||||
taosExpandDir(inputCfgDir, cfgDir, PATH_MAX);
|
||||
snprintf(cfgFile, sizeof(cfgFile), "%s" TD_DIRSEP "taos.cfg", cfgDir);
|
||||
|
||||
if (cfgLoad(pConfig, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
||||
uError("failed to load from apollo url:%s since %s\n", apolloUrl, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfgLoad(pConfig, CFG_STYPE_CFG_FILE, cfgFile) != 0) {
|
||||
if (cfgLoad(pConfig, CFG_STYPE_CFG_FILE, cfgDir) != 0) {
|
||||
uError("failed to load from config file:%s since %s\n", cfgFile, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfgLoad(pConfig, CFG_STYPE_ENV_FILE, envFile) != 0) {
|
||||
uError("failed to load from env file:%s since %s\n", envFile, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfgLoad(pConfig, CFG_STYPE_ENV_VAR, NULL) != 0) {
|
||||
uError("failed to load from global env variables since %s\n", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tscAddLogCfg(SConfig *pCfg) {
|
||||
if (cfgAddDir(pCfg, "logDir", "/var/log/taos") != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "asyncLog", 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "numOfLogLines", 10000000, 1000, 2000000000) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "cDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "jniDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "tmrDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "uDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "rpcDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tscSetLogCfg(SConfig *pCfg) {
|
||||
osSetLogDir(cfgGetItem(pCfg, "logDir")->str);
|
||||
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
|
||||
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
|
||||
tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32;
|
||||
cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32;
|
||||
jniDebugFlag = cfgGetItem(pCfg, "jniDebugFlag")->i32;
|
||||
tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32;
|
||||
uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32;
|
||||
rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->i32;
|
||||
|
||||
int32_t debugFlag = cfgGetItem(pCfg, "debugFlag")->i32;
|
||||
taosSetAllDebugFlag(debugFlag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tscInitLog(const char *cfgDir, const char *envFile, const char *apolloUrl) {
|
||||
if (tsLogInited) return 0;
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
|
||||
if (tscAddLogCfg(pCfg) != 0) {
|
||||
printf("failed to add log cfg since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tscLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
|
||||
printf("failed to load log cfg since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tscSetLogCfg(pCfg) != 0) {
|
||||
printf("failed to set log cfg since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int32_t maxLogFileNum = 10;
|
||||
if (taosInitLog("taoslog", maxLogFileNum) != 0) {
|
||||
printf("failed to init log file since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cfgDumpCfg(pCfg);
|
||||
cfgCleanup(pCfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tscAddEpCfg(SConfig *pCfg) {
|
||||
char defaultFqdn[TSDB_FQDN_LEN] = {0};
|
||||
if (taosGetFqdn(defaultFqdn) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
if (cfgAddString(pCfg, "fqdn", defaultFqdn) != 0) return -1;
|
||||
|
||||
int32_t defaultServerPort = 6030;
|
||||
if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056) != 0) return -1;
|
||||
|
||||
char defaultFirstEp[TSDB_EP_LEN] = {0};
|
||||
char defaultSecondEp[TSDB_EP_LEN] = {0};
|
||||
snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
snprintf(defaultSecondEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
if (cfgAddString(pCfg, "firstEp", defaultFirstEp) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "secondEp", defaultSecondEp) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tscAddCfg(SConfig *pCfg) {
|
||||
if (tscAddEpCfg(pCfg) != 0) return -1;
|
||||
|
||||
// if (cfgAddString(pCfg, "buildinfo", buildinfo) != 0) return -1;
|
||||
// if (cfgAddString(pCfg, "gitinfo", gitinfo) != 0) return -1;
|
||||
// if (cfgAddString(pCfg, "version", version) != 0) return -1;
|
||||
|
||||
// if (cfgAddDir(pCfg, "dataDir", osDataDir()) != 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", 1, 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, "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;
|
||||
if (cfgAddInt32(pCfg, "maxConnections", 50000, 1, 100000) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tscCheckCfg(SConfig *pCfg) {
|
||||
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
||||
|
|
|
@ -8,13 +8,13 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
|||
ADD_EXECUTABLE(clientTest clientTests.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
clientTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom config
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(tmqTest tmqTest.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
tmqTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom config
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -19,18 +19,32 @@
|
|||
#include "taosdef.h"
|
||||
#include "taoserror.h"
|
||||
#include "tcompare.h"
|
||||
#include "tconfig.h"
|
||||
#include "tep.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
#include "ulog.h"
|
||||
|
||||
// cluster
|
||||
int32_t tsVersion = 30000000;
|
||||
int32_t tsStatusInterval = 1; // second
|
||||
bool tsEnableTelemetryReporting = 0;
|
||||
|
||||
// common
|
||||
int32_t tsRpcTimer = 300;
|
||||
int32_t tsRpcMaxTime = 600; // seconds;
|
||||
bool tsRpcForceTcp = 1; // disable this, means query, show command use udp protocol as default
|
||||
int32_t tsMaxShellConns = 50000;
|
||||
int32_t tsMaxConnections = 50000;
|
||||
int32_t tsShellActivityTimer = 3; // second
|
||||
float tsNumOfThreadsPerCore = 1.0f;
|
||||
int32_t tsNumOfCommitThreads = 4;
|
||||
float tsRatioOfQueryCores = 1.0f;
|
||||
int32_t tsMaxBinaryDisplayWidth = 30;
|
||||
int8_t tsEnableSlaveQuery = 1;
|
||||
int8_t tsEnableAdjustMaster = 1;
|
||||
int8_t tsPrintAuth = 0;
|
||||
bool tsEnableSlaveQuery = 1;
|
||||
bool tsPrintAuth = 0;
|
||||
|
||||
/*
|
||||
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
||||
* metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server.
|
||||
|
@ -93,18 +107,21 @@ int32_t tsQueryBufferSize = -1;
|
|||
int64_t tsQueryBufferSizeBytes = -1;
|
||||
|
||||
// in retrieve blocking model, the retrieve threads will wait for the completion of the query processing.
|
||||
int32_t tsRetrieveBlockingModel = 0;
|
||||
bool tsRetrieveBlockingModel = 0;
|
||||
|
||||
// last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name
|
||||
int8_t tsKeepOriginalColumnName = 0;
|
||||
bool tsKeepOriginalColumnName = 0;
|
||||
|
||||
// long query death-lock
|
||||
int8_t tsDeadLockKillQuery = 0;
|
||||
bool tsDeadLockKillQuery = 0;
|
||||
|
||||
// tsdb config
|
||||
// For backward compatibility
|
||||
bool tsdbForceKeepFile = false;
|
||||
|
||||
int32_t tsDiskCfgNum = 0;
|
||||
SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0};
|
||||
|
||||
/*
|
||||
* minimum scale for whole system, millisecond by default
|
||||
* for TSDB_TIME_PRECISION_MILLI: 86400000L
|
||||
|
@ -113,414 +130,340 @@ bool tsdbForceKeepFile = false;
|
|||
*/
|
||||
int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L};
|
||||
|
||||
int32_t (*monStartSystemFp)() = NULL;
|
||||
void (*monStopSystemFp)() = NULL;
|
||||
void (*monExecuteSQLFp)(char *sql) = NULL;
|
||||
// lossy compress 6
|
||||
char tsLossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty
|
||||
// can close lossy compress.
|
||||
// below option can take effect when tsLossyColumns not empty
|
||||
double tsFPrecision = 1E-8; // float column precision
|
||||
double tsDPrecision = 1E-16; // double column precision
|
||||
uint32_t tsMaxRange = 500; // max range
|
||||
uint32_t tsCurRange = 100; // range
|
||||
char tsCompressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR
|
||||
|
||||
char *qtypeStr[] = {"rpc", "fwd", "wal", "cq", "query"};
|
||||
|
||||
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;
|
||||
|
||||
|
||||
int32_t taosCfgDynamicOptions(char *msg) {
|
||||
#if 0
|
||||
char *option, *value;
|
||||
int32_t olen, vlen;
|
||||
int32_t vint = 0;
|
||||
|
||||
paGetToken(msg, &option, &olen);
|
||||
if (olen == 0) return -1;
|
||||
|
||||
paGetToken(option + olen + 1, &value, &vlen);
|
||||
if (vlen == 0)
|
||||
vint = 135;
|
||||
else {
|
||||
vint = atoi(value);
|
||||
}
|
||||
|
||||
uInfo("change dynamic option: %s, value: %d", option, vint);
|
||||
|
||||
for (int32_t i = 0; i < tsGlobalConfigNum; ++i) {
|
||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||
// if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue;
|
||||
if (cfg->valType != TAOS_CFG_VTYPE_INT32 && cfg->valType != TAOS_CFG_VTYPE_INT8) continue;
|
||||
|
||||
int32_t cfgLen = (int32_t)strlen(cfg->option);
|
||||
if (cfgLen != olen) continue;
|
||||
if (strncasecmp(option, cfg->option, olen) != 0) continue;
|
||||
if (cfg->valType == TAOS_CFG_VTYPE_INT32) {
|
||||
*((int32_t *)cfg->ptr) = vint;
|
||||
} else {
|
||||
*((int8_t *)cfg->ptr) = (int8_t)vint;
|
||||
}
|
||||
|
||||
if (strncasecmp(cfg->option, "monitor", olen) == 0) {
|
||||
if (1 == vint) {
|
||||
if (monStartSystemFp) {
|
||||
(*monStartSystemFp)();
|
||||
uInfo("monitor is enabled");
|
||||
} else {
|
||||
uError("monitor can't be updated, for monitor not initialized");
|
||||
}
|
||||
} else {
|
||||
if (monStopSystemFp) {
|
||||
(*monStopSystemFp)();
|
||||
uInfo("monitor is disabled");
|
||||
} else {
|
||||
uError("monitor can't be updated, for monitor not initialized");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (strncasecmp(cfg->option, "debugFlag", olen) == 0) {
|
||||
taosSetAllDebugFlag();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strncasecmp(option, "resetlog", 8) == 0) {
|
||||
taosResetLog();
|
||||
taosPrintCfg();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strncasecmp(option, "resetQueryCache", 15) == 0) {
|
||||
if (monExecuteSQLFp) {
|
||||
(*monExecuteSQLFp)("resetQueryCache");
|
||||
uInfo("resetquerycache is executed");
|
||||
} else {
|
||||
uError("resetquerycache can't be executed, for monitor not started");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// void taosAddDataDir(int index, char *v1, int level, int primary) {
|
||||
// tstrncpy(tsDiskCfg[index].dir, v1, TSDB_FILENAME_LEN);
|
||||
// tsDiskCfg[index].level = level;
|
||||
// tsDiskCfg[index].primary = primary;
|
||||
// uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
|
||||
// }
|
||||
|
||||
#ifndef _STORAGE
|
||||
// void taosReadDataDirCfg(char *v1, char *v2, char *v3) {
|
||||
// if (tsDiskCfgNum == 1) {
|
||||
// SDiskCfg *cfg = &tsDiskCfg[0];
|
||||
// uInfo("dataDir:%s, level:%d primary:%d is replaced by %s", cfg->dir, cfg->level, cfg->primary, v1);
|
||||
// }
|
||||
// taosAddDataDir(0, v1, 0, 1);
|
||||
// tsDiskCfgNum = 1;
|
||||
// }
|
||||
|
||||
// void taosPrintDataDirCfg() {
|
||||
// for (int i = 0; i < tsDiskCfgNum; ++i) {
|
||||
// SDiskCfg *cfg = &tsDiskCfg[i];
|
||||
// uInfo(" dataDir: %s", cfg->dir);
|
||||
// }
|
||||
// }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static void doInitGlobalConfig(void) {
|
||||
osInit();
|
||||
srand(taosSafeRand());
|
||||
#if 0
|
||||
SGlobalCfg cfg = {0};
|
||||
|
||||
|
||||
cfg.option = "dataDir";
|
||||
cfg.ptr = osDataDir();
|
||||
cfg.valType = TAOS_CFG_VTYPE_DATA_DIRCTORY;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = TSDB_FILENAME_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
|
||||
cfg.option = "maxNumOfDistinctRes";
|
||||
cfg.ptr = &tsMaxNumOfDistinctResults;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 10 * 10000;
|
||||
cfg.maxValue = 10000 * 10000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "minSlidingTime";
|
||||
cfg.ptr = &tsMinSlidingTime;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 10;
|
||||
cfg.maxValue = 1000000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_MS;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "minIntervalTime";
|
||||
cfg.ptr = &tsMinIntervalTime;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 1000000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_MS;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxStreamCompDelay";
|
||||
cfg.ptr = &tsMaxStreamComputDelay;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 10;
|
||||
cfg.maxValue = 1000000000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_MS;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxFirstStreamCompDelay";
|
||||
cfg.ptr = &tsStreamCompStartDelay;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 1000;
|
||||
cfg.maxValue = 1000000000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_MS;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "retryStreamCompDelay";
|
||||
cfg.ptr = &tsRetryStreamCompDelay;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 10;
|
||||
cfg.maxValue = 1000000000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_MS;
|
||||
|
||||
taosAddConfigOption(cfg);
|
||||
cfg.option = "streamCompDelayRatio";
|
||||
cfg.ptr = &tsStreamComputDelayRatio;
|
||||
cfg.valType = TAOS_CFG_VTYPE_FLOAT;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0.1f;
|
||||
cfg.maxValue = 0.9f;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "compressMsgSize";
|
||||
cfg.ptr = &tsCompressMsgSize;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = -1;
|
||||
cfg.maxValue = 100000000.0f;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "compressColData";
|
||||
cfg.ptr = &tsCompressColData;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = -1;
|
||||
cfg.maxValue = 100000000.0f;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxWildCardsLength";
|
||||
cfg.ptr = &tsMaxWildCardsLen;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = TSDB_MAX_FIELD_LEN;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_BYTE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxRegexStringLen";
|
||||
cfg.ptr = &tsMaxRegexStringLen;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = TSDB_MAX_FIELD_LEN;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_BYTE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxNumOfOrderedRes";
|
||||
cfg.ptr = &tsMaxNumOfOrderedResults;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MAX_SQL_LEN;
|
||||
cfg.maxValue = TSDB_MAX_ALLOWED_SQL_LEN;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "queryBufferSize";
|
||||
cfg.ptr = &tsQueryBufferSize;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = -1;
|
||||
cfg.maxValue = 500000000000.0f;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_BYTE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "retrieveBlockingModel";
|
||||
cfg.ptr = &tsRetrieveBlockingModel;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 1;
|
||||
cfg.ptrLength = 1;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "keepColumnName";
|
||||
cfg.ptr = &tsKeepOriginalColumnName;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 1;
|
||||
cfg.ptrLength = 1;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
|
||||
|
||||
cfg.option = "slaveQuery";
|
||||
cfg.ptr = &tsEnableSlaveQuery;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 1;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
|
||||
cfg.option = "maxBinaryDisplayWidth";
|
||||
cfg.ptr = &tsMaxBinaryDisplayWidth;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 65536;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "tempDir";
|
||||
cfg.ptr = osTempDir();
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = PATH_MAX;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// enable kill long query
|
||||
cfg.option = "deadLockKillQuery";
|
||||
cfg.ptr = &tsDeadLockKillQuery;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 1;
|
||||
cfg.ptrLength = 1;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
#ifdef TD_TSZ
|
||||
// lossy compress
|
||||
cfg.option = "lossyColumns";
|
||||
cfg.ptr = lossyColumns;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = tListLen(lossyColumns);
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "fPrecision";
|
||||
cfg.ptr = &fPrecision;
|
||||
cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = MIN_FLOAT;
|
||||
cfg.maxValue = 100000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "dPrecision";
|
||||
cfg.ptr = &dPrecision;
|
||||
cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 100000;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxRange";
|
||||
cfg.ptr = &maxRange;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 65536;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "range";
|
||||
cfg.ptr = &curRange;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 65536;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
|
||||
#else
|
||||
// assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
void taosAddDataDir(int index, char *v1, int level, int primary) {
|
||||
tstrncpy(tsDiskCfg[index].dir, v1, TSDB_FILENAME_LEN);
|
||||
tsDiskCfg[index].level = level;
|
||||
tsDiskCfg[index].primary = primary;
|
||||
uTrace("dataDir:%s, level:%d primary:%d is configured", v1, level, primary);
|
||||
}
|
||||
|
||||
/*
|
||||
* alter dnode 1 balance "vnode:1-dnode:2"
|
||||
*/
|
||||
|
||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId) {
|
||||
int len = (int)strlen(option);
|
||||
if (strncasecmp(option, "vnode:", 6) != 0) {
|
||||
return false;
|
||||
void taosReadDataDirCfg(char *v1, char *v2, char *v3) {
|
||||
if (tsDiskCfgNum == 1) {
|
||||
SDiskCfg *cfg = &tsDiskCfg[0];
|
||||
uInfo("dataDir:%s, level:%d primary:%d is replaced by %s", cfg->dir, cfg->level, cfg->primary, v1);
|
||||
}
|
||||
taosAddDataDir(0, v1, 0, 1);
|
||||
tsDiskCfgNum = 1;
|
||||
}
|
||||
|
||||
void taosPrintDataDirCfg() {
|
||||
for (int i = 0; i < tsDiskCfgNum; ++i) {
|
||||
SDiskCfg *cfg = &tsDiskCfg[i];
|
||||
uInfo(" dataDir: %s", cfg->dir);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void taosInitGlobalCfg() { pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); }
|
||||
|
||||
int32_t taosCheckAndPrintCfg() {
|
||||
SEp ep = {0};
|
||||
if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
|
||||
taosSetAllDebugFlag();
|
||||
}
|
||||
|
||||
if (tsLocalFqdn[0] == 0) {
|
||||
taosGetFqdn(tsLocalFqdn);
|
||||
}
|
||||
|
||||
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
|
||||
uInfo("localEp is: %s", tsLocalEp);
|
||||
|
||||
if (tsFirst[0] == 0) {
|
||||
strcpy(tsFirst, tsLocalEp);
|
||||
} else {
|
||||
taosGetFqdnPortFromEp(tsFirst, &ep);
|
||||
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", ep.fqdn, ep.port);
|
||||
}
|
||||
|
||||
if (tsSecond[0] == 0) {
|
||||
strcpy(tsSecond, tsLocalEp);
|
||||
} else {
|
||||
taosGetFqdnPortFromEp(tsSecond, &ep);
|
||||
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", ep.fqdn, ep.port);
|
||||
}
|
||||
|
||||
taosCheckDataDirCfg();
|
||||
|
||||
if (taosDirExist(tsTempDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosGetSystemInfo();
|
||||
|
||||
tsSetLocale();
|
||||
|
||||
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
|
||||
if (cfg_timezone && cfg_timezone->cfgStatus == TAOS_CFG_CSTATUS_FILE) {
|
||||
tsSetTimeZone();
|
||||
}
|
||||
|
||||
if (tsNumOfCores <= 0) {
|
||||
tsNumOfCores = 1;
|
||||
}
|
||||
|
||||
if (tsQueryBufferSize >= 0) {
|
||||
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
|
||||
}
|
||||
|
||||
uInfo(" check global cfg completed");
|
||||
uInfo("==================================");
|
||||
taosPrintCfg();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosPrintLog(){}
|
||||
|
||||
#endif
|
||||
|
||||
static SConfig *tsCfg = NULL;
|
||||
|
||||
static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) {
|
||||
char cfgDir[PATH_MAX] = {0};
|
||||
char cfgFile[PATH_MAX + 100] = {0};
|
||||
|
||||
taosExpandDir(inputCfgDir, cfgDir, PATH_MAX);
|
||||
snprintf(cfgFile, sizeof(cfgFile), "%s" TD_DIRSEP "taos.cfg", cfgDir);
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
||||
uError("failed to load from apollo url:%s since %s\n", apolloUrl, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) {
|
||||
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgDir) != 0) {
|
||||
uError("failed to load from config file:%s since %s\n", cfgFile, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile) != 0) {
|
||||
uError("failed to load from env file:%s since %s\n", envFile, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL) != 0) {
|
||||
uError("failed to load from global env variables since %s\n", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void taosAddClientLogCfg(SConfig *pCfg) {
|
||||
cfgAddDir(pCfg, "logDir", osLogDir(), 1);
|
||||
cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, 1);
|
||||
cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1);
|
||||
cfgAddBool(pCfg, "asyncLog", tsAsyncLog, 1);
|
||||
cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000, 1);
|
||||
cfgAddInt32(pCfg, "cDebugFlag", cDebugFlag, 0, 255, 1);
|
||||
cfgAddInt32(pCfg, "uDebugFlag", uDebugFlag, 0, 255, 1);
|
||||
cfgAddInt32(pCfg, "rpcDebugFlag", rpcDebugFlag, 0, 255, 1);
|
||||
cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1);
|
||||
cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1);
|
||||
}
|
||||
|
||||
static void taosAddServerLogCfg(SConfig *pCfg) {
|
||||
taosAddClientLogCfg(pCfg);
|
||||
cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "vDebugFlag", vDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "mDebugFlag", mDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "wDebugFlag", wDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "sDebugFlag", sDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "tsdbDebugFlag", tsdbDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "tqDebugFlag", tqDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "fsDebugFlag", fsDebugFlag, 0, 255, 0);
|
||||
cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1);
|
||||
cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1);
|
||||
}
|
||||
|
||||
static void taosAddClientCfg(SConfig *pCfg) {
|
||||
char defaultFqdn[TSDB_FQDN_LEN] = {0};
|
||||
int32_t defaultServerPort = 6030;
|
||||
char defaultFirstEp[TSDB_EP_LEN] = {0};
|
||||
char defaultSecondEp[TSDB_EP_LEN] = {0};
|
||||
taosGetFqdn(defaultFqdn);
|
||||
snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
snprintf(defaultSecondEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
|
||||
cfgAddString(pCfg, "firstEp", defaultFirstEp, 1);
|
||||
cfgAddString(pCfg, "secondEp", defaultSecondEp, 1);
|
||||
cfgAddString(pCfg, "fqdn", defaultFqdn, 1);
|
||||
cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056, 1);
|
||||
cfgAddDir(pCfg, "tempDir", osTempDir(), 1);
|
||||
cfgAddString(pCfg, "configDir", configDir, 1);
|
||||
cfgAddString(pCfg, "scriptDir", configDir, 1);
|
||||
cfgAddFloat(pCfg, "minimalTempDirGB", 1.0f, 0.001f, 10000000, 1);
|
||||
cfgAddFloat(pCfg, "numOfThreadsPerCore", tsNumOfThreadsPerCore, 0, 10, 1);
|
||||
cfgAddInt32(pCfg, "maxTmrCtrl", tsMaxTmrCtrl, 8, 2048, 1);
|
||||
cfgAddInt32(pCfg, "rpcTimer", tsRpcTimer, 100, 3000, 1);
|
||||
cfgAddInt32(pCfg, "rpcMaxTime", tsRpcMaxTime, 100, 7200, 1);
|
||||
cfgAddBool(pCfg, "rpcForceTcp", tsRpcForceTcp, 1);
|
||||
cfgAddInt32(pCfg, "shellActivityTimer", tsShellActivityTimer, 1, 120, 1);
|
||||
cfgAddInt32(pCfg, "compressMsgSize", tsCompressMsgSize, -1, 100000000, 1);
|
||||
cfgAddInt32(pCfg, "compressColData", tsCompressColData, -1, 100000000, 1);
|
||||
cfgAddInt32(pCfg, "maxWildCardsLength", tsMaxWildCardsLen, 0, TSDB_MAX_FIELD_LEN, 1);
|
||||
cfgAddInt32(pCfg, "maxRegexStringLen", tsMaxRegexStringLen, 0, TSDB_MAX_FIELD_LEN, 1);
|
||||
cfgAddInt32(pCfg, "maxNumOfOrderedRes", tsMaxNumOfOrderedResults, 128, TSDB_MAX_ALLOWED_SQL_LEN, 1);
|
||||
cfgAddBool(pCfg, "keepColumnName", tsKeepOriginalColumnName, 1);
|
||||
cfgAddInt32(pCfg, "numOfCores", 1, 1, 100000, 1);
|
||||
cfgAddBool(pCfg, "enableCoreFile", 0, 1);
|
||||
cfgAddInt32(pCfg, "maxBinaryDisplayWidth", tsMaxBinaryDisplayWidth, 1, 65536, 1);
|
||||
cfgAddString(pCfg, "version", version, 1);
|
||||
cfgAddString(pCfg, "compatible_version", compatible_version, 1);
|
||||
cfgAddString(pCfg, "gitinfo", gitinfo, 1);
|
||||
cfgAddString(pCfg, "gitinfoOfInternal", gitinfoOfInternal, 1);
|
||||
cfgAddString(pCfg, "buildinfo", buildinfo, 1);
|
||||
cfgAddTimezone(pCfg, "timezone", osTimezone());
|
||||
cfgAddLocale(pCfg, "locale", osLocale());
|
||||
cfgAddCharset(pCfg, "charset", osCharset);
|
||||
}
|
||||
|
||||
static void taosAddServerCfg(SConfig *pCfg) {
|
||||
taosAddClientCfg(pCfg);
|
||||
cfgAddInt32(pCfg, "supportVnodes", 256, 0, 65536, 0);
|
||||
cfgAddDir(pCfg, "dataDir", osDataDir(), 0);
|
||||
cfgAddFloat(pCfg, "minimalDataDirGB", 2.0f, 0.001f, 10000000, 0);
|
||||
cfgAddInt32(pCfg, "numOfCommitThreads", tsNumOfCommitThreads, 1, 100, 0);
|
||||
cfgAddFloat(pCfg, "ratioOfQueryCores", tsRatioOfQueryCores, 0, 2, 0);
|
||||
cfgAddInt32(pCfg, "maxNumOfDistinctRes", tsMaxNumOfDistinctResults, 10 * 10000, 10000 * 10000, 0);
|
||||
cfgAddBool(pCfg, "telemetryReporting", tsEnableTelemetryReporting, 0);
|
||||
cfgAddInt32(pCfg, "maxConnections", tsMaxConnections, 1, 100000, 0);
|
||||
cfgAddInt32(pCfg, "maxShellConns", tsMaxShellConns, 10, 50000000, 0);
|
||||
cfgAddInt32(pCfg, "statusInterval", tsStatusInterval, 1, 30, 0);
|
||||
cfgAddInt32(pCfg, "minSlidingTime", tsMinSlidingTime, 10, 1000000, 0);
|
||||
cfgAddInt32(pCfg, "minIntervalTime", tsMinIntervalTime, 1, 1000000, 0);
|
||||
cfgAddInt32(pCfg, "maxStreamCompDelay", tsMaxStreamComputDelay, 10, 1000000000, 0);
|
||||
cfgAddInt32(pCfg, "maxFirstStreamCompDelay", tsStreamCompStartDelay, 1000, 1000000000, 0);
|
||||
cfgAddInt32(pCfg, "retryStreamCompDelay", tsRetryStreamCompDelay, 10, 1000000000, 0);
|
||||
cfgAddFloat(pCfg, "streamCompDelayRatio", tsStreamComputDelayRatio, 0.1, 0.9, 0);
|
||||
cfgAddInt32(pCfg, "queryBufferSize", tsQueryBufferSize, -1, 500000000000, 0);
|
||||
cfgAddBool(pCfg, "retrieveBlockingModel", tsRetrieveBlockingModel, 0);
|
||||
cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0);
|
||||
cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0);
|
||||
cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0);
|
||||
}
|
||||
|
||||
static void taosSetClientLogCfg(SConfig *pCfg) {
|
||||
osSetLogDir(cfgGetItem(pCfg, "logDir")->str);
|
||||
osSetDataReservedSpace(cfgGetItem(pCfg, "minimalLogDirGB")->fval);
|
||||
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
|
||||
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
|
||||
tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32;
|
||||
cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32;
|
||||
uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32;
|
||||
rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->i32;
|
||||
tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32;
|
||||
jniDebugFlag = cfgGetItem(pCfg, "jniDebugFlag")->i32;
|
||||
}
|
||||
|
||||
static void taosSetServerLogCfg(SConfig *pCfg) {
|
||||
dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32;
|
||||
vDebugFlag = cfgGetItem(pCfg, "vDebugFlag")->i32;
|
||||
mDebugFlag = cfgGetItem(pCfg, "mDebugFlag")->i32;
|
||||
qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32;
|
||||
wDebugFlag = cfgGetItem(pCfg, "wDebugFlag")->i32;
|
||||
sDebugFlag = cfgGetItem(pCfg, "sDebugFlag")->i32;
|
||||
tsdbDebugFlag = cfgGetItem(pCfg, "tsdbDebugFlag")->i32;
|
||||
tqDebugFlag = cfgGetItem(pCfg, "tqDebugFlag")->i32;
|
||||
fsDebugFlag = cfgGetItem(pCfg, "fsDebugFlag")->i32;
|
||||
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
|
||||
}
|
||||
|
||||
static void taosSetClientCfg(SConfig *pCfg) {
|
||||
osSetTempDir(cfgGetItem(pCfg, "tempDir")->str);
|
||||
osSetDataReservedSpace(cfgGetItem(pCfg, "minimalTempDirGB")->fval);
|
||||
}
|
||||
|
||||
static void taosSetServerCfg(SConfig *pCfg) {
|
||||
osSetDataDir(cfgGetItem(pCfg, "dataDir")->str);
|
||||
osSetTempReservedSpace(cfgGetItem(pCfg, "minimalDataDirGB")->fval);
|
||||
}
|
||||
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||
const char *apolloUrl, bool tsc) {
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (tsCfg == NULL) return -1;
|
||||
|
||||
if (tsc) {
|
||||
aosAddClientLogCfg(pCfg);
|
||||
} else {
|
||||
ttaosAddServerLogCfg(pCfg);
|
||||
}
|
||||
|
||||
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) {
|
||||
uError("failed to load cfg since %", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsc) {
|
||||
taosSetClientLogCfg(pCfg);
|
||||
} else {
|
||||
taosSetServerLogCfg(pCfg);
|
||||
}
|
||||
|
||||
if (taosInitLog(logname, logFileNum) != 0) {
|
||||
printf("failed to init log file since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cfgCleanup(pCfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, bool tsc) {
|
||||
if (tsCfg != NULL) return 0;
|
||||
tsCfg = cfgInit();
|
||||
if (tsCfg == NULL) return -1;
|
||||
|
||||
if (tsc) {
|
||||
taosAddServerCfg(tsCfg);
|
||||
} else {
|
||||
taosAddClientCfg(tsCfg);
|
||||
}
|
||||
|
||||
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) {
|
||||
uError("failed to load cfg since %", terrstr());
|
||||
cfgCleanup(tsCfg);
|
||||
tsCfg = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsc) {
|
||||
taosSetClientCfg(tsCfg);
|
||||
} else {
|
||||
taosSetServerCfg(tsCfg);
|
||||
}
|
||||
|
||||
cfgDumpCfg(tsCfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosCfgDynamicOptions(const char *option, const char *value) {
|
||||
if (strcasecmp(option, "debugFlag") == 0) {
|
||||
int32_t debugFlag = atoi(value);
|
||||
taosSetAllDebugFlag(debugFlag);
|
||||
}
|
||||
|
||||
if (strcasecmp(option, "resetlog") == 0) {
|
||||
taosResetLog();
|
||||
// taosPrintCfg();
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
for (; pos < len; ++pos) {
|
||||
if (option[pos] == '-') break;
|
||||
}
|
||||
|
||||
if (++pos >= len) return false;
|
||||
if (strncasecmp(option + pos, "dnode:", 6) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*vnodeId = strtol(option + 6, NULL, 10);
|
||||
*dnodeId = strtol(option + pos + 6, NULL, 10);
|
||||
if (*vnodeId <= 1 || *dnodeId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,4 +6,4 @@ target_include_directories(
|
|||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
target_link_libraries(taosd dnode config util os)
|
||||
target_link_libraries(taosd dnode util os)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#ifndef _TD_DMN_INT_H_
|
||||
#define _TD_DMN_INT_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "tconfig.h"
|
||||
#include "dnode.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
|
|
|
@ -16,47 +16,8 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "dmnInt.h"
|
||||
|
||||
static int32_t dmnAddEpCfg(SConfig *pCfg) {
|
||||
char defaultFqdn[TSDB_FQDN_LEN] = {0};
|
||||
if (taosGetFqdn(defaultFqdn) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
if (cfgAddString(pCfg, "fqdn", defaultFqdn) != 0) return -1;
|
||||
|
||||
int32_t defaultServerPort = 6030;
|
||||
if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056) != 0) return -1;
|
||||
|
||||
char defaultFirstEp[TSDB_EP_LEN] = {0};
|
||||
char defaultSecondEp[TSDB_EP_LEN] = {0};
|
||||
snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
snprintf(defaultSecondEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
if (cfgAddString(pCfg, "firstEp", defaultFirstEp) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "secondEp", defaultSecondEp) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmnAddDirCfg(SConfig *pCfg) {
|
||||
if (cfgAddDir(pCfg, "dataDir", osDataDir()) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "tempDir", osTempDir()) != 0) return -1;
|
||||
if (cfgAddFloat(pCfg, "minimalDataDirGB", 2.0f, 0.001f, 10000000) != 0) return -1;
|
||||
if (cfgAddFloat(pCfg, "minimalTempDirGB", 1.0f, 0.001f, 10000000) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmnCheckDirCfg(SConfig *pCfg) {
|
||||
osSetDataDir(cfgGetItem(pCfg, "dataDir")->str);
|
||||
osSetTempDir(cfgGetItem(pCfg, "tempDir")->str);
|
||||
osSetTempReservedSpace(cfgGetItem(pCfg, "minimalDataDirGB")->fval);
|
||||
osSetDataReservedSpace(cfgGetItem(pCfg, "minimalTempDirGB")->fval);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmnAddVersionCfg(SConfig *pCfg) {
|
||||
if (cfgAddString(pCfg, "buildinfo", buildinfo) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "gitinfo", gitinfo) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "version", version) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -167,7 +128,6 @@ void dmnDumpCfg(SConfig *pCfg) {
|
|||
printf("cfg:%s, value:%f src:%s\n", pItem->name, pItem->fval, cfgStypeStr(pItem->stype));
|
||||
break;
|
||||
case CFG_DTYPE_STRING:
|
||||
case CFG_DTYPE_IPSTR:
|
||||
case CFG_DTYPE_DIR:
|
||||
case CFG_DTYPE_LOCALE:
|
||||
case CFG_DTYPE_CHARSET:
|
||||
|
@ -197,11 +157,11 @@ SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg) {
|
|||
SDnodeObjCfg objCfg = {0};
|
||||
|
||||
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;
|
||||
// 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.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp));
|
||||
|
|
|
@ -46,9 +46,6 @@ int32_t dmnSetLogCfg(SConfig *pCfg) {
|
|||
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
|
||||
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
|
||||
tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32;
|
||||
dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32;
|
||||
vDebugFlag = cfgGetItem(pCfg, "vDebugFlag")->i32;
|
||||
mDebugFlag = cfgGetItem(pCfg, "mDebugFlag")->i32;
|
||||
cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32;
|
||||
jniDebugFlag = cfgGetItem(pCfg, "jniDebugFlag")->i32;
|
||||
tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32;
|
||||
|
|
|
@ -35,6 +35,7 @@ extern "C" {
|
|||
#include "tthread.h"
|
||||
#include "ttime.h"
|
||||
#include "tworker.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
#include "dnode.h"
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ void dndSendStatusReq(SDnode *pDnode) {
|
|||
req.numOfSupportVnodes = pDnode->cfg.numOfSupportVnodes;
|
||||
memcpy(req.dnodeEp, pDnode->cfg.localEp, TSDB_EP_LEN);
|
||||
|
||||
req.clusterCfg.statusInterval = pDnode->cfg.statusInterval;
|
||||
req.clusterCfg.statusInterval = tsStatusInterval;
|
||||
req.clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
|
@ -475,7 +475,7 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
|||
static void *dnodeThreadRoutine(void *param) {
|
||||
SDnode *pDnode = param;
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
int32_t ms = pDnode->cfg.statusInterval * 1000;
|
||||
int32_t ms = tsStatusInterval * 1000;
|
||||
|
||||
setThreadName("dnode-hb");
|
||||
|
||||
|
|
|
@ -275,8 +275,6 @@ static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
|||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->env.sver;
|
||||
pOption->cfg.enableTelem = pDnode->env.enableTelem;
|
||||
pOption->cfg.statusInterval = pDnode->cfg.statusInterval;
|
||||
pOption->cfg.shellActivityTimer = pDnode->cfg.shellActivityTimer;
|
||||
}
|
||||
|
||||
static void dndBuildMnodeDeployOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
|
|
|
@ -189,7 +189,7 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
rpcInit.cfp = dndProcessResponse;
|
||||
rpcInit.sessions = 1024;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = pDnode->cfg.shellActivityTimer * 1000;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.user = INTERNAL_USER;
|
||||
rpcInit.ckey = INTERNAL_CKEY;
|
||||
rpcInit.spi = 1;
|
||||
|
@ -344,7 +344,7 @@ static int32_t dndInitServer(SDnode *pDnode) {
|
|||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
dndInitMsgFp(pMgmt);
|
||||
|
||||
int32_t numOfThreads = (int32_t)((pDnode->env.numOfCores * pDnode->cfg.numOfThreadsPerCore) / 2.0);
|
||||
int32_t numOfThreads = (int32_t)((pDnode->env.numOfCores * tsNumOfThreadsPerCore) / 2.0);
|
||||
if (numOfThreads < 1) {
|
||||
numOfThreads = 1;
|
||||
}
|
||||
|
@ -355,9 +355,9 @@ static int32_t dndInitServer(SDnode *pDnode) {
|
|||
rpcInit.label = "D-S";
|
||||
rpcInit.numOfThreads = numOfThreads;
|
||||
rpcInit.cfp = dndProcessRequest;
|
||||
rpcInit.sessions = pDnode->cfg.maxShellConns;
|
||||
rpcInit.sessions = tsMaxShellConns;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = pDnode->cfg.shellActivityTimer * 1000;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.afp = dndRetrieveUserAuthInfo;
|
||||
rpcInit.parent = pDnode;
|
||||
|
||||
|
|
|
@ -875,7 +875,7 @@ static int32_t dndInitVnodeWorkers(SDnode *pDnode) {
|
|||
|
||||
int32_t maxFetchThreads = 4;
|
||||
int32_t minFetchThreads = TMIN(maxFetchThreads, pDnode->env.numOfCores);
|
||||
int32_t minQueryThreads = TMAX((int32_t)(pDnode->env.numOfCores * pDnode->cfg.ratioOfQueryCores), 1);
|
||||
int32_t minQueryThreads = TMAX((int32_t)(pDnode->env.numOfCores * tsRatioOfQueryCores), 1);
|
||||
int32_t maxQueryThreads = minQueryThreads;
|
||||
int32_t maxWriteThreads = TMAX(pDnode->env.numOfCores, 1);
|
||||
int32_t maxSyncThreads = TMAX(pDnode->env.numOfCores / 2, 1);
|
||||
|
|
|
@ -25,11 +25,6 @@ void* serverLoop(void* param) {
|
|||
SDnodeObjCfg TestServer::BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SDnodeObjCfg cfg = {0};
|
||||
cfg.numOfSupportVnodes = 16;
|
||||
cfg.statusInterval = 1;
|
||||
cfg.numOfThreadsPerCore = 1;
|
||||
cfg.ratioOfQueryCores = 1;
|
||||
cfg.maxShellConns = 1000;
|
||||
cfg.shellActivityTimer = 30;
|
||||
cfg.serverPort = port;
|
||||
strcpy(cfg.dataDir, path);
|
||||
snprintf(cfg.localEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
|
||||
|
|
|
@ -14,5 +14,4 @@ add_subdirectory(qcom)
|
|||
add_subdirectory(qworker)
|
||||
add_subdirectory(tfs)
|
||||
add_subdirectory(nodes)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(scalar)
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
aux_source_directory(src CONFIG_SRC)
|
||||
add_library(config STATIC ${CONFIG_SRC})
|
||||
target_include_directories(
|
||||
config
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/config"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
target_link_libraries(config os util common)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
ADD_SUBDIRECTORY(test)
|
||||
endif(${BUILD_TEST})
|
|
@ -1,47 +0,0 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_CFG_INT_H_
|
||||
#define _TD_CFG_INT_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "taoserror.h"
|
||||
#include "thash.h"
|
||||
#include "tutil.h"
|
||||
#include "ulog.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SConfig {
|
||||
ECfgSrcType stype;
|
||||
SHashObj *hash;
|
||||
} SConfig;
|
||||
|
||||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig);
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
|
||||
|
||||
int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_CFG_INT_H_*/
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "cfgInt.h"
|
||||
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
||||
uInfo("load from apoll url %s", url);
|
||||
return 0;
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "cfgInt.h"
|
||||
|
||||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
||||
char *line, *name, *value, *value2, *value3;
|
||||
int olen, vlen, vlen2, vlen3;
|
||||
ssize_t _bytes = 0;
|
||||
size_t len = 1024;
|
||||
|
||||
FILE *fp = fopen(filepath, "r");
|
||||
if (fp == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
line = malloc(len);
|
||||
|
||||
while (!feof(fp)) {
|
||||
memset(line, 0, len);
|
||||
|
||||
name = value = value2 = value3 = NULL;
|
||||
olen = vlen = vlen2 = vlen3 = 0;
|
||||
|
||||
_bytes = tgetline(&line, &len, fp);
|
||||
if (_bytes < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
line[len - 1] = 0;
|
||||
|
||||
paGetToken(line, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
name[olen] = 0;
|
||||
|
||||
paGetToken(name + olen + 1, &value, &vlen);
|
||||
if (vlen == 0) continue;
|
||||
value[vlen] = 0;
|
||||
|
||||
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||
if (vlen2 != 0) {
|
||||
value2[vlen2] = 0;
|
||||
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||
if (vlen3 != 0) value3[vlen3] = 0;
|
||||
}
|
||||
|
||||
cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE);
|
||||
// taosReadConfigOption(name, value, value2, value3);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
tfree(line);
|
||||
|
||||
uInfo("load from cfg file %s success", filepath);
|
||||
return 0;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "cfgInt.h"
|
||||
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) {
|
||||
uInfo("load from env file %s", filepath);
|
||||
return 0;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "cfgInt.h"
|
||||
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
||||
uInfo("load from global env variables");
|
||||
return 0;
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
enable_testing()
|
||||
|
||||
aux_source_directory(. CFG_TEST_SRC)
|
||||
add_executable(cfg_test ${CFG_TEST_SRC})
|
||||
target_link_libraries(
|
||||
cfg_test
|
||||
PUBLIC config
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME cfg_test
|
||||
COMMAND cfg_test
|
||||
)
|
|
@ -31,6 +31,7 @@ typedef struct SOsEnv {
|
|||
char locale[TD_LOCALE_LEN];
|
||||
char charset[TD_CHARSET_LEN];
|
||||
int8_t daylight;
|
||||
bool enableCoreFile;
|
||||
} SOsEnv;
|
||||
|
||||
static SOsEnv env = {0};
|
||||
|
@ -73,6 +74,7 @@ void osSetLogReservedSpace(float sizeInGB) { env.logSpace.reserved = sizeInGB; }
|
|||
void osSetTempReservedSpace(float sizeInGB) { env.tempSpace.reserved = sizeInGB; }
|
||||
void osSetDataReservedSpace(float sizeInGB) { env.dataSpace.reserved = sizeInGB; }
|
||||
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, env.timezone, &env.daylight); }
|
||||
bool osSetEnableCore(bool enable) { env.enableCoreFile = enable; }
|
||||
|
||||
void osInit() {
|
||||
srand(taosSafeRand());
|
||||
|
|
|
@ -14,12 +14,25 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "cfgInt.h"
|
||||
#include "tep.h"
|
||||
#include "tmsg.h"
|
||||
#include "tconfig.h"
|
||||
#include "taoserror.h"
|
||||
#include "thash.h"
|
||||
#include "tutil.h"
|
||||
#include "ulog.h"
|
||||
|
||||
#define CFG_NAME_PRINT_LEN 22
|
||||
#define CFG_SRC_PRINT_LEN 12
|
||||
#define CFG_SRC_PRINT_LEN 12
|
||||
|
||||
typedef struct SConfig {
|
||||
ECfgSrcType stype;
|
||||
SHashObj *hash;
|
||||
} SConfig;
|
||||
|
||||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath);
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig);
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
|
||||
int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype);
|
||||
|
||||
SConfig *cfgInit() {
|
||||
SConfig *pCfg = calloc(1, sizeof(SConfig));
|
||||
|
@ -131,23 +144,6 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgCheckAndSetIpStr(SConfigItem *pItem, const char *ip) {
|
||||
uint32_t value = taosInetAddr(ip);
|
||||
if (value == INADDR_NONE) {
|
||||
uError("ip:%s is not a valid ip address", ip);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tfree(pItem->str);
|
||||
pItem->str = strdup(ip);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgSetBool(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
bool tmp = false;
|
||||
if (strcasecmp(value, "true") == 0) {
|
||||
|
@ -223,20 +219,6 @@ static int32_t cfgSetString(SConfigItem *pItem, const char *value, ECfgSrcType s
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgSetIpStr(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
char *tmp = strdup(value);
|
||||
if (tmp == NULL || cfgCheckAndSetIpStr(pItem, value) != 0) {
|
||||
free(tmp);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s, use last src:%s value:%s", pItem->name,
|
||||
cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgSetDir(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
char *tmp = strdup(value);
|
||||
if (tmp == NULL || cfgCheckAndSetDir(pItem, value) != 0) {
|
||||
|
@ -310,8 +292,6 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
|
|||
return cfgSetFloat(pItem, value, stype);
|
||||
case CFG_DTYPE_STRING:
|
||||
return cfgSetString(pItem, value, stype);
|
||||
case CFG_DTYPE_IPSTR:
|
||||
return cfgSetIpStr(pItem, value, stype);
|
||||
case CFG_DTYPE_DIR:
|
||||
return cfgSetDir(pItem, value, stype);
|
||||
case CFG_DTYPE_TIMEZONE:
|
||||
|
@ -366,43 +346,43 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_BOOL, .bval = defaultVal};
|
||||
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal, bool tsc) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_BOOL, .bval = defaultVal, .tsc = tsc};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval) {
|
||||
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, bool tsc) {
|
||||
if (defaultVal < minval || defaultVal > maxval) {
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_INT32, .i32 = defaultVal, .imin = minval, .imax = maxval};
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_INT32, .i32 = defaultVal, .imin = minval, .imax = maxval, .tsc = tsc};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval) {
|
||||
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, bool tsc) {
|
||||
if (defaultVal < minval || defaultVal > maxval) {
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_INT64, .i64 = defaultVal, .imin = minval, .imax = maxval};
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_INT64, .i64 = defaultVal, .imin = minval, .imax = maxval, .tsc = tsc};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, double minval, double maxval) {
|
||||
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, double minval, double maxval, bool tsc) {
|
||||
if (defaultVal < minval || defaultVal > maxval) {
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_FLOAT, .fval = defaultVal, .fmin = minval, .fmax = maxval};
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_FLOAT, .fval = defaultVal, .fmin = minval, .fmax = maxval, .tsc = tsc};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_STRING};
|
||||
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_STRING, .tsc = tsc};
|
||||
item.str = strdup(defaultVal);
|
||||
if (item.str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -411,17 +391,8 @@ int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal) {
|
|||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddIpStr(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_IPSTR};
|
||||
if (cfgCheckAndSetIpStr(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_DIR};
|
||||
int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal, bool tsc) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_DIR, .tsc = tsc};
|
||||
if (cfgCheckAndSetDir(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -430,7 +401,7 @@ int32_t cfgAddDir(SConfig *pCfg, const char *name, const char *defaultVal) {
|
|||
}
|
||||
|
||||
int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_LOCALE};
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_LOCALE, .tsc = 1};
|
||||
if (cfgCheckAndSetLocale(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -439,7 +410,7 @@ int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal) {
|
|||
}
|
||||
|
||||
int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_CHARSET};
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_CHARSET, .tsc = 1};
|
||||
if (cfgCheckAndSetCharset(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -448,7 +419,7 @@ int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal) {
|
|||
}
|
||||
|
||||
int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_TIMEZONE};
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_TIMEZONE, .tsc = 1};
|
||||
if (cfgCheckAndSetTimezone(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -491,8 +462,6 @@ const char *cfgDtypeStr(ECfgDataType type) {
|
|||
return "float";
|
||||
case CFG_DTYPE_STRING:
|
||||
return "string";
|
||||
case CFG_DTYPE_IPSTR:
|
||||
return "ipstr";
|
||||
case CFG_DTYPE_DIR:
|
||||
return "dir";
|
||||
case CFG_DTYPE_LOCALE:
|
||||
|
@ -506,7 +475,7 @@ const char *cfgDtypeStr(ECfgDataType type) {
|
|||
}
|
||||
}
|
||||
|
||||
void cfgDumpCfg(SConfig *pCfg) {
|
||||
void cfgDumpCfg(SConfig *pCfg, bool tsc) {
|
||||
uInfo(" global config");
|
||||
uInfo("=================================================================");
|
||||
|
||||
|
@ -515,6 +484,7 @@ void cfgDumpCfg(SConfig *pCfg) {
|
|||
|
||||
SConfigItem *pItem = cfgIterate(pCfg, NULL);
|
||||
while (pItem != NULL) {
|
||||
if (tsc && !pItem->tsc) continue;
|
||||
tstrncpy(src, cfgStypeStr(pItem->stype), CFG_SRC_PRINT_LEN);
|
||||
for (int32_t i = 0; i < CFG_SRC_PRINT_LEN; ++i) {
|
||||
if (src[i] == 0) src[i] = ' ';
|
||||
|
@ -552,6 +522,7 @@ void cfgDumpCfg(SConfig *pCfg) {
|
|||
|
||||
uInfo("=================================================================");
|
||||
}
|
||||
|
||||
#if 0
|
||||
// int32_t cfgCheck(SConfig *pCfg) {
|
||||
// SConfigItem *pItem = NULL;
|
||||
|
@ -630,4 +601,72 @@ void cfgDumpCfg(SConfig *pCfg) {
|
|||
|
||||
// return 0;
|
||||
// }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
||||
uInfo("load from global env variables");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) {
|
||||
uInfo("load from env file %s", filepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
||||
char *line, *name, *value, *value2, *value3;
|
||||
int olen, vlen, vlen2, vlen3;
|
||||
ssize_t _bytes = 0;
|
||||
size_t len = 1024;
|
||||
|
||||
FILE *fp = fopen(filepath, "r");
|
||||
if (fp == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
line = malloc(len);
|
||||
|
||||
while (!feof(fp)) {
|
||||
memset(line, 0, len);
|
||||
|
||||
name = value = value2 = value3 = NULL;
|
||||
olen = vlen = vlen2 = vlen3 = 0;
|
||||
|
||||
_bytes = tgetline(&line, &len, fp);
|
||||
if (_bytes < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
line[len - 1] = 0;
|
||||
|
||||
paGetToken(line, &name, &olen);
|
||||
if (olen == 0) continue;
|
||||
name[olen] = 0;
|
||||
|
||||
paGetToken(name + olen + 1, &value, &vlen);
|
||||
if (vlen == 0) continue;
|
||||
value[vlen] = 0;
|
||||
|
||||
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||
if (vlen2 != 0) {
|
||||
value2[vlen2] = 0;
|
||||
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||
if (vlen3 != 0) value3[vlen3] = 0;
|
||||
}
|
||||
|
||||
cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE);
|
||||
// taosReadConfigOption(name, value, value2, value3);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
tfree(line);
|
||||
|
||||
uInfo("load from cfg file %s success", filepath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
||||
uInfo("load from apoll url %s", url);
|
||||
return 0;
|
||||
}
|
|
@ -111,7 +111,7 @@ typedef struct time_wheel_t {
|
|||
tmr_obj_t** slots;
|
||||
} time_wheel_t;
|
||||
|
||||
uint32_t tsMaxTmrCtrl = 512;
|
||||
int32_t tsMaxTmrCtrl = 512;
|
||||
|
||||
static pthread_once_t tmrModuleInit = PTHREAD_ONCE_INIT;
|
||||
static pthread_mutex_t tmrCtrlMutex;
|
||||
|
|
|
@ -51,4 +51,12 @@ target_link_libraries(queue_test os util gtest_main)
|
|||
add_test(
|
||||
NAME queue_test
|
||||
COMMAND queue_test
|
||||
)
|
||||
|
||||
# cfgTest
|
||||
add_executable(cfgTest "cfgTest.cpp")
|
||||
target_link_libraries(cfgTest os util gtest_main)
|
||||
add_test(
|
||||
NAME cfgTest
|
||||
COMMAND cfgTest
|
||||
)
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "config.h"
|
||||
#include "tconfig.h"
|
||||
|
||||
class CfgTest : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -43,7 +43,6 @@ TEST_F(CfgTest, 01_Str) {
|
|||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_INT64), "int64");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_FLOAT), "float");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_STRING), "string");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_IPSTR), "ipstr");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir");
|
||||
|
@ -55,15 +54,14 @@ TEST_F(CfgTest, 02_Basic) {
|
|||
SConfig *pConfig = cfgInit();
|
||||
ASSERT_NE(pConfig, nullptr);
|
||||
|
||||
EXPECT_EQ(cfgAddBool(pConfig, "test_bool", 0), 0);
|
||||
EXPECT_EQ(cfgAddInt32(pConfig, "test_int32", 1, 0, 16), 0);
|
||||
EXPECT_EQ(cfgAddInt64(pConfig, "test_int64", 2, 0, 16), 0);
|
||||
EXPECT_EQ(cfgAddFloat(pConfig, "test_float", 3, 0, 16), 0);
|
||||
EXPECT_EQ(cfgAddString(pConfig, "test_string", "4"), 0);
|
||||
EXPECT_EQ(cfgAddIpStr(pConfig, "test_ipstr", "192.168.0.1"), 0);
|
||||
EXPECT_EQ(cfgAddDir(pConfig, "test_dir", "/tmp"), 0);
|
||||
EXPECT_EQ(cfgAddBool(pConfig, "test_bool", 0, 0), 0);
|
||||
EXPECT_EQ(cfgAddInt32(pConfig, "test_int32", 1, 0, 16, 0), 0);
|
||||
EXPECT_EQ(cfgAddInt64(pConfig, "test_int64", 2, 0, 16, 0), 0);
|
||||
EXPECT_EQ(cfgAddFloat(pConfig, "test_float", 3, 0, 16, 0), 0);
|
||||
EXPECT_EQ(cfgAddString(pConfig, "test_string", "4", 0), 0);
|
||||
EXPECT_EQ(cfgAddDir(pConfig, "test_dir", "/tmp", 0), 0);
|
||||
|
||||
EXPECT_EQ(cfgGetSize(pConfig), 7);
|
||||
EXPECT_EQ(cfgGetSize(pConfig), 6);
|
||||
|
||||
int32_t size = 0;
|
||||
SConfigItem *pItem = cfgIterate(pConfig, NULL);
|
||||
|
@ -84,9 +82,6 @@ TEST_F(CfgTest, 02_Basic) {
|
|||
case CFG_DTYPE_STRING:
|
||||
printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->str);
|
||||
break;
|
||||
case CFG_DTYPE_IPSTR:
|
||||
printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->str);
|
||||
break;
|
||||
case CFG_DTYPE_DIR:
|
||||
printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->str);
|
||||
break;
|
||||
|
@ -99,7 +94,7 @@ TEST_F(CfgTest, 02_Basic) {
|
|||
}
|
||||
cfgCancelIterate(pConfig, pItem);
|
||||
|
||||
EXPECT_EQ(cfgGetSize(pConfig), 7);
|
||||
EXPECT_EQ(cfgGetSize(pConfig), 6);
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_bool");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
|
@ -131,12 +126,6 @@ TEST_F(CfgTest, 02_Basic) {
|
|||
EXPECT_STREQ(pItem->name, "test_string");
|
||||
EXPECT_STREQ(pItem->str, "4");
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_ipstr");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
EXPECT_EQ(pItem->dtype, CFG_DTYPE_IPSTR);
|
||||
EXPECT_STREQ(pItem->name, "test_ipstr");
|
||||
EXPECT_STREQ(pItem->str, "192.168.0.1");
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_dir");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
EXPECT_EQ(pItem->dtype, CFG_DTYPE_DIR);
|
Loading…
Reference in New Issue