Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f9662420
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f9662420
编写于
4月 25, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature(dnode): mul parameter start.
上级
7d8d382f
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
576 addition
and
78 deletion
+576
-78
CMakeLists.txt
CMakeLists.txt
+1
-1
examples/c/CMakeLists.txt
examples/c/CMakeLists.txt
+2
-2
include/common/tglobal.h
include/common/tglobal.h
+3
-3
include/util/tconfig.h
include/util/tconfig.h
+4
-1
include/util/tenv.h
include/util/tenv.h
+33
-0
include/util/tjson.h
include/util/tjson.h
+3
-0
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+2
-2
source/common/src/tglobal.c
source/common/src/tglobal.c
+15
-8
source/dnode/mgmt/exe/dmMain.c
source/dnode/mgmt/exe/dmMain.c
+22
-4
source/dnode/mgmt/interface/src/dmFile.c
source/dnode/mgmt/interface/src/dmFile.c
+1
-1
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+2
-2
source/libs/function/test/runUdf.c
source/libs/function/test/runUdf.c
+2
-2
source/libs/sync/CMakeLists.txt
source/libs/sync/CMakeLists.txt
+1
-1
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+39
-39
source/util/src/tconfig.c
source/util/src/tconfig.c
+344
-7
source/util/src/tenv.c
source/util/src/tenv.c
+78
-0
source/util/src/tjson.c
source/util/src/tjson.c
+19
-1
source/util/test/CMakeLists.txt
source/util/test/CMakeLists.txt
+1
-1
source/util/test/cfgTest.cpp
source/util/test/cfgTest.cpp
+1
-0
tests/tsim/src/simSystem.c
tests/tsim/src/simSystem.c
+2
-2
tools/shell/CMakeLists.txt
tools/shell/CMakeLists.txt
+1
-1
未找到文件。
CMakeLists.txt
浏览文件 @
f9662420
...
...
@@ -7,7 +7,7 @@ project(
)
if
(
NOT DEFINED TD_SOURCE_DIR
)
set
(
TD_SOURCE_DIR
${
CMAKE
_SOURCE_DIR
}
)
set
(
TD_SOURCE_DIR
${
PROJECT
_SOURCE_DIR
}
)
endif
()
set
(
TD_SUPPORT_DIR
"
${
TD_SOURCE_DIR
}
/cmake"
)
...
...
examples/c/CMakeLists.txt
浏览文件 @
f9662420
PROJECT
(
TDengine
)
IF
(
TD_LINUX
)
INCLUDE_DIRECTORIES
(
.
${
TD_
COMMUNITY_DIR
}
/src/inc
${
TD_COMMUNITY_DIR
}
/src/client/inc
${
TD_COMMUNITY
_DIR
}
/inc
)
INCLUDE_DIRECTORIES
(
.
${
TD_
SOURCE_DIR
}
/src/inc
${
TD_SOURCE_DIR
}
/src/client/inc
${
TD_SOURCE
_DIR
}
/inc
)
AUX_SOURCE_DIRECTORY
(
. SRC
)
ADD_EXECUTABLE
(
demo apitest.c
)
TARGET_LINK_LIBRARIES
(
demo taos_static trpc tutil pthread
)
...
...
@@ -13,7 +13,7 @@ IF (TD_LINUX)
TARGET_LINK_LIBRARIES
(
epoll taos_static trpc tutil pthread lua
)
ENDIF
()
IF
(
TD_DARWIN
)
INCLUDE_DIRECTORIES
(
.
${
TD_
COMMUNITY_DIR
}
/src/inc
${
TD_COMMUNITY_DIR
}
/src/client/inc
${
TD_COMMUNITY
_DIR
}
/inc
)
INCLUDE_DIRECTORIES
(
.
${
TD_
SOURCE_DIR
}
/src/inc
${
TD_SOURCE_DIR
}
/src/client/inc
${
TD_SOURCE
_DIR
}
/inc
)
AUX_SOURCE_DIRECTORY
(
. SRC
)
ADD_EXECUTABLE
(
demo demo.c
)
TARGET_LINK_LIBRARIES
(
demo taos_static trpc tutil pthread lua
)
...
...
include/common/tglobal.h
浏览文件 @
f9662420
...
...
@@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[];
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
int32_t
taosCreateLog
(
const
char
*
logname
,
int32_t
logFileNum
,
const
char
*
cfgDir
,
const
char
*
envFile
,
c
onst
c
har
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
);
int32_t
taosInitCfg
(
const
char
*
cfgDir
,
const
char
*
envFile
,
const
char
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
);
int32_t
taosCreateLog
(
const
char
*
logname
,
int32_t
logFileNum
,
const
char
*
*
envCmd
,
const
char
*
cfgDir
,
const
char
*
envFile
,
char
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
);
int32_t
taosInitCfg
(
const
char
*
*
envCmd
,
const
char
*
cfgDir
,
const
char
*
envFile
,
char
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
);
void
taosCleanupCfg
();
void
taosCfgDynamicOptions
(
const
char
*
option
,
const
char
*
value
);
void
taosAddDataDir
(
int32_t
index
,
char
*
v1
,
int32_t
level
,
int32_t
primary
);
...
...
include/util/tconfig.h
浏览文件 @
f9662420
...
...
@@ -30,6 +30,7 @@ typedef enum {
CFG_STYPE_CFG_FILE
,
CFG_STYPE_ENV_FILE
,
CFG_STYPE_ENV_VAR
,
CFG_STYPE_ENV_CMD
,
CFG_STYPE_APOLLO_URL
,
CFG_STYPE_ARG_LIST
,
CFG_STYPE_TAOS_OPTIONS
...
...
@@ -82,7 +83,7 @@ typedef struct SConfig {
}
SConfig
;
SConfig
*
cfgInit
();
int32_t
cfgLoad
(
SConfig
*
pCfg
,
ECfgSrcType
cfgType
,
const
char
*
sourceStr
);
int32_t
cfgLoad
(
SConfig
*
pCfg
,
ECfgSrcType
cfgType
,
const
void
*
sourceStr
);
int32_t
cfgLoadFromArray
(
SConfig
*
pCfg
,
SArray
*
pArgs
);
// SConfigPair
void
cfgCleanup
(
SConfig
*
pCfg
);
...
...
@@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type);
void
cfgDumpCfg
(
SConfig
*
pCfg
,
bool
tsc
,
bool
dump
);
int32_t
cfgGetApollUrl
(
const
char
**
envCmd
,
const
char
*
envFile
,
char
*
apolloUrl
);
#ifdef __cplusplus
}
#endif
...
...
include/util/tenv.h
0 → 100644
浏览文件 @
f9662420
/*
* 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_ENV_H_
#define _TD_ENV_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
taosEnvNameToCfgName
(
const
char
*
envNameStr
,
char
*
cfgNameStr
,
int32_t
cfgNameMaxLen
);
int32_t
taosEnvToCfg
(
const
char
*
envStr
,
char
*
cfgStr
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_ENV_H_*/
include/util/tjson.h
浏览文件 @
f9662420
...
...
@@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
int32_t
tjsonAddItemToArray
(
SJson
*
pJson
,
SJson
*
pItem
);
SJson
*
tjsonGetObjectItem
(
const
SJson
*
pJson
,
const
char
*
pName
);
int32_t
tjsonGetObjectName
(
const
SJson
*
pJson
,
char
**
pName
);
int32_t
tjsonGetObjectValueString
(
const
SJson
*
pJson
,
char
**
pStringValue
);
int32_t
tjsonGetStringValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
char
*
pVal
);
int32_t
tjsonDupStringValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
char
**
pVal
);
int32_t
tjsonGetBigIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
int64_t
*
pVal
);
...
...
@@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson);
SJson
*
tjsonParse
(
const
char
*
pStr
);
bool
tjsonValidateJson
(
const
char
*
pJson
);
const
char
*
tjsonGetError
();
#ifdef __cplusplus
}
...
...
source/client/src/clientEnv.c
浏览文件 @
f9662420
...
...
@@ -254,12 +254,12 @@ void taos_init_imp(void) {
deltaToUtcInitOnce
();
if
(
taosCreateLog
(
"taoslog"
,
10
,
configDir
,
NULL
,
NULL
,
NULL
,
1
)
!=
0
)
{
if
(
taosCreateLog
(
"taoslog"
,
10
,
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
1
)
!=
0
)
{
tscInitRes
=
-
1
;
return
;
}
if
(
taosInitCfg
(
configDir
,
NULL
,
NULL
,
NULL
,
1
)
!=
0
)
{
if
(
taosInitCfg
(
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
1
)
!=
0
)
{
tscInitRes
=
-
1
;
return
;
}
...
...
source/common/src/tglobal.c
浏览文件 @
f9662420
...
...
@@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() {
return
tsCfg
;
}
static
int32_t
taosLoadCfg
(
SConfig
*
pCfg
,
const
char
*
inputCfgDir
,
const
char
*
envFile
,
const
char
*
apolloUrl
)
{
static
int32_t
taosLoadCfg
(
SConfig
*
pCfg
,
const
char
*
*
envCmd
,
const
char
*
inputCfgDir
,
const
char
*
envFile
,
char
*
apolloUrl
)
{
char
cfgDir
[
PATH_MAX
]
=
{
0
};
char
cfgFile
[
PATH_MAX
+
100
]
=
{
0
};
...
...
@@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
tstrncpy
(
cfgFile
,
cfgDir
,
sizeof
(
cfgDir
));
}
if
(
apolloUrl
==
NULL
||
apolloUrl
[
0
]
==
'\0'
)
cfgGetApollUrl
(
envCmd
,
envFile
,
apolloUrl
);
if
(
cfgLoad
(
pCfg
,
CFG_STYPE_APOLLO_URL
,
apolloUrl
)
!=
0
)
{
uError
(
"failed to load from apollo url:%s since %s"
,
apolloUrl
,
terrstr
());
return
-
1
;
...
...
@@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
return
-
1
;
}
if
(
cfgLoad
(
pCfg
,
CFG_STYPE_ENV_CMD
,
envCmd
)
!=
0
)
{
uError
(
"failed to load from cmd env variables since %s"
,
terrstr
());
return
-
1
;
}
return
0
;
}
...
...
@@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
if
(
cfgAddFloat
(
pCfg
,
"numOfCores"
,
tsNumOfCores
,
0
,
100000
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"openMax"
,
tsOpenMax
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"streamMax"
,
tsStreamMax
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"pageSize
(KB)
"
,
tsPageSizeKB
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"totalMemory
(KB)
"
,
tsTotalMemoryKB
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"pageSize
KB
"
,
tsPageSizeKB
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt64
(
pCfg
,
"totalMemory
KB
"
,
tsTotalMemoryKB
,
0
,
INT64_MAX
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os sysname"
,
info
.
sysname
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os nodename"
,
info
.
nodename
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddString
(
pCfg
,
"os release"
,
info
.
release
,
1
)
!=
0
)
return
-
1
;
...
...
@@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
return
0
;
}
int32_t
taosCreateLog
(
const
char
*
logname
,
int32_t
logFileNum
,
const
char
*
cfgDir
,
const
char
*
envFile
,
c
onst
c
har
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
)
{
int32_t
taosCreateLog
(
const
char
*
logname
,
int32_t
logFileNum
,
const
char
*
*
envCmd
,
const
char
*
cfgDir
,
const
char
*
envFile
,
char
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
)
{
osDefaultInit
();
SConfig
*
pCfg
=
cfgInit
();
...
...
@@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
if
(
taosAddServerLogCfg
(
pCfg
)
!=
0
)
return
-
1
;
}
if
(
taosLoadCfg
(
pCfg
,
cfgDir
,
envFile
,
apolloUrl
)
!=
0
)
{
if
(
taosLoadCfg
(
pCfg
,
envCmd
,
cfgDir
,
envFile
,
apolloUrl
)
!=
0
)
{
uError
(
"failed to load cfg since %s"
,
terrstr
());
cfgCleanup
(
pCfg
);
return
-
1
;
...
...
@@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
return
0
;
}
int32_t
taosInitCfg
(
const
char
*
cfgDir
,
const
char
*
envFile
,
const
char
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
)
{
int32_t
taosInitCfg
(
const
char
*
*
envCmd
,
const
char
*
cfgDir
,
const
char
*
envFile
,
char
*
apolloUrl
,
SArray
*
pArgs
,
bool
tsc
)
{
if
(
tsCfg
!=
NULL
)
return
0
;
tsCfg
=
cfgInit
();
...
...
@@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
}
taosAddSystemCfg
(
tsCfg
);
if
(
taosLoadCfg
(
tsCfg
,
cfgDir
,
envFile
,
apolloUrl
)
!=
0
)
{
if
(
taosLoadCfg
(
tsCfg
,
envCmd
,
cfgDir
,
envFile
,
apolloUrl
)
!=
0
)
{
uError
(
"failed to load cfg since %s"
,
terrstr
());
cfgCleanup
(
tsCfg
);
tsCfg
=
NULL
;
...
...
source/dnode/mgmt/exe/dmMain.c
浏览文件 @
f9662420
...
...
@@ -24,6 +24,7 @@ static struct {
bool
printVersion
;
char
envFile
[
PATH_MAX
];
char
apolloUrl
[
PATH_MAX
];
const
char
**
envCmd
;
SArray
*
pArgs
;
// SConfigPair
SDnode
*
pDnode
;
EDndNodeType
ntype
;
...
...
@@ -56,6 +57,9 @@ static void dmSetSignalHandle() {
}
static
int32_t
dmParseArgs
(
int32_t
argc
,
char
const
*
argv
[])
{
int32_t
cmdEnvIndex
=
0
;
global
.
envCmd
=
taosMemoryMalloc
(
argc
-
1
);
memset
(
global
.
envCmd
,
0
,
argc
-
1
);
for
(
int32_t
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
strcmp
(
argv
[
i
],
"-c"
)
==
0
)
{
if
(
i
<
argc
-
1
)
{
...
...
@@ -70,7 +74,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
}
}
else
if
(
strcmp
(
argv
[
i
],
"-a"
)
==
0
)
{
tstrncpy
(
global
.
apolloUrl
,
argv
[
++
i
],
PATH_MAX
);
}
else
if
(
strcmp
(
argv
[
i
],
"-
e
"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"-
E
"
)
==
0
)
{
tstrncpy
(
global
.
envFile
,
argv
[
++
i
],
PATH_MAX
);
}
else
if
(
strcmp
(
argv
[
i
],
"-n"
)
==
0
)
{
global
.
ntype
=
atoi
(
argv
[
++
i
]);
...
...
@@ -84,6 +88,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
global
.
dumpConfig
=
true
;
}
else
if
(
strcmp
(
argv
[
i
],
"-V"
)
==
0
)
{
global
.
printVersion
=
true
;
}
else
if
(
strcmp
(
argv
[
i
],
"-e"
)
==
0
)
{
global
.
envCmd
[
cmdEnvIndex
]
=
argv
[
++
i
];
cmdEnvIndex
++
;
}
else
{
}
}
...
...
@@ -129,7 +136,7 @@ static SDnodeOpt dmGetOpt() {
static
int32_t
dmInitLog
()
{
char
logName
[
12
]
=
{
0
};
snprintf
(
logName
,
sizeof
(
logName
),
"%slog"
,
dmLogName
(
global
.
ntype
));
return
taosCreateLog
(
logName
,
1
,
configDir
,
global
.
envFile
,
global
.
apolloUrl
,
global
.
pArgs
,
0
);
return
taosCreateLog
(
logName
,
1
,
global
.
envCmd
,
configDir
,
global
.
envFile
,
global
.
apolloUrl
,
global
.
pArgs
,
0
);
}
static
void
dmSetProcInfo
(
int32_t
argc
,
char
**
argv
)
{
...
...
@@ -168,6 +175,10 @@ static int32_t dmRunDnode() {
return
code
;
}
static
void
taosCleanupArgs
()
{
if
(
global
.
envCmd
!=
NULL
)
taosMemoryFree
(
global
.
envCmd
);
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
if
(
!
taosCheckSystemIsSmallEnd
())
{
printf
(
"failed to start since on non-small-end machines
\n
"
);
...
...
@@ -176,26 +187,31 @@ int main(int argc, char const *argv[]) {
if
(
dmParseArgs
(
argc
,
argv
)
!=
0
)
{
printf
(
"failed to start since parse args error
\n
"
);
taosCleanupArgs
();
return
-
1
;
}
if
(
global
.
generateGrant
)
{
dmGenerateGrant
();
taosCleanupArgs
();
return
0
;
}
if
(
global
.
printVersion
)
{
dmPrintVersion
();
taosCleanupArgs
();
return
0
;
}
if
(
dmInitLog
()
!=
0
)
{
dError
(
"failed to start since init log error"
);
printf
(
"failed to start since init log error"
);
taosCleanupArgs
();
return
-
1
;
}
if
(
taosInitCfg
(
configDir
,
global
.
envFile
,
global
.
apolloUrl
,
global
.
pArgs
,
0
)
!=
0
)
{
if
(
taosInitCfg
(
global
.
envCmd
,
configDir
,
global
.
envFile
,
global
.
apolloUrl
,
global
.
pArgs
,
0
)
!=
0
)
{
dError
(
"failed to start since read config error"
);
taosCleanupArgs
();
return
-
1
;
}
...
...
@@ -203,9 +219,11 @@ int main(int argc, char const *argv[]) {
dmDumpCfg
();
taosCleanupCfg
();
taosCloseLog
();
taosCleanupArgs
();
return
0
;
}
dmSetProcInfo
(
argc
,
(
char
**
)
argv
);
taosCleanupArgs
();
return
dmRunDnode
();
}
source/dnode/mgmt/interface/src/dmFile.c
浏览文件 @
f9662420
...
...
@@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to
lock
file:%s since %s"
,
filepath
,
terrstr
());
dError
(
"failed to
open
file:%s since %s"
,
filepath
,
terrstr
());
return
NULL
;
}
...
...
source/libs/function/src/udfd.c
浏览文件 @
f9662420
...
...
@@ -548,7 +548,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
static
int32_t
udfdInitLog
()
{
char
logName
[
12
]
=
{
0
};
snprintf
(
logName
,
sizeof
(
logName
),
"%slog"
,
"udfd"
);
return
taosCreateLog
(
logName
,
1
,
configDir
,
NULL
,
NULL
,
NULL
,
0
);
return
taosCreateLog
(
logName
,
1
,
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
0
);
}
void
udfdCtrlAllocBufCb
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
...
...
@@ -656,7 +656,7 @@ int main(int argc, char *argv[]) {
return
-
1
;
}
if
(
taosInitCfg
(
configDir
,
NULL
,
NULL
,
NULL
,
0
)
!=
0
)
{
if
(
taosInitCfg
(
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
0
)
!=
0
)
{
fnError
(
"failed to start since read config error"
);
return
-
1
;
}
...
...
source/libs/function/test/runUdf.c
浏览文件 @
f9662420
...
...
@@ -31,13 +31,13 @@ static int32_t parseArgs(int32_t argc, char *argv[]) {
static
int32_t
initLog
()
{
char
logName
[
12
]
=
{
0
};
snprintf
(
logName
,
sizeof
(
logName
),
"%slog"
,
"udfc"
);
return
taosCreateLog
(
logName
,
1
,
configDir
,
NULL
,
NULL
,
NULL
,
0
);
return
taosCreateLog
(
logName
,
1
,
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
0
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
parseArgs
(
argc
,
argv
);
initLog
();
if
(
taosInitCfg
(
configDir
,
NULL
,
NULL
,
NULL
,
0
)
!=
0
)
{
if
(
taosInitCfg
(
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
0
)
!=
0
)
{
fnError
(
"failed to start since read config error"
);
return
-
1
;
}
...
...
source/libs/sync/CMakeLists.txt
浏览文件 @
f9662420
...
...
@@ -11,7 +11,7 @@ target_link_libraries(
target_include_directories
(
sync
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
PUBLIC
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
f9662420
...
...
@@ -199,197 +199,197 @@ target_sources(syncApplyMsgTest
target_include_directories
(
syncTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncEnvTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncPingTimerTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncIOTickQTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncIOTickPingTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncIOSendMsgTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncIOClientTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncIOServerTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRaftStoreTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncEnqTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncIndexTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncInitTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncUtilTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncVotesGrantedTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncVotesRespondTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncIndexMgrTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncLogStoreTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncEntryTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRequestVoteTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRequestVoteReplyTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncAppendEntriesTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncAppendEntriesReplyTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncClientRequestTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncTimeoutTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncPingTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncPingReplyTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRpcMsgTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncPingTimerTest2
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncPingSelfTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncElectTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncEncodeTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncWriteTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncReplicateTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRefTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncLogStoreCheck
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRaftCfgTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRespMgrTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncSnapshotTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncApplyMsgTest
PUBLIC
"
${
CMAKE
_SOURCE_DIR
}
/include/libs/sync"
"
${
TD
_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
...
...
source/util/src/tconfig.c
浏览文件 @
f9662420
...
...
@@ -18,6 +18,9 @@
#include "taoserror.h"
#include "tlog.h"
#include "tutil.h"
#include "tenv.h"
#include "cJSON.h"
#include "tjson.h"
#define CFG_NAME_PRINT_LEN 24
#define CFG_SRC_PRINT_LEN 12
...
...
@@ -25,6 +28,7 @@
int32_t
cfgLoadFromCfgFile
(
SConfig
*
pConfig
,
const
char
*
filepath
);
int32_t
cfgLoadFromEnvFile
(
SConfig
*
pConfig
,
const
char
*
filepath
);
int32_t
cfgLoadFromEnvVar
(
SConfig
*
pConfig
);
int32_t
cfgLoadFromEnvCmd
(
SConfig
*
pConfig
,
const
char
**
envCmd
);
int32_t
cfgLoadFromApollUrl
(
SConfig
*
pConfig
,
const
char
*
url
);
int32_t
cfgSetItem
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
value
,
ECfgSrcType
stype
);
...
...
@@ -45,7 +49,7 @@ SConfig *cfgInit() {
return
pCfg
;
}
int32_t
cfgLoad
(
SConfig
*
pCfg
,
ECfgSrcType
cfgType
,
const
char
*
sourceStr
)
{
int32_t
cfgLoad
(
SConfig
*
pCfg
,
ECfgSrcType
cfgType
,
const
void
*
sourceStr
)
{
switch
(
cfgType
)
{
case
CFG_STYPE_CFG_FILE
:
return
cfgLoadFromCfgFile
(
pCfg
,
sourceStr
);
...
...
@@ -55,6 +59,8 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
return
cfgLoadFromEnvVar
(
pCfg
);
case
CFG_STYPE_APOLLO_URL
:
return
cfgLoadFromApollUrl
(
pCfg
,
sourceStr
);
case
CFG_STYPE_ENV_CMD
:
return
cfgLoadFromEnvCmd
(
pCfg
,
(
const
char
**
)
sourceStr
);
default:
return
-
1
;
}
...
...
@@ -463,6 +469,8 @@ const char *cfgStypeStr(ECfgSrcType type) {
return
"arg_list"
;
case
CFG_STYPE_TAOS_OPTIONS
:
return
"taos_options"
;
case
CFG_STYPE_ENV_CMD
:
return
"env_cmd"
;
default:
return
"invalid"
;
}
...
...
@@ -584,12 +592,154 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
}
int32_t
cfgLoadFromEnvVar
(
SConfig
*
pConfig
)
{
uDebug
(
"load from env variables not implemented yet"
);
char
*
line
=
NULL
,
*
name
,
*
value
,
*
value2
,
*
value3
;
int32_t
olen
,
vlen
,
vlen2
,
vlen3
;
ssize_t
_bytes
=
0
;
TdCmdPtr
pCmd
=
taosOpenCmd
(
"set"
);
if
(
pCmd
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
while
(
!
taosEOFCmd
(
pCmd
))
{
name
=
value
=
value2
=
value3
=
NULL
;
olen
=
vlen
=
vlen2
=
vlen3
=
0
;
_bytes
=
taosGetLineCmd
(
pCmd
,
&
line
);
if
(
_bytes
<
0
)
{
break
;
}
if
(
line
[
_bytes
-
1
]
==
'\n'
)
line
[
_bytes
-
1
]
=
0
;
taosEnvToCfg
(
line
,
line
);
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_ENV_VAR
);
if
(
value2
!=
NULL
&&
value3
!=
NULL
&&
value2
[
0
]
!=
0
&&
value3
[
0
]
!=
0
&&
strcasecmp
(
name
,
"dataDir"
)
==
0
)
{
cfgSetTfsItem
(
pConfig
,
name
,
value
,
value2
,
value3
,
CFG_STYPE_ENV_VAR
);
}
}
taosCloseCmd
(
&
pCmd
);
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
uInfo
(
"load from env variables cfg success"
);
return
0
;
}
int32_t
cfgLoadFromEnvFile
(
SConfig
*
pConfig
,
const
char
*
filepath
)
{
uDebug
(
"load from env file not implemented yet"
);
int32_t
cfgLoadFromEnvCmd
(
SConfig
*
pConfig
,
const
char
**
envCmd
)
{
char
*
buf
,
*
name
,
*
value
,
*
value2
,
*
value3
;
int32_t
olen
,
vlen
,
vlen2
,
vlen3
;
int32_t
index
=
0
;
if
(
envCmd
==
NULL
)
return
0
;
while
(
envCmd
[
index
]
!=
NULL
)
{
buf
=
taosMemoryMalloc
(
strlen
(
envCmd
[
index
]));
taosEnvToCfg
(
envCmd
[
index
],
buf
);
index
++
;
name
=
value
=
value2
=
value3
=
NULL
;
olen
=
vlen
=
vlen2
=
vlen3
=
0
;
paGetToken
(
buf
,
&
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_ENV_CMD
);
if
(
value2
!=
NULL
&&
value3
!=
NULL
&&
value2
[
0
]
!=
0
&&
value3
[
0
]
!=
0
&&
strcasecmp
(
name
,
"dataDir"
)
==
0
)
{
cfgSetTfsItem
(
pConfig
,
name
,
value
,
value2
,
value3
,
CFG_STYPE_ENV_CMD
);
}
taosMemoryFree
(
buf
);
}
uInfo
(
"load from env cmd cfg success"
);
return
0
;
}
int32_t
cfgLoadFromEnvFile
(
SConfig
*
pConfig
,
const
char
*
envFile
)
{
char
*
line
=
NULL
,
*
name
,
*
value
,
*
value2
,
*
value3
;
int32_t
olen
,
vlen
,
vlen2
,
vlen3
;
ssize_t
_bytes
=
0
;
const
char
*
filepath
=
".env"
;
if
(
envFile
!=
NULL
&&
strlen
(
envFile
)
>
0
)
{
if
(
!
taosCheckExistFile
(
envFile
))
{
uError
(
"fial to load env file: %s"
,
envFile
);
return
-
1
;
}
filepath
=
envFile
;
}
else
{
if
(
!
taosCheckExistFile
(
filepath
))
{
uInfo
(
"fial to load env file: %s"
,
filepath
);
return
0
;
}
}
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
while
(
!
taosEOFFile
(
pFile
))
{
name
=
value
=
value2
=
value3
=
NULL
;
olen
=
vlen
=
vlen2
=
vlen3
=
0
;
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
(
_bytes
<=
0
)
{
break
;
}
if
(
line
[
_bytes
-
1
]
==
'\n'
)
line
[
_bytes
-
1
]
=
0
;
taosEnvToCfg
(
line
,
line
);
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_ENV_FILE
);
if
(
value2
!=
NULL
&&
value3
!=
NULL
&&
value2
[
0
]
!=
0
&&
value3
[
0
]
!=
0
&&
strcasecmp
(
name
,
"dataDir"
)
==
0
)
{
cfgSetTfsItem
(
pConfig
,
name
,
value
,
value2
,
value3
,
CFG_STYPE_ENV_FILE
);
}
}
taosCloseFile
(
&
pFile
);
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
uInfo
(
"load from env cfg file %s success"
,
filepath
);
return
0
;
}
...
...
@@ -617,11 +767,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
olen
=
vlen
=
vlen2
=
vlen3
=
0
;
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
(
_bytes
<
0
)
{
if
(
_bytes
<
=
0
)
{
break
;
}
line
[
_bytes
-
1
]
=
0
;
if
(
line
[
_bytes
-
1
]
==
'\n'
)
line
[
_bytes
-
1
]
=
0
;
paGetToken
(
line
,
&
name
,
&
olen
);
if
(
olen
==
0
)
continue
;
...
...
@@ -659,6 +809,193 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
}
int32_t
cfgLoadFromApollUrl
(
SConfig
*
pConfig
,
const
char
*
url
)
{
uDebug
(
"load from apoll url not implemented yet"
);
char
*
cfgLineBuf
=
NULL
,
*
name
,
*
value
,
*
value2
,
*
value3
;
int32_t
olen
,
vlen
,
vlen2
,
vlen3
;
if
(
url
==
NULL
||
strlen
(
url
)
==
0
)
{
uInfo
(
"fail to load apoll url"
);
return
0
;
}
char
*
p
=
strchr
(
url
,
':'
);
if
(
p
==
NULL
)
{
uError
(
"fail to load apoll url: %s, unknown format"
,
url
);
return
-
1
;
}
p
++
;
if
(
bcmp
(
url
,
"jsonFile"
,
8
)
==
0
)
{
char
*
filepath
=
p
;
if
(
!
taosCheckExistFile
(
filepath
))
{
uError
(
"fial to load json file: %s"
,
filepath
);
return
-
1
;
}
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
size_t
fileSize
=
taosLSeekFile
(
pFile
,
0
,
SEEK_END
);
char
*
buf
=
taosMemoryMalloc
(
fileSize
);
taosLSeekFile
(
pFile
,
0
,
SEEK_SET
);
if
(
taosReadFile
(
pFile
,
buf
,
fileSize
)
<=
0
)
{
taosCloseFile
(
&
pFile
);
uError
(
"load json file error: %s"
,
filepath
);
return
-
1
;
}
taosCloseFile
(
&
pFile
);
SJson
*
pJson
=
tjsonParse
(
buf
);
if
(
NULL
==
pJson
)
{
const
char
*
jsonParseError
=
tjsonGetError
();
if
(
jsonParseError
!=
NULL
)
{
uError
(
"load json file parse error: %s"
,
jsonParseError
);
}
return
-
1
;
}
taosMemoryFreeClear
(
buf
);
int32_t
jsonArraySize
=
tjsonGetArraySize
(
pJson
);
for
(
int32_t
i
=
0
;
i
<
jsonArraySize
;
i
++
)
{
cJSON
*
item
=
tjsonGetArrayItem
(
pJson
,
i
);
if
(
item
==
NULL
)
break
;
char
*
itemName
=
NULL
,
*
itemValueString
=
NULL
;
tjsonGetObjectName
(
item
,
&
itemName
);
tjsonGetObjectName
(
item
,
&
itemName
);
tjsonGetObjectValueString
(
item
,
&
itemValueString
);
if
(
itemValueString
!=
NULL
&&
itemName
!=
NULL
)
{
size_t
itemNameLen
=
strlen
(
itemName
);
size_t
itemValueStringLen
=
strlen
(
itemValueString
);
cfgLineBuf
=
taosMemoryMalloc
(
itemNameLen
+
itemValueStringLen
+
2
);
memcpy
(
cfgLineBuf
,
itemName
,
itemNameLen
);
cfgLineBuf
[
itemNameLen
]
=
' '
;
memcpy
(
&
cfgLineBuf
[
itemNameLen
+
1
],
itemValueString
,
itemValueStringLen
);
cfgLineBuf
[
itemNameLen
+
itemValueStringLen
+
1
]
=
'\0'
;
paGetToken
(
cfgLineBuf
,
&
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
;
}
printf
(
"%s(%d) %s name=%s, value=%s
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
name
,
value
);
cfgSetItem
(
pConfig
,
name
,
value
,
CFG_STYPE_APOLLO_URL
);
if
(
value2
!=
NULL
&&
value3
!=
NULL
&&
value2
[
0
]
!=
0
&&
value3
[
0
]
!=
0
&&
strcasecmp
(
name
,
"dataDir"
)
==
0
)
{
cfgSetTfsItem
(
pConfig
,
name
,
value
,
value2
,
value3
,
CFG_STYPE_APOLLO_URL
);
}
}
}
tjsonDelete
(
pJson
);
// } else if (bcmp(url, "jsonUrl", 7) == 0) {
// } else if (bcmp(url, "etcdUrl", 7) == 0) {
}
else
{
uError
(
"Unsupported url: %s"
,
url
);
return
-
1
;
}
uInfo
(
"load from apoll url not implemented yet"
);
return
0
;
}
int32_t
cfgGetApollUrl
(
const
char
**
envCmd
,
const
char
*
envFile
,
char
*
apolloUrl
)
{
int32_t
index
=
0
;
if
(
envCmd
==
NULL
)
return
0
;
while
(
envCmd
[
index
]
!=
NULL
)
{
if
(
bcmp
(
envCmd
[
index
],
"TAOS_APOLL_URL"
,
14
)
==
0
)
{
char
*
p
=
strchr
(
envCmd
[
index
],
'='
);
if
(
p
!=
NULL
)
{
p
++
;
if
(
*
p
==
'\''
)
{
p
++
;
p
[
strlen
(
p
)
-
1
]
=
'\0'
;
}
memcpy
(
apolloUrl
,
p
,
TMIN
(
strlen
(
p
)
+
1
,
PATH_MAX
));
uInfo
(
"get apollo url from env cmd success"
);
return
0
;
}
}
index
++
;
}
char
*
line
=
NULL
;
ssize_t
_bytes
=
0
;
TdCmdPtr
pCmd
=
taosOpenCmd
(
"set"
);
if
(
pCmd
!=
NULL
)
{
while
(
!
taosEOFCmd
(
pCmd
))
{
_bytes
=
taosGetLineCmd
(
pCmd
,
&
line
);
if
(
_bytes
<
0
)
{
break
;
}
if
(
line
[
_bytes
-
1
]
==
'\n'
)
line
[
_bytes
-
1
]
=
0
;
if
(
bcmp
(
line
,
"TAOS_APOLL_URL"
,
14
)
==
0
)
{
char
*
p
=
strchr
(
line
,
'='
);
if
(
p
!=
NULL
)
{
p
++
;
if
(
*
p
==
'\''
)
{
p
++
;
p
[
strlen
(
p
)
-
1
]
=
'\0'
;
}
memcpy
(
apolloUrl
,
p
,
TMIN
(
strlen
(
p
)
+
1
,
PATH_MAX
));
uInfo
(
"get apollo url from env variables success, apolloUrl=%s"
,
apolloUrl
);
taosCloseCmd
(
&
pCmd
);
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
return
0
;
}
}
}
taosCloseCmd
(
&
pCmd
);
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
}
const
char
*
filepath
=
".env"
;
if
(
envFile
!=
NULL
&&
strlen
(
envFile
)
>
0
)
{
if
(
!
taosCheckExistFile
(
envFile
))
{
uError
(
"fial to load env file: %s"
,
envFile
);
return
-
1
;
}
filepath
=
envFile
;
}
else
{
if
(
!
taosCheckExistFile
(
filepath
))
{
uInfo
(
"fial to load env file: %s"
,
filepath
);
return
0
;
}
}
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
!=
NULL
)
{
while
(
!
taosEOFFile
(
pFile
))
{
_bytes
=
taosGetLineFile
(
pFile
,
&
line
);
if
(
_bytes
<=
0
)
{
break
;
}
if
(
line
[
_bytes
-
1
]
==
'\n'
)
line
[
_bytes
-
1
]
=
0
;
if
(
bcmp
(
line
,
"TAOS_APOLL_URL"
,
14
)
==
0
)
{
char
*
p
=
strchr
(
line
,
'='
);
if
(
p
!=
NULL
)
{
p
++
;
if
(
*
p
==
'\''
)
{
p
++
;
p
[
strlen
(
p
)
-
1
]
=
'\0'
;
}
memcpy
(
apolloUrl
,
p
,
TMIN
(
strlen
(
p
)
+
1
,
PATH_MAX
));
taosCloseFile
(
&
pFile
);
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
uInfo
(
"get apollo url from env file success"
);
return
0
;
}
}
}
taosCloseFile
(
&
pFile
);
if
(
line
!=
NULL
)
taosMemoryFreeClear
(
line
);
}
uInfo
(
"fail get apollo url from cmd env file"
);
return
-
1
;
}
\ No newline at end of file
source/util/src/tenv.c
0 → 100644
浏览文件 @
f9662420
/*
* 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 "tenv.h"
#include "tconfig.h"
static
char
toLowChar
(
char
c
)
{
return
(
c
>
'Z'
||
c
<
'A'
?
c
:
(
c
-
'A'
+
'a'
));
}
int32_t
taosEnvNameToCfgName
(
const
char
*
envNameStr
,
char
*
cfgNameStr
,
int32_t
cfgNameMaxLen
)
{
if
(
envNameStr
==
NULL
||
cfgNameStr
==
NULL
)
return
-
1
;
char
*
p
=
cfgNameStr
;
if
(
envNameStr
[
0
]
!=
'T'
||
envNameStr
[
1
]
!=
'A'
||
envNameStr
[
2
]
!=
'O'
||
envNameStr
[
3
]
!=
'S'
||
envNameStr
[
4
]
!=
'_'
)
{
// if(p != envNameStr) strncpy(p, envNameStr, cfgNameMaxLen - 1);
// p[cfgNameMaxLen - 1] = '\0';
// return strlen(cfgNameStr);
cfgNameStr
[
0
]
=
'\0'
;
return
-
1
;
}
envNameStr
+=
5
;
if
(
*
envNameStr
!=
'\0'
)
{
*
p
=
toLowChar
(
*
envNameStr
);
p
++
;
envNameStr
++
;
}
for
(
size_t
i
=
1
;
i
<
cfgNameMaxLen
&&
*
envNameStr
!=
'\0'
;
i
++
)
{
if
(
*
envNameStr
==
'_'
)
{
envNameStr
++
;
*
p
=
*
envNameStr
;
if
(
*
envNameStr
==
'\0'
)
break
;
}
else
{
*
p
=
toLowChar
(
*
envNameStr
);
}
p
++
;
envNameStr
++
;
}
*
p
=
'\0'
;
return
strlen
(
cfgNameStr
);
}
int32_t
taosEnvToCfg
(
const
char
*
envStr
,
char
*
cfgStr
)
{
if
(
envStr
==
NULL
&&
cfgStr
==
NULL
)
{
return
-
1
;
}
if
(
cfgStr
!=
envStr
)
strcpy
(
cfgStr
,
envStr
);
char
*
p
=
strchr
(
cfgStr
,
'='
);
if
(
p
!=
NULL
)
{
char
buf
[
CFG_NAME_MAX_LEN
];
if
(
*
(
p
+
1
)
==
'\''
)
{
*
(
p
+
1
)
=
' '
;
char
*
pEnd
=
&
cfgStr
[
strlen
(
cfgStr
)
-
1
];
if
(
*
pEnd
==
'\''
)
*
pEnd
=
'\0'
;
}
*
p
=
'\0'
;
int32_t
cfgNameLen
=
taosEnvNameToCfgName
(
cfgStr
,
buf
,
CFG_NAME_MAX_LEN
);
if
(
cfgNameLen
>
0
)
{
memcpy
(
cfgStr
,
buf
,
cfgNameLen
);
memset
(
&
cfgStr
[
cfgNameLen
],
' '
,
p
-
cfgStr
-
cfgNameLen
+
1
);
}
}
return
strlen
(
cfgStr
);
}
\ No newline at end of file
source/util/src/tjson.c
浏览文件 @
f9662420
...
...
@@ -144,6 +144,22 @@ char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatt
SJson
*
tjsonGetObjectItem
(
const
SJson
*
pJson
,
const
char
*
pName
)
{
return
cJSON_GetObjectItem
(
pJson
,
pName
);
}
int32_t
tjsonGetObjectName
(
const
SJson
*
pJson
,
char
**
pName
)
{
*
pName
=
((
cJSON
*
)
pJson
)
->
string
;
if
(
NULL
==
*
pName
)
{
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
tjsonGetObjectValueString
(
const
SJson
*
pJson
,
char
**
pValueString
)
{
*
pValueString
=
((
cJSON
*
)
pJson
)
->
valuestring
;
if
(
NULL
==
*
pValueString
)
{
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
tjsonGetStringValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
char
*
pVal
)
{
char
*
p
=
cJSON_GetStringValue
(
tjsonGetObjectItem
((
cJSON
*
)
pJson
,
pName
));
if
(
NULL
==
p
)
{
...
...
@@ -309,4 +325,6 @@ bool tjsonValidateJson(const char *jIn) {
}
}
return
true
;
}
\ No newline at end of file
}
const
char
*
tjsonGetError
()
{
return
cJSON_GetErrorPtr
();
}
\ No newline at end of file
source/util/test/CMakeLists.txt
浏览文件 @
f9662420
...
...
@@ -31,7 +31,7 @@ ENDIF()
# TARGET_LINK_LIBRARIES(trefTest util common)
#ENDIF ()
INCLUDE_DIRECTORIES
(
${
TD_
COMMUNITY
_DIR
}
/src/util/inc
)
INCLUDE_DIRECTORIES
(
${
TD_
SOURCE
_DIR
}
/src/util/inc
)
# freelistTest
add_executable
(
freelistTest
""
)
...
...
source/util/test/cfgTest.cpp
浏览文件 @
f9662420
...
...
@@ -32,6 +32,7 @@ TEST_F(CfgTest, 01_Str) {
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_ENV_CMD
),
"env_cmd"
);
EXPECT_STREQ
(
cfgStypeStr
(
CFG_STYPE_APOLLO_URL
),
"apollo_url"
);
EXPECT_STREQ
(
cfgStypeStr
(
CFG_STYPE_ARG_LIST
),
"arg_list"
);
EXPECT_STREQ
(
cfgStypeStr
(
ECfgSrcType
(
1024
)),
"invalid"
);
...
...
tests/tsim/src/simSystem.c
浏览文件 @
f9662420
...
...
@@ -28,8 +28,8 @@ char simScriptDir[PATH_MAX] = {0};
extern
bool
simExecSuccess
;
int32_t
simInitCfg
()
{
taosCreateLog
(
"simlog"
,
1
,
configDir
,
NULL
,
NULL
,
NULL
,
1
);
taosInitCfg
(
configDir
,
NULL
,
NULL
,
NULL
,
1
);
taosCreateLog
(
"simlog"
,
1
,
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
1
);
taosInitCfg
(
NULL
,
configDir
,
NULL
,
NULL
,
NULL
,
1
);
SConfig
*
pCfg
=
taosGetCfg
();
simDebugFlag
=
cfgGetItem
(
pCfg
,
"simDebugFlag"
)
->
i32
;
...
...
tools/shell/CMakeLists.txt
浏览文件 @
f9662420
...
...
@@ -3,7 +3,7 @@ aux_source_directory(src SHELL_SRC)
add_executable
(
shell
${
SHELL_SRC
}
)
target_link_libraries
(
shell
PUBLIC taos
_static
PUBLIC taos
PRIVATE os common transport util
)
target_include_directories
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录