Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
22cb2ada
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看板
提交
22cb2ada
编写于
2月 22, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
config
上级
392d3df9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
84 addition
and
16 deletion
+84
-16
include/libs/config/config.h
include/libs/config/config.h
+6
-3
source/common/src/tglobal.c
source/common/src/tglobal.c
+2
-0
source/libs/config/src/config.c
source/libs/config/src/config.c
+72
-9
source/libs/config/test/cfgTest.cpp
source/libs/config/test/cfgTest.cpp
+4
-4
未找到文件。
include/libs/config/config.h
浏览文件 @
22cb2ada
...
@@ -46,6 +46,9 @@ typedef enum {
...
@@ -46,6 +46,9 @@ typedef enum {
CFG_DTYPE_STRING
,
CFG_DTYPE_STRING
,
CFG_DTYPE_IPSTR
,
CFG_DTYPE_IPSTR
,
CFG_DTYPE_DIR
,
CFG_DTYPE_DIR
,
CFG_DTYPE_LOCALE
,
CFG_DTYPE_CHARSET
,
CFG_DTYPE_TIMEZONE
}
ECfgDataType
;
}
ECfgDataType
;
typedef
enum
{
typedef
enum
{
...
@@ -71,8 +74,6 @@ typedef struct SConfigItem {
...
@@ -71,8 +74,6 @@ typedef struct SConfigItem {
int64_t
int64Val
;
int64_t
int64Val
;
float
floatVal
;
float
floatVal
;
char
*
strVal
;
char
*
strVal
;
char
*
ipstrVal
;
char
*
dirVal
;
};
};
union
{
union
{
int64_t
minIntVal
;
int64_t
minIntVal
;
...
@@ -82,7 +83,6 @@ typedef struct SConfigItem {
...
@@ -82,7 +83,6 @@ typedef struct SConfigItem {
int64_t
maxIntVal
;
int64_t
maxIntVal
;
double
maxFloatVal
;
double
maxFloatVal
;
};
};
}
SConfigItem
;
}
SConfigItem
;
typedef
struct
SConfig
SConfig
;
typedef
struct
SConfig
SConfig
;
...
@@ -110,6 +110,9 @@ int32_t cfgAddFloat(SConfig *pConfig, const char *name, float defaultVal, double
...
@@ -110,6 +110,9 @@ int32_t cfgAddFloat(SConfig *pConfig, const char *name, float defaultVal, double
int32_t
cfgAddString
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddString
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddIpStr
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddIpStr
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddDir
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddDir
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddLocale
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddCharset
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
int32_t
cfgAddTimezone
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
);
const
char
*
cfgStypeStr
(
ECfgSrcType
type
);
const
char
*
cfgStypeStr
(
ECfgSrcType
type
);
const
char
*
cfgDtypeStr
(
ECfgDataType
type
);
const
char
*
cfgDtypeStr
(
ECfgDataType
type
);
...
...
source/common/src/tglobal.c
浏览文件 @
22cb2ada
...
@@ -196,6 +196,7 @@ void taosSetAllDebugFlag() {
...
@@ -196,6 +196,7 @@ void taosSetAllDebugFlag() {
}
}
int32_t
taosCfgDynamicOptions
(
char
*
msg
)
{
int32_t
taosCfgDynamicOptions
(
char
*
msg
)
{
#if 0
char *option, *value;
char *option, *value;
int32_t olen, vlen;
int32_t olen, vlen;
int32_t vint = 0;
int32_t vint = 0;
...
@@ -265,6 +266,7 @@ int32_t taosCfgDynamicOptions(char *msg) {
...
@@ -265,6 +266,7 @@ int32_t taosCfgDynamicOptions(char *msg) {
}
}
}
}
#endif
return
false
;
return
false
;
}
}
...
...
source/libs/config/src/config.c
浏览文件 @
22cb2ada
...
@@ -262,10 +262,6 @@ static int32_t cfgAddItem(SConfig *pConfig, SConfigItem *pItem, const char *name
...
@@ -262,10 +262,6 @@ static int32_t cfgAddItem(SConfig *pConfig, SConfigItem *pItem, const char *name
if
(
taosHashPut
(
pConfig
->
hash
,
lowcaseName
,
strlen
(
lowcaseName
)
+
1
,
pItem
,
sizeof
(
SConfigItem
))
!=
0
)
{
if
(
taosHashPut
(
pConfig
->
hash
,
lowcaseName
,
strlen
(
lowcaseName
)
+
1
,
pItem
,
sizeof
(
SConfigItem
))
!=
0
)
{
if
(
pItem
->
dtype
==
CFG_DTYPE_STRING
)
{
if
(
pItem
->
dtype
==
CFG_DTYPE_STRING
)
{
free
(
pItem
->
strVal
);
free
(
pItem
->
strVal
);
}
else
if
(
pItem
->
dtype
==
CFG_DTYPE_IPSTR
)
{
free
(
pItem
->
ipstrVal
);
}
else
if
(
pItem
->
dtype
==
CFG_DTYPE_DIR
)
{
free
(
pItem
->
dirVal
);
}
}
free
(
pItem
->
name
);
free
(
pItem
->
name
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
@@ -367,8 +363,8 @@ int32_t cfgAddIpStr(SConfig *pConfig, const char *name, const char *defaultVal,
...
@@ -367,8 +363,8 @@ int32_t cfgAddIpStr(SConfig *pConfig, const char *name, const char *defaultVal,
}
}
SConfigItem
item
=
{.
dtype
=
CFG_DTYPE_IPSTR
};
SConfigItem
item
=
{.
dtype
=
CFG_DTYPE_IPSTR
};
item
.
ip
strVal
=
strdup
(
defaultVal
);
item
.
strVal
=
strdup
(
defaultVal
);
if
(
item
.
ip
strVal
==
NULL
)
{
if
(
item
.
strVal
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
...
@@ -394,9 +390,9 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
...
@@ -394,9 +390,9 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
return
-
1
;
return
-
1
;
}
}
tfree
(
pItem
->
di
rVal
);
tfree
(
pItem
->
st
rVal
);
pItem
->
di
rVal
=
strdup
(
fullDir
);
pItem
->
st
rVal
=
strdup
(
fullDir
);
if
(
pItem
->
di
rVal
==
NULL
)
{
if
(
pItem
->
st
rVal
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
...
@@ -409,6 +405,67 @@ int32_t cfgAddDir(SConfig *pConfig, const char *name, const char *defaultVal, EC
...
@@ -409,6 +405,67 @@ int32_t cfgAddDir(SConfig *pConfig, const char *name, const char *defaultVal, EC
if
(
cfgCheckAndSetDir
(
&
item
,
defaultVal
)
!=
0
)
{
if
(
cfgCheckAndSetDir
(
&
item
,
defaultVal
)
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
return
cfgAddItem
(
pConfig
,
&
item
,
name
,
utype
);
}
static
int32_t
cfgCheckAndSetLocale
(
SConfigItem
*
pItem
,
const
char
*
locale
)
{
tfree
(
pItem
->
strVal
);
pItem
->
strVal
=
strdup
(
locale
);
if
(
pItem
->
strVal
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
return
0
;
}
int32_t
cfgAddLocale
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
)
{
SConfigItem
item
=
{.
dtype
=
CFG_DTYPE_LOCALE
};
if
(
cfgCheckAndSetLocale
(
&
item
,
defaultVal
)
!=
0
)
{
return
-
1
;
}
return
cfgAddItem
(
pConfig
,
&
item
,
name
,
utype
);
}
static
int32_t
cfgCheckAndSetCharset
(
SConfigItem
*
pItem
,
const
char
*
charset
)
{
tfree
(
pItem
->
strVal
);
pItem
->
strVal
=
strdup
(
charset
);
if
(
pItem
->
strVal
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
return
0
;
}
int32_t
cfgAddCharset
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
)
{
SConfigItem
item
=
{.
dtype
=
CFG_DTYPE_CHARSET
};
if
(
cfgCheckAndSetCharset
(
&
item
,
defaultVal
)
!=
0
)
{
return
-
1
;
}
return
cfgAddItem
(
pConfig
,
&
item
,
name
,
utype
);
}
static
int32_t
cfgCheckAndSetTimezone
(
SConfigItem
*
pItem
,
const
char
*
timezone
)
{
tfree
(
pItem
->
strVal
);
pItem
->
strVal
=
strdup
(
timezone
);
if
(
pItem
->
strVal
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
return
0
;
}
int32_t
cfgAddTimezone
(
SConfig
*
pConfig
,
const
char
*
name
,
const
char
*
defaultVal
,
ECfgUnitType
utype
)
{
SConfigItem
item
=
{.
dtype
=
CFG_DTYPE_TIMEZONE
};
if
(
cfgCheckAndSetTimezone
(
&
item
,
defaultVal
)
!=
0
)
{
return
-
1
;
}
return
cfgAddItem
(
pConfig
,
&
item
,
name
,
utype
);
return
cfgAddItem
(
pConfig
,
&
item
,
name
,
utype
);
}
}
...
@@ -455,6 +512,12 @@ const char *cfgDtypeStr(ECfgDataType type) {
...
@@ -455,6 +512,12 @@ const char *cfgDtypeStr(ECfgDataType type) {
return
"ipstr"
;
return
"ipstr"
;
case
CFG_DTYPE_DIR
:
case
CFG_DTYPE_DIR
:
return
"dir"
;
return
"dir"
;
case
CFG_DTYPE_LOCALE
:
return
"locale"
;
case
CFG_DTYPE_CHARSET
:
return
"charset"
;
case
CFG_DTYPE_TIMEZONE
:
return
"timezone"
;
default:
default:
return
"invalid"
;
return
"invalid"
;
}
}
...
...
source/libs/config/test/cfgTest.cpp
浏览文件 @
22cb2ada
...
@@ -102,10 +102,10 @@ TEST_F(CfgTest, 02_Basic) {
...
@@ -102,10 +102,10 @@ TEST_F(CfgTest, 02_Basic) {
printf
(
"index:%d, cfg:%s value:%s
\n
"
,
size
,
pItem
->
name
,
pItem
->
strVal
);
printf
(
"index:%d, cfg:%s value:%s
\n
"
,
size
,
pItem
->
name
,
pItem
->
strVal
);
break
;
break
;
case
CFG_DTYPE_IPSTR
:
case
CFG_DTYPE_IPSTR
:
printf
(
"index:%d, cfg:%s value:%s
\n
"
,
size
,
pItem
->
name
,
pItem
->
ip
strVal
);
printf
(
"index:%d, cfg:%s value:%s
\n
"
,
size
,
pItem
->
name
,
pItem
->
strVal
);
break
;
break
;
case
CFG_DTYPE_DIR
:
case
CFG_DTYPE_DIR
:
printf
(
"index:%d, cfg:%s value:%s
\n
"
,
size
,
pItem
->
name
,
pItem
->
di
rVal
);
printf
(
"index:%d, cfg:%s value:%s
\n
"
,
size
,
pItem
->
name
,
pItem
->
st
rVal
);
break
;
break
;
default:
default:
printf
(
"index:%d, cfg:%s invalid cfg dtype:%d
\n
"
,
size
,
pItem
->
name
,
pItem
->
dtype
);
printf
(
"index:%d, cfg:%s invalid cfg dtype:%d
\n
"
,
size
,
pItem
->
name
,
pItem
->
dtype
);
...
@@ -172,14 +172,14 @@ TEST_F(CfgTest, 02_Basic) {
...
@@ -172,14 +172,14 @@ TEST_F(CfgTest, 02_Basic) {
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_IPSTR
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_IPSTR
);
EXPECT_STREQ
(
pItem
->
name
,
"test_ipstr"
);
EXPECT_STREQ
(
pItem
->
name
,
"test_ipstr"
);
EXPECT_STREQ
(
pItem
->
ip
strVal
,
"192.168.0.1"
);
EXPECT_STREQ
(
pItem
->
strVal
,
"192.168.0.1"
);
pItem
=
cfgGetItem
(
pConfig
,
"test_dir"
);
pItem
=
cfgGetItem
(
pConfig
,
"test_dir"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_STYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_STYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_DIR
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_DIR
);
EXPECT_STREQ
(
pItem
->
name
,
"test_dir"
);
EXPECT_STREQ
(
pItem
->
name
,
"test_dir"
);
EXPECT_STREQ
(
pItem
->
di
rVal
,
"/tmp"
);
EXPECT_STREQ
(
pItem
->
st
rVal
,
"/tmp"
);
cfgCleanup
(
pConfig
);
cfgCleanup
(
pConfig
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录