Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9a9e87ec
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看板
提交
9a9e87ec
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
config from hash to array
上级
f486e7ed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
48 deletion
+33
-48
include/util/tconfig.h
include/util/tconfig.h
+4
-3
source/common/src/tglobal.c
source/common/src/tglobal.c
+4
-4
source/util/src/tconfig.c
source/util/src/tconfig.c
+21
-34
source/util/test/cfgTest.cpp
source/util/test/cfgTest.cpp
+4
-7
未找到文件。
include/util/tconfig.h
浏览文件 @
9a9e87ec
...
@@ -75,7 +75,10 @@ typedef struct {
...
@@ -75,7 +75,10 @@ typedef struct {
const
char
*
value
;
const
char
*
value
;
}
SConfigPair
;
}
SConfigPair
;
typedef
struct
SConfig
SConfig
;
typedef
struct
SConfig
{
ECfgSrcType
stype
;
SArray
*
array
;
}
SConfig
;
SConfig
*
cfgInit
();
SConfig
*
cfgInit
();
int32_t
cfgLoad
(
SConfig
*
pCfg
,
ECfgSrcType
cfgType
,
const
char
*
sourceStr
);
int32_t
cfgLoad
(
SConfig
*
pCfg
,
ECfgSrcType
cfgType
,
const
char
*
sourceStr
);
...
@@ -83,8 +86,6 @@ int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
...
@@ -83,8 +86,6 @@ int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void
cfgCleanup
(
SConfig
*
pCfg
);
void
cfgCleanup
(
SConfig
*
pCfg
);
int32_t
cfgGetSize
(
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
);
SConfigItem
*
cfgGetItem
(
SConfig
*
pCfg
,
const
char
*
name
);
int32_t
cfgSetItem
(
SConfig
*
pCfg
,
const
char
*
name
,
const
char
*
value
,
ECfgSrcType
stype
);
int32_t
cfgSetItem
(
SConfig
*
pCfg
,
const
char
*
name
,
const
char
*
value
,
ECfgSrcType
stype
);
...
...
source/common/src/tglobal.c
浏览文件 @
9a9e87ec
...
@@ -207,6 +207,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
...
@@ -207,6 +207,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
}
}
static
int32_t
taosAddClientLogCfg
(
SConfig
*
pCfg
)
{
static
int32_t
taosAddClientLogCfg
(
SConfig
*
pCfg
)
{
if
(
cfgAddDir
(
pCfg
,
"configDir"
,
configDir
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddDir
(
pCfg
,
"scriptDir"
,
configDir
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddDir
(
pCfg
,
"logDir"
,
tsLogDir
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddDir
(
pCfg
,
"logDir"
,
tsLogDir
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddFloat
(
pCfg
,
"minimalLogDirGB"
,
1
.
0
f
,
0
.
001
f
,
10000000
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddFloat
(
pCfg
,
"minimalLogDirGB"
,
1
.
0
f
,
0
.
001
f
,
10000000
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"numOfLogLines"
,
tsNumOfLogLines
,
1000
,
2000000000
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"numOfLogLines"
,
tsNumOfLogLines
,
1000
,
2000000000
,
1
)
!=
0
)
return
-
1
;
...
@@ -218,8 +220,6 @@ static int32_t taosAddClientLogCfg(SConfig *pCfg) {
...
@@ -218,8 +220,6 @@ static int32_t taosAddClientLogCfg(SConfig *pCfg) {
if
(
cfgAddInt32
(
pCfg
,
"tmrDebugFlag"
,
tmrDebugFlag
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"tmrDebugFlag"
,
tmrDebugFlag
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"jniDebugFlag"
,
jniDebugFlag
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"jniDebugFlag"
,
jniDebugFlag
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"simDebugFlag"
,
143
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"simDebugFlag"
,
143
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddDir
(
pCfg
,
"configDir"
,
configDir
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddDir
(
pCfg
,
"scriptDir"
,
configDir
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"debugFlag"
,
0
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"debugFlag"
,
0
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
return
0
;
return
0
;
}
}
...
@@ -488,10 +488,10 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
...
@@ -488,10 +488,10 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
if
(
taosAddClientLogCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddClientLogCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddClientCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddClientCfg
(
tsCfg
)
!=
0
)
return
-
1
;
}
else
{
}
else
{
if
(
taosAddClientLogCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddServerLogCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddClientCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddClientCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddServerCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddServerCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddClientLogCfg
(
tsCfg
)
!=
0
)
return
-
1
;
if
(
taosAddServerLogCfg
(
tsCfg
)
!=
0
)
return
-
1
;
}
}
taosAddSystemCfg
(
tsCfg
);
taosAddSystemCfg
(
tsCfg
);
...
...
source/util/src/tconfig.c
浏览文件 @
9a9e87ec
...
@@ -16,18 +16,12 @@
...
@@ -16,18 +16,12 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "tconfig.h"
#include "tconfig.h"
#include "taoserror.h"
#include "taoserror.h"
#include "thash.h"
#include "tlog.h"
#include "tlog.h"
#include "tutil.h"
#include "tutil.h"
#define CFG_NAME_PRINT_LEN 24
#define CFG_NAME_PRINT_LEN 24
#define CFG_SRC_PRINT_LEN 12
#define CFG_SRC_PRINT_LEN 12
typedef
struct
SConfig
{
ECfgSrcType
stype
;
SHashObj
*
hash
;
}
SConfig
;
int32_t
cfgLoadFromCfgFile
(
SConfig
*
pConfig
,
const
char
*
filepath
);
int32_t
cfgLoadFromCfgFile
(
SConfig
*
pConfig
,
const
char
*
filepath
);
int32_t
cfgLoadFromEnvFile
(
SConfig
*
pConfig
,
const
char
*
filepath
);
int32_t
cfgLoadFromEnvFile
(
SConfig
*
pConfig
,
const
char
*
filepath
);
int32_t
cfgLoadFromEnvVar
(
SConfig
*
pConfig
);
int32_t
cfgLoadFromEnvVar
(
SConfig
*
pConfig
);
...
@@ -41,8 +35,8 @@ SConfig *cfgInit() {
...
@@ -41,8 +35,8 @@ SConfig *cfgInit() {
return
NULL
;
return
NULL
;
}
}
pCfg
->
hash
=
taosHashInit
(
16
,
MurmurHash3_32
,
false
,
HASH_NO_LOCK
);
pCfg
->
array
=
taosArrayInit
(
32
,
sizeof
(
SConfigItem
)
);
if
(
pCfg
->
hash
==
NULL
)
{
if
(
pCfg
->
array
==
NULL
)
{
free
(
pCfg
);
free
(
pCfg
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
...
@@ -91,25 +85,18 @@ static void cfgFreeItem(SConfigItem *pItem) {
...
@@ -91,25 +85,18 @@ static void cfgFreeItem(SConfigItem *pItem) {
void
cfgCleanup
(
SConfig
*
pCfg
)
{
void
cfgCleanup
(
SConfig
*
pCfg
)
{
if
(
pCfg
!=
NULL
)
{
if
(
pCfg
!=
NULL
)
{
if
(
pCfg
->
hash
!=
NULL
)
{
int32_t
size
=
taosArrayGetSize
(
pCfg
->
array
);
SConfigItem
*
pItem
=
taosHashIterate
(
pCfg
->
hash
,
NULL
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
while
(
pItem
!=
NULL
)
{
SConfigItem
*
pItem
=
taosArrayGet
(
pCfg
->
array
,
i
);
cfgFreeItem
(
pItem
);
cfgFreeItem
(
pItem
);
tfree
(
pItem
->
name
);
tfree
(
pItem
->
name
);
pItem
=
taosHashIterate
(
pCfg
->
hash
,
pItem
);
}
taosHashCleanup
(
pCfg
->
hash
);
pCfg
->
hash
==
NULL
;
}
}
taosArrayDestroy
(
pCfg
->
array
);
free
(
pCfg
);
free
(
pCfg
);
}
}
}
}
int32_t
cfgGetSize
(
SConfig
*
pCfg
)
{
return
taosHashGetSize
(
pCfg
->
hash
);
}
int32_t
cfgGetSize
(
SConfig
*
pCfg
)
{
return
taosArrayGetSize
(
pCfg
->
array
);
}
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
)
{
static
int32_t
cfgCheckAndSetTimezone
(
SConfigItem
*
pItem
,
const
char
*
timezone
)
{
cfgFreeItem
(
pItem
);
cfgFreeItem
(
pItem
);
...
@@ -358,16 +345,16 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
...
@@ -358,16 +345,16 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
}
}
SConfigItem
*
cfgGetItem
(
SConfig
*
pCfg
,
const
char
*
name
)
{
SConfigItem
*
cfgGetItem
(
SConfig
*
pCfg
,
const
char
*
name
)
{
int32_t
len
=
strlen
(
name
);
int32_t
size
=
taosArrayGetSize
(
pCfg
->
array
);
char
lowcaseName
[
CFG_NAME_MAX_LEN
+
1
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
strntolower
(
lowcaseName
,
name
,
TMIN
(
CFG_NAME_MAX_LEN
,
len
));
SConfigItem
*
pItem
=
taosArrayGet
(
pCfg
->
array
,
i
);
if
(
strcasecmp
(
pItem
->
name
,
name
)
==
0
)
{
SConfigItem
*
pItem
=
taosHashGet
(
pCfg
->
hash
,
lowcaseName
,
len
+
1
);
return
pItem
;
if
(
pItem
==
NULL
)
{
}
terrno
=
TSDB_CODE_CFG_NOT_FOUND
;
}
}
return
pItem
;
terrno
=
TSDB_CODE_CFG_NOT_FOUND
;
return
NULL
;
}
}
static
int32_t
cfgAddItem
(
SConfig
*
pCfg
,
SConfigItem
*
pItem
,
const
char
*
name
)
{
static
int32_t
cfgAddItem
(
SConfig
*
pCfg
,
SConfigItem
*
pItem
,
const
char
*
name
)
{
...
@@ -382,7 +369,7 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
...
@@ -382,7 +369,7 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
char
lowcaseName
[
CFG_NAME_MAX_LEN
+
1
]
=
{
0
};
char
lowcaseName
[
CFG_NAME_MAX_LEN
+
1
]
=
{
0
};
strntolower
(
lowcaseName
,
name
,
TMIN
(
CFG_NAME_MAX_LEN
,
len
));
strntolower
(
lowcaseName
,
name
,
TMIN
(
CFG_NAME_MAX_LEN
,
len
));
if
(
taos
HashPut
(
pCfg
->
hash
,
lowcaseName
,
len
+
1
,
pItem
,
sizeof
(
SConfigItem
))
!=
0
)
{
if
(
taos
ArrayPush
(
pCfg
->
array
,
pItem
)
==
NULL
)
{
if
(
pItem
->
dtype
==
CFG_DTYPE_STRING
)
{
if
(
pItem
->
dtype
==
CFG_DTYPE_STRING
)
{
free
(
pItem
->
str
);
free
(
pItem
->
str
);
}
}
...
@@ -535,8 +522,9 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
...
@@ -535,8 +522,9 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
char
src
[
CFG_SRC_PRINT_LEN
+
1
]
=
{
0
};
char
src
[
CFG_SRC_PRINT_LEN
+
1
]
=
{
0
};
char
name
[
CFG_NAME_PRINT_LEN
+
1
]
=
{
0
};
char
name
[
CFG_NAME_PRINT_LEN
+
1
]
=
{
0
};
SConfigItem
*
pItem
=
cfgIterate
(
pCfg
,
NULL
);
int32_t
size
=
taosArrayGetSize
(
pCfg
->
array
);
while
(
pItem
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SConfigItem
*
pItem
=
taosArrayGet
(
pCfg
->
array
,
i
);
if
(
tsc
&&
!
pItem
->
tsc
)
continue
;
if
(
tsc
&&
!
pItem
->
tsc
)
continue
;
tstrncpy
(
src
,
cfgStypeStr
(
pItem
->
stype
),
CFG_SRC_PRINT_LEN
);
tstrncpy
(
src
,
cfgStypeStr
(
pItem
->
stype
),
CFG_SRC_PRINT_LEN
);
for
(
int32_t
i
=
0
;
i
<
CFG_SRC_PRINT_LEN
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
CFG_SRC_PRINT_LEN
;
++
i
)
{
...
@@ -595,7 +583,6 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
...
@@ -595,7 +583,6 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
}
}
break
;
break
;
}
}
pItem
=
cfgIterate
(
pCfg
,
pItem
);
}
}
if
(
dump
)
{
if
(
dump
)
{
...
...
source/util/test/cfgTest.cpp
浏览文件 @
9a9e87ec
...
@@ -62,9 +62,9 @@ TEST_F(CfgTest, 02_Basic) {
...
@@ -62,9 +62,9 @@ TEST_F(CfgTest, 02_Basic) {
EXPECT_EQ
(
cfgGetSize
(
pConfig
),
6
);
EXPECT_EQ
(
cfgGetSize
(
pConfig
),
6
);
int32_t
size
=
0
;
int32_t
size
=
taosArrayGetSize
(
pConfig
->
array
)
;
SConfigItem
*
pItem
=
cfgIterate
(
pConfig
,
NULL
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
while
(
pItem
!=
NULL
)
{
SConfigItem
*
pItem
=
(
SConfigItem
*
)
taosArrayGet
(
pConfig
->
array
,
i
);
switch
(
pItem
->
dtype
)
{
switch
(
pItem
->
dtype
)
{
case
CFG_DTYPE_BOOL
:
case
CFG_DTYPE_BOOL
:
printf
(
"index:%d, cfg:%s value:%d
\n
"
,
size
,
pItem
->
name
,
pItem
->
bval
);
printf
(
"index:%d, cfg:%s value:%d
\n
"
,
size
,
pItem
->
name
,
pItem
->
bval
);
...
@@ -89,13 +89,10 @@ TEST_F(CfgTest, 02_Basic) {
...
@@ -89,13 +89,10 @@ TEST_F(CfgTest, 02_Basic) {
break
;
break
;
}
}
size
++
;
size
++
;
pItem
=
cfgIterate
(
pConfig
,
pItem
);
}
}
cfgCancelIterate
(
pConfig
,
pItem
);
EXPECT_EQ
(
cfgGetSize
(
pConfig
),
6
);
EXPECT_EQ
(
cfgGetSize
(
pConfig
),
6
);
pItem
=
cfgGetItem
(
pConfig
,
"test_bool"
);
SConfigItem
*
pItem
=
cfgGetItem
(
pConfig
,
"test_bool"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_STYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_STYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_BOOL
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_BOOL
);
EXPECT_STREQ
(
pItem
->
name
,
"test_bool"
);
EXPECT_STREQ
(
pItem
->
name
,
"test_bool"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录