commit
842eb5e5a8
|
@ -23,7 +23,7 @@ typedef struct SBlockOrderInfo {
|
|||
// bool hasNull;
|
||||
} SBlockOrderInfo;
|
||||
|
||||
int taosGetFqdnPortFromEp(const char *ep, SEp *pEp);
|
||||
int taosGetFqdnPortFromEp(const char *ep, uint16_t defaultPort, SEp *pEp);
|
||||
void addEpIntoEpSet(SEpSet *pEpSet, const char *fqdn, uint16_t port);
|
||||
|
||||
bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2);
|
||||
|
|
|
@ -24,11 +24,6 @@ extern "C" {
|
|||
#include "tcfg.h"
|
||||
|
||||
// cluster
|
||||
extern char tsFirst[];
|
||||
extern char tsSecond[];
|
||||
extern char tsLocalFqdn[];
|
||||
extern char tsLocalEp[];
|
||||
extern uint16_t tsServerPort;
|
||||
extern int32_t tsStatusInterval;
|
||||
extern int8_t tsEnableTelemetryReporting;
|
||||
extern int32_t tsNumOfSupportVnodes;
|
||||
|
@ -105,13 +100,10 @@ extern uint32_t tsMaxRange;
|
|||
extern uint32_t tsCurRange;
|
||||
extern char tsCompressor[];
|
||||
|
||||
extern int32_t tsDiskCfgNum;
|
||||
extern SDiskCfg tsDiskCfg[];
|
||||
|
||||
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||
|
||||
void taosInitGlobalCfg();
|
||||
int32_t taosCheckAndPrintCfg();
|
||||
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);
|
||||
|
|
|
@ -135,8 +135,9 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS, "mnode-trans", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "mnode-trans-tmr", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_KILL_TRANS, "mnode-kill-trans", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "mnode-telem-tmr", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "mnode-grant", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "mnode-auth", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "mnode-create-topic", SMCreateTopicReq, SMCreateTopicRsp)
|
||||
|
@ -144,7 +145,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-get-sub-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-timer", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
|
||||
|
||||
|
|
|
@ -27,15 +27,16 @@ typedef struct SDnode SDnode;
|
|||
|
||||
/* ------------------------ Environment ------------------ */
|
||||
typedef struct {
|
||||
int32_t sver;
|
||||
int32_t numOfCores;
|
||||
int16_t numOfCommitThreads;
|
||||
int8_t enableTelem;
|
||||
char timezone[TSDB_TIMEZONE_LEN];
|
||||
char locale[TSDB_LOCALE_LEN];
|
||||
char charset[TSDB_LOCALE_LEN];
|
||||
char buildinfo[64];
|
||||
char gitinfo[48];
|
||||
int32_t sver;
|
||||
int32_t numOfCores;
|
||||
uint16_t numOfCommitThreads;
|
||||
bool enableTelem;
|
||||
bool printAuth;
|
||||
char timezone[TSDB_TIMEZONE_LEN];
|
||||
char locale[TSDB_LOCALE_LEN];
|
||||
char charset[TSDB_LOCALE_LEN];
|
||||
char buildinfo[64];
|
||||
char gitinfo[48];
|
||||
} SDnodeEnvCfg;
|
||||
|
||||
/**
|
||||
|
@ -65,6 +66,7 @@ typedef struct {
|
|||
char localEp[TSDB_EP_LEN];
|
||||
char localFqdn[TSDB_FQDN_LEN];
|
||||
char firstEp[TSDB_EP_LEN];
|
||||
char secondEp[TSDB_EP_LEN];
|
||||
} SDnodeObjCfg;
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,7 +46,8 @@ typedef struct SMnodeLoad {
|
|||
|
||||
typedef struct SMnodeCfg {
|
||||
int32_t sver;
|
||||
int8_t enableTelem;
|
||||
bool enableTelem;
|
||||
bool printAuth;
|
||||
int32_t statusInterval;
|
||||
int32_t shellActivityTimer;
|
||||
char *timezone;
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
|
||||
/*
|
||||
* 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_CONFIG_H_
|
||||
#define _TD_CONFIG_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CFG_NAME_MAX_LEN 128
|
||||
|
||||
typedef enum {
|
||||
CFG_STYPE_DEFAULT,
|
||||
CFG_STYPE_CFG_FILE,
|
||||
CFG_STYPE_ENV_FILE,
|
||||
CFG_STYPE_ENV_VAR,
|
||||
CFG_STYPE_APOLLO_URL,
|
||||
CFG_STYPE_ARG_LIST,
|
||||
CFG_STYPE_API_OPTION
|
||||
} ECfgSrcType;
|
||||
|
||||
typedef enum {
|
||||
CFG_DTYPE_NONE,
|
||||
CFG_DTYPE_BOOL,
|
||||
CFG_DTYPE_INT32,
|
||||
CFG_DTYPE_INT64,
|
||||
CFG_DTYPE_FLOAT,
|
||||
CFG_DTYPE_STRING,
|
||||
CFG_DTYPE_IPSTR,
|
||||
CFG_DTYPE_DIR,
|
||||
CFG_DTYPE_LOCALE,
|
||||
CFG_DTYPE_CHARSET,
|
||||
CFG_DTYPE_TIMEZONE
|
||||
} ECfgDataType;
|
||||
|
||||
typedef struct SConfigItem {
|
||||
ECfgSrcType stype;
|
||||
ECfgDataType dtype;
|
||||
char *name;
|
||||
union {
|
||||
bool bval;
|
||||
float fval;
|
||||
int32_t i32;
|
||||
int64_t i64;
|
||||
char *str;
|
||||
};
|
||||
union {
|
||||
int64_t imin;
|
||||
double fmin;
|
||||
};
|
||||
union {
|
||||
int64_t imax;
|
||||
double fmax;
|
||||
};
|
||||
} SConfigItem;
|
||||
|
||||
typedef struct SConfig SConfig;
|
||||
|
||||
SConfig *cfgInit();
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
|
||||
void cfgCleanup(SConfig *pCfg);
|
||||
|
||||
int32_t cfgGetSize(SConfig *pCfg);
|
||||
SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter);
|
||||
void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter);
|
||||
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name);
|
||||
|
||||
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 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);
|
||||
|
||||
const char *cfgStypeStr(ECfgSrcType type);
|
||||
const char *cfgDtypeStr(ECfgDataType type);
|
||||
|
||||
void cfgDumpCfg(SConfig *pCfg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_CONFIG_H_*/
|
|
@ -24,7 +24,7 @@ void taosRemoveDir(const char *dirname);
|
|||
int32_t taosDirExist(char *dirname);
|
||||
int32_t taosMkDir(const char *dirname);
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||
int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
|
||||
int32_t taosRealPath(char *dirname, int32_t maxlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -22,8 +22,6 @@ extern "C" {
|
|||
|
||||
extern char tsOsName[];
|
||||
extern char tsDataDir[];
|
||||
extern char tsLogDir[];
|
||||
extern char tsScriptDir[];
|
||||
extern char configDir[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -55,7 +55,7 @@ void taosSetMaskSIGPIPE();
|
|||
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen);
|
||||
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t *optlen);
|
||||
|
||||
uint32_t taosInetAddr(char *ipAddr);
|
||||
uint32_t taosInetAddr(const char *ipAddr);
|
||||
const char *taosInetNtoa(struct in_addr ipInt);
|
||||
|
||||
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
|
||||
|
|
|
@ -73,6 +73,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0109)
|
||||
#define TSDB_CODE_INVALID_PARA TAOS_DEF_ERROR_CODE(0, 0x010A)
|
||||
#define TSDB_CODE_REPEAT_INIT TAOS_DEF_ERROR_CODE(0, 0x010B)
|
||||
#define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C)
|
||||
#define TSDB_CODE_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D)
|
||||
|
||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110)
|
||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111)
|
||||
|
|
|
@ -1,97 +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_UTIL_CONFIG_H
|
||||
#define _TD_UTIL_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TSDB_CFG_MAX_NUM 115
|
||||
#define TSDB_CFG_PRINT_LEN 23
|
||||
#define TSDB_CFG_OPTION_LEN 24
|
||||
#define TSDB_CFG_VALUE_LEN 41
|
||||
|
||||
#define TSDB_CFG_CTYPE_B_CONFIG 1U // can be configured from file
|
||||
#define TSDB_CFG_CTYPE_B_SHOW 2U // can displayed by "show configs" commands
|
||||
#define TSDB_CFG_CTYPE_B_LOG 4U // is a log type configuration
|
||||
#define TSDB_CFG_CTYPE_B_CLIENT 8U // can be displayed in the client log
|
||||
#define TSDB_CFG_CTYPE_B_OPTION 16U // can be configured by taos_options function
|
||||
#define TSDB_CFG_CTYPE_B_NOT_PRINT 32U // such as password
|
||||
|
||||
#define MAX_FLOAT 100000
|
||||
#define MIN_FLOAT 0
|
||||
|
||||
enum {
|
||||
TAOS_CFG_CSTATUS_NONE, // not configured
|
||||
TAOS_CFG_CSTATUS_DEFAULT, // use system default value
|
||||
TAOS_CFG_CSTATUS_FILE, // configured from file
|
||||
TAOS_CFG_CSTATUS_OPTION, // configured by taos_options function
|
||||
TAOS_CFG_CSTATUS_ARG, // configured by program argument
|
||||
};
|
||||
|
||||
enum {
|
||||
TAOS_CFG_VTYPE_INT8,
|
||||
TAOS_CFG_VTYPE_INT16,
|
||||
TAOS_CFG_VTYPE_INT32,
|
||||
TAOS_CFG_VTYPE_UINT16,
|
||||
TAOS_CFG_VTYPE_FLOAT,
|
||||
TAOS_CFG_VTYPE_STRING,
|
||||
TAOS_CFG_VTYPE_IPSTR,
|
||||
TAOS_CFG_VTYPE_DIRECTORY,
|
||||
TAOS_CFG_VTYPE_DATA_DIRCTORY,
|
||||
TAOS_CFG_VTYPE_DOUBLE,
|
||||
};
|
||||
|
||||
enum {
|
||||
TAOS_CFG_UTYPE_NONE,
|
||||
TAOS_CFG_UTYPE_PERCENT,
|
||||
TAOS_CFG_UTYPE_GB,
|
||||
TAOS_CFG_UTYPE_MB,
|
||||
TAOS_CFG_UTYPE_BYTE,
|
||||
TAOS_CFG_UTYPE_SECOND,
|
||||
TAOS_CFG_UTYPE_MS
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char * option;
|
||||
void * ptr;
|
||||
float minValue;
|
||||
float maxValue;
|
||||
int8_t cfgType;
|
||||
int8_t cfgStatus;
|
||||
int8_t unitType;
|
||||
int8_t valType;
|
||||
int32_t ptrLength;
|
||||
} SGlobalCfg;
|
||||
|
||||
extern SGlobalCfg tsGlobalConfig[];
|
||||
extern int32_t tsGlobalConfigNum;
|
||||
extern char * tsCfgStatusStr[];
|
||||
|
||||
void taosReadGlobalLogCfg();
|
||||
int32_t taosReadCfgFromFile();
|
||||
void taosPrintCfg();
|
||||
void taosDumpGlobalCfg();
|
||||
|
||||
void taosAddConfigOption(SGlobalCfg cfg);
|
||||
SGlobalCfg *taosGetConfigOption(const char *option);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_CONFIG_H*/
|
|
@ -22,8 +22,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// log
|
||||
extern int8_t tsAsyncLog;
|
||||
extern char tsLogDir[];
|
||||
extern bool tsLogInited;
|
||||
extern bool tsAsyncLog;
|
||||
extern int32_t tsNumOfLogLines;
|
||||
extern int32_t tsLogKeepDays;
|
||||
extern int32_t dDebugFlag;
|
||||
|
@ -32,9 +33,6 @@ extern int32_t mDebugFlag;
|
|||
extern int32_t cDebugFlag;
|
||||
extern int32_t jniDebugFlag;
|
||||
extern int32_t tmrDebugFlag;
|
||||
extern int32_t httpDebugFlag;
|
||||
extern int32_t mqttDebugFlag;
|
||||
extern int32_t monDebugFlag;
|
||||
extern int32_t uDebugFlag;
|
||||
extern int32_t rpcDebugFlag;
|
||||
extern int32_t qDebugFlag;
|
||||
|
@ -42,23 +40,23 @@ extern int32_t wDebugFlag;
|
|||
extern int32_t sDebugFlag;
|
||||
extern int32_t tsdbDebugFlag;
|
||||
extern int32_t tqDebugFlag;
|
||||
extern int32_t cqDebugFlag;
|
||||
extern int32_t debugFlag;
|
||||
|
||||
#define DEBUG_FATAL 1U
|
||||
#define DEBUG_ERROR DEBUG_FATAL
|
||||
#define DEBUG_WARN 2U
|
||||
#define DEBUG_INFO DEBUG_WARN
|
||||
#define DEBUG_DEBUG 4U
|
||||
#define DEBUG_TRACE 8U
|
||||
#define DEBUG_DUMP 16U
|
||||
extern int32_t fsDebugFlag;
|
||||
|
||||
#define DEBUG_FATAL 1U
|
||||
#define DEBUG_ERROR DEBUG_FATAL
|
||||
#define DEBUG_WARN 2U
|
||||
#define DEBUG_INFO DEBUG_WARN
|
||||
#define DEBUG_DEBUG 4U
|
||||
#define DEBUG_TRACE 8U
|
||||
#define DEBUG_DUMP 16U
|
||||
#define DEBUG_SCREEN 64U
|
||||
#define DEBUG_FILE 128U
|
||||
#define DEBUG_FILE 128U
|
||||
|
||||
int32_t taosInitLog(char *logName, int32_t numOfLogLines, int32_t maxFiles);
|
||||
int32_t taosInitLog(const char *logName, int32_t maxFiles);
|
||||
void taosCloseLog();
|
||||
void taosResetLog();
|
||||
void taosSetAllDebugFlag(int32_t flag);
|
||||
void taosDumpData(unsigned char *msg, int32_t len);
|
||||
|
||||
void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...)
|
||||
#ifdef __GNUC__
|
||||
|
@ -72,8 +70,6 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, .
|
|||
#endif
|
||||
;
|
||||
|
||||
void taosDumpData(unsigned char *msg, int32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,7 @@ target_include_directories(
|
|||
target_link_libraries(
|
||||
taos
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport parser planner catalog scheduler function qcom
|
||||
PRIVATE os util common transport parser planner catalog scheduler function qcom config
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
|
|
|
@ -32,6 +32,8 @@ extern "C" {
|
|||
#include "query.h"
|
||||
#include "parser.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define CHECK_CODE_GOTO(expr, label) \
|
||||
do { \
|
||||
int32_t code = expr; \
|
||||
|
@ -253,6 +255,11 @@ int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* v
|
|||
// --- mq
|
||||
void hbMgrInitMqHbRspHandle();
|
||||
|
||||
// config
|
||||
int32_t tscInitLog(const char *cfgDir, const char *envFile, const char *apolloUrl);
|
||||
int32_t tscInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl);
|
||||
|
||||
extern SConfig *tscCfg;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* 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 "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) {
|
||||
tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
|
||||
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", tsDataDir) != 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, "maxShellConns", 50000, 10, 50000000) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "shellActivityTimer", 3, 1, 120) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tscCheckCfg(SConfig *pCfg) {
|
||||
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
||||
taosSetCoreDump(enableCore);
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SConfig *tscInitCfgImp(const char *cfgDir, const char *envFile, const char *apolloUrl) {
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return NULL;
|
||||
|
||||
if (tscAddCfg(pCfg) != 0) {
|
||||
uError("failed to init tsc cfg since %s", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (tscLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
|
||||
printf("failed to load tsc cfg since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (tscCheckCfg(pCfg) != 0) {
|
||||
uError("failed to check cfg since %s", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cfgDumpCfg(pCfg);
|
||||
return pCfg;
|
||||
}
|
||||
|
||||
int32_t tscInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl) {
|
||||
tscCfg = tscInitCfgImp(cfgDir, envFile, apolloUrl);
|
||||
if (tscCfg == NULL) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -21,7 +21,6 @@
|
|||
#include "scheduler.h"
|
||||
#include "tmsg.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
|
@ -73,22 +72,6 @@ static void deregisterRequest(SRequestObj* pRequest) {
|
|||
taosReleaseRef(clientConnRefPool, pTscObj->id);
|
||||
}
|
||||
|
||||
static void tscInitLogFile() {
|
||||
taosReadGlobalLogCfg();
|
||||
if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) {
|
||||
printf("failed to create log dir:%s\n", tsLogDir);
|
||||
}
|
||||
|
||||
const char *defaultLogFileNamePrefix = "taoslog";
|
||||
const int32_t maxLogFileNum = 10;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
}
|
||||
|
||||
// todo close the transporter properly
|
||||
void closeTransporter(STscObj* pTscObj) {
|
||||
if (pTscObj == NULL || pTscObj->pAppInfo->pTransporter == NULL) {
|
||||
|
@ -225,11 +208,13 @@ void taos_init_imp(void) {
|
|||
srand(taosGetTimestampSec());
|
||||
|
||||
deltaToUtcInitOnce();
|
||||
taosInitGlobalCfg();
|
||||
taosReadCfgFromFile();
|
||||
|
||||
tscInitLogFile();
|
||||
if (taosCheckAndPrintCfg()) {
|
||||
if (tscInitLog(configDir, NULL, NULL) != 0) {
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (tscInitCfg(configDir, NULL, NULL) != 0) {
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
|
@ -245,7 +230,7 @@ void taos_init_imp(void) {
|
|||
|
||||
SSchedulerCfg scfg = {.maxJobNum = 100};
|
||||
schedulerInit(&scfg);
|
||||
tscDebug("starting to initialize TAOS driver, local ep: %s", tsLocalEp);
|
||||
tscDebug("starting to initialize TAOS driver");
|
||||
|
||||
taosSetCoreDump(true);
|
||||
|
||||
|
@ -269,6 +254,7 @@ int taos_init() {
|
|||
}
|
||||
|
||||
int taos_options_imp(TSDB_OPTION option, const char *str) {
|
||||
#if 0
|
||||
SGlobalCfg *cfg = NULL;
|
||||
|
||||
switch (option) {
|
||||
|
@ -419,7 +405,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
tscError("Invalid option %d", option);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "tpagedbuf.h"
|
||||
#include "tref.h"
|
||||
|
||||
static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet);
|
||||
static int32_t initEpSetFromCfg(const char* ip, uint16_t port, SCorEpSet* pEpSet);
|
||||
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest);
|
||||
static void destroySendMsgInfo(SMsgSendInfo* pMsgBody);
|
||||
static void setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp);
|
||||
|
@ -81,19 +81,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
|
|||
}
|
||||
|
||||
SCorEpSet epSet = {0};
|
||||
if (ip) {
|
||||
if (initEpSetFromCfg(ip, NULL, &epSet) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (port) {
|
||||
epSet.epSet.eps[0].port = port;
|
||||
}
|
||||
} else {
|
||||
if (initEpSetFromCfg(tsFirst, tsSecond, &epSet) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
initEpSetFromCfg(ip, port, &epSet);
|
||||
|
||||
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
||||
SAppInstInfo** pInst = NULL;
|
||||
|
@ -282,32 +270,40 @@ _return:
|
|||
return pRequest;
|
||||
}
|
||||
|
||||
int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet) {
|
||||
pEpSet->version = 0;
|
||||
int initEpSetFromCfg(const char* ip, uint16_t port, SCorEpSet* pEpSet) {
|
||||
SConfigItem* pFirst = cfgGetItem(tscCfg, "firstEp");
|
||||
SConfigItem* pSecond = cfgGetItem(tscCfg, "secondEp");
|
||||
SConfigItem* pPort = cfgGetItem(tscCfg, "serverPort");
|
||||
|
||||
// init mnode ip set
|
||||
SEpSet* mgmtEpSet = &(pEpSet->epSet);
|
||||
mgmtEpSet->numOfEps = 0;
|
||||
mgmtEpSet->inUse = 0;
|
||||
pEpSet->version = 0;
|
||||
|
||||
if (firstEp && firstEp[0] != 0) {
|
||||
if (strlen(firstEp) >= TSDB_EP_LEN) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosGetFqdnPortFromEp(firstEp, &mgmtEpSet->eps[0]);
|
||||
if (ip != NULL) {
|
||||
taosGetFqdnPortFromEp(ip, (uint16_t)pPort->i32, &mgmtEpSet->eps[0]);
|
||||
mgmtEpSet->numOfEps++;
|
||||
}
|
||||
|
||||
if (secondEp && secondEp[0] != 0) {
|
||||
if (strlen(secondEp) >= TSDB_EP_LEN) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
if (port) {
|
||||
mgmtEpSet->eps[0].port = port;
|
||||
}
|
||||
} else {
|
||||
if (pFirst->str[0] != 0) {
|
||||
if (strlen(pFirst->str) >= TSDB_EP_LEN) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
}
|
||||
taosGetFqdnPortFromEp(pFirst->str, (uint16_t)pPort->i32, &mgmtEpSet->eps[0]);
|
||||
mgmtEpSet->numOfEps++;
|
||||
}
|
||||
if (pSecond->str[0] != 0) {
|
||||
if (strlen(pSecond->str) >= TSDB_EP_LEN) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_FQDN;
|
||||
return -1;
|
||||
}
|
||||
taosGetFqdnPortFromEp(pSecond->str, (uint16_t)pPort->i32, &mgmtEpSet->eps[1]);
|
||||
mgmtEpSet->numOfEps++;
|
||||
}
|
||||
|
||||
taosGetFqdnPortFromEp(secondEp, &mgmtEpSet->eps[mgmtEpSet->numOfEps]);
|
||||
mgmtEpSet->numOfEps++;
|
||||
}
|
||||
|
||||
if (mgmtEpSet->numOfEps == 0) {
|
||||
|
|
|
@ -56,9 +56,7 @@ void taos_cleanup(void) {
|
|||
}
|
||||
|
||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
||||
int32_t p = (port != 0) ? port : tsServerPort;
|
||||
|
||||
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, p, user, db);
|
||||
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db);
|
||||
if (user == NULL) {
|
||||
user = TSDB_DEFAULT_USER;
|
||||
}
|
||||
|
@ -67,7 +65,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
|
|||
pass = TSDB_DEFAULT_PASS;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, pass, NULL, db, p);
|
||||
return taos_connect_internal(ip, user, pass, NULL, db, port);
|
||||
}
|
||||
|
||||
void taos_close(TAOS* taos) {
|
||||
|
|
|
@ -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
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom config
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(tmqTest tmqTest.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
tmqTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom config
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "tglobal.h"
|
||||
#include "tlockfree.h"
|
||||
|
||||
int taosGetFqdnPortFromEp(const char *ep, SEp* pEp) {
|
||||
int taosGetFqdnPortFromEp(const char *ep, uint16_t defaultPort, SEp* pEp) {
|
||||
pEp->port = 0;
|
||||
strcpy(pEp->fqdn, ep);
|
||||
|
||||
|
@ -15,7 +15,7 @@ int taosGetFqdnPortFromEp(const char *ep, SEp* pEp) {
|
|||
}
|
||||
|
||||
if (pEp->port == 0) {
|
||||
pEp->port = tsServerPort;
|
||||
pEp->port = defaultPort;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "taosdef.h"
|
||||
#include "taoserror.h"
|
||||
#include "tcompare.h"
|
||||
#include "tconfig.h"
|
||||
#include "tep.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlocale.h"
|
||||
|
@ -29,11 +28,6 @@
|
|||
#include "ulog.h"
|
||||
|
||||
// cluster
|
||||
char tsFirst[TSDB_EP_LEN] = {0};
|
||||
char tsSecond[TSDB_EP_LEN] = {0};
|
||||
char tsLocalFqdn[TSDB_FQDN_LEN] = {0};
|
||||
char tsLocalEp[TSDB_EP_LEN] = {0}; // Local End Point, hostname:port
|
||||
uint16_t tsServerPort = 6030;
|
||||
int32_t tsStatusInterval = 1; // second
|
||||
int8_t tsEnableTelemetryReporting = 0;
|
||||
char tsEmail[TSDB_FQDN_LEN] = {0};
|
||||
|
@ -131,8 +125,6 @@ int8_t tsDeadLockKillQuery = 0;
|
|||
// For backward compatibility
|
||||
bool tsdbForceKeepFile = false;
|
||||
|
||||
int32_t tsDiskCfgNum = 0;
|
||||
|
||||
#ifndef _STORAGE
|
||||
SDiskCfg tsDiskCfg[1];
|
||||
#else
|
||||
|
@ -179,24 +171,9 @@ char *qtypeStr[] = {"rpc", "fwd", "wal", "cq", "query"};
|
|||
|
||||
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;
|
||||
|
||||
void taosSetAllDebugFlag() {
|
||||
if (debugFlag != 0) {
|
||||
mDebugFlag = debugFlag;
|
||||
dDebugFlag = debugFlag;
|
||||
vDebugFlag = debugFlag;
|
||||
jniDebugFlag = debugFlag;
|
||||
qDebugFlag = debugFlag;
|
||||
rpcDebugFlag = debugFlag;
|
||||
uDebugFlag = debugFlag;
|
||||
sDebugFlag = debugFlag;
|
||||
wDebugFlag = debugFlag;
|
||||
tsdbDebugFlag = debugFlag;
|
||||
cqDebugFlag = debugFlag;
|
||||
uInfo("all debug flag are set to %d", debugFlag);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t taosCfgDynamicOptions(char *msg) {
|
||||
#if 0
|
||||
char *option, *value;
|
||||
int32_t olen, vlen;
|
||||
int32_t vint = 0;
|
||||
|
@ -266,6 +243,7 @@ int32_t taosCfgDynamicOptions(char *msg) {
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -277,119 +255,31 @@ void taosAddDataDir(int index, char *v1, int level, int 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 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);
|
||||
}
|
||||
}
|
||||
// void taosPrintDataDirCfg() {
|
||||
// for (int i = 0; i < tsDiskCfgNum; ++i) {
|
||||
// SDiskCfg *cfg = &tsDiskCfg[i];
|
||||
// uInfo(" dataDir: %s", cfg->dir);
|
||||
// }
|
||||
// }
|
||||
#endif
|
||||
|
||||
static void taosCheckDataDirCfg() {
|
||||
if (tsDiskCfgNum <= 0) {
|
||||
taosAddDataDir(0, tsDataDir, 0, 1);
|
||||
tsDiskCfgNum = 1;
|
||||
uTrace("dataDir:%s, level:0 primary:1 is configured by default", tsDataDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void doInitGlobalConfig(void) {
|
||||
osInit();
|
||||
srand(taosSafeRand());
|
||||
|
||||
#if 0
|
||||
SGlobalCfg cfg = {0};
|
||||
|
||||
// ip address
|
||||
cfg.option = "firstEp";
|
||||
cfg.ptr = tsFirst;
|
||||
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 = TSDB_EP_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "secondEp";
|
||||
cfg.ptr = tsSecond;
|
||||
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 = TSDB_EP_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "fqdn";
|
||||
cfg.ptr = tsLocalFqdn;
|
||||
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 = TSDB_FQDN_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// port
|
||||
cfg.option = "serverPort";
|
||||
cfg.ptr = &tsServerPort;
|
||||
cfg.valType = TAOS_CFG_VTYPE_UINT16;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 65056;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "supportVnodes";
|
||||
cfg.ptr = &tsNumOfSupportVnodes;
|
||||
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 = 0;
|
||||
cfg.maxValue = 65536;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// directory
|
||||
cfg.option = "configDir";
|
||||
cfg.ptr = configDir;
|
||||
cfg.valType = TAOS_CFG_VTYPE_DIRECTORY;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = TSDB_FILENAME_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "logDir";
|
||||
cfg.ptr = tsLogDir;
|
||||
cfg.valType = TAOS_CFG_VTYPE_DIRECTORY;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = TSDB_FILENAME_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "scriptDir";
|
||||
cfg.ptr = tsScriptDir;
|
||||
cfg.valType = TAOS_CFG_VTYPE_DIRECTORY;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = TSDB_FILENAME_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "dataDir";
|
||||
cfg.ptr = tsDataDir;
|
||||
|
@ -401,36 +291,6 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// dnode configs
|
||||
cfg.option = "numOfThreadsPerCore";
|
||||
cfg.ptr = &tsNumOfThreadsPerCore;
|
||||
cfg.valType = TAOS_CFG_VTYPE_FLOAT;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 10;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "numOfCommitThreads";
|
||||
cfg.ptr = &tsNumOfCommitThreads;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 100;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "ratioOfQueryCores";
|
||||
cfg.ptr = &tsRatioOfQueryCores;
|
||||
cfg.valType = TAOS_CFG_VTYPE_FLOAT;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = 0.0f;
|
||||
cfg.maxValue = 2.0f;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxNumOfDistinctRes";
|
||||
cfg.ptr = &tsMaxNumOfDistinctResults;
|
||||
|
@ -493,25 +353,6 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "statusInterval";
|
||||
cfg.ptr = &tsStatusInterval;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 10;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "shellActivityTimer";
|
||||
cfg.ptr = &tsShellActivityTimer;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 120;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "minSlidingTime";
|
||||
cfg.ptr = &tsMinSlidingTime;
|
||||
|
@ -653,47 +494,6 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// locale & charset
|
||||
cfg.option = "timezone";
|
||||
cfg.ptr = tsTimezone;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = TSDB_TIMEZONE_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "locale";
|
||||
cfg.ptr = tsLocale;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = TSDB_LOCALE_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "charset";
|
||||
cfg.ptr = tsCharset;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = TSDB_LOCALE_LEN;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// connect configs
|
||||
cfg.option = "maxShellConns";
|
||||
cfg.ptr = &tsMaxShellConns;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = 10;
|
||||
cfg.maxValue = 50000000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxConnections";
|
||||
cfg.ptr = &tsMaxConnections;
|
||||
|
@ -745,176 +545,7 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// debug flag
|
||||
cfg.option = "numOfLogLines";
|
||||
cfg.ptr = &tsNumOfLogLines;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 1000;
|
||||
cfg.maxValue = 2000000000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "logKeepDays";
|
||||
cfg.ptr = &tsLogKeepDays;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = -365000;
|
||||
cfg.maxValue = 365000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "asyncLog";
|
||||
cfg.ptr = &tsAsyncLog;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 1;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "debugFlag";
|
||||
cfg.ptr = &debugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "mDebugFlag";
|
||||
cfg.ptr = &mDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "dDebugFlag";
|
||||
cfg.ptr = &dDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "sDebugFlag";
|
||||
cfg.ptr = &sDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "wDebugFlag";
|
||||
cfg.ptr = &wDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "rpcDebugFlag";
|
||||
cfg.ptr = &rpcDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "tmrDebugFlag";
|
||||
cfg.ptr = &tmrDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "cDebugFlag";
|
||||
cfg.ptr = &cDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "jniDebugFlag";
|
||||
cfg.ptr = &jniDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "uDebugFlag";
|
||||
cfg.ptr = &uDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "qDebugFlag";
|
||||
cfg.ptr = &qDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "vDebugFlag";
|
||||
cfg.ptr = &vDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "tsdbDebugFlag";
|
||||
cfg.ptr = &tsdbDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "cqDebugFlag";
|
||||
cfg.ptr = &cqDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "enableRecordSql";
|
||||
cfg.ptr = &tsTscEnableRecordSql;
|
||||
|
@ -936,46 +567,6 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
// version info
|
||||
cfg.option = "gitinfo";
|
||||
cfg.ptr = gitinfo;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "gitinfoOfInternal";
|
||||
cfg.ptr = gitinfoOfInternal;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "buildinfo";
|
||||
cfg.ptr = buildinfo;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "version";
|
||||
cfg.ptr = version;
|
||||
cfg.valType = TAOS_CFG_VTYPE_STRING;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
||||
cfg.option = "maxBinaryDisplayWidth";
|
||||
cfg.ptr = &tsMaxBinaryDisplayWidth;
|
||||
|
@ -1025,7 +616,7 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = MIN_FLOAT;
|
||||
cfg.maxValue = MAX_FLOAT;
|
||||
cfg.maxValue = 100000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
|
||||
|
@ -1035,8 +626,8 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.ptr = &dPrecision;
|
||||
cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
|
||||
cfg.minValue = MIN_FLOAT;
|
||||
cfg.maxValue = MAX_FLOAT;
|
||||
cfg.minValue = 100000;
|
||||
cfg.maxValue = 0;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosAddConfigOption(cfg);
|
||||
|
@ -1064,67 +655,12 @@ static void doInitGlobalConfig(void) {
|
|||
#else
|
||||
// assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* alter dnode 1 balance "vnode:1-dnode:2"
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "os.h"
|
||||
#include "ulog.h"
|
||||
#include "tglobal.h"
|
||||
#include "tconfig.h"
|
||||
#include "tutil.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
aux_source_directory(src DAEMON_SRC)
|
||||
add_executable(taosd ${DAEMON_SRC})
|
||||
target_link_libraries(
|
||||
|
||||
target_include_directories(
|
||||
taosd
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
target_link_libraries(taosd dnode config util os)
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
/*
|
||||
* 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_DMN_INT_H_
|
||||
#define _TD_DMN_INT_H_
|
||||
|
||||
#include "config.h"
|
||||
#include "dnode.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
#include "ulog.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t dmnAddLogCfg(SConfig *pCfg);
|
||||
int32_t dmnInitLog(const char *cfgDir, const char *envFile, const char *apolloUrl);
|
||||
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);
|
||||
SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg);
|
||||
SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg);
|
||||
|
||||
void dmnDumpCfg(SConfig *pCfg);
|
||||
void dmnPrintVersion();
|
||||
void dmnGenerateGrant();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DMN_INT_H_*/
|
|
@ -1,218 +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 "dnode.h"
|
||||
#include "os.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "ulog.h"
|
||||
|
||||
static struct {
|
||||
bool stop;
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
char configDir[PATH_MAX];
|
||||
} dmn = {0};
|
||||
|
||||
void dmnSigintHandle(int signum, void *info, void *ctx) {
|
||||
uInfo("singal:%d is received", signum);
|
||||
dmn.stop = true;
|
||||
}
|
||||
|
||||
void dmnSetSignalHandle() {
|
||||
taosSetSignal(SIGTERM, dmnSigintHandle);
|
||||
taosSetSignal(SIGHUP, dmnSigintHandle);
|
||||
taosSetSignal(SIGINT, dmnSigintHandle);
|
||||
taosSetSignal(SIGABRT, dmnSigintHandle);
|
||||
taosSetSignal(SIGBREAK, dmnSigintHandle);
|
||||
}
|
||||
|
||||
int dmnParseOption(int argc, char const *argv[]) {
|
||||
tstrncpy(dmn.configDir, "/etc/taos", PATH_MAX);
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("config file path overflow");
|
||||
return -1;
|
||||
}
|
||||
tstrncpy(dmn.configDir, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-C") == 0) {
|
||||
dmn.dumpConfig = true;
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
dmn.generateGrant = true;
|
||||
} else if (strcmp(argv[i], "-A") == 0) {
|
||||
dmn.printAuth = true;
|
||||
} else if (strcmp(argv[i], "-V") == 0) {
|
||||
dmn.printVersion = true;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmnGenerateGrant() {
|
||||
#if 0
|
||||
grantParseParameter();
|
||||
#endif
|
||||
}
|
||||
|
||||
void dmnPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
char *releaseName = "community";
|
||||
#endif
|
||||
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
|
||||
printf("gitinfo: %s\n", gitinfo);
|
||||
printf("gitinfoI: %s\n", gitinfoOfInternal);
|
||||
printf("builuInfo: %s\n", buildinfo);
|
||||
}
|
||||
|
||||
int dmnReadConfig(const char *path) {
|
||||
tstrncpy(configDir, dmn.configDir, PATH_MAX);
|
||||
taosInitGlobalCfg();
|
||||
taosReadGlobalLogCfg();
|
||||
|
||||
if (taosMkDir(tsLogDir) != 0) {
|
||||
printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
char temp[PATH_MAX];
|
||||
snprintf(temp, PATH_MAX, "%s/taosdlog", tsLogDir);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
|
||||
printf("failed to init log file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosInitNotes() != 0) {
|
||||
printf("failed to init log file\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosReadCfgFromFile() != 0) {
|
||||
uError("failed to read config");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosCheckAndPrintCfg() != 0) {
|
||||
uError("failed to check config");
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosSetCoreDump(tsEnableCoreFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmnDumpConfig() { taosDumpGlobalCfg(); }
|
||||
|
||||
void dmnWaitSignal() {
|
||||
dmnSetSignalHandle();
|
||||
while (!dmn.stop) {
|
||||
taosMsleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
void dnmInitEnvCfg(SDnodeEnvCfg *pCfg) {
|
||||
pCfg->sver = 30000000; // 3.0.0.0
|
||||
pCfg->numOfCores = tsNumOfCores;
|
||||
pCfg->numOfCommitThreads = tsNumOfCommitThreads;
|
||||
pCfg->enableTelem = 0;
|
||||
tstrncpy(pCfg->timezone, tsTimezone, TSDB_TIMEZONE_LEN);
|
||||
tstrncpy(pCfg->locale, tsLocale, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pCfg->charset, tsCharset, TSDB_LOCALE_LEN);
|
||||
tstrncpy(pCfg->buildinfo, buildinfo, 64);
|
||||
tstrncpy(pCfg->gitinfo, gitinfo, 48);
|
||||
}
|
||||
|
||||
void dmnInitObjCfg(SDnodeObjCfg *pCfg) {
|
||||
pCfg->numOfSupportVnodes = tsNumOfSupportVnodes;
|
||||
pCfg->statusInterval = tsStatusInterval;
|
||||
pCfg->numOfThreadsPerCore = tsNumOfThreadsPerCore;
|
||||
pCfg->ratioOfQueryCores = tsRatioOfQueryCores;
|
||||
pCfg->maxShellConns = tsMaxShellConns;
|
||||
pCfg->shellActivityTimer = tsShellActivityTimer;
|
||||
pCfg->serverPort = tsServerPort;
|
||||
tstrncpy(pCfg->dataDir, tsDataDir, TSDB_FILENAME_LEN);
|
||||
tstrncpy(pCfg->localEp, tsLocalEp, TSDB_EP_LEN);
|
||||
tstrncpy(pCfg->localFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
tstrncpy(pCfg->firstEp, tsFirst, TSDB_EP_LEN);
|
||||
}
|
||||
|
||||
int dmnRunDnode() {
|
||||
SDnodeEnvCfg envCfg = {0};
|
||||
SDnodeObjCfg objCfg = {0};
|
||||
|
||||
dnmInitEnvCfg(&envCfg);
|
||||
dmnInitObjCfg(&objCfg);
|
||||
|
||||
if (dndInit(&envCfg) != 0) {
|
||||
uInfo("Failed to start TDengine, please check the log at %s", tsLogDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnode *pDnode = dndCreate(&objCfg);
|
||||
if (pDnode == NULL) {
|
||||
uInfo("Failed to start TDengine, please check the log at %s", tsLogDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uInfo("Started TDengine service successfully.");
|
||||
dmnWaitSignal();
|
||||
uInfo("TDengine is shut down!");
|
||||
|
||||
dndClose(pDnode);
|
||||
dndCleanup();
|
||||
taosCloseLog();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
if (dmnParseOption(argc, argv) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmn.generateGrant) {
|
||||
dmnGenerateGrant();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dmn.printVersion) {
|
||||
dmnPrintVersion();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dmnReadConfig(dmn.configDir) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmn.dumpConfig) {
|
||||
dmnDumpConfig();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return dmnRunDnode();
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
/*
|
||||
* 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 "dmnInt.h"
|
||||
#include "tlocale.h"
|
||||
#include "ttimezone.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", tsDataDir) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "tmpDir", tsTempDir) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
static int32_t dmnCheckDirCfg(SConfig *pCfg) {
|
||||
SConfigItem *pItem = NULL;
|
||||
|
||||
pItem = cfgGetItem(pCfg, "tmpDir");
|
||||
if (taosDirExist(pItem->str) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmnCheckCfg(SConfig *pCfg) {
|
||||
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
||||
taosSetCoreDump(enableCore);
|
||||
|
||||
if (dmnCheckDirCfg(pCfg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosGetSystemInfo();
|
||||
|
||||
tsSetTimeZone();
|
||||
tsSetLocale();
|
||||
|
||||
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_IPSTR:
|
||||
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};
|
||||
|
||||
const char *vstr = cfgGetItem(pCfg, "version")->str;
|
||||
envCfg.sver = 30000000;
|
||||
tstrncpy(envCfg.buildinfo, cfgGetItem(pCfg, "buildinfo")->str, sizeof(envCfg.buildinfo));
|
||||
tstrncpy(envCfg.gitinfo, cfgGetItem(pCfg, "gitinfo")->str, sizeof(envCfg.gitinfo));
|
||||
tstrncpy(envCfg.timezone, cfgGetItem(pCfg, "timezone")->str, sizeof(envCfg.timezone));
|
||||
tstrncpy(envCfg.locale, cfgGetItem(pCfg, "locale")->str, sizeof(envCfg.locale));
|
||||
tstrncpy(envCfg.charset, cfgGetItem(pCfg, "charset")->str, sizeof(envCfg.charset));
|
||||
envCfg.numOfCores = cfgGetItem(pCfg, "numOfCores")->i32;
|
||||
envCfg.numOfCommitThreads = (uint16_t)cfgGetItem(pCfg, "numOfCommitThreads")->i32;
|
||||
envCfg.enableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval;
|
||||
|
||||
return envCfg;
|
||||
}
|
||||
|
||||
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;
|
||||
tstrncpy(objCfg.dataDir, cfgGetItem(pCfg, "dataDir")->str, sizeof(objCfg.dataDir));
|
||||
|
||||
tstrncpy(objCfg.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp));
|
||||
tstrncpy(objCfg.secondEp, cfgGetItem(pCfg, "secondEp")->str, sizeof(objCfg.firstEp));
|
||||
objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
||||
tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn));
|
||||
snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort);
|
||||
return objCfg;
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* 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 "dmnInt.h"
|
||||
|
||||
int32_t dmnAddLogCfg(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, "dDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "vDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "mDebugFlag", 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;
|
||||
if (cfgAddInt32(pCfg, "qDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "wDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "sDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "tsdbDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "tqDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "fsDebugFlag", 0, 0, 255) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmnSetLogCfg(SConfig *pCfg) {
|
||||
tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
|
||||
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;
|
||||
uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32;
|
||||
rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->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;
|
||||
|
||||
int32_t debugFlag = cfgGetItem(pCfg, "debugFlag")->i32;
|
||||
taosSetAllDebugFlag(debugFlag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmnInitLog(const char *cfgDir, const char *envFile, const char *apolloUrl) {
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
|
||||
if (dmnAddLogCfg(pCfg) != 0) {
|
||||
printf("failed to add log cfg since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmnLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
|
||||
printf("failed to load log cfg since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmnSetLogCfg(pCfg) != 0) {
|
||||
printf("failed to set log cfg since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosInitLog("taosdlog", 1) != 0) {
|
||||
printf("failed to init log file since %s\n", terrstr());
|
||||
cfgCleanup(pCfg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cfgCleanup(pCfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmnLoadCfg(SConfig *pConfig, const char *inputCfgDir, const char *envFile, const char *apolloUrl) {
|
||||
char configDir[PATH_MAX] = {0};
|
||||
char configFile[PATH_MAX + 100] = {0};
|
||||
|
||||
taosExpandDir(inputCfgDir, configDir, PATH_MAX);
|
||||
snprintf(configFile, sizeof(configFile), "%s" TD_DIRSEP "taos.cfg", configDir);
|
||||
|
||||
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, configFile) != 0) {
|
||||
if (cfgLoad(pConfig, CFG_STYPE_CFG_FILE, configDir) != 0) {
|
||||
uError("failed to load from config file:%s since %s\n", configFile, 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;
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* 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 "dmnInt.h"
|
||||
|
||||
static struct {
|
||||
bool stop;
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
char envFile[PATH_MAX];
|
||||
char apolloUrl[PATH_MAX];
|
||||
} dmn = {0};
|
||||
|
||||
static void dmnSigintHandle(int signum, void *info, void *ctx) {
|
||||
uInfo("singal:%d is received", signum);
|
||||
dmn.stop = true;
|
||||
}
|
||||
|
||||
static void dmnSetSignalHandle() {
|
||||
taosSetSignal(SIGTERM, dmnSigintHandle);
|
||||
taosSetSignal(SIGHUP, dmnSigintHandle);
|
||||
taosSetSignal(SIGINT, dmnSigintHandle);
|
||||
taosSetSignal(SIGABRT, dmnSigintHandle);
|
||||
taosSetSignal(SIGBREAK, dmnSigintHandle);
|
||||
}
|
||||
|
||||
static void dmnWaitSignal() {
|
||||
dmnSetSignalHandle();
|
||||
while (!dmn.stop) {
|
||||
taosMsleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dmnParseOption(int32_t argc, char const *argv[]) {
|
||||
for (int32_t i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("config file path overflow");
|
||||
return -1;
|
||||
}
|
||||
tstrncpy(configDir, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-C") == 0) {
|
||||
dmn.dumpConfig = true;
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
dmn.generateGrant = true;
|
||||
} else if (strcmp(argv[i], "-V") == 0) {
|
||||
dmn.printVersion = true;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmnRunDnode(SConfig *pCfg) {
|
||||
SDnodeEnvCfg envCfg = dmnGetEnvCfg(pCfg);
|
||||
if (dndInit(&envCfg) != 0) {
|
||||
uInfo("Failed to start TDengine, please check the log");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeObjCfg objCfg = dmnGetObjCfg(pCfg);
|
||||
SDnode *pDnode = dndCreate(&objCfg);
|
||||
if (pDnode == NULL) {
|
||||
uInfo("Failed to start TDengine, please check the log");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uInfo("Started TDengine service successfully.");
|
||||
dmnWaitSignal();
|
||||
uInfo("TDengine is shut down!");
|
||||
|
||||
dndClose(pDnode);
|
||||
dndCleanup();
|
||||
taosCloseLog();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
if (dmnParseOption(argc, argv) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmn.generateGrant) {
|
||||
dmnGenerateGrant();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dmn.printVersion) {
|
||||
dmnPrintVersion();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dmnInitLog(configDir, dmn.envFile, dmn.apolloUrl) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SConfig *pCfg = dmnReadCfg(configDir, dmn.envFile, dmn.apolloUrl);
|
||||
if (pCfg == NULL) {
|
||||
uInfo("Failed to start TDengine since read config error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmn.dumpConfig) {
|
||||
dmnDumpCfg(pCfg);
|
||||
cfgCleanup(pCfg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t code = dmnRunDnode(pCfg);
|
||||
cfgCleanup(pCfg);
|
||||
return code;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 "dmnInt.h"
|
||||
|
||||
void dmnGenerateGrant() {
|
||||
#if 0
|
||||
grantParseParameter();
|
||||
#endif
|
||||
}
|
||||
|
||||
void dmnPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
char *releaseName = "community";
|
||||
#endif
|
||||
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
|
||||
printf("gitinfo: %s\n", gitinfo);
|
||||
printf("gitinfoI: %s\n", gitinfoOfInternal);
|
||||
printf("builuInfo: %s\n", buildinfo);
|
||||
}
|
|
@ -296,7 +296,7 @@ PRASE_DNODE_OVER:
|
|||
if (taosArrayGetSize(pMgmt->pDnodeEps) == 0) {
|
||||
SDnodeEp dnodeEp = {0};
|
||||
dnodeEp.isMnode = 1;
|
||||
taosGetFqdnPortFromEp(pDnode->cfg.firstEp, &dnodeEp.ep);
|
||||
taosGetFqdnPortFromEp(pDnode->cfg.firstEp, pDnode->cfg.serverPort, &dnodeEp.ep);
|
||||
taosArrayPush(pMgmt->pDnodeEps, &dnodeEp);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "os.h"
|
||||
|
||||
#include "dnode.h"
|
||||
#include "tconfig.h"
|
||||
#include "tmsg.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmsg.h"
|
||||
|
|
|
@ -28,16 +28,13 @@ void Testbase::InitLog(const char* path) {
|
|||
wDebugFlag = 0;
|
||||
sDebugFlag = 0;
|
||||
tsdbDebugFlag = 0;
|
||||
cqDebugFlag = 0;
|
||||
tscEmbeddedInUtil = 1;
|
||||
tsAsyncLog = 0;
|
||||
|
||||
taosRemoveDir(path);
|
||||
taosMkDir(path);
|
||||
|
||||
char temp[PATH_MAX];
|
||||
snprintf(temp, PATH_MAX, "%s/taosdlog", path);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
|
||||
tstrncpy(tsLogDir, path, PATH_MAX);
|
||||
if (taosInitLog("taosdlog", 1) != 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,12 +56,9 @@ typedef struct {
|
|||
} SProfileMgmt;
|
||||
|
||||
typedef struct {
|
||||
int8_t enable;
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t cond;
|
||||
volatile int32_t exit;
|
||||
pthread_t thread;
|
||||
char email[TSDB_FQDN_LEN];
|
||||
bool enable;
|
||||
SRWLatch lock;
|
||||
char email[TSDB_FQDN_LEN];
|
||||
} STelemMgmt;
|
||||
|
||||
typedef struct {
|
||||
|
@ -81,6 +78,7 @@ typedef struct SMnode {
|
|||
tmr_h timer;
|
||||
tmr_h transTimer;
|
||||
tmr_h mqTimer;
|
||||
tmr_h telemTimer;
|
||||
char *path;
|
||||
SMnodeCfg cfg;
|
||||
int64_t checkTime;
|
||||
|
|
|
@ -52,7 +52,7 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
SClusterObj *pCluster = sdbAcquire(pSdb, SDB_CLUSTER, &pMnode->clusterId);
|
||||
if (pCluster = NULL) {
|
||||
if (pCluster == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "tversion.h"
|
||||
|
||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||
#define TELEMETRY_PORT 80
|
||||
#define REPORT_INTERVAL 86400
|
||||
#define TELEMETRY_PORT 80
|
||||
#define REPORT_INTERVAL 86400
|
||||
|
||||
static void mndBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); }
|
||||
|
||||
|
@ -33,25 +33,8 @@ static void mndCloseObject(SBufferWriter* bw) {
|
|||
} else {
|
||||
tbufWriteChar(bw, '}');
|
||||
}
|
||||
tbufWriteChar(bw, ',');
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void beginArray(SBufferWriter* bw) {
|
||||
tbufWriteChar(bw, '[');
|
||||
}
|
||||
|
||||
static void closeArray(SBufferWriter* bw) {
|
||||
size_t len = tbufTell(bw);
|
||||
if (tbufGetData(bw, false)[len - 1] == ',') {
|
||||
tbufWriteCharAt(bw, len - 1, ']');
|
||||
} else {
|
||||
tbufWriteChar(bw, ']');
|
||||
}
|
||||
tbufWriteChar(bw, ',');
|
||||
}
|
||||
#endif
|
||||
|
||||
static void mndWriteString(SBufferWriter* bw, const char* str) {
|
||||
tbufWriteChar(bw, '"');
|
||||
tbufWrite(bw, str, strlen(str));
|
||||
|
@ -61,7 +44,7 @@ static void mndWriteString(SBufferWriter* bw, const char* str) {
|
|||
static void mndAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
|
||||
mndWriteString(bw, k);
|
||||
tbufWriteChar(bw, ':');
|
||||
char buf[32];
|
||||
char buf[32] = {0};
|
||||
sprintf(buf, "%" PRId64, v);
|
||||
tbufWrite(bw, buf, strlen(buf));
|
||||
tbufWriteChar(bw, ',');
|
||||
|
@ -184,24 +167,17 @@ static void mndAddRuntimeInfo(SMnode* pMnode, SBufferWriter* bw) {
|
|||
}
|
||||
|
||||
static void mndSendTelemetryReport(SMnode* pMnode) {
|
||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||
|
||||
char buf[128] = {0};
|
||||
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
||||
if (ip == 0xffffffff) {
|
||||
mDebug("failed to get IP address of " TELEMETRY_SERVER " since :%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
SOCKET fd = taosOpenTcpClientSocket(ip, TELEMETRY_PORT, 0);
|
||||
if (fd < 0) {
|
||||
mDebug("failed to create socket for telemetry, reason:%s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||
SBufferWriter bw = tbufInitWriter(NULL, false);
|
||||
int32_t code = -1;
|
||||
char buf[128] = {0};
|
||||
SOCKET fd = 0;
|
||||
|
||||
char clusterName[64] = {0};
|
||||
mndGetClusterName(pMnode, clusterName, sizeof(clusterName));
|
||||
if (mndGetClusterName(pMnode, clusterName, sizeof(clusterName)) != 0) {
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
SBufferWriter bw = tbufInitWriter(NULL, false);
|
||||
mndBeginObject(&bw);
|
||||
mndAddStringField(&bw, "instanceId", clusterName);
|
||||
mndAddIntField(&bw, "reportVersion", 1);
|
||||
|
@ -212,54 +188,69 @@ static void mndSendTelemetryReport(SMnode* pMnode) {
|
|||
mndAddRuntimeInfo(pMnode, &bw);
|
||||
mndCloseObject(&bw);
|
||||
|
||||
uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER);
|
||||
if (ip == 0xffffffff) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to get ip of %s since :%s", TELEMETRY_SERVER, terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
fd = taosOpenTcpClientSocket(ip, TELEMETRY_PORT, 0);
|
||||
if (fd < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create socket to %s:%d since:%s", TELEMETRY_SERVER, TELEMETRY_PORT, terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
const char* header =
|
||||
"POST /report HTTP/1.1\n"
|
||||
"Host: " TELEMETRY_SERVER
|
||||
"\n"
|
||||
"Content-Type: application/json\n"
|
||||
"Content-Length: ";
|
||||
if (taosWriteSocket(fd, (void*)header, (int32_t)strlen(header)) < 0) {
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
taosWriteSocket(fd, (void*)header, (int32_t)strlen(header));
|
||||
int32_t contLen = (int32_t)(tbufTell(&bw) - 1);
|
||||
int32_t contLen = (int32_t)(tbufTell(&bw));
|
||||
sprintf(buf, "%d\n\n", contLen);
|
||||
taosWriteSocket(fd, buf, (int32_t)strlen(buf));
|
||||
taosWriteSocket(fd, tbufGetData(&bw, false), contLen);
|
||||
tbufCloseWriter(&bw);
|
||||
if (taosWriteSocket(fd, buf, (int32_t)strlen(buf)) < 0) {
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
const char* pCont = tbufGetData(&bw, false);
|
||||
if (taosWriteSocket(fd, (void*)pCont, contLen) < 0) {
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
// read something to avoid nginx error 499
|
||||
if (taosReadSocket(fd, buf, 10) < 0) {
|
||||
mDebug("failed to receive response since %s", strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to receive response since %s", terrstr());
|
||||
goto SEND_OVER;
|
||||
}
|
||||
|
||||
mInfo("send telemetry to %s:%d, len:%d content: %s", TELEMETRY_SERVER, TELEMETRY_PORT, contLen, pCont);
|
||||
code = 0;
|
||||
|
||||
SEND_OVER:
|
||||
tbufCloseWriter(&bw);
|
||||
taosCloseSocket(fd);
|
||||
|
||||
if (code != 0) {
|
||||
mError("failed to send telemetry to %s:%d since %s", TELEMETRY_SERVER, TELEMETRY_PORT, terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
static void* mndTelemThreadFp(void* param) {
|
||||
SMnode* pMnode = param;
|
||||
static int32_t mndProcessTelemTimer(SMnodeMsg* pReq) {
|
||||
SMnode* pMnode = pReq->pMnode;
|
||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||
if (!pMgmt->enable) return 0;
|
||||
|
||||
struct timespec end = {0};
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
end.tv_sec += 300; // wait 5 minutes before send first report
|
||||
|
||||
setThreadName("mnd-telem");
|
||||
|
||||
while (!pMgmt->exit) {
|
||||
int32_t r = 0;
|
||||
struct timespec ts = end;
|
||||
pthread_mutex_lock(&pMgmt->lock);
|
||||
r = pthread_cond_timedwait(&pMgmt->cond, &pMgmt->lock, &ts);
|
||||
pthread_mutex_unlock(&pMgmt->lock);
|
||||
if (r == 0) break;
|
||||
if (r != ETIMEDOUT) continue;
|
||||
|
||||
if (mndIsMaster(pMnode)) {
|
||||
mndSendTelemetryReport(pMnode);
|
||||
}
|
||||
end.tv_sec += REPORT_INTERVAL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
taosWLockLatch(&pMgmt->lock);
|
||||
mndSendTelemetryReport(pMnode);
|
||||
taosWUnLockLatch(&pMgmt->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mndGetEmail(SMnode* pMnode, char* filepath) {
|
||||
|
@ -280,43 +271,12 @@ static void mndGetEmail(SMnode* pMnode, char* filepath) {
|
|||
int32_t mndInitTelem(SMnode* pMnode) {
|
||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||
pMgmt->enable = pMnode->cfg.enableTelem;
|
||||
|
||||
if (!pMgmt->enable) return 0;
|
||||
|
||||
pMgmt->exit = 0;
|
||||
pthread_mutex_init(&pMgmt->lock, NULL);
|
||||
pthread_cond_init(&pMgmt->cond, NULL);
|
||||
pMgmt->email[0] = 0;
|
||||
|
||||
taosInitRWLatch(&pMgmt->lock);
|
||||
mndGetEmail(pMnode, "/usr/local/taos/email");
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
int32_t code = pthread_create(&pMgmt->thread, &attr, mndTelemThreadFp, pMnode);
|
||||
pthread_attr_destroy(&attr);
|
||||
if (code != 0) {
|
||||
mDebug("failed to create telemetry thread since :%s", strerror(code));
|
||||
}
|
||||
|
||||
mInfo("mnd telemetry is initialized");
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer);
|
||||
mDebug("mnode telemetry is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mndCleanupTelem(SMnode* pMnode) {
|
||||
STelemMgmt* pMgmt = &pMnode->telemMgmt;
|
||||
if (!pMgmt->enable) return;
|
||||
|
||||
if (taosCheckPthreadValid(pMgmt->thread)) {
|
||||
pthread_mutex_lock(&pMgmt->lock);
|
||||
pMgmt->exit = 1;
|
||||
pthread_cond_signal(&pMgmt->cond);
|
||||
pthread_mutex_unlock(&pMgmt->lock);
|
||||
|
||||
pthread_join(pMgmt->thread, NULL);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&pMgmt->lock);
|
||||
pthread_cond_destroy(&pMgmt->cond);
|
||||
}
|
||||
void mndCleanupTelem(SMnode* pMnode) {}
|
||||
|
|
|
@ -71,7 +71,7 @@ int32_t mndInitTrans(SMnode *pMnode) {
|
|||
.updateFp = (SdbUpdateFp)mndTransActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndTransActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TRANS_TIMER, mndProcessTransReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_KILL_TRANS, mndProcessKillTransReq);
|
||||
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndGetTransMeta);
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
|
||||
#define MQ_TIMER_MS 3000
|
||||
#define TRNAS_TIMER_MS 6000
|
||||
#define TELEM_TIMER_MS 86400000
|
||||
|
||||
int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) {
|
||||
terrno = TSDB_CODE_MND_NOT_READY;
|
||||
|
@ -74,16 +78,16 @@ static void *mndBuildTimerMsg(int32_t *pContLen) {
|
|||
return pReq;
|
||||
}
|
||||
|
||||
static void mndTransReExecute(void *param, void *tmrId) {
|
||||
static void mndPullupTrans(void *param, void *tmrId) {
|
||||
SMnode *pMnode = param;
|
||||
if (mndIsMaster(pMnode)) {
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pReq, .contLen = contLen};
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen};
|
||||
pMnode->putReqToMWriteQFp(pMnode->pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
taosTmrReset(mndTransReExecute, 3000, pMnode, pMnode->timer, &pMnode->transTimer);
|
||||
taosTmrReset(mndPullupTrans, TRNAS_TIMER_MS, pMnode, pMnode->timer, &pMnode->transTimer);
|
||||
}
|
||||
|
||||
static void mndCalMqRebalance(void *param, void *tmrId) {
|
||||
|
@ -95,25 +99,39 @@ static void mndCalMqRebalance(void *param, void *tmrId) {
|
|||
pMnode->putReqToMReadQFp(pMnode->pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
taosTmrReset(mndCalMqRebalance, 3000, pMnode, pMnode->timer, &pMnode->mqTimer);
|
||||
taosTmrReset(mndCalMqRebalance, MQ_TIMER_MS, pMnode, pMnode->timer, &pMnode->mqTimer);
|
||||
}
|
||||
|
||||
static void mndPullupTelem(void *param, void *tmrId) {
|
||||
SMnode *pMnode = param;
|
||||
if (mndIsMaster(pMnode)) {
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen};
|
||||
pMnode->putReqToMReadQFp(pMnode->pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
taosTmrReset(mndPullupTelem, TELEM_TIMER_MS, pMnode, pMnode->timer, &pMnode->telemTimer);
|
||||
}
|
||||
|
||||
static int32_t mndInitTimer(SMnode *pMnode) {
|
||||
if (pMnode->timer == NULL) {
|
||||
pMnode->timer = taosTmrInit(5000, 200, 3600000, "MND");
|
||||
}
|
||||
|
||||
pMnode->timer = taosTmrInit(5000, 200, 3600000, "MND");
|
||||
if (pMnode->timer == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosTmrReset(mndTransReExecute, 6000, pMnode, pMnode->timer, &pMnode->transTimer)) {
|
||||
if (taosTmrReset(mndPullupTrans, TRNAS_TIMER_MS, pMnode, pMnode->timer, &pMnode->transTimer)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosTmrReset(mndCalMqRebalance, 3000, pMnode, pMnode->timer, &pMnode->mqTimer)) {
|
||||
if (taosTmrReset(mndCalMqRebalance, MQ_TIMER_MS, pMnode, pMnode->timer, &pMnode->mqTimer)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosTmrReset(mndPullupTelem, 60000, pMnode, pMnode->timer, &pMnode->telemTimer)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -127,6 +145,8 @@ static void mndCleanupTimer(SMnode *pMnode) {
|
|||
pMnode->transTimer = NULL;
|
||||
taosTmrStop(pMnode->mqTimer);
|
||||
pMnode->mqTimer = NULL;
|
||||
taosTmrStop(pMnode->telemTimer);
|
||||
pMnode->telemTimer = NULL;
|
||||
taosTmrCleanUp(pMnode->timer);
|
||||
pMnode->timer = NULL;
|
||||
}
|
||||
|
@ -406,8 +426,8 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (pRpcMsg->msgType != TDMT_MND_TRANS && pRpcMsg->msgType != TDMT_MND_MQ_TIMER &&
|
||||
pRpcMsg->msgType != TDMT_MND_MQ_DO_REBALANCE) {
|
||||
if (pRpcMsg->msgType != TDMT_MND_TRANS_TIMER && pRpcMsg->msgType != TDMT_MND_MQ_TIMER &&
|
||||
pRpcMsg->msgType != TDMT_MND_MQ_DO_REBALANCE && pRpcMsg->msgType != TDMT_MND_TELEM_TIMER) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) {
|
||||
taosFreeQitem(pMsg);
|
||||
|
|
|
@ -14,4 +14,5 @@ add_subdirectory(qcom)
|
|||
add_subdirectory(qworker)
|
||||
add_subdirectory(tfs)
|
||||
add_subdirectory(nodes)
|
||||
add_subdirectory(scalar)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(scalar)
|
||||
|
|
|
@ -131,9 +131,7 @@ void ctgTestInitLogFile() {
|
|||
|
||||
ctgDbgEnableDebug("api");
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
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})
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
/*
|
||||
* 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_*/
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
|
@ -0,0 +1,635 @@
|
|||
/*
|
||||
* 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"
|
||||
#include "tep.h"
|
||||
#include "tlocale.h"
|
||||
#include "tmsg.h"
|
||||
#include "ttimezone.h"
|
||||
|
||||
#define CFG_NAME_PRINT_LEN 22
|
||||
#define CFG_SRC_PRINT_LEN 12
|
||||
|
||||
SConfig *cfgInit() {
|
||||
SConfig *pCfg = calloc(1, sizeof(SConfig));
|
||||
if (pCfg == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCfg->hash = taosHashInit(16, MurmurHash3_32, false, HASH_NO_LOCK);
|
||||
if (pCfg->hash == NULL) {
|
||||
free(pCfg);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pCfg;
|
||||
}
|
||||
|
||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
|
||||
switch (cfgType) {
|
||||
case CFG_STYPE_CFG_FILE:
|
||||
return cfgLoadFromCfgFile(pCfg, sourceStr);
|
||||
case CFG_STYPE_ENV_FILE:
|
||||
return cfgLoadFromEnvFile(pCfg, sourceStr);
|
||||
case CFG_STYPE_ENV_VAR:
|
||||
return cfgLoadFromEnvVar(pCfg);
|
||||
case CFG_STYPE_APOLLO_URL:
|
||||
return cfgLoadFromApollUrl(pCfg, sourceStr);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void cfgCleanup(SConfig *pCfg) {
|
||||
if (pCfg != NULL) {
|
||||
if (pCfg->hash != NULL) {
|
||||
taosHashCleanup(pCfg->hash);
|
||||
pCfg->hash == NULL;
|
||||
}
|
||||
free(pCfg);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t cfgGetSize(SConfig *pCfg) { return taosHashGetSize(pCfg->hash); }
|
||||
|
||||
SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashIterate(pCfg->hash, pIter); }
|
||||
|
||||
void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter) { return taosHashCancelIterate(pCfg->hash, pIter); }
|
||||
|
||||
static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) {
|
||||
tfree(pItem->str);
|
||||
pItem->str = strdup(timezone);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) {
|
||||
tfree(pItem->str);
|
||||
pItem->str = strdup(charset);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgCheckAndSetLocale(SConfigItem *pItem, const char *locale) {
|
||||
tfree(pItem->str);
|
||||
pItem->str = strdup(locale);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
|
||||
char fullDir[PATH_MAX] = {0};
|
||||
if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to expand dir:%s since %s", inputDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosRealPath(fullDir, PATH_MAX) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to get realpath of dir:%s since %s", inputDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosMkDir(fullDir) != 0) {
|
||||
uError("failed to create dir:%s realpath:%s since %s", inputDir, fullDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
tfree(pItem->str);
|
||||
pItem->str = strdup(fullDir);
|
||||
if (pItem->str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
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) {
|
||||
tmp = true;
|
||||
}
|
||||
if (atoi(value) > 0) {
|
||||
tmp = true;
|
||||
}
|
||||
|
||||
pItem->bval = tmp;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgSetInt32(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
int32_t ival = (int32_t)atoi(value);
|
||||
if (ival < pItem->imin || ival > pItem->imax) {
|
||||
uError("cfg:%s, type:%s src:%s value:%d out of range[%" PRId64 ", %" PRId64 "], use last src:%s value:%d",
|
||||
pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->imin, pItem->imax,
|
||||
cfgStypeStr(pItem->stype), pItem->i32);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pItem->i32 = ival;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgSetInt64(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
int64_t ival = (int64_t)atoi(value);
|
||||
if (ival < pItem->imin || ival > pItem->imax) {
|
||||
uError("cfg:%s, type:%s src:%s value:%" PRId64 " out of range[%" PRId64 ", %" PRId64
|
||||
"], use last src:%s value:%" PRId64,
|
||||
pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->imin, pItem->imax,
|
||||
cfgStypeStr(pItem->stype), pItem->i64);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pItem->i64 = ival;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgSetFloat(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
float fval = (float)atof(value);
|
||||
if (fval < pItem->fmin || fval > pItem->fmax) {
|
||||
uError("cfg:%s, type:%s src:%s value:%f out of range[%f, %f], use last src:%s value:%f", pItem->name,
|
||||
cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), fval, pItem->fmin, pItem->fmax, cfgStypeStr(pItem->stype),
|
||||
pItem->fval);
|
||||
terrno = TSDB_CODE_OUT_OF_RANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pItem->fval = fval;
|
||||
pItem->stype = stype;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgSetString(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
char *tmp = strdup(value);
|
||||
if (tmp == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
free(pItem->str);
|
||||
pItem->str = tmp;
|
||||
pItem->stype = stype;
|
||||
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) {
|
||||
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 cfgSetLocale(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
char *tmp = strdup(value);
|
||||
if (tmp == NULL || cfgCheckAndSetLocale(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 cfgSetCharset(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
char *tmp = strdup(value);
|
||||
if (tmp == NULL || cfgCheckAndSetCharset(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 cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
|
||||
char *tmp = strdup(value);
|
||||
if (tmp == NULL || cfgCheckAndSetTimezone(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;
|
||||
}
|
||||
|
||||
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype) {
|
||||
SConfigItem *pItem = cfgGetItem(pCfg, name);
|
||||
if (pItem == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (pItem->dtype) {
|
||||
case CFG_DTYPE_BOOL:
|
||||
return cfgSetBool(pItem, value, stype);
|
||||
case CFG_DTYPE_INT32:
|
||||
return cfgSetInt32(pItem, value, stype);
|
||||
case CFG_DTYPE_INT64:
|
||||
return cfgSetInt64(pItem, value, stype);
|
||||
case CFG_DTYPE_FLOAT:
|
||||
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:
|
||||
return cfgSetTimezone(pItem, value, stype);
|
||||
case CFG_DTYPE_CHARSET:
|
||||
return cfgSetCharset(pItem, value, stype);
|
||||
case CFG_DTYPE_LOCALE:
|
||||
return cfgSetLocale(pItem, value, stype);
|
||||
case CFG_DTYPE_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name) {
|
||||
char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0};
|
||||
memcpy(lowcaseName, name, CFG_NAME_MAX_LEN);
|
||||
strntolower(lowcaseName, name, CFG_NAME_MAX_LEN);
|
||||
|
||||
SConfigItem *pItem = taosHashGet(pCfg->hash, lowcaseName, strlen(lowcaseName) + 1);
|
||||
if (pItem == NULL) {
|
||||
terrno = TSDB_CODE_CFG_NOT_FOUND;
|
||||
}
|
||||
|
||||
return pItem;
|
||||
}
|
||||
|
||||
static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
|
||||
pItem->stype = CFG_STYPE_DEFAULT;
|
||||
pItem->name = strdup(name);
|
||||
if (pItem->name == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0};
|
||||
memcpy(lowcaseName, name, CFG_NAME_MAX_LEN);
|
||||
strntolower(lowcaseName, name, CFG_NAME_MAX_LEN);
|
||||
|
||||
if (taosHashPut(pCfg->hash, lowcaseName, strlen(lowcaseName) + 1, pItem, sizeof(SConfigItem)) != 0) {
|
||||
if (pItem->dtype == CFG_DTYPE_STRING) {
|
||||
free(pItem->str);
|
||||
}
|
||||
free(pItem->name);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t cfgAddBool(SConfig *pCfg, const char *name, bool defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_BOOL, .bval = defaultVal};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddInt32(SConfig *pCfg, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval) {
|
||||
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};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddInt64(SConfig *pCfg, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval) {
|
||||
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};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddFloat(SConfig *pCfg, const char *name, float defaultVal, double minval, double maxval) {
|
||||
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};
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_STRING};
|
||||
item.str = strdup(defaultVal);
|
||||
if (item.str == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
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};
|
||||
if (cfgCheckAndSetDir(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddLocale(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_LOCALE};
|
||||
if (cfgCheckAndSetLocale(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddCharset(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_CHARSET};
|
||||
if (cfgCheckAndSetCharset(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal) {
|
||||
SConfigItem item = {.dtype = CFG_DTYPE_TIMEZONE};
|
||||
if (cfgCheckAndSetTimezone(&item, defaultVal) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return cfgAddItem(pCfg, &item, name);
|
||||
}
|
||||
|
||||
const char *cfgStypeStr(ECfgSrcType type) {
|
||||
switch (type) {
|
||||
case CFG_STYPE_DEFAULT:
|
||||
return "default";
|
||||
case CFG_STYPE_CFG_FILE:
|
||||
return "cfg_file";
|
||||
case CFG_STYPE_ENV_FILE:
|
||||
return "env_file";
|
||||
case CFG_STYPE_ENV_VAR:
|
||||
return "env_var";
|
||||
case CFG_STYPE_APOLLO_URL:
|
||||
return "apollo_url";
|
||||
case CFG_STYPE_ARG_LIST:
|
||||
return "arg_list";
|
||||
case CFG_STYPE_API_OPTION:
|
||||
return "api_option";
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
const char *cfgDtypeStr(ECfgDataType type) {
|
||||
switch (type) {
|
||||
case CFG_DTYPE_NONE:
|
||||
return "none";
|
||||
case CFG_DTYPE_BOOL:
|
||||
return "bool";
|
||||
case CFG_DTYPE_INT32:
|
||||
return "int32";
|
||||
case CFG_DTYPE_INT64:
|
||||
return "int64";
|
||||
case CFG_DTYPE_FLOAT:
|
||||
return "float";
|
||||
case CFG_DTYPE_STRING:
|
||||
return "string";
|
||||
case CFG_DTYPE_IPSTR:
|
||||
return "ipstr";
|
||||
case CFG_DTYPE_DIR:
|
||||
return "dir";
|
||||
case CFG_DTYPE_LOCALE:
|
||||
return "locale";
|
||||
case CFG_DTYPE_CHARSET:
|
||||
return "charset";
|
||||
case CFG_DTYPE_TIMEZONE:
|
||||
return "timezone";
|
||||
default:
|
||||
return "invalid";
|
||||
}
|
||||
}
|
||||
|
||||
void cfgDumpCfg(SConfig *pCfg) {
|
||||
uInfo(" global config");
|
||||
uInfo("=================================================================");
|
||||
|
||||
char src[CFG_SRC_PRINT_LEN + 1] = {0};
|
||||
char name[CFG_NAME_PRINT_LEN + 1] = {0};
|
||||
|
||||
SConfigItem *pItem = cfgIterate(pCfg, NULL);
|
||||
while (pItem != NULL) {
|
||||
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] = ' ';
|
||||
}
|
||||
|
||||
tstrncpy(name, pItem->name, CFG_NAME_PRINT_LEN);
|
||||
for (int32_t i = 0; i < CFG_NAME_PRINT_LEN; ++i) {
|
||||
if (name[i] == 0) name[i] = ' ';
|
||||
}
|
||||
|
||||
switch (pItem->dtype) {
|
||||
case CFG_DTYPE_BOOL:
|
||||
uInfo("%s %s %u", src, name, pItem->bval);
|
||||
break;
|
||||
case CFG_DTYPE_INT32:
|
||||
uInfo("%s %s %d", src, name, pItem->i32);
|
||||
break;
|
||||
case CFG_DTYPE_INT64:
|
||||
uInfo("%s %s %" PRId64, src, name, pItem->i64);
|
||||
break;
|
||||
case CFG_DTYPE_FLOAT:
|
||||
uInfo("%s %s %f", src, name, pItem->fval);
|
||||
break;
|
||||
case CFG_DTYPE_STRING:
|
||||
case CFG_DTYPE_IPSTR:
|
||||
case CFG_DTYPE_DIR:
|
||||
case CFG_DTYPE_LOCALE:
|
||||
case CFG_DTYPE_CHARSET:
|
||||
case CFG_DTYPE_TIMEZONE:
|
||||
uInfo("%s %s %s", src, name, pItem->str);
|
||||
break;
|
||||
}
|
||||
pItem = cfgIterate(pCfg, pItem);
|
||||
}
|
||||
|
||||
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(tsDataDir, pItem->str, PATH_MAX);
|
||||
// }
|
||||
|
||||
// if (tsDiskCfgNum <= 0) {
|
||||
// taosAddDataDir(0, tsDataDir, 0, 1);
|
||||
// tsDiskCfgNum = 1;
|
||||
// uTrace("dataDir:%s, level:0 primary:1 is configured by default", tsDataDir);
|
||||
// }
|
||||
|
||||
// if (taosDirExist(tsTempDir) != 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
|
|
@ -0,0 +1,14 @@
|
|||
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
|
||||
)
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
* @file cfgTest.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief config module tests
|
||||
* @version 1.0
|
||||
* @date 2022-02-20
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "config.h"
|
||||
|
||||
class CfgTest : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {}
|
||||
static void TearDownTestSuite() {}
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
void InitCfg(SConfig *pConfig);
|
||||
|
||||
static const char *pConfig;
|
||||
};
|
||||
|
||||
const char *CfgTest::pConfig;
|
||||
|
||||
TEST_F(CfgTest, 01_Str) {
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_DEFAULT), "default");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list");
|
||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_API_OPTION), "api_option");
|
||||
EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid");
|
||||
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_NONE), "none");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_BOOL), "bool");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_INT32), "int32");
|
||||
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");
|
||||
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir");
|
||||
EXPECT_STREQ(cfgDtypeStr(ECfgDataType(1024)), "invalid");
|
||||
}
|
||||
|
||||
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(cfgGetSize(pConfig), 7);
|
||||
|
||||
int32_t size = 0;
|
||||
SConfigItem *pItem = cfgIterate(pConfig, NULL);
|
||||
while (pItem != NULL) {
|
||||
switch (pItem->dtype) {
|
||||
case CFG_DTYPE_BOOL:
|
||||
printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->bval);
|
||||
break;
|
||||
case CFG_DTYPE_INT32:
|
||||
printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->i32);
|
||||
break;
|
||||
case CFG_DTYPE_INT64:
|
||||
printf("index:%d, cfg:%s value:%" PRId64 "\n", size, pItem->name, pItem->i64);
|
||||
break;
|
||||
case CFG_DTYPE_FLOAT:
|
||||
printf("index:%d, cfg:%s value:%f\n", size, pItem->name, pItem->fval);
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
printf("index:%d, cfg:%s invalid cfg dtype:%d\n", size, pItem->name, pItem->dtype);
|
||||
break;
|
||||
}
|
||||
size++;
|
||||
pItem = cfgIterate(pConfig, pItem);
|
||||
}
|
||||
cfgCancelIterate(pConfig, pItem);
|
||||
|
||||
EXPECT_EQ(cfgGetSize(pConfig), 7);
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_bool");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
EXPECT_EQ(pItem->dtype, CFG_DTYPE_BOOL);
|
||||
EXPECT_STREQ(pItem->name, "test_bool");
|
||||
EXPECT_EQ(pItem->bval, 0);
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_int32");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
EXPECT_EQ(pItem->dtype, CFG_DTYPE_INT32);
|
||||
EXPECT_STREQ(pItem->name, "test_int32");
|
||||
EXPECT_EQ(pItem->i32, 1);
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_int64");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
EXPECT_EQ(pItem->dtype, CFG_DTYPE_INT64);
|
||||
EXPECT_STREQ(pItem->name, "test_int64");
|
||||
EXPECT_EQ(pItem->i64, 2);
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_float");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
EXPECT_EQ(pItem->dtype, CFG_DTYPE_FLOAT);
|
||||
EXPECT_STREQ(pItem->name, "test_float");
|
||||
EXPECT_EQ(pItem->fval, 3);
|
||||
|
||||
pItem = cfgGetItem(pConfig, "test_string");
|
||||
EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT);
|
||||
EXPECT_EQ(pItem->dtype, CFG_DTYPE_STRING);
|
||||
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);
|
||||
EXPECT_STREQ(pItem->name, "test_dir");
|
||||
EXPECT_STREQ(pItem->str, "/tmp");
|
||||
|
||||
cfgCleanup(pConfig);
|
||||
}
|
|
@ -30,8 +30,8 @@ static void EnvInit() {
|
|||
taosRemoveDir(path.c_str());
|
||||
taosMkDir(path.c_str());
|
||||
// init log file
|
||||
snprintf(indexlog, PATH_MAX, "%s/tindex.idx", path.c_str());
|
||||
if (taosInitLog(indexlog, tsNumOfLogLines, 1) != 0) {
|
||||
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
|
||||
if (taosInitLog("tindex.idx", 1) != 0) {
|
||||
printf("failed to init log");
|
||||
}
|
||||
// init index file
|
||||
|
|
|
@ -101,9 +101,7 @@ void qwtInitLogFile() {
|
|||
tsAsyncLog = 0;
|
||||
qDebugFlag = 159;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,9 +52,7 @@ void flttInitLogFile() {
|
|||
tsAsyncLog = 0;
|
||||
qDebugFlag = 159;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,9 +51,7 @@ void scltInitLogFile() {
|
|||
tsAsyncLog = 0;
|
||||
qDebugFlag = 159;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,9 +66,7 @@ void schtInitLogFile() {
|
|||
tsAsyncLog = 0;
|
||||
qDebugFlag = 159;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
taosInitLog("client.log", 100000, 10);
|
||||
taosInitLog("client.log", 10);
|
||||
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
|
|
|
@ -169,7 +169,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
tsAsyncLog = 0;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
taosInitLog("server.log", 100000, 10);
|
||||
taosInitLog("server.log", 10);
|
||||
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
|
|
|
@ -169,7 +169,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
taosInitLog("client.log", 100000, 10);
|
||||
taosInitLog("client.log", 10);
|
||||
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
|
|
|
@ -148,7 +148,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
taosInitLog("client.log", 100000, 10);
|
||||
taosInitLog("client.log", 10);
|
||||
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
|
|
|
@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
tsAsyncLog = 0;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
taosInitLog("server.log", 100000, 10);
|
||||
taosInitLog("server.log", 10);
|
||||
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
|
|
|
@ -170,7 +170,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
taosInitLog("client.log", 100000, 10);
|
||||
taosInitLog("client.log", 10);
|
||||
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
|
|
|
@ -148,7 +148,6 @@ class TransObj {
|
|||
wDebugFlag = 0;
|
||||
sDebugFlag = 0;
|
||||
tsdbDebugFlag = 0;
|
||||
cqDebugFlag = 0;
|
||||
tscEmbeddedInUtil = 1;
|
||||
tsAsyncLog = 0;
|
||||
|
||||
|
@ -156,9 +155,8 @@ class TransObj {
|
|||
taosRemoveDir(path.c_str());
|
||||
taosMkDir(path.c_str());
|
||||
|
||||
char temp[PATH_MAX];
|
||||
snprintf(temp, PATH_MAX, "%s/taosdlog", path.c_str());
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
|
||||
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
|
||||
if (taosInitLog("taosdlog", 1) != 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
cli = new Client;
|
||||
|
|
|
@ -114,7 +114,7 @@ void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
|
|||
rmdir(dirname);
|
||||
}
|
||||
|
||||
int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen) {
|
||||
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
|
||||
wordexp_t full_path;
|
||||
if (0 != wordexp(dirname, &full_path, 0)) {
|
||||
//printf("failed to expand path:%s since %s", dirname, strerror(errno));
|
||||
|
|
|
@ -23,7 +23,6 @@ char tsOsName[10] = "Windows";
|
|||
char configDir[PATH_MAX] = "C:/TDengine/cfg";
|
||||
char tsDataDir[PATH_MAX] = "C:/TDengine/data";
|
||||
char tsLogDir[PATH_MAX] = "C:/TDengine/log";
|
||||
char tsScriptDir[PATH_MAX] = "C:/TDengine/script";
|
||||
char tsTempDir[PATH_MAX] = "C:\\Windows\\Temp";
|
||||
|
||||
extern taosWinSocketInit();
|
||||
|
@ -47,7 +46,6 @@ char tsOsName[10] = "Darwin";
|
|||
char configDir[PATH_MAX] = "/usr/local/etc/taos";
|
||||
char tsDataDir[PATH_MAX] = "/usr/local/var/lib/taos";
|
||||
char tsLogDir[PATH_MAX] = "/usr/local/var/log/taos";
|
||||
char tsScriptDir[PATH_MAX] = "/usr/local/etc/taos";
|
||||
char tsTempDir[PATH_MAX] = "/tmp/taosd";
|
||||
|
||||
void osInit() {}
|
||||
|
@ -58,7 +56,6 @@ char tsOsName[10] = "Linux";
|
|||
char configDir[PATH_MAX] = "/etc/taos";
|
||||
char tsDataDir[PATH_MAX] = "/var/lib/taos";
|
||||
char tsLogDir[PATH_MAX] = "/var/log/taos";
|
||||
char tsScriptDir[PATH_MAX] = "/etc/taos";
|
||||
char tsTempDir[PATH_MAX] = "/tmp/";
|
||||
|
||||
void osInit() {}
|
||||
|
|
|
@ -150,7 +150,7 @@ int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
|
|||
|
||||
#if !((defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) && defined(_MSC_VER))
|
||||
|
||||
uint32_t taosInetAddr(char *ipAddr) { return inet_addr(ipAddr); }
|
||||
uint32_t taosInetAddr(const char *ipAddr) { return inet_addr(ipAddr); }
|
||||
|
||||
const char *taosInetNtoa(struct in_addr ipInt) { return inet_ntoa(ipInt); }
|
||||
|
||||
|
@ -240,7 +240,7 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
|
|||
#ifdef _MSC_VER
|
||||
//#if _MSC_VER >= 1900
|
||||
|
||||
uint32_t taosInetAddr(char *ipAddr) {
|
||||
uint32_t taosInetAddr(const char *ipAddr) {
|
||||
uint32_t value;
|
||||
int32_t ret = inet_pton(AF_INET, ipAddr, &value);
|
||||
if (ret <= 0) {
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "ulog.h"
|
||||
#include "tglobal.h"
|
||||
#include "tconfig.h"
|
||||
#include "tutil.h"
|
||||
// #include "ulog.h"
|
||||
// #include "tglobal.h"
|
||||
// #include "tutil.h"
|
||||
|
||||
// TODO refactor to set the tz value through parameter
|
||||
void tsSetTimeZone() {
|
||||
#if 0
|
||||
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
|
||||
if (cfg_timezone != NULL) {
|
||||
uInfo("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]);
|
||||
|
@ -64,4 +64,6 @@ void tsSetTimeZone() {
|
|||
tsDaylight = daylight;
|
||||
|
||||
uInfo("timezone format changed to %s", tsTimezone);
|
||||
|
||||
#endif
|
||||
}
|
|
@ -1,507 +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 "os.h"
|
||||
#include "tconfig.h"
|
||||
#include "tutil.h"
|
||||
#include "ulog.h"
|
||||
|
||||
SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {{0}};
|
||||
int32_t tsGlobalConfigNum = 0;
|
||||
|
||||
static char *tsGlobalUnit[] = {
|
||||
" ",
|
||||
"(%)",
|
||||
"(GB)",
|
||||
"(Mb)",
|
||||
"(byte)",
|
||||
"(s)",
|
||||
"(ms)"
|
||||
};
|
||||
|
||||
char *tsCfgStatusStr[] = {
|
||||
"none",
|
||||
"system default",
|
||||
"config file",
|
||||
"taos_options",
|
||||
"program argument list"
|
||||
};
|
||||
|
||||
static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) {
|
||||
float value = (float)atof(input_value);
|
||||
float *option = (float *)cfg->ptr;
|
||||
if (value < cfg->minValue || value > cfg->maxValue) {
|
||||
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
|
||||
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
*option = value;
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], *option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
|
||||
double value = atof(input_value);
|
||||
double *option = (double *)cfg->ptr;
|
||||
if (value < cfg->minValue || value > cfg->maxValue) {
|
||||
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f",
|
||||
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
*option = value;
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], *option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
|
||||
int32_t value = atoi(input_value);
|
||||
int32_t *option = (int32_t *)cfg->ptr;
|
||||
if (value < cfg->minValue || value > cfg->maxValue) {
|
||||
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
|
||||
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
*option = value;
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], *option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) {
|
||||
int32_t value = atoi(input_value);
|
||||
int16_t *option = (int16_t *)cfg->ptr;
|
||||
if (value < cfg->minValue || value > cfg->maxValue) {
|
||||
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
|
||||
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
*option = (int16_t)value;
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], *option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void taosReadUInt16Config(SGlobalCfg *cfg, char *input_value) {
|
||||
int32_t value = atoi(input_value);
|
||||
uint16_t *option = (uint16_t *)cfg->ptr;
|
||||
if (value < cfg->minValue || value > cfg->maxValue) {
|
||||
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
|
||||
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
*option = (uint16_t)value;
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], *option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void taosReadInt8Config(SGlobalCfg *cfg, char *input_value) {
|
||||
int32_t value = atoi(input_value);
|
||||
int8_t *option = (int8_t *)cfg->ptr;
|
||||
if (value < cfg->minValue || value > cfg->maxValue) {
|
||||
uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d",
|
||||
cfg->option, input_value, cfg->minValue, cfg->maxValue, *option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
*option = (int8_t)value;
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], *option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
|
||||
int length = (int)strlen(input_value);
|
||||
char *option = (char *)cfg->ptr;
|
||||
if (length <= 0 || length > cfg->ptrLength) {
|
||||
uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", cfg->option,
|
||||
input_value, cfg->ptrLength, option);
|
||||
return false;
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
taosExpandDir(input_value, option, cfg->ptrLength);
|
||||
taosRealPath(option, cfg->ptrLength);
|
||||
|
||||
if (taosMkDir(option) != 0) {
|
||||
uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value,
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], option);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) {
|
||||
uint32_t value = taosInetAddr(input_value);
|
||||
char * option = (char *)cfg->ptr;
|
||||
if (value == INADDR_NONE) {
|
||||
uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s",
|
||||
cfg->option, input_value, option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
strncpy(option, input_value, cfg->ptrLength);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) {
|
||||
int length = (int) strlen(input_value);
|
||||
char *option = (char *)cfg->ptr;
|
||||
if (length <= 0 || length > cfg->ptrLength) {
|
||||
uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s",
|
||||
cfg->option, input_value, cfg->ptrLength, option);
|
||||
} else {
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||
strncpy(option, input_value, cfg->ptrLength);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
|
||||
} else {
|
||||
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
|
||||
tsCfgStatusStr[cfg->cfgStatus], option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void taosReadLogOption(char *option, char *value) {
|
||||
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG) || !(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue;
|
||||
if (strcasecmp(cfg->option, option) != 0) continue;
|
||||
|
||||
switch (cfg->valType) {
|
||||
case TAOS_CFG_VTYPE_INT32:
|
||||
taosReadInt32Config(cfg, value);
|
||||
// if (strcasecmp(cfg->option, "debugFlag") == 0) {
|
||||
// taosSetAllDebugFlag();
|
||||
// }
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_DIRECTORY:
|
||||
taosReadDirectoryConfig(cfg, value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SGlobalCfg *taosGetConfigOption(const char *option) {
|
||||
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||
if (strcasecmp(cfg->option, option) != 0) continue;
|
||||
return cfg;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void taosReadConfigOption(const char *option, char *value, char *value2, char *value3) {
|
||||
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue;
|
||||
if (strcasecmp(cfg->option, option) != 0) continue;
|
||||
|
||||
switch (cfg->valType) {
|
||||
case TAOS_CFG_VTYPE_INT8:
|
||||
taosReadInt8Config(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_INT16:
|
||||
taosReadInt16Config(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_INT32:
|
||||
taosReadInt32Config(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_UINT16:
|
||||
taosReadUInt16Config(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_FLOAT:
|
||||
taosReadFloatConfig(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_DOUBLE:
|
||||
taosReadDoubleConfig(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_STRING:
|
||||
taosReadStringConfig(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_IPSTR:
|
||||
taosReadIpStrConfig(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_DIRECTORY:
|
||||
taosReadDirectoryConfig(cfg, value);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_DATA_DIRCTORY:
|
||||
if (taosReadDirectoryConfig(cfg, value)) {
|
||||
// taosReadDataDirCfg(value, value2, value3);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
uError("config option:%s, input value:%s, can't be recognized", option, value);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void taosAddConfigOption(SGlobalCfg cfg) {
|
||||
tsGlobalConfig[tsGlobalConfigNum++] = cfg;
|
||||
}
|
||||
|
||||
void taosReadGlobalLogCfg() {
|
||||
FILE * fp;
|
||||
char * line, *option, *value;
|
||||
int olen, vlen;
|
||||
char fileName[PATH_MAX] = {0};
|
||||
|
||||
taosExpandDir(configDir, configDir, PATH_MAX);
|
||||
taosReadLogOption("logDir", tsLogDir);
|
||||
|
||||
sprintf(fileName, "%s/taos.cfg", configDir);
|
||||
fp = fopen(fileName, "r");
|
||||
if (fp == NULL) {
|
||||
printf("\nconfig file:%s not found, all variables are set to default\n", fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
ssize_t _bytes = 0;
|
||||
size_t len = 1024;
|
||||
line = calloc(1, len);
|
||||
|
||||
while (!feof(fp)) {
|
||||
memset(line, 0, len);
|
||||
|
||||
option = value = NULL;
|
||||
olen = vlen = 0;
|
||||
|
||||
_bytes = tgetline(&line, &len, fp);
|
||||
if (_bytes < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
line[len - 1] = 0;
|
||||
|
||||
paGetToken(line, &option, &olen);
|
||||
if (olen == 0) continue;
|
||||
option[olen] = 0;
|
||||
|
||||
paGetToken(option + olen + 1, &value, &vlen);
|
||||
if (vlen == 0) continue;
|
||||
value[vlen] = 0;
|
||||
|
||||
taosReadLogOption(option, value);
|
||||
}
|
||||
|
||||
tfree(line);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
int32_t taosReadCfgFromFile() {
|
||||
char * line, *option, *value, *value2, *value3;
|
||||
int olen, vlen, vlen2, vlen3;
|
||||
char fileName[PATH_MAX] = {0};
|
||||
|
||||
sprintf(fileName, "%s/taos.cfg", configDir);
|
||||
FILE *fp = fopen(fileName, "r");
|
||||
if (fp == NULL) {
|
||||
fp = fopen(configDir, "r");
|
||||
if (fp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t _bytes = 0;
|
||||
size_t len = 1024;
|
||||
line = calloc(1, len);
|
||||
|
||||
while (!feof(fp)) {
|
||||
memset(line, 0, len);
|
||||
|
||||
option = value = value2 = value3 = NULL;
|
||||
olen = vlen = vlen2 = vlen3 = 0;
|
||||
|
||||
_bytes = tgetline(&line, &len, fp);
|
||||
if (_bytes < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
line[len - 1] = 0;
|
||||
|
||||
paGetToken(line, &option, &olen);
|
||||
if (olen == 0) continue;
|
||||
option[olen] = 0;
|
||||
|
||||
paGetToken(option + 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;
|
||||
}
|
||||
|
||||
taosReadConfigOption(option, value, value2, value3);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
tfree(line);
|
||||
|
||||
// if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
|
||||
// taosSetAllDebugFlag();
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosPrintCfg() {
|
||||
uInfo(" taos config & system info:");
|
||||
uInfo("==================================");
|
||||
|
||||
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||
if (tscEmbeddedInUtil == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
|
||||
if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
|
||||
|
||||
int optionLen = (int)strlen(cfg->option);
|
||||
int blankLen = TSDB_CFG_PRINT_LEN - optionLen;
|
||||
blankLen = blankLen < 0 ? 0 : blankLen;
|
||||
|
||||
char blank[TSDB_CFG_PRINT_LEN];
|
||||
memset(blank, ' ', TSDB_CFG_PRINT_LEN);
|
||||
blank[blankLen] = 0;
|
||||
|
||||
switch (cfg->valType) {
|
||||
case TAOS_CFG_VTYPE_INT8:
|
||||
uInfo(" %s:%s%d%s", cfg->option, blank, *((int8_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_INT16:
|
||||
uInfo(" %s:%s%d%s", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_INT32:
|
||||
uInfo(" %s:%s%d%s", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_UINT16:
|
||||
uInfo(" %s:%s%d%s", cfg->option, blank, *((uint16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_FLOAT:
|
||||
uInfo(" %s:%s%f%s", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_DOUBLE:
|
||||
uInfo(" %s:%s%f%s", cfg->option, blank, *((double *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_STRING:
|
||||
case TAOS_CFG_VTYPE_IPSTR:
|
||||
case TAOS_CFG_VTYPE_DIRECTORY:
|
||||
uInfo(" %s:%s%s%s", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
taosPrintOsInfo();
|
||||
uInfo("==================================");
|
||||
}
|
||||
|
||||
static void taosDumpCfg(SGlobalCfg *cfg) {
|
||||
int optionLen = (int)strlen(cfg->option);
|
||||
int blankLen = TSDB_CFG_PRINT_LEN - optionLen;
|
||||
blankLen = blankLen < 0 ? 0 : blankLen;
|
||||
|
||||
char blank[TSDB_CFG_PRINT_LEN];
|
||||
memset(blank, ' ', TSDB_CFG_PRINT_LEN);
|
||||
blank[blankLen] = 0;
|
||||
|
||||
switch (cfg->valType) {
|
||||
case TAOS_CFG_VTYPE_INT8:
|
||||
printf(" %s:%s%d%s\n", cfg->option, blank, *((int8_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_INT16:
|
||||
printf(" %s:%s%d%s\n", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_INT32:
|
||||
printf(" %s:%s%d%s\n", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_UINT16:
|
||||
printf(" %s:%s%d%s\n", cfg->option, blank, *((uint16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_FLOAT:
|
||||
printf(" %s:%s%f%s\n", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
case TAOS_CFG_VTYPE_STRING:
|
||||
case TAOS_CFG_VTYPE_IPSTR:
|
||||
case TAOS_CFG_VTYPE_DIRECTORY:
|
||||
printf(" %s:%s%s%s\n", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void taosDumpGlobalCfg() {
|
||||
printf("taos global config:\n");
|
||||
printf("==================================\n");
|
||||
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||
if (tscEmbeddedInUtil == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
|
||||
if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
|
||||
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW)) continue;
|
||||
|
||||
taosDumpCfg(cfg);
|
||||
}
|
||||
|
||||
printf("\ntaos local config:\n");
|
||||
printf("==================================\n");
|
||||
|
||||
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||
if (tscEmbeddedInUtil == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
|
||||
if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue;
|
||||
if (cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW) continue;
|
||||
|
||||
taosDumpCfg(cfg);
|
||||
}
|
||||
}
|
|
@ -81,6 +81,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG, "Invalid message")
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PARA, "Invalid parameters")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_CFG_NOT_FOUND, "Config not found")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CFG, "Invalid config option")
|
||||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs")
|
||||
|
|
|
@ -70,7 +70,8 @@ typedef struct {
|
|||
int8_t tscEmbeddedInUtil = 0;
|
||||
|
||||
int32_t tsLogKeepDays = 0;
|
||||
int8_t tsAsyncLog = 1;
|
||||
bool tsAsyncLog = true;
|
||||
bool tsLogInited = false;
|
||||
float tsTotalLogDirGB = 0;
|
||||
float tsAvailLogDirGB = 0;
|
||||
float tsMinimalLogDirGB = 1.0f;
|
||||
|
@ -79,20 +80,19 @@ int32_t writeInterval = DEFAULT_LOG_INTERVAL;
|
|||
|
||||
// log
|
||||
int32_t tsNumOfLogLines = 10000000;
|
||||
int32_t mDebugFlag = 131;
|
||||
int32_t dDebugFlag = 135;
|
||||
int32_t vDebugFlag = 135;
|
||||
int32_t mDebugFlag = 131;
|
||||
int32_t cDebugFlag = 131;
|
||||
int32_t jniDebugFlag = 131;
|
||||
int32_t qDebugFlag = 131;
|
||||
int32_t rpcDebugFlag = 131;
|
||||
int32_t tmrDebugFlag = 131;
|
||||
int32_t uDebugFlag = 131;
|
||||
int32_t debugFlag = 0;
|
||||
int32_t sDebugFlag = 135;
|
||||
int32_t rpcDebugFlag = 131;
|
||||
int32_t qDebugFlag = 131;
|
||||
int32_t wDebugFlag = 135;
|
||||
int32_t sDebugFlag = 135;
|
||||
int32_t tsdbDebugFlag = 131;
|
||||
int32_t tqDebugFlag = 135;
|
||||
int32_t cqDebugFlag = 131;
|
||||
int32_t fsDebugFlag = 135;
|
||||
|
||||
int64_t dbgEmptyW = 0;
|
||||
|
@ -120,11 +120,17 @@ static int32_t taosStartLog() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosInitLog(char *logName, int numOfLogLines, int maxFiles) {
|
||||
int32_t taosInitLog(const char *logName, int maxFiles) {
|
||||
if (tsLogInited) return 0;
|
||||
|
||||
char fullName[PATH_MAX] = {0};
|
||||
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logName);
|
||||
|
||||
tsLogObj.logHandle = taosLogBuffNew(TSDB_DEFAULT_LOG_BUF_SIZE);
|
||||
if (tsLogObj.logHandle == NULL) return -1;
|
||||
if (taosOpenLogFile(logName, numOfLogLines, maxFiles) < 0) return -1;
|
||||
if (taosOpenLogFile(fullName, tsNumOfLogLines, maxFiles) < 0) return -1;
|
||||
if (taosStartLog() < 0) return -1;
|
||||
tsLogInited = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -217,7 +223,7 @@ static void *taosThreadToOpenNewFile(void *param) {
|
|||
|
||||
uInfo(" new log file:%d is opened", tsLogObj.flag);
|
||||
uInfo("==================================");
|
||||
taosPrintCfg();
|
||||
// taosPrintCfg();
|
||||
taosKeepOldLog(keepName);
|
||||
|
||||
return NULL;
|
||||
|
@ -773,3 +779,23 @@ void taosPrintOsInfo() {
|
|||
uInfo(" os version: %s", info.version);
|
||||
uInfo(" os machine: %s", info.machine);
|
||||
}
|
||||
|
||||
void taosSetAllDebugFlag(int32_t flag) {
|
||||
if (!(flag & DEBUG_TRACE || flag & DEBUG_DEBUG || flag & DEBUG_DUMP)) return;
|
||||
|
||||
dDebugFlag = flag;
|
||||
vDebugFlag = flag;
|
||||
mDebugFlag = flag;
|
||||
cDebugFlag = flag;
|
||||
jniDebugFlag = flag;
|
||||
uDebugFlag = flag;
|
||||
rpcDebugFlag = flag;
|
||||
qDebugFlag = flag;
|
||||
wDebugFlag = flag;
|
||||
sDebugFlag = flag;
|
||||
tsdbDebugFlag = flag;
|
||||
tqDebugFlag = flag;
|
||||
fsDebugFlag = flag;
|
||||
|
||||
uInfo("all debug flag are set to %d", flag);
|
||||
}
|
|
@ -111,7 +111,6 @@ typedef struct time_wheel_t {
|
|||
tmr_obj_t** slots;
|
||||
} time_wheel_t;
|
||||
|
||||
int32_t tmrDebugFlag = 131;
|
||||
uint32_t tsMaxTmrCtrl = 512;
|
||||
|
||||
static pthread_once_t tmrModuleInit = PTHREAD_ONCE_INIT;
|
||||
|
|
|
@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
taosInitLog("tref.log", 5000000, 10);
|
||||
taosInitLog("tref.log", 10);
|
||||
|
||||
SRefSpace *pSpaceList = (SRefSpace *) calloc(sizeof(SRefSpace), threads);
|
||||
pthread_t *pThreadList = (pthread_t *) calloc(sizeof(pthread_t), threads);
|
||||
|
|
2
tests
2
tests
|
@ -1 +1 @@
|
|||
Subproject commit 4da4bb00c5615f0b1bea04340abef5d9d15a96b4
|
||||
Subproject commit 498e17e225c454f2b45ff16eaa6d3eb595b107cf
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "os.h"
|
||||
#include "shell.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
pthread_t pid;
|
||||
|
|
Loading…
Reference in New Issue