Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7fea9e2f
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
7fea9e2f
编写于
12月 11, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into feature/vnode
上级
7a2a6a7c
044388b3
变更
56
隐藏空白更改
内联
并排
Showing
56 changed file
with
4286 addition
and
695 deletion
+4286
-695
include/common/taosmsg.h
include/common/taosmsg.h
+111
-68
include/common/tglobal.h
include/common/tglobal.h
+0
-1
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+30
-1
include/util/taoserror.h
include/util/taoserror.h
+31
-21
include/util/tdef.h
include/util/tdef.h
+30
-30
include/util/tutil.h
include/util/tutil.h
+11
-10
source/common/src/tglobal.c
source/common/src/tglobal.c
+0
-69
source/dnode/mgmt/impl/src/dndMnode.c
source/dnode/mgmt/impl/src/dndMnode.c
+7
-6
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+2
-6
source/dnode/mgmt/impl/test/CMakeLists.txt
source/dnode/mgmt/impl/test/CMakeLists.txt
+5
-4
source/dnode/mgmt/impl/test/cluster/cluster.cpp
source/dnode/mgmt/impl/test/cluster/cluster.cpp
+3
-3
source/dnode/mgmt/impl/test/profile/profile.cpp
source/dnode/mgmt/impl/test/profile/profile.cpp
+14
-14
source/dnode/mgmt/impl/test/show/show.cpp
source/dnode/mgmt/impl/test/show/show.cpp
+7
-7
source/dnode/mgmt/impl/test/sut/deploy.cpp
source/dnode/mgmt/impl/test/sut/deploy.cpp
+0
-1
source/dnode/mgmt/impl/test/user/CMakeLists.txt
source/dnode/mgmt/impl/test/user/CMakeLists.txt
+29
-0
source/dnode/mgmt/impl/test/user/user.cpp
source/dnode/mgmt/impl/test/user/user.cpp
+407
-0
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+56
-64
source/dnode/mnode/impl/inc/mndDnode.h
source/dnode/mnode/impl/inc/mndDnode.h
+2
-0
source/dnode/mnode/impl/inc/mndInt.h
source/dnode/mnode/impl/inc/mndInt.h
+1
-0
source/dnode/mnode/impl/inc/mndMnode.h
source/dnode/mnode/impl/inc/mndMnode.h
+1
-0
source/dnode/mnode/impl/inc/mndOper.h
source/dnode/mnode/impl/inc/mndOper.h
+0
-30
source/dnode/mnode/impl/inc/mndShow.h
source/dnode/mnode/impl/inc/mndShow.h
+1
-0
source/dnode/mnode/impl/inc/mndSync.h
source/dnode/mnode/impl/inc/mndSync.h
+1
-1
source/dnode/mnode/impl/inc/mndTrans.h
source/dnode/mnode/impl/inc/mndTrans.h
+2
-5
source/dnode/mnode/impl/inc/mndVgroup.h
source/dnode/mnode/impl/inc/mndVgroup.h
+2
-0
source/dnode/mnode/impl/src/mndAcct.c
source/dnode/mnode/impl/src/mndAcct.c
+10
-10
source/dnode/mnode/impl/src/mndCluster.c
source/dnode/mnode/impl/src/mndCluster.c
+5
-5
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+853
-6
source/dnode/mnode/impl/src/mndDnode.c
source/dnode/mnode/impl/src/mndDnode.c
+466
-48
source/dnode/mnode/impl/src/mndFunc.c
source/dnode/mnode/impl/src/mndFunc.c
+494
-4
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+351
-42
source/dnode/mnode/impl/src/mndOper.c
source/dnode/mnode/impl/src/mndOper.c
+0
-21
source/dnode/mnode/impl/src/mndProfile.c
source/dnode/mnode/impl/src/mndProfile.c
+3
-3
source/dnode/mnode/impl/src/mndShow.c
source/dnode/mnode/impl/src/mndShow.c
+2
-7
source/dnode/mnode/impl/src/mndStable.c
source/dnode/mnode/impl/src/mndStable.c
+410
-4
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+9
-3
source/dnode/mnode/impl/src/mndTelem.c
source/dnode/mnode/impl/src/mndTelem.c
+4
-4
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+141
-85
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+284
-23
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+368
-4
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+9
-7
source/dnode/mnode/sdb/inc/sdbInt.h
source/dnode/mnode/sdb/inc/sdbInt.h
+0
-1
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+2
-2
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+1
-1
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+30
-26
source/dnode/mnode/sdb/src/sdbRaw.c
source/dnode/mnode/sdb/src/sdbRaw.c
+6
-1
source/dnode/vnode/impl/CMakeLists.txt
source/dnode/vnode/impl/CMakeLists.txt
+3
-3
source/libs/function/src/tfunction.c
source/libs/function/src/tfunction.c
+1
-1
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+1
-1
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+34
-11
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+2
-2
source/libs/parser/src/astGenerator.c
source/libs/parser/src/astGenerator.c
+0
-7
source/libs/parser/src/parserUtil.c
source/libs/parser/src/parserUtil.c
+1
-1
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+2
-2
source/util/src/terror.c
source/util/src/terror.c
+24
-15
source/util/src/tutil.c
source/util/src/tutil.c
+17
-4
未找到文件。
include/common/taosmsg.h
浏览文件 @
7fea9e2f
...
@@ -70,11 +70,9 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DB, "drop-db" )
...
@@ -70,11 +70,9 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DB, "drop-db" )
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_USE_DB
,
"use-db"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_USE_DB
,
"use-db"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_ALTER_DB
,
"alter-db"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_ALTER_DB
,
"alter-db"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_SYNC_DB
,
"sync-db"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_SYNC_DB
,
"sync-db"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_TOPIC
,
"create-topic"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_COMPACT_DB
,
"compact-db"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_DROP_TOPIC
,
"drop-topic"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_ALTER_TOPIC
,
"alter-topic"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_FUNCTION
,
"create-function"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_FUNCTION
,
"create-function"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_
ALTER_FUNCTION
,
"alter
-function"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_
RETRIEVE_FUNCTION
,
"retrieve
-function"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_DROP_FUNCTION
,
"drop-function"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_DROP_FUNCTION
,
"drop-function"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_STABLE
,
"create-stable"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_STABLE
,
"create-stable"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_ALTER_STABLE
,
"alter-stable"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_ALTER_STABLE
,
"alter-stable"
)
...
@@ -86,8 +84,6 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" )
...
@@ -86,8 +84,6 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" )
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_HEARTBEAT
,
"heartbeat"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_HEARTBEAT
,
"heartbeat"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_SHOW
,
"show"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_SHOW
,
"show"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_SHOW_RETRIEVE
,
"retrieve"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_SHOW_RETRIEVE
,
"retrieve"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC
,
"retrieve-func"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_COMPACT_VNODE
,
"compact-vnode"
)
// message from client to qnode
// message from client to qnode
// message from client to dnode
// message from client to dnode
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_NETWORK_TEST
,
"nettest"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_NETWORK_TEST
,
"nettest"
)
...
@@ -163,7 +159,7 @@ typedef enum _mgmt_table {
...
@@ -163,7 +159,7 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_DNODE
,
TSDB_MGMT_TABLE_DNODE
,
TSDB_MGMT_TABLE_MNODE
,
TSDB_MGMT_TABLE_MNODE
,
TSDB_MGMT_TABLE_VGROUP
,
TSDB_MGMT_TABLE_VGROUP
,
TSDB_MGMT_TABLE_
METRIC
,
TSDB_MGMT_TABLE_
STABLE
,
TSDB_MGMT_TABLE_MODULE
,
TSDB_MGMT_TABLE_MODULE
,
TSDB_MGMT_TABLE_QUERIES
,
TSDB_MGMT_TABLE_QUERIES
,
TSDB_MGMT_TABLE_STREAMS
,
TSDB_MGMT_TABLE_STREAMS
,
...
@@ -276,14 +272,12 @@ typedef struct {
...
@@ -276,14 +272,12 @@ typedef struct {
SShellSubmitRspBlock
failedBlocks
[];
SShellSubmitRspBlock
failedBlocks
[];
}
SShellSubmitRspMsg
;
}
SShellSubmitRspMsg
;
//#if 0
typedef
struct
SSchema
{
typedef
struct
SSchema
{
uint8_t
type
;
int8_t
type
;
char
name
[
TSDB_COL_NAME_LEN
];
int32_t
colId
;
int16_t
colId
;
int32_t
bytes
;
int32_t
bytes
;
char
name
[
TSDB_COL_NAME_LEN
];
}
SSchema
;
}
SSchema
;
//#endif
typedef
struct
{
typedef
struct
{
int32_t
contLen
;
int32_t
contLen
;
...
@@ -571,7 +565,6 @@ typedef struct {
...
@@ -571,7 +565,6 @@ typedef struct {
char
db
[
TSDB_FULL_DB_NAME_LEN
];
char
db
[
TSDB_FULL_DB_NAME_LEN
];
int32_t
cacheBlockSize
;
// MB
int32_t
cacheBlockSize
;
// MB
int32_t
totalBlocks
;
int32_t
totalBlocks
;
int32_t
maxTables
;
int32_t
daysPerFile
;
int32_t
daysPerFile
;
int32_t
daysToKeep0
;
int32_t
daysToKeep0
;
int32_t
daysToKeep1
;
int32_t
daysToKeep1
;
...
@@ -580,58 +573,93 @@ typedef struct {
...
@@ -580,58 +573,93 @@ typedef struct {
int32_t
maxRowsPerFileBlock
;
int32_t
maxRowsPerFileBlock
;
int32_t
commitTime
;
int32_t
commitTime
;
int32_t
fsyncPeriod
;
int32_t
fsyncPeriod
;
int8_t
walLevel
;
int8_t
precision
;
// time resolution
int8_t
precision
;
// time resolution
int8_t
compression
;
int8_t
compression
;
int8_t
walLevel
;
int8_t
replications
;
int8_t
replications
;
int8_t
quorum
;
int8_t
quorum
;
int8_t
ignoreExist
;
int8_t
update
;
int8_t
update
;
int8_t
cacheLastRow
;
int8_t
cacheLastRow
;
int8_t
dbType
;
int8_t
ignoreExist
;
int16_t
partitions
;
int32_t
reserve
[
8
];
int8_t
reserve
[
5
];
}
SCreateDbMsg
;
}
SCreateDbMsg
,
SAlterDbMsg
;
typedef
struct
{
char
db
[
TSDB_FULL_DB_NAME_LEN
];
int32_t
totalBlocks
;
int32_t
daysToKeep0
;
int32_t
daysToKeep1
;
int32_t
daysToKeep2
;
int32_t
fsyncPeriod
;
int8_t
walLevel
;
int8_t
quorum
;
int8_t
cacheLastRow
;
int32_t
reserve
[
8
];
}
SAlterDbMsg
;
typedef
struct
{
char
db
[
TSDB_TABLE_FNAME_LEN
];
int8_t
ignoreNotExists
;
int32_t
reserve
[
8
];
}
SDropDbMsg
;
typedef
struct
{
char
db
[
TSDB_TABLE_FNAME_LEN
];
int8_t
ignoreNotExists
;
int32_t
reserve
[
8
];
}
SUseDbMsg
;
typedef
struct
{
char
db
[
TSDB_TABLE_FNAME_LEN
];
int32_t
reserve
[
8
];
}
SSyncDbMsg
;
typedef
struct
{
char
db
[
TSDB_TABLE_FNAME_LEN
];
int32_t
reserve
[
8
];
}
SCompactDbMsg
;
typedef
struct
{
typedef
struct
{
char
name
[
TSDB_FUNC_NAME_LEN
];
char
name
[
TSDB_FUNC_NAME_LEN
];
char
path
[
PATH_MAX
];
int8_t
funcType
;
int32_t
funcType
;
int8_t
scriptType
;
int8_t
align
;
int8_t
outputType
;
int8_t
outputType
;
int
16
_t
outputLen
;
int
32
_t
outputLen
;
int32_t
bufSize
;
int32_t
bufSize
;
int32_t
codeLen
;
int64_t
sigature
;
char
code
[];
int32_t
commentSize
;
int32_t
codeSize
;
char
pCont
[];
}
SCreateFuncMsg
;
}
SCreateFuncMsg
;
typedef
struct
{
typedef
struct
{
int32_t
num
;
char
name
[
TSDB_FUNC_NAME_LEN
];
char
name
[];
}
SDropFuncMsg
;
typedef
struct
{
int32_t
numOfFuncs
;
char
pFuncNames
[];
}
SRetrieveFuncMsg
;
}
SRetrieveFuncMsg
;
typedef
struct
{
typedef
struct
{
char
name
[
TSDB_FUNC_NAME_LEN
];
char
name
[
TSDB_FUNC_NAME_LEN
];
int32_t
funcType
;
int8_t
funcType
;
int8_t
resType
;
int8_t
scriptType
;
int16_t
resBytes
;
int8_t
align
;
int8_t
outputType
;
int32_t
outputLen
;
int32_t
bufSize
;
int32_t
bufSize
;
int32_t
len
;
int64_t
sigature
;
char
content
[];
int32_t
commentSize
;
}
SFunctionInfoMsg
;
int32_t
codeSize
;
char
pCont
[];
typedef
struct
{
}
SFuncInfo
;
int32_t
num
;
char
content
[];
}
SUdfFuncMsg
;
typedef
struct
{
typedef
struct
{
char
name
[
TSDB_FUNC_NAME_LEN
];
int32_t
numOfFuncs
;
}
SDropFuncMsg
;
char
pFuncInfos
[];
}
SRetrieveFuncRsp
;
typedef
struct
{
char
db
[
TSDB_TABLE_FNAME_LEN
];
int8_t
ignoreNotExists
;
}
SDropDbMsg
,
SUseDbMsg
,
SSyncDbMsg
;
typedef
struct
{
typedef
struct
{
int32_t
statusInterval
;
int32_t
statusInterval
;
...
@@ -736,13 +764,17 @@ typedef struct {
...
@@ -736,13 +764,17 @@ typedef struct {
}
SAuthVnodeMsg
;
}
SAuthVnodeMsg
;
typedef
struct
{
typedef
struct
{
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
char
name
[
TSDB_TABLE_FNAME_LEN
];
int16_t
createFlag
;
}
SStableInfoMsg
;
char
tags
[];
typedef
struct
{
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
int8_t
createFlag
;
char
tags
[];
}
STableInfoMsg
;
}
STableInfoMsg
;
typedef
struct
{
typedef
struct
{
uint8_t
metaClone
;
// create local clone of the cached table meta
int8_t
metaClone
;
// create local clone of the cached table meta
int32_t
numOfVgroups
;
int32_t
numOfVgroups
;
int32_t
numOfTables
;
int32_t
numOfTables
;
int32_t
numOfUdfs
;
int32_t
numOfUdfs
;
...
@@ -760,25 +792,24 @@ typedef struct {
...
@@ -760,25 +792,24 @@ typedef struct {
}
SVgroupMsg
;
}
SVgroupMsg
;
typedef
struct
{
typedef
struct
{
int32_t
numOfVgroups
;
int32_t
numOfVgroups
;
SVgroupMsg
vgroups
[];
SVgroupMsg
vgroups
[];
}
SVgroupsMsg
,
SVgroupsInfo
;
}
SVgroupsMsg
,
SVgroupsInfo
;
typedef
struct
STableMetaMsg
{
typedef
struct
{
int32_t
contLen
;
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
// table id
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
// table id
int8_t
numOfTags
;
char
stableFname
[
TSDB_TABLE_FNAME_LEN
];
int32_t
numOfTags
;
int32_t
numOfColumns
;
int8_t
precision
;
int8_t
precision
;
int8_t
tableType
;
int8_t
tableType
;
int
16_t
numOfColumns
;
int
8_t
update
;
int
16
_t
sversion
;
int
32
_t
sversion
;
int
16
_t
tversion
;
int
32
_t
tversion
;
int32_t
t
id
;
uint64_t
tu
id
;
int64_t
uid
;
uint64_t
s
uid
;
SVgroupMsg
vgroup
;
SVgroupMsg
vgroup
;
char
sTableName
[
TSDB_TABLE_FNAME_LEN
];
SSchema
pSchema
[];
int64_t
suid
;
SSchema
schema
[];
}
STableMetaMsg
;
}
STableMetaMsg
;
typedef
struct
SMultiTableMeta
{
typedef
struct
SMultiTableMeta
{
...
@@ -823,14 +854,31 @@ typedef struct SShowRsp {
...
@@ -823,14 +854,31 @@ typedef struct SShowRsp {
typedef
struct
{
typedef
struct
{
char
ep
[
TSDB_EP_LEN
];
// end point, hostname:port
char
ep
[
TSDB_EP_LEN
];
// end point, hostname:port
}
SCreateDnodeMsg
,
SDropDnodeMsg
;
}
SCreateDnodeMsg
;
typedef
struct
{
int32_t
dnodeId
;
}
SDropDnodeMsg
;
typedef
struct
{
int32_t
dnodeId
;
char
config
[
128
];
}
SCfgDnodeMsg
;
typedef
struct
{
int32_t
dnodeId
;
}
SCreateMnodeMsg
,
SDropMnodeMsg
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
int8_t
align
[
3
];
int8_t
replica
;
int8_t
replica
;
int8_t
reserved
[
3
];
SReplica
replicas
[
TSDB_MAX_REPLICA
];
SReplica
replicas
[
TSDB_MAX_REPLICA
];
}
SCreateMnodeMsg
,
SAlterMnodeMsg
,
SDropMnodeMsg
;
}
SCreateMnodeInMsg
,
SAlterMnodeInMsg
;
typedef
struct
{
int32_t
dnodeId
;
}
SDropMnodeInMsg
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
...
@@ -843,11 +891,6 @@ typedef struct {
...
@@ -843,11 +891,6 @@ typedef struct {
int32_t
vgId
;
int32_t
vgId
;
}
SConfigVnodeMsg
;
}
SConfigVnodeMsg
;
typedef
struct
{
char
ep
[
TSDB_EP_LEN
];
// end point, hostname:port
char
config
[
64
];
}
SCfgDnodeMsg
;
typedef
struct
{
typedef
struct
{
char
sql
[
TSDB_SHOW_SQL_LEN
];
char
sql
[
TSDB_SHOW_SQL_LEN
];
int32_t
queryId
;
int32_t
queryId
;
...
...
include/common/tglobal.h
浏览文件 @
7fea9e2f
...
@@ -196,7 +196,6 @@ extern SDiskCfg tsDiskCfg[];
...
@@ -196,7 +196,6 @@ extern SDiskCfg tsDiskCfg[];
void
taosInitGlobalCfg
();
void
taosInitGlobalCfg
();
int32_t
taosCheckGlobalCfg
();
int32_t
taosCheckGlobalCfg
();
int32_t
taosCfgDynamicOptions
(
char
*
msg
);
int32_t
taosCfgDynamicOptions
(
char
*
msg
);
int
taosGetFqdnPortFromEp
(
const
char
*
ep
,
char
*
fqdn
,
uint16_t
*
port
);
bool
taosCheckBalanceCfgOptions
(
const
char
*
option
,
int32_t
*
vnodeId
,
int32_t
*
dnodeId
);
bool
taosCheckBalanceCfgOptions
(
const
char
*
option
,
int32_t
*
vnodeId
,
int32_t
*
dnodeId
);
void
taosAddDataDir
(
int
index
,
char
*
v1
,
int
level
,
int
primary
);
void
taosAddDataDir
(
int
index
,
char
*
v1
,
int
level
,
int
primary
);
void
taosReadDataDirCfg
(
char
*
v1
,
char
*
v2
,
char
*
v3
);
void
taosReadDataDirCfg
(
char
*
v1
,
char
*
v2
,
char
*
v3
);
...
...
include/dnode/mnode/sdb/sdb.h
浏览文件 @
7fea9e2f
...
@@ -65,6 +65,16 @@ extern "C" {
...
@@ -65,6 +65,16 @@ extern "C" {
dataPos += valLen; \
dataPos += valLen; \
}
}
#define SDB_GET_RESERVE(pRaw, pRow, dataPos, valLen) \
{ \
char val[valLen] = {0}; \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
sdbFreeRow(pRow); \
return NULL; \
} \
dataPos += valLen; \
}
#define SDB_SET_INT64(pRaw, dataPos, val) \
#define SDB_SET_INT64(pRaw, dataPos, val) \
{ \
{ \
if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \
if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \
...
@@ -110,6 +120,16 @@ extern "C" {
...
@@ -110,6 +120,16 @@ extern "C" {
dataPos += valLen; \
dataPos += valLen; \
}
}
#define SDB_SET_RESERVE(pRaw, dataPos, valLen) \
{ \
char val[valLen] = {0}; \
if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
sdbFreeRaw(pRaw); \
return NULL; \
} \
dataPos += valLen; \
}
#define SDB_SET_DATALEN(pRaw, dataLen) \
#define SDB_SET_DATALEN(pRaw, dataLen) \
{ \
{ \
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
...
@@ -258,7 +278,7 @@ int32_t sdbDeploy(SSdb *pSdb);
...
@@ -258,7 +278,7 @@ int32_t sdbDeploy(SSdb *pSdb);
int32_t
sdbReadFile
(
SSdb
*
pSdb
);
int32_t
sdbReadFile
(
SSdb
*
pSdb
);
/**
/**
* @brief Parse and write raw data to sdb
.
* @brief Parse and write raw data to sdb
, then free the pRaw object
*
*
* @param pSdb The sdb object.
* @param pSdb The sdb object.
* @param pRaw The raw data.
* @param pRaw The raw data.
...
@@ -266,6 +286,15 @@ int32_t sdbReadFile(SSdb *pSdb);
...
@@ -266,6 +286,15 @@ int32_t sdbReadFile(SSdb *pSdb);
*/
*/
int32_t
sdbWrite
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
);
int32_t
sdbWrite
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
);
/**
* @brief Parse and write raw data to sdb.
*
* @param pSdb The sdb object.
* @param pRaw The raw data.
* @return int32_t 0 for success, -1 for failure.
*/
int32_t
sdbWriteNotFree
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
);
/**
/**
* @brief Acquire a row from sdb
* @brief Acquire a row from sdb
*
*
...
...
include/util/taoserror.h
浏览文件 @
7fea9e2f
...
@@ -183,6 +183,7 @@ int32_t* taosGetErrno();
...
@@ -183,6 +183,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0348) //"Mnode already exists")
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0348) //"Mnode already exists")
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0349) //"Mnode not there")
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0349) //"Mnode not there")
// mnode-table
#define TSDB_CODE_MND_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) //"Table already exists")
#define TSDB_CODE_MND_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) //"Table already exists")
#define TSDB_CODE_MND_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0361) //"Table name too long")
#define TSDB_CODE_MND_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0361) //"Table name too long")
#define TSDB_CODE_MND_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0362) //"Table does not exist")
#define TSDB_CODE_MND_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0362) //"Table does not exist")
...
@@ -200,32 +201,41 @@ int32_t* taosGetErrno();
...
@@ -200,32 +201,41 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG TAOS_DEF_ERROR_CODE(0, 0x036E) //"Invalid create table message")
#define TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG TAOS_DEF_ERROR_CODE(0, 0x036E) //"Invalid create table message")
#define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x036F) //"Exceed max row bytes")
#define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x036F) //"Exceed max row bytes")
#define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x0370) //"Invalid func name")
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0370)
#define TSDB_CODE_MND_INVALID_FUNC_LEN TAOS_DEF_ERROR_CODE(0, 0x0371) //"Invalid func length")
#define TSDB_CODE_MND_FUNC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0371)
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x0372) //"Invalid func code")
#define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x0372)
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0373) //"Func already exists")
#define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x0373)
#define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x0374) //"Invalid func")
#define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x0374)
#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x0375) //"Invalid func bufSize")
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x0375)
#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x0376)
#define TSDB_CODE_MND_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0376) //"invalid tag length")
#define TSDB_CODE_MND_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0376) //"invalid tag length")
#define TSDB_CODE_MND_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0377) //"invalid column length")
#define TSDB_CODE_MND_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0377) //"invalid column length")
#define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380) //"Database not specified or available")
#define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380)
#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381) //"Database already exists")
#define TSDB_CODE_MND_DB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381)
#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382) //"Invalid database options")
#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381)
#define TSDB_CODE_MND_INVALID_DB TAOS_DEF_ERROR_CODE(0, 0x0383) //"Invalid database name")
#define TSDB_CODE_MND_INVALID_DB TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_MONITOR_DB_FORBIDDEN TAOS_DEF_ERROR_CODE(0, 0x0384) //"Cannot delete monitor database")
#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382)
#define TSDB_CODE_MND_INVALID_DB_CACHE_SIZE TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_TOTAL_BLOCKS TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_DAYS TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_KEEP0 TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_KEEP1 TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_KEEP2 TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_MIN_ROWS TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_MAX_ROWS TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_COMMIT_TIME TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_FSYNC_PERIOD TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_WAL_LEVEL TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_PRECISION TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_COMP TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_REPLICA TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_QUORUM TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_UPDATE TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_INVALID_DB_CACHE_LAST TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_DB_OPTION_UNCHANGED TAOS_DEF_ERROR_CODE(0, 0x0383)
#define TSDB_CODE_MND_TOO_MANY_DATABASES TAOS_DEF_ERROR_CODE(0, 0x0385) //"Too many databases for account")
#define TSDB_CODE_MND_TOO_MANY_DATABASES TAOS_DEF_ERROR_CODE(0, 0x0385) //"Too many databases for account")
#define TSDB_CODE_MND_DB_IN_DROPPING TAOS_DEF_ERROR_CODE(0, 0x0386) //"Database not available")
#define TSDB_CODE_MND_VGROUP_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0387) //"Database unsynced")
#define TSDB_CODE_MND_INVALID_DB_OPTION_DAYS TAOS_DEF_ERROR_CODE(0, 0x0390) //"Invalid database option: days out of range")
#define TSDB_CODE_MND_INVALID_DB_OPTION_KEEP TAOS_DEF_ERROR_CODE(0, 0x0391) //"Invalid database option: keep >= keep1 >= keep0 >= days")
#define TSDB_CODE_MND_INVALID_TOPIC TAOS_DEF_ERROR_CODE(0, 0x0392) //"Invalid topic name)
#define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x0393) //"Invalid topic option)
#define TSDB_CODE_MND_INVALID_TOPIC_PARTITONS TAOS_DEF_ERROR_CODE(0, 0x0394) //"Invalid topic partitons num, valid range: [1, 1000])
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0395) //"Topic already exists)
// dnode
// dnode
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
...
...
include/util/tdef.h
浏览文件 @
7fea9e2f
...
@@ -163,9 +163,14 @@ do { \
...
@@ -163,9 +163,14 @@ do { \
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
#define TSDB_DB_NAME_LEN 33
#define TSDB_DB_NAME_LEN 33
#define TSDB_FULL_DB_NAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN)
#define TSDB_FULL_DB_NAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN)
#define TSDB_FUNC_NAME_LEN 65
#define TSDB_FUNC_CODE_LEN (65535 - 512)
#define TSDB_FUNC_NAME_LEN 65
#define TSDB_FUNC_BUF_SIZE 512
#define TSDB_FUNC_COMMENT_LEN 4096
#define TSDB_FUNC_CODE_LEN (65535 - 512)
#define TSDB_FUNC_BUF_SIZE 512
#define TSDB_FUNC_TYPE_SCALAR 1
#define TSDB_FUNC_TYPE_AGGREGATE 2
#define TSDB_TYPE_STR_MAX_LEN 32
#define TSDB_TYPE_STR_MAX_LEN 32
#define TSDB_TABLE_FNAME_LEN (TSDB_FULL_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
#define TSDB_TABLE_FNAME_LEN (TSDB_FULL_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
#define TSDB_COL_NAME_LEN 65
#define TSDB_COL_NAME_LEN 65
...
@@ -245,12 +250,6 @@ do { \
...
@@ -245,12 +250,6 @@ do { \
#define TSDB_MAX_TOTAL_BLOCKS 10000
#define TSDB_MAX_TOTAL_BLOCKS 10000
#define TSDB_DEFAULT_TOTAL_BLOCKS 6
#define TSDB_DEFAULT_TOTAL_BLOCKS 6
#define TSDB_MIN_TABLES 4
#define TSDB_MAX_TABLES 10000000
#define TSDB_DEFAULT_TABLES 1000000
#define TSDB_TABLES_STEP 1000
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
#define TSDB_MIN_DAYS_PER_FILE 1
#define TSDB_MIN_DAYS_PER_FILE 1
#define TSDB_MAX_DAYS_PER_FILE 3650
#define TSDB_MAX_DAYS_PER_FILE 3650
#define TSDB_DEFAULT_DAYS_PER_FILE 10
#define TSDB_DEFAULT_DAYS_PER_FILE 10
...
@@ -259,18 +258,26 @@ do { \
...
@@ -259,18 +258,26 @@ do { \
#define TSDB_MAX_KEEP 365000 // data in db to be reserved.
#define TSDB_MAX_KEEP 365000 // data in db to be reserved.
#define TSDB_DEFAULT_KEEP 3650 // ten years
#define TSDB_DEFAULT_KEEP 3650 // ten years
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
#define TSDB_MIN_MIN_ROW_FBLOCK 10
#define TSDB_MIN_MIN_ROW_FBLOCK 10
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
#define TSDB_MIN_MAX_ROW_FBLOCK 200
#define TSDB_MIN_MAX_ROW_FBLOCK 200
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
#define TSDB_MIN_COMMIT_TIME 30
#define TSDB_MIN_COMMIT_TIME 30
#define TSDB_MAX_COMMIT_TIME 40960
#define TSDB_MAX_COMMIT_TIME 40960
#define TSDB_DEFAULT_COMMIT_TIME 3600
#define TSDB_DEFAULT_COMMIT_TIME 3600
#define TSDB_MIN_FSYNC_PERIOD 0
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
#define TSDB_MIN_WAL_LEVEL 0
#define TSDB_MAX_WAL_LEVEL 2
#define TSDB_DEFAULT_WAL_LEVEL 1
#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI
#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI
#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO
#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO
#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI
#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI
...
@@ -279,9 +286,13 @@ do { \
...
@@ -279,9 +286,13 @@ do { \
#define TSDB_MAX_COMP_LEVEL 2
#define TSDB_MAX_COMP_LEVEL 2
#define TSDB_DEFAULT_COMP_LEVEL 2
#define TSDB_DEFAULT_COMP_LEVEL 2
#define TSDB_MIN_WAL_LEVEL 0
#define TSDB_MIN_DB_REPLICA_OPTION 1
#define TSDB_MAX_WAL_LEVEL 2
#define TSDB_MAX_DB_REPLICA_OPTION 3
#define TSDB_DEFAULT_WAL_LEVEL 1
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
#define TSDB_MIN_DB_QUORUM_OPTION 1
#define TSDB_MAX_DB_QUORUM_OPTION 2
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
#define TSDB_MIN_DB_UPDATE 0
#define TSDB_MIN_DB_UPDATE 0
#define TSDB_MAX_DB_UPDATE 2
#define TSDB_MAX_DB_UPDATE 2
...
@@ -291,22 +302,6 @@ do { \
...
@@ -291,22 +302,6 @@ do { \
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
#define TSDB_MIN_FSYNC_PERIOD 0
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
#define TSDB_MIN_DB_REPLICA_OPTION 1
#define TSDB_MAX_DB_REPLICA_OPTION 3
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
#define TSDB_MIN_DB_PARTITON_OPTION 0
#define TSDB_MAX_DB_PARTITON_OPTION 1000
#define TSDB_DEFAULT_DB_PARTITON_OPTION 4
#define TSDB_MIN_DB_QUORUM_OPTION 1
#define TSDB_MAX_DB_QUORUM_OPTION 2
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
#define TSDB_MAX_JOIN_TABLE_NUM 10
#define TSDB_MAX_JOIN_TABLE_NUM 10
#define TSDB_MAX_UNION_CLAUSE 5
#define TSDB_MAX_UNION_CLAUSE 5
...
@@ -320,6 +315,11 @@ do { \
...
@@ -320,6 +315,11 @@ do { \
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
/*
/*
* 1. ordinary sub query for select * from super_table
* 1. ordinary sub query for select * from super_table
* 2. all sqlobj generated by createSubqueryObj with this flag
* 2. all sqlobj generated by createSubqueryObj with this flag
...
...
include/util/tutil.h
浏览文件 @
7fea9e2f
...
@@ -21,22 +21,22 @@ extern "C" {
...
@@ -21,22 +21,22 @@ extern "C" {
#endif
#endif
#include "os.h"
#include "os.h"
#include "tmd5.h"
#include "tcrc32c.h"
#include "tcrc32c.h"
#include "tdef.h"
#include "tdef.h"
#include "tmd5.h"
int32_t
strdequote
(
char
*
src
);
int32_t
strdequote
(
char
*
src
);
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
);
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
);
int32_t
strRmquote
(
char
*
z
,
int32_t
len
);
int32_t
strRmquote
(
char
*
z
,
int32_t
len
);
size_t
strtrim
(
char
*
src
);
size_t
strtrim
(
char
*
src
);
char
*
strnchr
(
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
);
char
*
strnchr
(
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
);
char
**
strsplit
(
char
*
src
,
const
char
*
delim
,
int32_t
*
num
);
char
**
strsplit
(
char
*
src
,
const
char
*
delim
,
int32_t
*
num
);
char
*
strtolower
(
char
*
dst
,
const
char
*
src
);
char
*
strtolower
(
char
*
dst
,
const
char
*
src
);
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
);
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
);
char
*
strntolower_s
(
char
*
dst
,
const
char
*
src
,
int32_t
n
);
char
*
strntolower_s
(
char
*
dst
,
const
char
*
src
,
int32_t
n
);
int64_t
strnatoi
(
char
*
num
,
int32_t
len
);
int64_t
strnatoi
(
char
*
num
,
int32_t
len
);
char
*
strbetween
(
char
*
string
,
char
*
begin
,
char
*
end
);
char
*
strbetween
(
char
*
string
,
char
*
begin
,
char
*
end
);
char
*
paGetToken
(
char
*
src
,
char
**
token
,
int32_t
*
tokenLen
);
char
*
paGetToken
(
char
*
src
,
char
**
token
,
int32_t
*
tokenLen
);
int32_t
taosByteArrayToHexStr
(
char
bytes
[],
int32_t
len
,
char
hexstr
[]);
int32_t
taosByteArrayToHexStr
(
char
bytes
[],
int32_t
len
,
char
hexstr
[]);
int32_t
taosHexStrToByteArray
(
char
hexstr
[],
char
bytes
[]);
int32_t
taosHexStrToByteArray
(
char
hexstr
[],
char
bytes
[]);
...
@@ -45,6 +45,7 @@ char *taosIpStr(uint32_t ipInt);
...
@@ -45,6 +45,7 @@ char *taosIpStr(uint32_t ipInt);
uint32_t
ip2uint
(
const
char
*
const
ip_addr
);
uint32_t
ip2uint
(
const
char
*
const
ip_addr
);
void
taosIp2String
(
uint32_t
ip
,
char
*
str
);
void
taosIp2String
(
uint32_t
ip
,
char
*
str
);
void
taosIpPort2String
(
uint32_t
ip
,
uint16_t
port
,
char
*
str
);
void
taosIpPort2String
(
uint32_t
ip
,
uint16_t
port
,
char
*
str
);
int32_t
taosGetFqdnPortFromEp
(
const
char
*
ep
,
char
*
fqdn
,
uint16_t
*
port
);
static
FORCE_INLINE
void
taosEncryptPass
(
uint8_t
*
inBuf
,
size_t
inLen
,
char
*
target
)
{
static
FORCE_INLINE
void
taosEncryptPass
(
uint8_t
*
inBuf
,
size_t
inLen
,
char
*
target
)
{
T_MD5_CTX
context
;
T_MD5_CTX
context
;
...
@@ -58,4 +59,4 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
...
@@ -58,4 +59,4 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
}
}
#endif
#endif
#endif
/*_TD_UTIL_UTIL_H*/
#endif
/*_TD_UTIL_UTIL_H*/
source/common/src/tglobal.c
浏览文件 @
7fea9e2f
...
@@ -142,13 +142,9 @@ int8_t tsWAL = TSDB_DEFAULT_WAL_LEVEL;
...
@@ -142,13 +142,9 @@ int8_t tsWAL = TSDB_DEFAULT_WAL_LEVEL;
int32_t
tsFsyncPeriod
=
TSDB_DEFAULT_FSYNC_PERIOD
;
int32_t
tsFsyncPeriod
=
TSDB_DEFAULT_FSYNC_PERIOD
;
int32_t
tsReplications
=
TSDB_DEFAULT_DB_REPLICA_OPTION
;
int32_t
tsReplications
=
TSDB_DEFAULT_DB_REPLICA_OPTION
;
int32_t
tsQuorum
=
TSDB_DEFAULT_DB_QUORUM_OPTION
;
int32_t
tsQuorum
=
TSDB_DEFAULT_DB_QUORUM_OPTION
;
int16_t
tsPartitons
=
TSDB_DEFAULT_DB_PARTITON_OPTION
;
int8_t
tsUpdate
=
TSDB_DEFAULT_DB_UPDATE_OPTION
;
int8_t
tsUpdate
=
TSDB_DEFAULT_DB_UPDATE_OPTION
;
int8_t
tsCacheLastRow
=
TSDB_DEFAULT_CACHE_LAST_ROW
;
int8_t
tsCacheLastRow
=
TSDB_DEFAULT_CACHE_LAST_ROW
;
int32_t
tsMaxVgroupsPerDb
=
0
;
int32_t
tsMaxVgroupsPerDb
=
0
;
int32_t
tsMinTablePerVnode
=
TSDB_TABLES_STEP
;
int32_t
tsMaxTablePerVnode
=
TSDB_DEFAULT_TABLES
;
int32_t
tsTableIncStepPerVnode
=
TSDB_TABLES_STEP
;
int32_t
tsTsdbMetaCompactRatio
=
TSDB_META_COMPACT_RATIO
;
int32_t
tsTsdbMetaCompactRatio
=
TSDB_META_COMPACT_RATIO
;
// tsdb config
// tsdb config
...
@@ -736,37 +732,6 @@ static void doInitGlobalConfig(void) {
...
@@ -736,37 +732,6 @@ static void doInitGlobalConfig(void) {
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
taosInitConfigOption
(
cfg
);
// database configs
cfg
.
option
=
"maxTablesPerVnode"
;
cfg
.
ptr
=
&
tsMaxTablePerVnode
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_SHOW
;
cfg
.
minValue
=
TSDB_MIN_TABLES
;
cfg
.
maxValue
=
TSDB_MAX_TABLES
;
cfg
.
ptrLength
=
0
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"minTablesPerVnode"
;
cfg
.
ptr
=
&
tsMinTablePerVnode
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_SHOW
;
cfg
.
minValue
=
TSDB_MIN_TABLES
;
cfg
.
maxValue
=
TSDB_MAX_TABLES
;
cfg
.
ptrLength
=
0
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"tableIncStepPerVnode"
;
cfg
.
ptr
=
&
tsTableIncStepPerVnode
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_SHOW
;
cfg
.
minValue
=
TSDB_MIN_TABLES
;
cfg
.
maxValue
=
TSDB_MAX_TABLES
;
cfg
.
ptrLength
=
0
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"cache"
;
cfg
.
option
=
"cache"
;
cfg
.
ptr
=
&
tsCacheBlockSize
;
cfg
.
ptr
=
&
tsCacheBlockSize
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
...
@@ -877,16 +842,6 @@ static void doInitGlobalConfig(void) {
...
@@ -877,16 +842,6 @@ static void doInitGlobalConfig(void) {
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"partitions"
;
cfg
.
ptr
=
&
tsPartitons
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT16
;
cfg
.
cfgType
=
TSDB_CFG_CTYPE_B_CONFIG
|
TSDB_CFG_CTYPE_B_SHOW
;
cfg
.
minValue
=
TSDB_MIN_DB_PARTITON_OPTION
;
cfg
.
maxValue
=
TSDB_MAX_DB_PARTITON_OPTION
;
cfg
.
ptrLength
=
0
;
cfg
.
unitType
=
TAOS_CFG_UTYPE_NONE
;
taosInitConfigOption
(
cfg
);
cfg
.
option
=
"quorum"
;
cfg
.
option
=
"quorum"
;
cfg
.
ptr
=
&
tsQuorum
;
cfg
.
ptr
=
&
tsQuorum
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
cfg
.
valType
=
TAOS_CFG_VTYPE_INT32
;
...
@@ -1704,12 +1659,6 @@ int32_t taosCheckGlobalCfg() {
...
@@ -1704,12 +1659,6 @@ int32_t taosCheckGlobalCfg() {
}
}
}
}
if
(
tsMaxTablePerVnode
<
tsMinTablePerVnode
)
{
uError
(
"maxTablesPerVnode(%d) < minTablesPerVnode(%d), reset to minTablesPerVnode(%d)"
,
tsMaxTablePerVnode
,
tsMinTablePerVnode
,
tsMinTablePerVnode
);
tsMaxTablePerVnode
=
tsMinTablePerVnode
;
}
// todo refactor
// todo refactor
tsVersion
=
0
;
tsVersion
=
0
;
for
(
int
ver
=
0
,
i
=
0
;
i
<
TSDB_VERSION_LEN
;
++
i
)
{
for
(
int
ver
=
0
,
i
=
0
;
i
<
TSDB_VERSION_LEN
;
++
i
)
{
...
@@ -1738,24 +1687,6 @@ int32_t taosCheckGlobalCfg() {
...
@@ -1738,24 +1687,6 @@ int32_t taosCheckGlobalCfg() {
return
0
;
return
0
;
}
}
int
taosGetFqdnPortFromEp
(
const
char
*
ep
,
char
*
fqdn
,
uint16_t
*
port
)
{
*
port
=
0
;
strcpy
(
fqdn
,
ep
);
char
*
temp
=
strchr
(
fqdn
,
':'
);
if
(
temp
)
{
*
temp
=
0
;
*
port
=
atoi
(
temp
+
1
);
}
if
(
*
port
==
0
)
{
*
port
=
tsServerPort
;
return
-
1
;
}
return
0
;
}
/*
/*
* alter dnode 1 balance "vnode:1-dnode:2"
* alter dnode 1 balance "vnode:1-dnode:2"
*/
*/
...
...
source/dnode/mgmt/impl/src/dndMnode.c
浏览文件 @
7fea9e2f
...
@@ -366,7 +366,7 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
...
@@ -366,7 +366,7 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
memcpy
(
&
pOption
->
replicas
,
pMgmt
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
memcpy
(
&
pOption
->
replicas
,
pMgmt
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
}
}
static
int32_t
dndBuildMnodeOptionFromMsg
(
SDnode
*
pDnode
,
SMnodeOpt
*
pOption
,
SCreateMnodeMsg
*
pMsg
)
{
static
int32_t
dndBuildMnodeOptionFromMsg
(
SDnode
*
pDnode
,
SMnodeOpt
*
pOption
,
SCreateMnode
In
Msg
*
pMsg
)
{
dndInitMnodeOption
(
pDnode
,
pOption
);
dndInitMnodeOption
(
pDnode
,
pOption
);
pOption
->
dnodeId
=
dndGetDnodeId
(
pDnode
);
pOption
->
dnodeId
=
dndGetDnodeId
(
pDnode
);
pOption
->
clusterId
=
dndGetClusterId
(
pDnode
);
pOption
->
clusterId
=
dndGetClusterId
(
pDnode
);
...
@@ -488,8 +488,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
...
@@ -488,8 +488,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
return
0
;
return
0
;
}
}
static
SCreateMnodeMsg
*
dndParseCreateMnodeMsg
(
SRpcMsg
*
pRpcMsg
)
{
static
SCreateMnode
In
Msg
*
dndParseCreateMnodeMsg
(
SRpcMsg
*
pRpcMsg
)
{
SCreateMnodeMsg
*
pMsg
=
pRpcMsg
->
pCont
;
SCreateMnode
In
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
for
(
int32_t
i
=
0
;
i
<
pMsg
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pMsg
->
replica
;
++
i
)
{
pMsg
->
replicas
[
i
].
id
=
htonl
(
pMsg
->
replicas
[
i
].
id
);
pMsg
->
replicas
[
i
].
id
=
htonl
(
pMsg
->
replicas
[
i
].
id
);
...
@@ -500,7 +500,7 @@ static SCreateMnodeMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
...
@@ -500,7 +500,7 @@ static SCreateMnodeMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
}
}
static
int32_t
dndProcessCreateMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
static
int32_t
dndProcessCreateMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
SCreateMnodeMsg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
->
pCont
);
SCreateMnode
In
Msg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
->
pCont
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
...
@@ -516,7 +516,7 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
...
@@ -516,7 +516,7 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
static
int32_t
dndProcessAlterMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
static
int32_t
dndProcessAlterMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
SAlterMnodeMsg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
->
pCont
);
SAlterMnode
In
Msg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
->
pCont
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
...
@@ -531,7 +531,8 @@ static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
...
@@ -531,7 +531,8 @@ static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
static
int32_t
dndProcessDropMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
static
int32_t
dndProcessDropMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
SDropMnodeMsg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
->
pCont
);
SDropMnodeInMsg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
...
...
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
7fea9e2f
...
@@ -65,11 +65,9 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
...
@@ -65,11 +65,9 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_USE_DB
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_USE_DB
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_ALTER_DB
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_ALTER_DB
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_SYNC_DB
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_SYNC_DB
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CREATE_TOPIC
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_COMPACT_DB
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_DROP_TOPIC
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_ALTER_TOPIC
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CREATE_FUNCTION
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CREATE_FUNCTION
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_
ALTER
_FUNCTION
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_
RETRIEVE
_FUNCTION
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_DROP_FUNCTION
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_DROP_FUNCTION
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CREATE_STABLE
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CREATE_STABLE
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_ALTER_STABLE
]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_ALTER_STABLE
]
=
dndProcessMnodeWriteMsg
;
...
@@ -81,8 +79,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
...
@@ -81,8 +79,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_HEARTBEAT
]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_HEARTBEAT
]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_SHOW
]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_SHOW
]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_SHOW_RETRIEVE
]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_SHOW_RETRIEVE
]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC
]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_COMPACT_VNODE
]
=
dndProcessMnodeWriteMsg
;
// message from client to dnode
// message from client to dnode
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_NETWORK_TEST
]
=
dndProcessDnodeReq
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_NETWORK_TEST
]
=
dndProcessDnodeReq
;
...
...
source/dnode/mgmt/impl/test/CMakeLists.txt
浏览文件 @
7fea9e2f
add_subdirectory
(
acct
)
# add_subdirectory(acct)
add_subdirectory
(
cluster
)
# add_subdirectory(cluster)
add_subdirectory
(
profile
)
# add_subdirectory(profile)
add_subdirectory
(
show
)
# add_subdirectory(show)
add_subdirectory
(
user
)
source/dnode/mgmt/impl/test/cluster/cluster.cpp
浏览文件 @
7fea9e2f
...
@@ -93,21 +93,21 @@ TEST_F(DndTestCluster, ShowCluster) {
...
@@ -93,21 +93,21 @@ TEST_F(DndTestCluster, ShowCluster) {
EXPECT_EQ
(
pMeta
->
suid
,
0
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
SSchema
*
pSchema
=
NULL
;
SSchema
*
pSchema
=
NULL
;
pSchema
=
&
pMeta
->
s
chema
[
0
];
pSchema
=
&
pMeta
->
pS
chema
[
0
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"id"
);
EXPECT_STREQ
(
pSchema
->
name
,
"id"
);
pSchema
=
&
pMeta
->
s
chema
[
1
];
pSchema
=
&
pMeta
->
pS
chema
[
1
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_CLUSTER_ID_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_CLUSTER_ID_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"name"
);
EXPECT_STREQ
(
pSchema
->
name
,
"name"
);
pSchema
=
&
pMeta
->
s
chema
[
2
];
pSchema
=
&
pMeta
->
pS
chema
[
2
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
...
...
source/dnode/mgmt/impl/test/profile/profile.cpp
浏览文件 @
7fea9e2f
...
@@ -152,49 +152,49 @@ TEST_F(DndTestProfile, SConnectMsg_03) {
...
@@ -152,49 +152,49 @@ TEST_F(DndTestProfile, SConnectMsg_03) {
EXPECT_EQ
(
pMeta
->
suid
,
0
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
SSchema
*
pSchema
=
NULL
;
SSchema
*
pSchema
=
NULL
;
pSchema
=
&
pMeta
->
s
chema
[
0
];
pSchema
=
&
pMeta
->
pS
chema
[
0
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
pSchema
=
&
pMeta
->
s
chema
[
1
];
pSchema
=
&
pMeta
->
pS
chema
[
1
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"user"
);
EXPECT_STREQ
(
pSchema
->
name
,
"user"
);
pSchema
=
&
pMeta
->
s
chema
[
2
];
pSchema
=
&
pMeta
->
pS
chema
[
2
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"program"
);
EXPECT_STREQ
(
pSchema
->
name
,
"program"
);
pSchema
=
&
pMeta
->
s
chema
[
3
];
pSchema
=
&
pMeta
->
pS
chema
[
3
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"pid"
);
EXPECT_STREQ
(
pSchema
->
name
,
"pid"
);
pSchema
=
&
pMeta
->
s
chema
[
4
];
pSchema
=
&
pMeta
->
pS
chema
[
4
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_IPv4ADDR_LEN
+
6
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_IPv4ADDR_LEN
+
6
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"ip:port"
);
EXPECT_STREQ
(
pSchema
->
name
,
"ip:port"
);
pSchema
=
&
pMeta
->
s
chema
[
5
];
pSchema
=
&
pMeta
->
pS
chema
[
5
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
bytes
,
8
);
EXPECT_EQ
(
pSchema
->
bytes
,
8
);
EXPECT_STREQ
(
pSchema
->
name
,
"login_time"
);
EXPECT_STREQ
(
pSchema
->
name
,
"login_time"
);
pSchema
=
&
pMeta
->
s
chema
[
6
];
pSchema
=
&
pMeta
->
pS
chema
[
6
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
...
@@ -493,28 +493,28 @@ TEST_F(DndTestProfile, SKillQueryMsg_03) {
...
@@ -493,28 +493,28 @@ TEST_F(DndTestProfile, SKillQueryMsg_03) {
EXPECT_EQ
(
pMeta
->
suid
,
0
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
SSchema
*
pSchema
=
NULL
;
SSchema
*
pSchema
=
NULL
;
pSchema
=
&
pMeta
->
s
chema
[
0
];
pSchema
=
&
pMeta
->
pS
chema
[
0
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"queryId"
);
EXPECT_STREQ
(
pSchema
->
name
,
"queryId"
);
pSchema
=
&
pMeta
->
s
chema
[
1
];
pSchema
=
&
pMeta
->
pS
chema
[
1
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
pSchema
=
&
pMeta
->
s
chema
[
2
];
pSchema
=
&
pMeta
->
pS
chema
[
2
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"user"
);
EXPECT_STREQ
(
pSchema
->
name
,
"user"
);
pSchema
=
&
pMeta
->
s
chema
[
3
];
pSchema
=
&
pMeta
->
pS
chema
[
3
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
...
@@ -680,21 +680,21 @@ TEST_F(DndTestProfile, SKillStreamMsg_03) {
...
@@ -680,21 +680,21 @@ TEST_F(DndTestProfile, SKillStreamMsg_03) {
EXPECT_EQ
(
pMeta
->
suid
,
0
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
SSchema
*
pSchema
=
NULL
;
SSchema
*
pSchema
=
NULL
;
pSchema
=
&
pMeta
->
s
chema
[
0
];
pSchema
=
&
pMeta
->
pS
chema
[
0
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"streamId"
);
EXPECT_STREQ
(
pSchema
->
name
,
"streamId"
);
pSchema
=
&
pMeta
->
s
chema
[
1
];
pSchema
=
&
pMeta
->
pS
chema
[
1
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
pSchema
=
&
pMeta
->
s
chema
[
2
];
pSchema
=
&
pMeta
->
pS
chema
[
2
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
...
...
source/dnode/mgmt/impl/test/show/show.cpp
浏览文件 @
7fea9e2f
...
@@ -154,49 +154,49 @@ TEST_F(DndTestShow, SShowMsg_04) {
...
@@ -154,49 +154,49 @@ TEST_F(DndTestShow, SShowMsg_04) {
EXPECT_EQ
(
pMeta
->
suid
,
0
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
SSchema
*
pSchema
=
NULL
;
SSchema
*
pSchema
=
NULL
;
pSchema
=
&
pMeta
->
s
chema
[
0
];
pSchema
=
&
pMeta
->
pS
chema
[
0
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
EXPECT_STREQ
(
pSchema
->
name
,
"connId"
);
pSchema
=
&
pMeta
->
s
chema
[
1
];
pSchema
=
&
pMeta
->
pS
chema
[
1
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"user"
);
EXPECT_STREQ
(
pSchema
->
name
,
"user"
);
pSchema
=
&
pMeta
->
s
chema
[
2
];
pSchema
=
&
pMeta
->
pS
chema
[
2
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"program"
);
EXPECT_STREQ
(
pSchema
->
name
,
"program"
);
pSchema
=
&
pMeta
->
s
chema
[
3
];
pSchema
=
&
pMeta
->
pS
chema
[
3
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"pid"
);
EXPECT_STREQ
(
pSchema
->
name
,
"pid"
);
pSchema
=
&
pMeta
->
s
chema
[
4
];
pSchema
=
&
pMeta
->
pS
chema
[
4
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_IPv4ADDR_LEN
+
6
+
VARSTR_HEADER_SIZE
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_IPv4ADDR_LEN
+
6
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"ip:port"
);
EXPECT_STREQ
(
pSchema
->
name
,
"ip:port"
);
pSchema
=
&
pMeta
->
s
chema
[
5
];
pSchema
=
&
pMeta
->
pS
chema
[
5
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
bytes
,
8
);
EXPECT_EQ
(
pSchema
->
bytes
,
8
);
EXPECT_STREQ
(
pSchema
->
name
,
"login_time"
);
EXPECT_STREQ
(
pSchema
->
name
,
"login_time"
);
pSchema
=
&
pMeta
->
s
chema
[
6
];
pSchema
=
&
pMeta
->
pS
chema
[
6
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
...
...
source/dnode/mgmt/impl/test/sut/deploy.cpp
浏览文件 @
7fea9e2f
...
@@ -34,7 +34,6 @@ void initLog(const char* path) {
...
@@ -34,7 +34,6 @@ void initLog(const char* path) {
sDebugFlag
=
0
;
sDebugFlag
=
0
;
tsdbDebugFlag
=
0
;
tsdbDebugFlag
=
0
;
cqDebugFlag
=
0
;
cqDebugFlag
=
0
;
debugFlag
=
0
;
char
temp
[
PATH_MAX
];
char
temp
[
PATH_MAX
];
snprintf
(
temp
,
PATH_MAX
,
"%s/taosdlog"
,
path
);
snprintf
(
temp
,
PATH_MAX
,
"%s/taosdlog"
,
path
);
...
...
source/dnode/mgmt/impl/test/user/CMakeLists.txt
0 → 100644
浏览文件 @
7fea9e2f
add_executable
(
dndTestUser
""
)
target_sources
(
dndTestUser
PRIVATE
"user.cpp"
"../sut/deploy.cpp"
)
target_link_libraries
(
dndTestUser
PUBLIC dnode
PUBLIC util
PUBLIC os
PUBLIC gtest_main
)
target_include_directories
(
dndTestUser
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/server/dnode/mgmt"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../sut"
)
enable_testing
()
add_test
(
NAME dndTestUser
COMMAND dndTestUser
)
source/dnode/mgmt/impl/test/user/user.cpp
0 → 100644
浏览文件 @
7fea9e2f
/*
* 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/>.
*/
#include "deploy.h"
class
DndTestUser
:
public
::
testing
::
Test
{
protected:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
static
void
SetUpTestSuite
()
{
const
char
*
user
=
"root"
;
const
char
*
pass
=
"taosdata"
;
const
char
*
path
=
"/tmp/dndTestUser"
;
const
char
*
fqdn
=
"localhost"
;
uint16_t
port
=
9524
;
pServer
=
createServer
(
path
,
fqdn
,
port
);
ASSERT
(
pServer
);
pClient
=
createClient
(
user
,
pass
,
fqdn
,
port
);
}
static
void
TearDownTestSuite
()
{
dropServer
(
pServer
);
dropClient
(
pClient
);
}
static
SServer
*
pServer
;
static
SClient
*
pClient
;
static
int32_t
connId
;
};
SServer
*
DndTestUser
::
pServer
;
SClient
*
DndTestUser
::
pClient
;
int32_t
DndTestUser
::
connId
;
#if 0
TEST_F(DndTestUser, ShowUser) {
int32_t showId = 0;
//--- meta ---
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
pShow->type = TSDB_MGMT_TABLE_USER;
strcpy(pShow->db, "");
SRpcMsg showRpcMsg = {0};
showRpcMsg.pCont = pShow;
showRpcMsg.contLen = sizeof(SShowMsg);
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
sendMsg(pClient, &showRpcMsg);
ASSERT_NE(pClient->pRsp, nullptr);
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
ASSERT_NE(pShowRsp, nullptr);
pShowRsp->showId = htonl(pShowRsp->showId);
STableMetaMsg* pMeta = &pShowRsp->tableMeta;
pMeta->contLen = htonl(pMeta->contLen);
pMeta->numOfColumns = htons(pMeta->numOfColumns);
pMeta->sversion = htons(pMeta->sversion);
pMeta->tversion = htons(pMeta->tversion);
pMeta->tid = htonl(pMeta->tid);
pMeta->uid = htobe64(pMeta->uid);
pMeta->suid = htobe64(pMeta->suid);
showId = pShowRsp->showId;
EXPECT_NE(pShowRsp->showId, 0);
EXPECT_EQ(pMeta->contLen, 0);
EXPECT_STREQ(pMeta->tableFname, "show users");
EXPECT_EQ(pMeta->numOfTags, 0);
EXPECT_EQ(pMeta->precision, 0);
EXPECT_EQ(pMeta->tableType, 0);
EXPECT_EQ(pMeta->numOfColumns, 4);
EXPECT_EQ(pMeta->sversion, 0);
EXPECT_EQ(pMeta->tversion, 0);
EXPECT_EQ(pMeta->tid, 0);
EXPECT_EQ(pMeta->uid, 0);
EXPECT_STREQ(pMeta->sTableName, "");
EXPECT_EQ(pMeta->suid, 0);
SSchema* pSchema = NULL;
pSchema = &pMeta->pSchema[0];
pSchema->bytes = htons(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
EXPECT_STREQ(pSchema->name, "name");
pSchema = &pMeta->pSchema[1];
pSchema->bytes = htons(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
EXPECT_EQ(pSchema->bytes, 10 + VARSTR_HEADER_SIZE);
EXPECT_STREQ(pSchema->name, "privilege");
pSchema = &pMeta->pSchema[2];
pSchema->bytes = htons(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
EXPECT_EQ(pSchema->bytes, 8);
EXPECT_STREQ(pSchema->name, "create_time");
pSchema = &pMeta->pSchema[3];
pSchema->bytes = htons(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
EXPECT_STREQ(pSchema->name, "account");
//--- retrieve ---
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
pRetrieve->showId = htonl(showId);
pRetrieve->free = 0;
SRpcMsg retrieveRpcMsg = {0};
retrieveRpcMsg.pCont = pRetrieve;
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
sendMsg(pClient, &retrieveRpcMsg);
ASSERT_NE(pClient->pRsp, nullptr);
ASSERT_EQ(pClient->pRsp->code, 0);
SRetrieveTableRsp* pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
ASSERT_NE(pRetrieveRsp, nullptr);
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
EXPECT_EQ(pRetrieveRsp->numOfRows, 2);
EXPECT_EQ(pRetrieveRsp->offset, 0);
EXPECT_EQ(pRetrieveRsp->useconds, 0);
EXPECT_EQ(pRetrieveRsp->completed, 1);
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
EXPECT_EQ(pRetrieveRsp->compressed, 0);
EXPECT_EQ(pRetrieveRsp->reserved, 0);
EXPECT_EQ(pRetrieveRsp->compLen, 0);
char* pData = pRetrieveRsp->data;
int32_t pos = 0;
char* strVal = NULL;
int64_t int64Val = 0;
//--- name ---
{
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "root");
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "_root");
}
//--- privilege ---
{
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += 10;
EXPECT_STREQ(strVal, "super");
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += 10;
EXPECT_STREQ(strVal, "writable");
}
//--- create_time ---
{
int64Val = *((int64_t*)(pData + pos));
pos += sizeof(int64_t);
EXPECT_GT(int64Val, 0);
int64Val = *((int64_t*)(pData + pos));
pos += sizeof(int64_t);
EXPECT_GT(int64Val, 0);
}
//--- account ---
{
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "root");
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "root");
}
}
#endif
TEST_F
(
DndTestUser
,
CreateUser_01
)
{
ASSERT_NE
(
pClient
,
nullptr
);
//--- create user ---
SCreateUserMsg
*
pReq
=
(
SCreateUserMsg
*
)
rpcMallocCont
(
sizeof
(
SCreateUserMsg
));
strcpy
(
pReq
->
user
,
"u1"
);
strcpy
(
pReq
->
pass
,
"p1"
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SCreateUserMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_CREATE_USER
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
//--- meta ---
SShowMsg
*
pShow
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
));
pShow
->
type
=
TSDB_MGMT_TABLE_USER
;
SRpcMsg
showRpcMsg
=
{
0
};
showRpcMsg
.
pCont
=
pShow
;
showRpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
showRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
showRpcMsg
);
SShowRsp
*
pShowRsp
=
(
SShowRsp
*
)
pClient
->
pRsp
->
pCont
;
STableMetaMsg
*
pMeta
=
&
pShowRsp
->
tableMeta
;
pMeta
->
numOfColumns
=
htons
(
pMeta
->
numOfColumns
);
EXPECT_EQ
(
pMeta
->
numOfColumns
,
4
);
//--- retrieve ---
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableMsg
));
pRetrieve
->
showId
=
pShowRsp
->
showId
;
SRpcMsg
retrieveRpcMsg
=
{
0
};
retrieveRpcMsg
.
pCont
=
pRetrieve
;
retrieveRpcMsg
.
contLen
=
sizeof
(
SRetrieveTableMsg
);
retrieveRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
sendMsg
(
pClient
,
&
retrieveRpcMsg
);
SRetrieveTableRsp
*
pRetrieveRsp
=
(
SRetrieveTableRsp
*
)
pClient
->
pRsp
->
pCont
;
pRetrieveRsp
->
numOfRows
=
htonl
(
pRetrieveRsp
->
numOfRows
);
EXPECT_EQ
(
pRetrieveRsp
->
numOfRows
,
3
);
char
*
pData
=
pRetrieveRsp
->
data
;
int32_t
pos
=
0
;
char
*
strVal
=
NULL
;
//--- name ---
{
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"u1"
);
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"root"
);
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"_root"
);
}
}
TEST_F
(
DndTestUser
,
AlterUser_01
)
{
ASSERT_NE
(
pClient
,
nullptr
);
//--- drop user ---
SAlterUserMsg
*
pReq
=
(
SAlterUserMsg
*
)
rpcMallocCont
(
sizeof
(
SAlterUserMsg
));
strcpy
(
pReq
->
user
,
"u1"
);
strcpy
(
pReq
->
pass
,
"p2"
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SAlterUserMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_ALTER_USER
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
//--- meta ---
SShowMsg
*
pShow
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
));
pShow
->
type
=
TSDB_MGMT_TABLE_USER
;
SRpcMsg
showRpcMsg
=
{
0
};
showRpcMsg
.
pCont
=
pShow
;
showRpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
showRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
showRpcMsg
);
SShowRsp
*
pShowRsp
=
(
SShowRsp
*
)
pClient
->
pRsp
->
pCont
;
STableMetaMsg
*
pMeta
=
&
pShowRsp
->
tableMeta
;
pMeta
->
numOfColumns
=
htons
(
pMeta
->
numOfColumns
);
EXPECT_EQ
(
pMeta
->
numOfColumns
,
4
);
//--- retrieve ---
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableMsg
));
pRetrieve
->
showId
=
pShowRsp
->
showId
;
SRpcMsg
retrieveRpcMsg
=
{
0
};
retrieveRpcMsg
.
pCont
=
pRetrieve
;
retrieveRpcMsg
.
contLen
=
sizeof
(
SRetrieveTableMsg
);
retrieveRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
sendMsg
(
pClient
,
&
retrieveRpcMsg
);
SRetrieveTableRsp
*
pRetrieveRsp
=
(
SRetrieveTableRsp
*
)
pClient
->
pRsp
->
pCont
;
pRetrieveRsp
->
numOfRows
=
htonl
(
pRetrieveRsp
->
numOfRows
);
EXPECT_EQ
(
pRetrieveRsp
->
numOfRows
,
3
);
char
*
pData
=
pRetrieveRsp
->
data
;
int32_t
pos
=
0
;
char
*
strVal
=
NULL
;
//--- name ---
{
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"u1"
);
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"root"
);
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"_root"
);
}
}
TEST_F
(
DndTestUser
,
DropUser_01
)
{
ASSERT_NE
(
pClient
,
nullptr
);
//--- drop user ---
SDropUserMsg
*
pReq
=
(
SDropUserMsg
*
)
rpcMallocCont
(
sizeof
(
SDropUserMsg
));
strcpy
(
pReq
->
user
,
"u1"
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SDropUserMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_DROP_USER
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
//--- meta ---
SShowMsg
*
pShow
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
));
pShow
->
type
=
TSDB_MGMT_TABLE_USER
;
SRpcMsg
showRpcMsg
=
{
0
};
showRpcMsg
.
pCont
=
pShow
;
showRpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
showRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
showRpcMsg
);
SShowRsp
*
pShowRsp
=
(
SShowRsp
*
)
pClient
->
pRsp
->
pCont
;
STableMetaMsg
*
pMeta
=
&
pShowRsp
->
tableMeta
;
pMeta
->
numOfColumns
=
htons
(
pMeta
->
numOfColumns
);
EXPECT_EQ
(
pMeta
->
numOfColumns
,
4
);
//--- retrieve ---
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableMsg
));
pRetrieve
->
showId
=
pShowRsp
->
showId
;
SRpcMsg
retrieveRpcMsg
=
{
0
};
retrieveRpcMsg
.
pCont
=
pRetrieve
;
retrieveRpcMsg
.
contLen
=
sizeof
(
SRetrieveTableMsg
);
retrieveRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
sendMsg
(
pClient
,
&
retrieveRpcMsg
);
SRetrieveTableRsp
*
pRetrieveRsp
=
(
SRetrieveTableRsp
*
)
pClient
->
pRsp
->
pCont
;
pRetrieveRsp
->
numOfRows
=
htonl
(
pRetrieveRsp
->
numOfRows
);
EXPECT_EQ
(
pRetrieveRsp
->
numOfRows
,
2
);
char
*
pData
=
pRetrieveRsp
->
data
;
int32_t
pos
=
0
;
char
*
strVal
=
NULL
;
//--- name ---
{
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"root"
);
pos
+=
sizeof
(
VarDataLenT
);
strVal
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_USER_LEN
;
EXPECT_STREQ
(
strVal
,
"_root"
);
}
}
\ No newline at end of file
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
7fea9e2f
...
@@ -47,7 +47,6 @@ typedef struct SAcctObj SAcctObj;
...
@@ -47,7 +47,6 @@ typedef struct SAcctObj SAcctObj;
typedef
struct
SUserObj
SUserObj
;
typedef
struct
SUserObj
SUserObj
;
typedef
struct
SDbObj
SDbObj
;
typedef
struct
SDbObj
SDbObj
;
typedef
struct
SVgObj
SVgObj
;
typedef
struct
SVgObj
SVgObj
;
typedef
struct
SSTableObj
SSTableObj
;
typedef
struct
SFuncObj
SFuncObj
;
typedef
struct
SFuncObj
SFuncObj
;
typedef
struct
SOperObj
SOperObj
;
typedef
struct
SOperObj
SOperObj
;
...
@@ -195,7 +194,6 @@ typedef struct SUserObj {
...
@@ -195,7 +194,6 @@ typedef struct SUserObj {
typedef
struct
{
typedef
struct
{
int32_t
cacheBlockSize
;
int32_t
cacheBlockSize
;
int32_t
totalBlocks
;
int32_t
totalBlocks
;
int32_t
maxTables
;
int32_t
daysPerFile
;
int32_t
daysPerFile
;
int32_t
daysToKeep0
;
int32_t
daysToKeep0
;
int32_t
daysToKeep1
;
int32_t
daysToKeep1
;
...
@@ -204,102 +202,91 @@ typedef struct {
...
@@ -204,102 +202,91 @@ typedef struct {
int32_t
maxRowsPerFileBlock
;
int32_t
maxRowsPerFileBlock
;
int32_t
commitTime
;
int32_t
commitTime
;
int32_t
fsyncPeriod
;
int32_t
fsyncPeriod
;
int8_t
walLevel
;
int8_t
precision
;
int8_t
precision
;
int8_t
compression
;
int8_t
compression
;
int8_t
walLevel
;
int8_t
replications
;
int8_t
replications
;
int8_t
quorum
;
int8_t
quorum
;
int8_t
update
;
int8_t
update
;
int8_t
cacheLastRow
;
int8_t
cacheLastRow
;
int8_t
dbType
;
int16_t
partitions
;
}
SDbCfg
;
}
SDbCfg
;
typedef
struct
SDbObj
{
typedef
struct
SDbObj
{
char
name
[
TSDB_FULL_DB_NAME_LEN
];
char
name
[
TSDB_FULL_DB_NAME_LEN
];
char
acct
[
TSDB_USER_LEN
];
char
acct
[
TSDB_USER_LEN
];
int64_t
createdTime
;
int64_t
createdTime
;
int64_t
updateTime
;
int64_t
updateTime
;
SDbCfg
cfg
;
int64_t
uid
;
int64_t
uid
;
SDbCfg
cfg
;
int8_t
status
;
int32_t
numOfVgroups
;
int32_t
numOfTables
;
int32_t
numOfSuperTables
;
int32_t
vgListSize
;
int32_t
vgListIndex
;
SVgObj
**
vgList
;
SAcctObj
*
pAcct
;
}
SDbObj
;
}
SDbObj
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
int8_t
role
;
ESyncState
role
;
SDnodeObj
*
pDnode
;
}
SVnodeGid
;
}
SVnodeGid
;
typedef
struct
SVgObj
{
typedef
struct
SVgObj
{
uint32_t
vgId
;
int32_t
vgId
;
int32_t
numOfVnodes
;
int64_t
createdTime
;
int64_t
createdTime
;
int64_t
updateTime
;
int64_t
updateTime
;
int32_t
lbDnodeId
;
int32_t
version
;
int32_t
lbTime
;
char
dbName
[
TSDB_FULL_DB_NAME_LEN
];
char
dbName
[
TSDB_FULL_DB_NAME_LEN
];
int8_t
inUse
;
int8_t
accessState
;
int8_t
status
;
SVnodeGid
vnodeGid
[
TSDB_MAX_REPLICA
];
int32_t
vgCfgVersion
;
int8_t
compact
;
int32_t
numOfTables
;
int32_t
numOfTables
;
int32_t
numOfTimeSeries
;
int64_t
totalStorage
;
int64_t
totalStorage
;
int64_t
compStorage
;
int64_t
compStorage
;
int64_t
pointsWritten
;
int64_t
pointsWritten
;
SDbObj
*
pDb
;
int8_t
compact
;
int8_t
replica
;
SVnodeGid
vnodeGid
[
TSDB_MAX_REPLICA
];
}
SVgObj
;
}
SVgObj
;
typedef
struct
SS
T
ableObj
{
typedef
struct
SS
t
ableObj
{
char
tableId
[
TSDB_TABLE_
NAME_LEN
];
char
name
[
TSDB_TABLE_F
NAME_LEN
];
uint64_t
uid
;
char
db
[
TSDB_FULL_DB_NAME_LEN
]
;
int64_t
createdTime
;
int64_t
createdTime
;
int64_t
updateTime
;
int64_t
updateTime
;
int32_t
numOfColumns
;
// used by normal table
uint64_t
uid
;
int32_t
version
;
int32_t
numOfColumns
;
int32_t
numOfTags
;
int32_t
numOfTags
;
SSchema
*
schema
;
SRWLatch
lock
;
}
SSTableObj
;
SSchema
*
columnSchema
;
SSchema
*
tagSchema
;
}
SStableObj
;
typedef
struct
SFuncObj
{
typedef
struct
SFuncObj
{
char
name
[
TSDB_FUNC_NAME_LEN
];
char
name
[
TSDB_FUNC_NAME_LEN
];
char
path
[
128
];
int32_t
contLen
;
char
cont
[
TSDB_FUNC_CODE_LEN
];
int32_t
funcType
;
int32_t
bufSize
;
int64_t
createdTime
;
int64_t
createdTime
;
uint8_t
resType
;
int8_t
funcType
;
int16_t
resBytes
;
int8_t
scriptType
;
int64_t
sig
;
int8_t
align
;
int16_t
type
;
int8_t
outputType
;
int32_t
outputLen
;
int32_t
bufSize
;
int64_t
sigature
;
int32_t
commentSize
;
int32_t
codeSize
;
char
*
pComment
;
char
*
pCode
;
char
pData
[];
}
SFuncObj
;
}
SFuncObj
;
typedef
struct
SShowObj
SShowObj
;
typedef
struct
{
typedef
struct
SShowObj
{
int32_t
id
;
int8_t
type
;
int8_t
type
;
int8_t
maxReplica
;
int8_t
replica
;
int16_t
numOfColumns
;
int16_t
numOfColumns
;
int32_t
id
;
int32_t
rowSize
;
int32_t
rowSize
;
int32_t
numOfRows
;
int32_t
numOfRows
;
int32_t
numOfReads
;
int32_t
numOfReads
;
int32_t
payloadLen
;
uint16_t
payloadLen
;
void
*
pIter
;
void
*
pIter
;
SMnode
*
pMnode
;
void
*
pVgIter
;
char
db
[
TSDB_FULL_DB_NAME_LEN
];
SMnode
*
pMnode
;
int16_t
offset
[
TSDB_MAX_COLUMNS
];
char
db
[
TSDB_FULL_DB_NAME_LEN
];
int32_t
bytes
[
TSDB_MAX_COLUMNS
];
int16_t
offset
[
TSDB_MAX_COLUMNS
];
char
payload
[];
int32_t
bytes
[
TSDB_MAX_COLUMNS
];
char
payload
[];
}
SShowObj
;
}
SShowObj
;
typedef
struct
SMnodeMsg
{
typedef
struct
SMnodeMsg
{
...
@@ -318,6 +305,11 @@ typedef struct SMnodeMsg {
...
@@ -318,6 +305,11 @@ typedef struct SMnodeMsg {
void
*
pCont
;
void
*
pCont
;
}
SMnodeMsg
;
}
SMnodeMsg
;
typedef
struct
{
int32_t
id
;
void
*
rpcHandle
;
}
STransMsg
;
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/dnode/mnode/impl/inc/mndDnode.h
浏览文件 @
7fea9e2f
...
@@ -26,6 +26,8 @@ int32_t mndInitDnode(SMnode *pMnode);
...
@@ -26,6 +26,8 @@ int32_t mndInitDnode(SMnode *pMnode);
void
mndCleanupDnode
(
SMnode
*
pMnode
);
void
mndCleanupDnode
(
SMnode
*
pMnode
);
SDnodeObj
*
mndAcquireDnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
);
SDnodeObj
*
mndAcquireDnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
);
void
mndReleaseDnode
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
);
void
mndReleaseDnode
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
);
SEpSet
mndGetDnodeEpset
(
SDnodeObj
*
pDnode
);
int32_t
mndGetDnodeSize
(
SMnode
*
pMnode
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/impl/inc/mndInt.h
浏览文件 @
7fea9e2f
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "sdb.h"
#include "sdb.h"
#include "tcache.h"
#include "tcache.h"
#include "tqueue.h"
#include "tqueue.h"
#include "ttime.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
...
source/dnode/mnode/impl/inc/mndMnode.h
浏览文件 @
7fea9e2f
...
@@ -26,6 +26,7 @@ int32_t mndInitMnode(SMnode *pMnode);
...
@@ -26,6 +26,7 @@ int32_t mndInitMnode(SMnode *pMnode);
void
mndCleanupMnode
(
SMnode
*
pMnode
);
void
mndCleanupMnode
(
SMnode
*
pMnode
);
bool
mndIsMnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
);
bool
mndIsMnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
);
void
mndGetMnodeEpSet
(
SMnode
*
pMnode
,
SEpSet
*
pEpSet
);
void
mndGetMnodeEpSet
(
SMnode
*
pMnode
,
SEpSet
*
pEpSet
);
char
*
mndGetRoleStr
(
int32_t
role
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/impl/inc/mndOper.h
已删除
100644 → 0
浏览文件 @
7a2a6a7c
/*
* 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_MND_OPER_H_
#define _TD_MND_OPER_H_
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitOper
(
SMnode
*
pMnode
);
void
mndCleanupOper
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_OPER_H_*/
source/dnode/mnode/impl/inc/mndShow.h
浏览文件 @
7fea9e2f
...
@@ -28,6 +28,7 @@ void mndAddShowMetaHandle(SMnode *pMnode, EShowType showType, ShowMetaFp fp);
...
@@ -28,6 +28,7 @@ void mndAddShowMetaHandle(SMnode *pMnode, EShowType showType, ShowMetaFp fp);
void
mndAddShowRetrieveHandle
(
SMnode
*
pMnode
,
EShowType
showType
,
ShowRetrieveFp
fp
);
void
mndAddShowRetrieveHandle
(
SMnode
*
pMnode
,
EShowType
showType
,
ShowRetrieveFp
fp
);
void
mndAddShowFreeIterHandle
(
SMnode
*
pMnode
,
EShowType
msgType
,
ShowFreeIterFp
fp
);
void
mndAddShowFreeIterHandle
(
SMnode
*
pMnode
,
EShowType
msgType
,
ShowFreeIterFp
fp
);
void
mnodeVacuumResult
(
char
*
data
,
int32_t
numOfCols
,
int32_t
rows
,
int32_t
capacity
,
SShowObj
*
pShow
);
void
mnodeVacuumResult
(
char
*
data
,
int32_t
numOfCols
,
int32_t
rows
,
int32_t
capacity
,
SShowObj
*
pShow
);
char
*
mndShowStr
(
int32_t
showType
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/impl/inc/mndSync.h
浏览文件 @
7fea9e2f
...
@@ -25,7 +25,7 @@ extern "C" {
...
@@ -25,7 +25,7 @@ extern "C" {
int32_t
mndInitSync
(
SMnode
*
pMnode
);
int32_t
mndInitSync
(
SMnode
*
pMnode
);
void
mndCleanupSync
(
SMnode
*
pMnode
);
void
mndCleanupSync
(
SMnode
*
pMnode
);
bool
mndIsMaster
(
SMnode
*
pMnode
);
bool
mndIsMaster
(
SMnode
*
pMnode
);
int32_t
mndSyncPropose
(
S
SdbRaw
*
pRaw
,
void
*
pData
);
int32_t
mndSyncPropose
(
S
Mnode
*
pMnode
,
SSdbRaw
*
pRaw
,
STransMsg
*
pMsg
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/impl/inc/mndTrans.h
浏览文件 @
7fea9e2f
...
@@ -33,13 +33,10 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
...
@@ -33,13 +33,10 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
int32_t
mndTransPrepare
(
STrans
*
pTrans
,
int32_t
(
*
syncfp
)(
SSdbRaw
*
pRaw
,
void
*
pData
)
);
int32_t
mndTransPrepare
(
STrans
*
pTrans
);
int32_t
mndTransApply
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
void
*
pData
,
int32_t
code
);
void
mndTransApply
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
STransMsg
*
pMsg
,
int32_t
code
);
int32_t
mndTransExecute
(
SSdb
*
pSdb
,
int32_t
tranId
);
int32_t
mndTransExecute
(
SSdb
*
pSdb
,
int32_t
tranId
);
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
);
SSdbRow
*
mndTransActionDecode
(
SSdbRaw
*
pRaw
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/dnode/mnode/impl/inc/mndVgroup.h
浏览文件 @
7fea9e2f
...
@@ -24,6 +24,8 @@ extern "C" {
...
@@ -24,6 +24,8 @@ extern "C" {
int32_t
mndInitVgroup
(
SMnode
*
pMnode
);
int32_t
mndInitVgroup
(
SMnode
*
pMnode
);
void
mndCleanupVgroup
(
SMnode
*
pMnode
);
void
mndCleanupVgroup
(
SMnode
*
pMnode
);
SVgObj
*
mndAcquireVgroup
(
SMnode
*
pMnode
,
int32_t
vgId
);
void
mndReleaseVgroup
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/impl/src/mndAcct.c
浏览文件 @
7fea9e2f
...
@@ -24,7 +24,7 @@ static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct);
...
@@ -24,7 +24,7 @@ static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct);
static
SSdbRow
*
mnodeAcctActionDecode
(
SSdbRaw
*
pRaw
);
static
SSdbRow
*
mnodeAcctActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mnodeAcctActionInsert
(
SSdb
*
pSdb
,
SAcctObj
*
pAcct
);
static
int32_t
mnodeAcctActionInsert
(
SSdb
*
pSdb
,
SAcctObj
*
pAcct
);
static
int32_t
mnodeAcctActionDelete
(
SSdb
*
pSdb
,
SAcctObj
*
pAcct
);
static
int32_t
mnodeAcctActionDelete
(
SSdb
*
pSdb
,
SAcctObj
*
pAcct
);
static
int32_t
mnodeAcctActionUpdate
(
SSdb
*
pSdb
,
SAcctObj
*
p
SrcAcct
,
SAcctObj
*
pDst
Acct
);
static
int32_t
mnodeAcctActionUpdate
(
SSdb
*
pSdb
,
SAcctObj
*
p
OldAcct
,
SAcctObj
*
pNew
Acct
);
static
int32_t
mndProcessCreateAcctMsg
(
SMnodeMsg
*
pMnodeMsg
);
static
int32_t
mndProcessCreateAcctMsg
(
SMnodeMsg
*
pMnodeMsg
);
static
int32_t
mndProcessAlterAcctMsg
(
SMnodeMsg
*
pMnodeMsg
);
static
int32_t
mndProcessAlterAcctMsg
(
SMnodeMsg
*
pMnodeMsg
);
static
int32_t
mndProcessDropAcctMsg
(
SMnodeMsg
*
pMnodeMsg
);
static
int32_t
mndProcessDropAcctMsg
(
SMnodeMsg
*
pMnodeMsg
);
...
@@ -65,7 +65,7 @@ static int32_t mnodeCreateDefaultAcct(SMnode *pMnode) {
...
@@ -65,7 +65,7 @@ static int32_t mnodeCreateDefaultAcct(SMnode *pMnode) {
if
(
pRaw
==
NULL
)
return
-
1
;
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
m
Trace
(
"acct:%s, will be created while deploy sdb"
,
acctObj
.
acct
);
m
Debug
(
"acct:%s, will be created while deploy sdb"
,
acctObj
.
acct
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
}
...
@@ -131,15 +131,15 @@ static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
...
@@ -131,15 +131,15 @@ static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
return
0
;
return
0
;
}
}
static
int32_t
mnodeAcctActionUpdate
(
SSdb
*
pSdb
,
SAcctObj
*
p
SrcAcct
,
SAcctObj
*
pDst
Acct
)
{
static
int32_t
mnodeAcctActionUpdate
(
SSdb
*
pSdb
,
SAcctObj
*
p
OldAcct
,
SAcctObj
*
pNew
Acct
)
{
mTrace
(
"acct:%s, perform update action"
,
p
Src
Acct
->
acct
);
mTrace
(
"acct:%s, perform update action"
,
p
Old
Acct
->
acct
);
memcpy
(
p
SrcAcct
->
acct
,
pDst
Acct
->
acct
,
TSDB_USER_LEN
);
memcpy
(
p
OldAcct
->
acct
,
pNew
Acct
->
acct
,
TSDB_USER_LEN
);
p
SrcAcct
->
createdTime
=
pDst
Acct
->
createdTime
;
p
OldAcct
->
createdTime
=
pNew
Acct
->
createdTime
;
p
SrcAcct
->
updateTime
=
pDst
Acct
->
updateTime
;
p
OldAcct
->
updateTime
=
pNew
Acct
->
updateTime
;
p
SrcAcct
->
acctId
=
pDst
Acct
->
acctId
;
p
OldAcct
->
acctId
=
pNew
Acct
->
acctId
;
p
SrcAcct
->
status
=
pDst
Acct
->
status
;
p
OldAcct
->
status
=
pNew
Acct
->
status
;
p
SrcAcct
->
cfg
=
pDst
Acct
->
cfg
;
p
OldAcct
->
cfg
=
pNew
Acct
->
cfg
;
return
0
;
return
0
;
}
}
...
...
source/dnode/mnode/impl/src/mndCluster.c
浏览文件 @
7fea9e2f
...
@@ -24,7 +24,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
...
@@ -24,7 +24,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
static
SSdbRow
*
mndClusterActionDecode
(
SSdbRaw
*
pRaw
);
static
SSdbRow
*
mndClusterActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndClusterActionInsert
(
SSdb
*
pSdb
,
SClusterObj
*
pCluster
);
static
int32_t
mndClusterActionInsert
(
SSdb
*
pSdb
,
SClusterObj
*
pCluster
);
static
int32_t
mndClusterActionDelete
(
SSdb
*
pSdb
,
SClusterObj
*
pCluster
);
static
int32_t
mndClusterActionDelete
(
SSdb
*
pSdb
,
SClusterObj
*
pCluster
);
static
int32_t
mndClusterActionUpdate
(
SSdb
*
pSdb
,
SClusterObj
*
p
SrcCluster
,
SClusterObj
*
pDst
Cluster
);
static
int32_t
mndClusterActionUpdate
(
SSdb
*
pSdb
,
SClusterObj
*
p
OldCluster
,
SClusterObj
*
pNew
Cluster
);
static
int32_t
mndCreateDefaultCluster
(
SMnode
*
pMnode
);
static
int32_t
mndCreateDefaultCluster
(
SMnode
*
pMnode
);
static
int32_t
mndGetClusterMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndGetClusterMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveClusters
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
int32_t
mndRetrieveClusters
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
...
@@ -107,8 +107,8 @@ static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) {
...
@@ -107,8 +107,8 @@ static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) {
return
0
;
return
0
;
}
}
static
int32_t
mndClusterActionUpdate
(
SSdb
*
pSdb
,
SClusterObj
*
p
SrcCluster
,
SClusterObj
*
pDst
Cluster
)
{
static
int32_t
mndClusterActionUpdate
(
SSdb
*
pSdb
,
SClusterObj
*
p
OldCluster
,
SClusterObj
*
pNew
Cluster
)
{
mTrace
(
"cluster:%d, perform update action"
,
p
Src
Cluster
->
id
);
mTrace
(
"cluster:%d, perform update action"
,
p
Old
Cluster
->
id
);
return
0
;
return
0
;
}
}
...
@@ -132,13 +132,13 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
...
@@ -132,13 +132,13 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
if
(
pRaw
==
NULL
)
return
-
1
;
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
m
Trace
(
"cluster:%d, will be created while deploy sdb"
,
clusterObj
.
id
);
m
Debug
(
"cluster:%d, will be created while deploy sdb"
,
clusterObj
.
id
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
}
static
int32_t
mndGetClusterMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
static
int32_t
mndGetClusterMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
int32_t
cols
=
0
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
s
chema
;
SSchema
*
pSchema
=
pMeta
->
pS
chema
;
pShow
->
bytes
[
cols
]
=
4
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
7fea9e2f
...
@@ -15,16 +15,146 @@
...
@@ -15,16 +15,146 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "mndDb.h"
#include "mndDb.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndUser.h"
static
int32_t
mnodeProcessUseMsg
(
SMnodeMsg
*
pMsg
);
#define TSDB_DB_VER_NUM 1
#define TSDB_DB_RESERVE_SIZE 64
static
SSdbRaw
*
mndDbActionEncode
(
SDbObj
*
pDb
);
static
SSdbRow
*
mndDbActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndDbActionInsert
(
SSdb
*
pSdb
,
SDbObj
*
pDb
);
static
int32_t
mndDbActionDelete
(
SSdb
*
pSdb
,
SDbObj
*
pDb
);
static
int32_t
mndDbActionUpdate
(
SSdb
*
pSdb
,
SDbObj
*
pOldDb
,
SDbObj
*
pNewDb
);
static
int32_t
mndProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessUseDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessSyncDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCompactDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetDbMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveDbs
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextDb
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitDb
(
SMnode
*
pMnode
)
{
int32_t
mndInitDb
(
SMnode
*
pMnode
)
{
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_USE_DB
,
mnodeProcessUseMsg
);
SSdbTable
table
=
{.
sdbType
=
SDB_DB
,
return
0
;
.
keyType
=
SDB_KEY_BINARY
,
.
encodeFp
=
(
SdbEncodeFp
)
mndDbActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndDbActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndDbActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndDbActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndDbActionDelete
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_DB
,
mndProcessCreateDbMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_ALTER_DB
,
mndProcessAlterDbMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_DB
,
mndProcessDropDbMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_USE_DB
,
mndProcessUseDbMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_SYNC_DB
,
mndProcessSyncDbMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_COMPACT_DB
,
mndProcessCompactDbMsg
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_DB
,
mndGetDbMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_DB
,
mndRetrieveDbs
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_DB
,
mndCancelGetNextDb
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
}
void
mndCleanupDb
(
SMnode
*
pMnode
)
{}
void
mndCleanupDb
(
SMnode
*
pMnode
)
{}
static
SSdbRaw
*
mndDbActionEncode
(
SDbObj
*
pDb
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_DB
,
TSDB_DB_VER_NUM
,
sizeof
(
SDbObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pDb
->
name
,
TSDB_FULL_DB_NAME_LEN
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pDb
->
acct
,
TSDB_USER_LEN
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pDb
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pDb
->
updateTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pDb
->
uid
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
cacheBlockSize
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
totalBlocks
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
daysPerFile
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
daysToKeep0
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
daysToKeep1
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
daysToKeep2
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
minRowsPerFileBlock
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
maxRowsPerFileBlock
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
commitTime
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
fsyncPeriod
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
walLevel
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
precision
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
compression
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
replications
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
quorum
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
update
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
cacheLastRow
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_DB_RESERVE_SIZE
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
return
pRaw
;
}
static
SSdbRow
*
mndDbActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_DB_VER_NUM
)
{
mError
(
"failed to decode db since %s"
,
terrstr
());
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
return
NULL
;
}
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
SDbObj
));
SDbObj
*
pDb
=
sdbGetRowObj
(
pRow
);
if
(
pDb
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pDb
->
name
,
TSDB_FULL_DB_NAME_LEN
)
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pDb
->
acct
,
TSDB_USER_LEN
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
updateTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
uid
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
cacheBlockSize
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
totalBlocks
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
daysPerFile
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
daysToKeep0
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
daysToKeep1
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
daysToKeep2
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
minRowsPerFileBlock
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
maxRowsPerFileBlock
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
commitTime
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
fsyncPeriod
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
walLevel
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
precision
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
compression
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
replications
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
quorum
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
update
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
cacheLastRow
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_DB_RESERVE_SIZE
)
return
pRow
;
}
static
int32_t
mndDbActionInsert
(
SSdb
*
pSdb
,
SDbObj
*
pDb
)
{
mTrace
(
"db:%s, perform insert action"
,
pDb
->
name
);
return
0
;
}
static
int32_t
mndDbActionDelete
(
SSdb
*
pSdb
,
SDbObj
*
pDb
)
{
mTrace
(
"db:%s, perform delete action"
,
pDb
->
name
);
return
0
;
}
static
int32_t
mndDbActionUpdate
(
SSdb
*
pSdb
,
SDbObj
*
pOldDb
,
SDbObj
*
pNewDb
)
{
mTrace
(
"db:%s, perform update action"
,
pOldDb
->
name
);
memcpy
(
pOldDb
,
pNewDb
,
sizeof
(
SDbObj
));
return
0
;
}
SDbObj
*
mndAcquireDb
(
SMnode
*
pMnode
,
char
*
db
)
{
SDbObj
*
mndAcquireDb
(
SMnode
*
pMnode
,
char
*
db
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbAcquire
(
pSdb
,
SDB_DB
,
db
);
return
sdbAcquire
(
pSdb
,
SDB_DB
,
db
);
...
@@ -35,14 +165,459 @@ void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) {
...
@@ -35,14 +165,459 @@ void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) {
sdbRelease
(
pSdb
,
pDb
);
sdbRelease
(
pSdb
,
pDb
);
}
}
static
int32_t
mnodeProcessUseMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mndCheckDbCfg
(
SMnode
*
pMnode
,
SDbCfg
*
pCfg
)
{
if
(
pCfg
->
cacheBlockSize
<
TSDB_MIN_CACHE_BLOCK_SIZE
||
pCfg
->
cacheBlockSize
>
TSDB_MAX_CACHE_BLOCK_SIZE
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_CACHE_SIZE
;
return
-
1
;
}
if
(
pCfg
->
totalBlocks
<
TSDB_MIN_TOTAL_BLOCKS
||
pCfg
->
totalBlocks
>
TSDB_MAX_TOTAL_BLOCKS
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_TOTAL_BLOCKS
;
return
-
1
;
}
if
(
pCfg
->
daysPerFile
<
TSDB_MIN_DAYS_PER_FILE
||
pCfg
->
daysPerFile
>
TSDB_MAX_DAYS_PER_FILE
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_DAYS
;
return
-
1
;
}
if
(
pCfg
->
daysToKeep0
<
pCfg
->
daysPerFile
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_KEEP0
;
return
-
1
;
}
if
(
pCfg
->
daysToKeep0
<
TSDB_MIN_KEEP
||
pCfg
->
daysToKeep0
>
TSDB_MAX_KEEP
||
pCfg
->
daysToKeep0
>
pCfg
->
daysToKeep1
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_KEEP0
;
return
-
1
;
}
if
(
pCfg
->
daysToKeep1
<
TSDB_MIN_KEEP
||
pCfg
->
daysToKeep1
>
TSDB_MAX_KEEP
||
pCfg
->
daysToKeep1
>
pCfg
->
daysToKeep2
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_KEEP1
;
return
-
1
;
}
if
(
pCfg
->
daysToKeep2
<
TSDB_MIN_KEEP
||
pCfg
->
daysToKeep2
>
TSDB_MAX_KEEP
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_KEEP1
;
return
-
1
;
}
if
(
pCfg
->
minRowsPerFileBlock
<
TSDB_MIN_MIN_ROW_FBLOCK
||
pCfg
->
minRowsPerFileBlock
>
TSDB_MAX_MIN_ROW_FBLOCK
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_MIN_ROWS
;
return
-
1
;
}
if
(
pCfg
->
maxRowsPerFileBlock
<
TSDB_MIN_MAX_ROW_FBLOCK
||
pCfg
->
maxRowsPerFileBlock
>
TSDB_MAX_MAX_ROW_FBLOCK
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_MAX_ROWS
;
return
-
1
;
}
if
(
pCfg
->
minRowsPerFileBlock
>
pCfg
->
maxRowsPerFileBlock
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_MIN_ROWS
;
return
-
1
;
}
if
(
pCfg
->
commitTime
<
TSDB_MIN_COMMIT_TIME
||
pCfg
->
commitTime
>
TSDB_MAX_COMMIT_TIME
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_COMMIT_TIME
;
return
-
1
;
}
if
(
pCfg
->
fsyncPeriod
<
TSDB_MIN_FSYNC_PERIOD
||
pCfg
->
fsyncPeriod
>
TSDB_MAX_FSYNC_PERIOD
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_FSYNC_PERIOD
;
return
-
1
;
}
if
(
pCfg
->
walLevel
<
TSDB_MIN_WAL_LEVEL
||
pCfg
->
walLevel
>
TSDB_MAX_WAL_LEVEL
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_WAL_LEVEL
;
return
-
1
;
}
if
(
pCfg
->
precision
<
TSDB_MIN_PRECISION
&&
pCfg
->
precision
>
TSDB_MAX_PRECISION
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_PRECISION
;
return
-
1
;
}
if
(
pCfg
->
compression
<
TSDB_MIN_COMP_LEVEL
||
pCfg
->
compression
>
TSDB_MAX_COMP_LEVEL
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_COMP
;
return
-
1
;
}
if
(
pCfg
->
replications
<
TSDB_MIN_DB_REPLICA_OPTION
||
pCfg
->
replications
>
TSDB_MAX_DB_REPLICA_OPTION
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_REPLICA
;
return
-
1
;
}
if
(
pCfg
->
replications
>
mndGetDnodeSize
(
pMnode
))
{
terrno
=
TSDB_CODE_MND_INVALID_DB_REPLICA
;
return
-
1
;
}
if
(
pCfg
->
quorum
<
TSDB_MIN_DB_QUORUM_OPTION
||
pCfg
->
quorum
>
TSDB_MAX_DB_QUORUM_OPTION
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_QUORUM
;
return
-
1
;
}
if
(
pCfg
->
quorum
>
pCfg
->
replications
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_QUORUM
;
return
-
1
;
}
if
(
pCfg
->
update
<
TSDB_MIN_DB_UPDATE
||
pCfg
->
update
>
TSDB_MAX_DB_UPDATE
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_UPDATE
;
return
-
1
;
}
if
(
pCfg
->
cacheLastRow
<
TSDB_MIN_DB_CACHE_LAST_ROW
||
pCfg
->
cacheLastRow
>
TSDB_MAX_DB_CACHE_LAST_ROW
)
{
terrno
=
TSDB_CODE_MND_INVALID_DB_CACHE_LAST
;
return
-
1
;
}
return
TSDB_CODE_SUCCESS
;
}
static
void
mndSetDefaultDbCfg
(
SDbCfg
*
pCfg
)
{
if
(
pCfg
->
cacheBlockSize
<
0
)
pCfg
->
cacheBlockSize
=
TSDB_DEFAULT_CACHE_BLOCK_SIZE
;
if
(
pCfg
->
totalBlocks
<
0
)
pCfg
->
totalBlocks
=
TSDB_DEFAULT_TOTAL_BLOCKS
;
if
(
pCfg
->
daysPerFile
<
0
)
pCfg
->
daysPerFile
=
TSDB_DEFAULT_DAYS_PER_FILE
;
if
(
pCfg
->
daysToKeep0
<
0
)
pCfg
->
daysToKeep0
=
TSDB_DEFAULT_KEEP
;
if
(
pCfg
->
daysToKeep1
<
0
)
pCfg
->
daysToKeep1
=
TSDB_DEFAULT_KEEP
;
if
(
pCfg
->
daysToKeep2
<
0
)
pCfg
->
daysToKeep2
=
TSDB_DEFAULT_KEEP
;
if
(
pCfg
->
minRowsPerFileBlock
<
0
)
pCfg
->
minRowsPerFileBlock
=
TSDB_DEFAULT_MIN_ROW_FBLOCK
;
if
(
pCfg
->
maxRowsPerFileBlock
<
0
)
pCfg
->
maxRowsPerFileBlock
=
TSDB_DEFAULT_MAX_ROW_FBLOCK
;
if
(
pCfg
->
commitTime
<
0
)
pCfg
->
commitTime
=
TSDB_DEFAULT_COMMIT_TIME
;
if
(
pCfg
->
fsyncPeriod
<
0
)
pCfg
->
fsyncPeriod
=
TSDB_DEFAULT_FSYNC_PERIOD
;
if
(
pCfg
->
walLevel
<
0
)
pCfg
->
walLevel
=
TSDB_DEFAULT_WAL_LEVEL
;
if
(
pCfg
->
precision
<
0
)
pCfg
->
precision
=
TSDB_DEFAULT_PRECISION
;
if
(
pCfg
->
compression
<
0
)
pCfg
->
compression
=
TSDB_DEFAULT_COMP_LEVEL
;
if
(
pCfg
->
replications
<
0
)
pCfg
->
replications
=
TSDB_DEFAULT_DB_REPLICA_OPTION
;
if
(
pCfg
->
quorum
<
0
)
pCfg
->
quorum
=
TSDB_DEFAULT_DB_QUORUM_OPTION
;
if
(
pCfg
->
update
<
0
)
pCfg
->
update
=
TSDB_DEFAULT_DB_UPDATE_OPTION
;
if
(
pCfg
->
cacheLastRow
<
0
)
pCfg
->
cacheLastRow
=
TSDB_DEFAULT_CACHE_LAST_ROW
;
}
static
int32_t
mndCreateDb
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateDbMsg
*
pCreate
,
char
*
acct
)
{
SDbObj
dbObj
=
{
0
};
tstrncpy
(
dbObj
.
name
,
pCreate
->
db
,
TSDB_FULL_DB_NAME_LEN
);
tstrncpy
(
dbObj
.
acct
,
acct
,
TSDB_USER_LEN
);
dbObj
.
createdTime
=
taosGetTimestampMs
();
dbObj
.
updateTime
=
dbObj
.
createdTime
;
dbObj
.
uid
=
1234
;
dbObj
.
cfg
=
(
SDbCfg
){.
cacheBlockSize
=
pCreate
->
cacheBlockSize
,
.
totalBlocks
=
pCreate
->
totalBlocks
,
.
daysPerFile
=
pCreate
->
daysPerFile
,
.
daysToKeep0
=
pCreate
->
daysToKeep0
,
.
daysToKeep1
=
pCreate
->
daysToKeep1
,
.
daysToKeep2
=
pCreate
->
daysToKeep2
,
.
minRowsPerFileBlock
=
pCreate
->
minRowsPerFileBlock
,
.
maxRowsPerFileBlock
=
pCreate
->
maxRowsPerFileBlock
,
.
fsyncPeriod
=
pCreate
->
fsyncPeriod
,
.
commitTime
=
pCreate
->
commitTime
,
.
precision
=
pCreate
->
precision
,
.
compression
=
pCreate
->
compression
,
.
walLevel
=
pCreate
->
walLevel
,
.
replications
=
pCreate
->
replications
,
.
quorum
=
pCreate
->
quorum
,
.
update
=
pCreate
->
update
,
.
cacheLastRow
=
pCreate
->
cacheLastRow
};
mndSetDefaultDbCfg
(
&
dbObj
.
cfg
);
if
(
mndCheckDbCfg
(
pMnode
,
&
dbObj
.
cfg
)
!=
0
)
{
mError
(
"db:%s, failed to create since %s"
,
pCreate
->
db
,
terrstr
());
return
-
1
;
}
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"db:%s, failed to create since %s"
,
pCreate
->
db
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to create db:%s"
,
pTrans
->
id
,
pCreate
->
db
);
SSdbRaw
*
pRedoRaw
=
mndDbActionEncode
(
&
dbObj
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
);
SSdbRaw
*
pUndoRaw
=
mndDbActionEncode
(
&
dbObj
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
);
SSdbRaw
*
pCommitRaw
=
mndDbActionEncode
(
&
dbObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateDbMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
cacheBlockSize
=
htonl
(
pCreate
->
cacheBlockSize
);
pCreate
->
totalBlocks
=
htonl
(
pCreate
->
totalBlocks
);
pCreate
->
daysPerFile
=
htonl
(
pCreate
->
daysPerFile
);
pCreate
->
daysToKeep0
=
htonl
(
pCreate
->
daysToKeep0
);
pCreate
->
daysToKeep1
=
htonl
(
pCreate
->
daysToKeep1
);
pCreate
->
daysToKeep2
=
htonl
(
pCreate
->
daysToKeep2
);
pCreate
->
minRowsPerFileBlock
=
htonl
(
pCreate
->
minRowsPerFileBlock
);
pCreate
->
maxRowsPerFileBlock
=
htonl
(
pCreate
->
maxRowsPerFileBlock
);
pCreate
->
commitTime
=
htonl
(
pCreate
->
commitTime
);
pCreate
->
fsyncPeriod
=
htonl
(
pCreate
->
fsyncPeriod
);
mDebug
(
"db:%s, start to create"
,
pCreate
->
db
);
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pCreate
->
db
);
if
(
pDb
!=
NULL
)
{
sdbRelease
(
pMnode
->
pSdb
,
pDb
);
if
(
pCreate
->
ignoreExist
)
{
mDebug
(
"db:%s, already exist, ignore exist is set"
,
pCreate
->
db
);
return
0
;
}
else
{
terrno
=
TSDB_CODE_MND_DB_ALREADY_EXIST
;
mError
(
"db:%s, failed to create since %s"
,
pCreate
->
db
,
terrstr
());
return
-
1
;
}
}
SUserObj
*
pOperUser
=
mndAcquireUser
(
pMnode
,
pMsg
->
user
);
if
(
pOperUser
==
NULL
)
{
mError
(
"db:%s, failed to create since %s"
,
pCreate
->
db
,
terrstr
());
return
-
1
;
}
int32_t
code
=
mndCreateDb
(
pMnode
,
pMsg
,
pCreate
,
pOperUser
->
acct
);
mndReleaseUser
(
pMnode
,
pOperUser
);
if
(
code
!=
0
)
{
terrno
=
code
;
mError
(
"db:%s, failed to create since %s"
,
pCreate
->
db
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mnodeSetDbCfgFromAlterDbMsg
(
SDbObj
*
pDb
,
SAlterDbMsg
*
pAlter
)
{
bool
changed
=
false
;
if
(
pAlter
->
totalBlocks
>=
0
&&
pAlter
->
totalBlocks
!=
pDb
->
cfg
.
totalBlocks
)
{
pDb
->
cfg
.
totalBlocks
=
pAlter
->
totalBlocks
;
changed
=
true
;
}
if
(
pAlter
->
daysToKeep0
>=
0
&&
pAlter
->
daysToKeep0
!=
pDb
->
cfg
.
daysToKeep0
)
{
pDb
->
cfg
.
daysToKeep0
=
pAlter
->
daysToKeep0
;
changed
=
true
;
}
if
(
pAlter
->
daysToKeep1
>=
0
&&
pAlter
->
daysToKeep1
!=
pDb
->
cfg
.
daysToKeep1
)
{
pDb
->
cfg
.
daysToKeep1
=
pAlter
->
daysToKeep1
;
changed
=
true
;
}
if
(
pAlter
->
daysToKeep2
>=
0
&&
pAlter
->
daysToKeep2
!=
pDb
->
cfg
.
daysToKeep2
)
{
pDb
->
cfg
.
daysToKeep2
=
pAlter
->
daysToKeep2
;
changed
=
true
;
}
if
(
pAlter
->
fsyncPeriod
>=
0
&&
pAlter
->
fsyncPeriod
!=
pDb
->
cfg
.
fsyncPeriod
)
{
pDb
->
cfg
.
fsyncPeriod
=
pAlter
->
fsyncPeriod
;
changed
=
true
;
}
if
(
pAlter
->
walLevel
>=
0
&&
pAlter
->
walLevel
!=
pDb
->
cfg
.
walLevel
)
{
pDb
->
cfg
.
walLevel
=
pAlter
->
walLevel
;
changed
=
true
;
}
if
(
pAlter
->
quorum
>=
0
&&
pAlter
->
quorum
!=
pDb
->
cfg
.
quorum
)
{
pDb
->
cfg
.
quorum
=
pAlter
->
quorum
;
changed
=
true
;
}
if
(
pAlter
->
cacheLastRow
>=
0
&&
pAlter
->
cacheLastRow
!=
pDb
->
cfg
.
cacheLastRow
)
{
pDb
->
cfg
.
cacheLastRow
=
pAlter
->
cacheLastRow
;
changed
=
true
;
}
if
(
!
changed
)
{
terrno
=
TSDB_CODE_MND_DB_OPTION_UNCHANGED
;
return
-
1
;
}
return
0
;
}
static
int32_t
mndUpdateDb
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDbObj
*
pOldDb
,
SDbObj
*
pNewDb
)
{
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"db:%s, failed to update since %s"
,
pOldDb
->
name
,
terrstr
());
return
terrno
;
}
mDebug
(
"trans:%d, used to update db:%s"
,
pTrans
->
id
,
pOldDb
->
name
);
SSdbRaw
*
pRedoRaw
=
mndDbActionEncode
(
pNewDb
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pUndoRaw
=
mndDbActionEncode
(
pOldDb
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SAlterDbMsg
*
pAlter
=
pMsg
->
rpcMsg
.
pCont
;
pAlter
->
totalBlocks
=
htonl
(
pAlter
->
totalBlocks
);
pAlter
->
daysToKeep0
=
htonl
(
pAlter
->
daysToKeep0
);
pAlter
->
daysToKeep1
=
htonl
(
pAlter
->
daysToKeep1
);
pAlter
->
daysToKeep2
=
htonl
(
pAlter
->
daysToKeep2
);
pAlter
->
fsyncPeriod
=
htonl
(
pAlter
->
fsyncPeriod
);
mDebug
(
"db:%s, start to alter"
,
pAlter
->
db
);
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pAlter
->
db
);
if
(
pDb
==
NULL
)
{
mError
(
"db:%s, failed to alter since %s"
,
pAlter
->
db
,
terrstr
());
return
TSDB_CODE_MND_DB_NOT_EXIST
;
}
SDbObj
dbObj
=
{
0
};
memcpy
(
&
dbObj
,
pDb
,
sizeof
(
SDbObj
));
int32_t
code
=
mnodeSetDbCfgFromAlterDbMsg
(
&
dbObj
,
pAlter
);
if
(
code
!=
0
)
{
mndReleaseDb
(
pMnode
,
pDb
);
mError
(
"db:%s, failed to alter since %s"
,
pAlter
->
db
,
tstrerror
(
code
));
return
code
;
}
code
=
mndUpdateDb
(
pMnode
,
pMsg
,
pDb
,
&
dbObj
);
mndReleaseDb
(
pMnode
,
pDb
);
if
(
code
!=
0
)
{
mError
(
"db:%s, failed to alter since %s"
,
pAlter
->
db
,
tstrerror
(
code
));
return
code
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndDropDb
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDbObj
*
pDb
)
{
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"db:%s, failed to drop since %s"
,
pDb
->
name
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to drop db:%s"
,
pTrans
->
id
,
pDb
->
name
);
SSdbRaw
*
pRedoRaw
=
mndDbActionEncode
(
pDb
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
);
SSdbRaw
*
pUndoRaw
=
mndDbActionEncode
(
pDb
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pCommitRaw
=
mndDbActionEncode
(
pDb
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessDropDbMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SDropDbMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
mDebug
(
"db:%s, start to drop"
,
pDrop
->
db
);
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pDrop
->
db
);
if
(
pDb
==
NULL
)
{
if
(
pDrop
->
ignoreNotExists
)
{
mDebug
(
"db:%s, not exist, ignore not exist is set"
,
pDrop
->
db
);
return
TSDB_CODE_SUCCESS
;
}
else
{
terrno
=
TSDB_CODE_MND_DB_NOT_EXIST
;
mError
(
"db:%s, failed to drop since %s"
,
pDrop
->
db
,
terrstr
());
return
-
1
;
}
}
int32_t
code
=
mndDropDb
(
pMnode
,
pMsg
,
pDb
);
mndReleaseDb
(
pMnode
,
pDb
);
if
(
code
!=
0
)
{
terrno
=
code
;
mError
(
"db:%s, failed to drop since %s"
,
pDrop
->
db
,
terrstr
());
return
code
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessUseDbMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SUseDbMsg
*
pUse
=
pMsg
->
rpcMsg
.
pCont
;
SUseDbMsg
*
pUse
=
pMsg
->
rpcMsg
.
pCont
;
strncpy
(
pMsg
->
db
,
pUse
->
db
,
TSDB_FULL_DB_NAME_LEN
);
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pMsg
->
db
);
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pMsg
->
db
);
if
(
pDb
!=
NULL
)
{
if
(
pDb
!=
NULL
)
{
strncpy
(
pMsg
->
db
,
pUse
->
db
,
TSDB_FULL_DB_NAME_LEN
);
mndReleaseDb
(
pMnode
,
pDb
);
mndReleaseDb
(
pMnode
,
pDb
);
return
0
;
return
0
;
}
else
{
}
else
{
...
@@ -50,3 +625,275 @@ static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
...
@@ -50,3 +625,275 @@ static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) {
return
-
1
;
return
-
1
;
}
}
}
}
static
int32_t
mndProcessSyncDbMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSyncDbMsg
*
pSync
=
pMsg
->
rpcMsg
.
pCont
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pMsg
->
db
);
if
(
pDb
==
NULL
)
{
mError
(
"db:%s, failed to process sync db msg since %s"
,
pMsg
->
db
,
terrstr
());
return
-
1
;
}
else
{
mndReleaseDb
(
pMnode
,
pDb
);
return
0
;
}
}
static
int32_t
mndProcessCompactDbMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCompactDbMsg
*
pCompact
=
pMsg
->
rpcMsg
.
pCont
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
pMsg
->
db
);
if
(
pDb
==
NULL
)
{
mError
(
"db:%s, failed to process compact db msg since %s"
,
pMsg
->
db
,
terrstr
());
return
-
1
;
}
else
{
mndReleaseDb
(
pMnode
,
pDb
);
return
0
;
}
}
static
int32_t
mndGetDbMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
(
TSDB_DB_NAME_LEN
-
1
)
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"replica"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"quorum"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"days"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
24
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"keep0,keep1,keep2"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"cache(MB)"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"blocks"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"minrows"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"maxrows"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
1
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TINYINT
;
strcpy
(
pSchema
[
cols
].
name
,
"wallevel"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"fsync"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
1
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TINYINT
;
strcpy
(
pSchema
[
cols
].
name
,
"comp"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
1
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TINYINT
;
strcpy
(
pSchema
[
cols
].
name
,
"cachelast"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
3
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"precision"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
1
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TINYINT
;
strcpy
(
pSchema
[
cols
].
name
,
"update"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_DB
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
char
*
mnodeGetDbStr
(
char
*
src
)
{
char
*
pos
=
strstr
(
src
,
TS_PATH_DELIMITER
);
if
(
pos
!=
NULL
)
++
pos
;
return
pos
;
}
static
int32_t
mndRetrieveDbs
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SDbObj
*
pDb
=
NULL
;
char
*
pWrite
;
int32_t
cols
=
0
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_DB
,
pShow
->
pIter
,
(
void
**
)
&
pDb
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
name
=
mnodeGetDbStr
(
pDb
->
name
);
if
(
name
!=
NULL
)
{
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
name
,
pShow
->
bytes
[
cols
]);
}
else
{
STR_TO_VARSTR
(
pWrite
,
"NULL"
);
}
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pDb
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDb
->
cfg
.
replications
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDb
->
cfg
.
quorum
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDb
->
cfg
.
daysPerFile
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
tmp
[
128
]
=
{
0
};
if
(
pDb
->
cfg
.
daysToKeep0
>
pDb
->
cfg
.
daysToKeep1
||
pDb
->
cfg
.
daysToKeep0
>
pDb
->
cfg
.
daysToKeep2
)
{
sprintf
(
tmp
,
"%d,%d,%d"
,
pDb
->
cfg
.
daysToKeep1
,
pDb
->
cfg
.
daysToKeep2
,
pDb
->
cfg
.
daysToKeep0
);
}
else
{
sprintf
(
tmp
,
"%d,%d,%d"
,
pDb
->
cfg
.
daysToKeep0
,
pDb
->
cfg
.
daysToKeep1
,
pDb
->
cfg
.
daysToKeep2
);
}
STR_WITH_SIZE_TO_VARSTR
(
pWrite
,
tmp
,
strlen
(
tmp
));
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDb
->
cfg
.
cacheBlockSize
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDb
->
cfg
.
totalBlocks
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDb
->
cfg
.
minRowsPerFileBlock
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDb
->
cfg
.
maxRowsPerFileBlock
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int8_t
*
)
pWrite
=
pDb
->
cfg
.
walLevel
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDb
->
cfg
.
fsyncPeriod
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int8_t
*
)
pWrite
=
pDb
->
cfg
.
compression
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int8_t
*
)
pWrite
=
pDb
->
cfg
.
cacheLastRow
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
prec
=
NULL
;
switch
(
pDb
->
cfg
.
precision
)
{
case
TSDB_TIME_PRECISION_MILLI
:
prec
=
TSDB_TIME_PRECISION_MILLI_STR
;
break
;
case
TSDB_TIME_PRECISION_MICRO
:
prec
=
TSDB_TIME_PRECISION_MICRO_STR
;
break
;
case
TSDB_TIME_PRECISION_NANO
:
prec
=
TSDB_TIME_PRECISION_NANO_STR
;
break
;
default:
assert
(
false
);
break
;
}
STR_WITH_SIZE_TO_VARSTR
(
pWrite
,
prec
,
2
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int8_t
*
)
pWrite
=
pDb
->
cfg
.
update
;
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pDb
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextDb
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndDnode.c
浏览文件 @
7fea9e2f
...
@@ -16,12 +16,17 @@
...
@@ -16,12 +16,17 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "mndDnode.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndMnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndTrans.h"
#include "ttime.h"
#include "ttime.h"
#include "tutil.h"
#define SDB_DNODE_VER 1
#define TSDB_DNODE_VER 1
#define TSDB_CONFIG_OPTION_LEN 16
#define TSDB_CONIIG_VALUE_LEN 48
#define TSDB_CONFIG_NUMBER 8
static
char
*
offlineReason
[]
=
{
static
c
onst
c
har
*
offlineReason
[]
=
{
""
,
""
,
"status msg timeout"
,
"status msg timeout"
,
"status not received"
,
"status not received"
,
...
@@ -36,8 +41,74 @@ static char *offlineReason[] = {
...
@@ -36,8 +41,74 @@ static char *offlineReason[] = {
"unknown"
,
"unknown"
,
};
};
static
const
char
*
dnodeStatus
[]
=
{
"offline"
,
"ready"
,
"creating"
,
"dropping"
};
static
int32_t
mndCreateDefaultDnode
(
SMnode
*
pMnode
);
static
SSdbRaw
*
mndDnodeActionEncode
(
SDnodeObj
*
pDnode
);
static
SSdbRow
*
mndDnodeActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndDnodeActionInsert
(
SSdb
*
pSdb
,
SDnodeObj
*
pDnode
);
static
int32_t
mndDnodeActionDelete
(
SSdb
*
pSdb
,
SDnodeObj
*
pDnode
);
static
int32_t
mndDnodeActionUpdate
(
SSdb
*
pSdb
,
SDnodeObj
*
pOldDnode
,
SDnodeObj
*
pNewDnode
);
static
int32_t
mndProcessCreateDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessConfigDnodeMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessConfigDnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessStatusMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetConfigMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveConfigs
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextConfig
(
SMnode
*
pMnode
,
void
*
pIter
);
static
int32_t
mndGetDnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveDnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextDnode
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitDnode
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_DNODE
,
.
keyType
=
SDB_KEY_INT32
,
.
deployFp
=
(
SdbDeployFp
)
mndCreateDefaultDnode
,
.
encodeFp
=
(
SdbEncodeFp
)
mndDnodeActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndDnodeActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndDnodeActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndDnodeActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndDnodeActionDelete
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_DNODE
,
mndProcessCreateDnodeMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_DNODE
,
mndProcessDropDnodeMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CONFIG_DNODE
,
mndProcessConfigDnodeMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP
,
mndProcessConfigDnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_STATUS
,
mndProcessStatusMsg
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_VARIABLES
,
mndGetConfigMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_VARIABLES
,
mndRetrieveConfigs
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_VARIABLES
,
mndCancelGetNextConfig
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_DNODE
,
mndGetDnodeMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_DNODE
,
mndRetrieveDnodes
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_DNODE
,
mndCancelGetNextDnode
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupDnode
(
SMnode
*
pMnode
)
{}
static
int32_t
mndCreateDefaultDnode
(
SMnode
*
pMnode
)
{
SDnodeObj
dnodeObj
=
{
0
};
dnodeObj
.
id
=
1
;
dnodeObj
.
createdTime
=
taosGetTimestampMs
();
dnodeObj
.
updateTime
=
dnodeObj
.
createdTime
;
dnodeObj
.
port
=
pMnode
->
replicas
[
0
].
port
;
memcpy
(
&
dnodeObj
.
fqdn
,
pMnode
->
replicas
[
0
].
fqdn
,
TSDB_FQDN_LEN
);
SSdbRaw
*
pRaw
=
mndDnodeActionEncode
(
&
dnodeObj
);
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
mDebug
(
"dnode:%d, will be created while deploy sdb"
,
dnodeObj
.
id
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
static
SSdbRaw
*
mndDnodeActionEncode
(
SDnodeObj
*
pDnode
)
{
static
SSdbRaw
*
mndDnodeActionEncode
(
SDnodeObj
*
pDnode
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_DNODE
,
SDB_DNODE_VER
,
sizeof
(
SDnodeObj
));
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_DNODE
,
T
SDB_DNODE_VER
,
sizeof
(
SDnodeObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
int32_t
dataPos
=
0
;
...
@@ -55,7 +126,7 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
...
@@ -55,7 +126,7 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
SDB_DNODE_VER
)
{
if
(
sver
!=
T
SDB_DNODE_VER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode dnode since %s"
,
terrstr
());
mError
(
"failed to decode dnode since %s"
,
terrstr
());
return
NULL
;
return
NULL
;
...
@@ -101,30 +172,30 @@ static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
...
@@ -101,30 +172,30 @@ static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
return
0
;
return
0
;
}
}
static
int32_t
mndDnodeActionUpdate
(
SSdb
*
pSdb
,
SDnodeObj
*
p
SrcDnode
,
SDnodeObj
*
pDst
Dnode
)
{
static
int32_t
mndDnodeActionUpdate
(
SSdb
*
pSdb
,
SDnodeObj
*
p
OldDnode
,
SDnodeObj
*
pNew
Dnode
)
{
mTrace
(
"dnode:%d, perform update action"
,
p
Src
Dnode
->
id
);
mTrace
(
"dnode:%d, perform update action"
,
p
Old
Dnode
->
id
);
p
SrcDnode
->
id
=
pDst
Dnode
->
id
;
p
OldDnode
->
id
=
pNew
Dnode
->
id
;
p
SrcDnode
->
createdTime
=
pDst
Dnode
->
createdTime
;
p
OldDnode
->
createdTime
=
pNew
Dnode
->
createdTime
;
p
SrcDnode
->
updateTime
=
pDst
Dnode
->
updateTime
;
p
OldDnode
->
updateTime
=
pNew
Dnode
->
updateTime
;
p
SrcDnode
->
port
=
pDst
Dnode
->
port
;
p
OldDnode
->
port
=
pNew
Dnode
->
port
;
memcpy
(
p
SrcDnode
->
fqdn
,
pDstDnode
->
fqdn
,
TSDB_FQDN_LEN
);
memcpy
(
p
OldDnode
->
fqdn
,
pNewDnode
->
fqdn
,
TSDB_FQDN_LEN
);
return
0
;
return
0
;
}
}
static
int32_t
mndCreateDefaultDnode
(
SMnode
*
pMnode
)
{
SDnodeObj
*
mndAcquireDnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
SDnodeObj
dnodeObj
=
{
0
};
SSdb
*
pSdb
=
pMnode
->
pSdb
;
dnodeObj
.
id
=
1
;
return
sdbAcquire
(
pSdb
,
SDB_DNODE
,
&
dnodeId
);
dnodeObj
.
createdTime
=
taosGetTimestampMs
();
}
dnodeObj
.
updateTime
=
dnodeObj
.
createdTime
;
dnodeObj
.
port
=
pMnode
->
replicas
[
0
].
port
;
memcpy
(
&
dnodeObj
.
fqdn
,
pMnode
->
replicas
[
0
].
fqdn
,
TSDB_FQDN_LEN
);
SSdbRaw
*
pRaw
=
mndDnodeActionEncode
(
&
dnodeObj
);
void
mndReleaseDnode
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
)
{
if
(
pRaw
==
NULL
)
return
-
1
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
sdbRelease
(
pSdb
,
pDnode
);
}
mTrace
(
"dnode:%d, will be created while deploy sdb"
,
dnodeObj
.
id
);
SEpSet
mndGetDnodeEpset
(
SDnodeObj
*
pDnode
)
{
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
SEpSet
epSet
=
{.
inUse
=
0
,
.
numOfEps
=
1
,
.
port
[
0
]
=
pDnode
->
port
};
memcpy
(
epSet
.
fqdn
[
0
],
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
return
epSet
;
}
}
static
SDnodeObj
*
mndAcquireDnodeByEp
(
SMnode
*
pMnode
,
char
*
pEpStr
)
{
static
SDnodeObj
*
mndAcquireDnodeByEp
(
SMnode
*
pMnode
,
char
*
pEpStr
)
{
...
@@ -145,7 +216,7 @@ static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
...
@@ -145,7 +216,7 @@ static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
return
NULL
;
return
NULL
;
}
}
static
int32_t
mndGetDnodeSize
(
SMnode
*
pMnode
)
{
int32_t
mndGetDnodeSize
(
SMnode
*
pMnode
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbGetSize
(
pSdb
,
SDB_DNODE
);
return
sdbGetSize
(
pSdb
,
SDB_DNODE
);
}
}
...
@@ -317,38 +388,385 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
...
@@ -317,38 +388,385 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
return
0
;
return
0
;
}
}
static
int32_t
mndProcessCreateDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndCreateDnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateDnodeMsg
*
pCreate
)
{
SDnodeObj
dnodeObj
=
{
0
};
dnodeObj
.
id
=
1
;
// todo
dnodeObj
.
createdTime
=
taosGetTimestampMs
();
dnodeObj
.
updateTime
=
dnodeObj
.
createdTime
;
taosGetFqdnPortFromEp
(
pCreate
->
ep
,
dnodeObj
.
fqdn
,
&
dnodeObj
.
port
);
static
int32_t
mndProcessDropDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
if
(
dnodeObj
.
fqdn
[
0
]
==
0
||
dnodeObj
.
port
<=
0
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
mError
(
"dnode:%s, failed to create since %s"
,
pCreate
->
ep
,
terrstr
());
return
terrno
;
}
static
int32_t
mndProcessConfigDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"dnode:%s, failed to create since %s"
,
pCreate
->
ep
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to create dnode:%s"
,
pTrans
->
id
,
pCreate
->
ep
);
int32_t
mndInitDnode
(
SMnode
*
pMnode
)
{
SSdbRaw
*
pRedoRaw
=
mndDnodeActionEncode
(
&
dnodeObj
);
SSdbTable
table
=
{.
sdbType
=
SDB_DNODE
,
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
.
keyType
=
SDB_KEY_INT32
,
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
.
deployFp
=
(
SdbDeployFp
)
mndCreateDefaultDnode
,
mndTransDrop
(
pTrans
);
.
encodeFp
=
(
SdbEncodeFp
)
mndDnodeActionEncode
,
return
-
1
;
.
decodeFp
=
(
SdbDecodeFp
)
mndDnodeActionDecode
,
}
.
insertFp
=
(
SdbInsertFp
)
mndDnodeActionInsert
,
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
);
.
updateFp
=
(
SdbUpdateFp
)
mndDnodeActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndDnodeActionDelete
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_DNODE
,
mndProcessCreateDnodeMsg
);
SSdbRaw
*
pUndoRaw
=
mndDnodeActionEncode
(
&
dnodeObj
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_DNODE
,
mndProcessDropDnodeMsg
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CONFIG_DNODE
,
mndProcessConfigDnodeMsg
);
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_STATUS
,
mndProcessStatusMsg
);
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
SSdbRaw
*
pCommitRaw
=
mndDnodeActionEncode
(
&
dnodeObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
}
void
mndCleanupDnode
(
SMnode
*
pMnode
)
{}
static
int32_t
mndProcessCreateDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateDnodeMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
SDnodeObj
*
mndAcquireDnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
mDebug
(
"dnode:%s, start to create"
,
pCreate
->
ep
);
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbAcquire
(
pSdb
,
SDB_DNODE
,
&
dnodeId
);
if
(
pCreate
->
ep
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
mError
(
"dnode:%s, failed to create since %s"
,
pCreate
->
ep
,
terrstr
());
return
-
1
;
}
SDnodeObj
*
pDnode
=
mndAcquireDnodeByEp
(
pMnode
,
pCreate
->
ep
);
if
(
pDnode
!=
NULL
)
{
mError
(
"dnode:%d, already exist"
,
pDnode
->
id
);
sdbRelease
(
pMnode
->
pSdb
,
pDnode
);
terrno
=
TSDB_CODE_MND_DNODE_ALREADY_EXIST
;
return
-
1
;
}
int32_t
code
=
mndCreateDnode
(
pMnode
,
pMsg
,
pCreate
);
if
(
code
!=
0
)
{
mError
(
"dnode:%s, failed to create since %s"
,
pCreate
->
ep
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
}
void
mndReleaseDnode
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
)
{
static
int32_t
mndDropDnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDnodeObj
*
pDnode
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
sdbRelease
(
pSdb
,
pDnode
);
if
(
pTrans
==
NULL
)
{
mError
(
"dnode:%d, failed to drop since %s"
,
pDnode
->
id
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to drop user:%d"
,
pTrans
->
id
,
pDnode
->
id
);
SSdbRaw
*
pRedoRaw
=
mndDnodeActionEncode
(
pDnode
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
);
SSdbRaw
*
pUndoRaw
=
mndDnodeActionEncode
(
pDnode
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pCommitRaw
=
mndDnodeActionEncode
(
pDnode
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
}
static
int32_t
mndProcessDropDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SDropDnodeMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
mDebug
(
"dnode:%d, start to drop"
,
pDrop
->
dnodeId
);
if
(
pDrop
->
dnodeId
<=
0
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
mError
(
"dnode:%d, failed to drop since %s"
,
pDrop
->
dnodeId
,
terrstr
());
return
-
1
;
}
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pDrop
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"dnode:%d, not exist"
,
pDrop
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndDropDnode
(
pMnode
,
pMsg
,
pDnode
);
if
(
code
!=
0
)
{
mError
(
"dnode:%d, failed to drop since %s"
,
pDrop
->
dnodeId
,
terrstr
());
return
-
1
;
}
sdbRelease
(
pMnode
->
pSdb
,
pDnode
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessConfigDnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCfgDnodeMsg
*
pCfg
=
pMsg
->
rpcMsg
.
pCont
;
pCfg
->
dnodeId
=
htonl
(
pCfg
->
dnodeId
);
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCfg
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
mError
(
"dnode:%d, failed to cfg since %s "
,
pCfg
->
dnodeId
,
terrstr
());
return
-
1
;
}
SEpSet
epSet
=
mndGetDnodeEpset
(
pDnode
);
mndReleaseDnode
(
pMnode
,
pDnode
);
SCfgDnodeMsg
*
pCfgDnode
=
rpcMallocCont
(
sizeof
(
SCfgDnodeMsg
));
pCfgDnode
->
dnodeId
=
htonl
(
pCfg
->
dnodeId
);
memcpy
(
pCfgDnode
->
config
,
pCfg
->
config
,
128
);
SRpcMsg
rpcMsg
=
{.
msgType
=
TSDB_MSG_TYPE_CONFIG_DNODE_IN
,
.
pCont
=
pCfgDnode
,
.
contLen
=
sizeof
(
SCfgDnodeMsg
)};
mInfo
(
"dnode:%d, is configured"
,
pCfg
->
dnodeId
);
mndSendMsgToDnode
(
pMnode
,
&
epSet
,
&
rpcMsg
);
return
0
;
}
static
int32_t
mndProcessConfigDnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mInfo
(
"cfg dnode rsp is received"
);
}
static
int32_t
mndGetConfigMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
TSDB_CONFIG_OPTION_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
tstrncpy
(
pSchema
[
cols
].
name
,
"name"
,
sizeof
(
pSchema
[
cols
].
name
));
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_CONIIG_VALUE_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
tstrncpy
(
pSchema
[
cols
].
name
,
"value"
,
sizeof
(
pSchema
[
cols
].
name
));
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
TSDB_CONFIG_NUMBER
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pIter
=
NULL
;
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveConfigs
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
int32_t
numOfRows
=
0
;
char
*
cfgOpts
[
TSDB_CONFIG_NUMBER
]
=
{
0
};
char
cfgVals
[
TSDB_CONFIG_NUMBER
][
TSDB_CONIIG_VALUE_LEN
+
1
]
=
{
0
};
char
*
pWrite
;
int32_t
cols
=
0
;
cfgOpts
[
numOfRows
]
=
"statusInterval"
;
snprintf
(
cfgVals
[
numOfRows
],
TSDB_CONIIG_VALUE_LEN
,
"%d"
,
pMnode
->
cfg
.
statusInterval
);
numOfRows
++
;
cfgOpts
[
numOfRows
]
=
"timezone"
;
snprintf
(
cfgVals
[
numOfRows
],
TSDB_CONIIG_VALUE_LEN
,
"%s"
,
pMnode
->
cfg
.
timezone
);
numOfRows
++
;
cfgOpts
[
numOfRows
]
=
"locale"
;
snprintf
(
cfgVals
[
numOfRows
],
TSDB_CONIIG_VALUE_LEN
,
"%s"
,
pMnode
->
cfg
.
locale
);
numOfRows
++
;
cfgOpts
[
numOfRows
]
=
"charset"
;
snprintf
(
cfgVals
[
numOfRows
],
TSDB_CONIIG_VALUE_LEN
,
"%s"
,
pMnode
->
cfg
.
charset
);
numOfRows
++
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
i
++
)
{
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
cfgOpts
[
i
],
TSDB_CONFIG_OPTION_LEN
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
cfgVals
[
i
],
TSDB_CONIIG_VALUE_LEN
);
cols
++
;
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextConfig
(
SMnode
*
pMnode
,
void
*
pIter
)
{}
static
int32_t
mndGetDnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"end point"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"vnodes"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"cores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
10
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"status"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
24
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"offline reason"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_DNODE
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveDnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_DNODE
,
pShow
->
pIter
,
(
void
**
)
&
pDnode
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
id
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pDnode
->
ep
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
numOfVnodes
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
numOfCores
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
const
char
*
status
=
dnodeStatus
[
pDnode
->
status
];
STR_TO_VARSTR
(
pWrite
,
status
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pDnode
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_TO_VARSTR
(
pWrite
,
offlineReason
[
pDnode
->
offlineReason
]);
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pDnode
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextDnode
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndFunc.c
浏览文件 @
7fea9e2f
...
@@ -14,8 +14,498 @@
...
@@ -14,8 +14,498 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndFunc.h"
#include "mndInt.h"
#include "mndShow.h"
#include "mndSync.h"
#include "mndTrans.h"
int32_t
mndInitFunc
(
SMnode
*
pMnode
)
{
return
0
;
}
#define SDB_FUNC_VER 1
void
mndCleanupFunc
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
static
SSdbRaw
*
mndFuncActionEncode
(
SFuncObj
*
pFunc
);
static
SSdbRow
*
mndFuncActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndFuncActionInsert
(
SSdb
*
pSdb
,
SFuncObj
*
pFunc
);
static
int32_t
mndFuncActionDelete
(
SSdb
*
pSdb
,
SFuncObj
*
pFunc
);
static
int32_t
mndFuncActionUpdate
(
SSdb
*
pSdb
,
SFuncObj
*
pOldFunc
,
SFuncObj
*
pNewFunc
);
static
int32_t
mndCreateFunc
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateFuncMsg
*
pCreate
);
static
int32_t
mndDropFunc
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SFuncObj
*
pFunc
);
static
int32_t
mndProcessCreateFuncMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropFuncMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessRetrieveFuncMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetFuncMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveFuncs
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextFunc
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitFunc
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_FUNC
,
.
keyType
=
SDB_KEY_BINARY
,
.
encodeFp
=
(
SdbEncodeFp
)
mndFuncActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndFuncActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndFuncActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndFuncActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndFuncActionDelete
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_FUNCTION
,
mndProcessCreateFuncMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_FUNCTION
,
mndProcessDropFuncMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_RETRIEVE_FUNCTION
,
mndProcessRetrieveFuncMsg
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_FUNCTION
,
mndGetFuncMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_FUNCTION
,
mndRetrieveFuncs
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_FUNCTION
,
mndCancelGetNextFunc
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupFunc
(
SMnode
*
pMnode
)
{}
static
SSdbRaw
*
mndFuncActionEncode
(
SFuncObj
*
pFunc
)
{
int32_t
size
=
pFunc
->
commentSize
+
pFunc
->
codeSize
+
sizeof
(
SFuncObj
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_FUNC
,
SDB_FUNC_VER
,
size
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pFunc
->
name
,
TSDB_FUNC_NAME_LEN
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pFunc
->
createdTime
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pFunc
->
funcType
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pFunc
->
scriptType
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pFunc
->
align
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pFunc
->
outputType
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pFunc
->
outputLen
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pFunc
->
bufSize
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pFunc
->
sigature
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pFunc
->
commentSize
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pFunc
->
codeSize
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pFunc
->
pComment
,
pFunc
->
commentSize
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pFunc
->
pCode
,
pFunc
->
codeSize
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
return
pRaw
;
}
static
SSdbRow
*
mndFuncActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
SDB_FUNC_VER
)
{
mError
(
"failed to decode func since %s"
,
terrstr
());
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
return
NULL
;
}
int32_t
size
=
sizeof
(
SFuncObj
)
+
TSDB_FUNC_COMMENT_LEN
+
TSDB_FUNC_CODE_LEN
;
SSdbRow
*
pRow
=
sdbAllocRow
(
size
);
SFuncObj
*
pFunc
=
sdbGetRowObj
(
pRow
);
if
(
pFunc
==
NULL
)
return
NULL
;
char
*
tmp
=
(
char
*
)
pFunc
+
sizeof
(
SFuncObj
);
int32_t
dataPos
=
0
;
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pFunc
->
name
,
TSDB_FUNC_NAME_LEN
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
createdTime
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
funcType
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
scriptType
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
align
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
outputType
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
outputLen
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
bufSize
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
sigature
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
commentSize
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pFunc
->
codeSize
)
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pFunc
->
pData
,
pFunc
->
commentSize
+
pFunc
->
codeSize
)
pFunc
->
pComment
=
pFunc
->
pData
;
pFunc
->
pCode
=
(
pFunc
->
pData
+
pFunc
->
commentSize
);
return
pRow
;
}
static
int32_t
mndFuncActionInsert
(
SSdb
*
pSdb
,
SFuncObj
*
pFunc
)
{
mTrace
(
"func:%s, perform insert action"
,
pFunc
->
name
);
return
0
;
}
static
int32_t
mndFuncActionDelete
(
SSdb
*
pSdb
,
SFuncObj
*
pFunc
)
{
mTrace
(
"func:%s, perform delete action"
,
pFunc
->
name
);
return
0
;
}
static
int32_t
mndFuncActionUpdate
(
SSdb
*
pSdb
,
SFuncObj
*
pOldFunc
,
SFuncObj
*
pNewFunc
)
{
mTrace
(
"func:%s, perform update action"
,
pOldFunc
->
name
);
return
0
;
}
static
int32_t
mndCreateFunc
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateFuncMsg
*
pCreate
)
{
SFuncObj
*
pFunc
=
calloc
(
1
,
sizeof
(
SFuncObj
)
+
pCreate
->
commentSize
+
pCreate
->
codeSize
);
pFunc
->
createdTime
=
taosGetTimestampMs
();
pFunc
->
funcType
=
pCreate
->
funcType
;
pFunc
->
scriptType
=
pCreate
->
scriptType
;
pFunc
->
outputType
=
pCreate
->
outputType
;
pFunc
->
outputLen
=
pCreate
->
outputLen
;
pFunc
->
bufSize
=
pCreate
->
bufSize
;
pFunc
->
sigature
=
pCreate
->
sigature
;
pFunc
->
commentSize
=
pCreate
->
commentSize
;
pFunc
->
codeSize
=
pCreate
->
codeSize
;
pFunc
->
pComment
=
pFunc
->
pData
;
memcpy
(
pFunc
->
pComment
,
pCreate
->
pCont
,
pCreate
->
commentSize
);
pFunc
->
pCode
=
pFunc
->
pData
+
pCreate
->
commentSize
;
memcpy
(
pFunc
->
pCode
,
pCreate
->
pCont
+
pCreate
->
commentSize
,
pFunc
->
codeSize
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
free
(
pFunc
);
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to create func:%s"
,
pTrans
->
id
,
pCreate
->
name
);
SSdbRaw
*
pRedoRaw
=
mndFuncActionEncode
(
pFunc
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
free
(
pFunc
);
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
);
SSdbRaw
*
pUndoRaw
=
mndFuncActionEncode
(
pFunc
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
free
(
pFunc
);
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
);
SSdbRaw
*
pCommitRaw
=
mndFuncActionEncode
(
pFunc
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
free
(
pFunc
);
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
free
(
pFunc
);
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndDropFunc
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SFuncObj
*
pFunc
)
{
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"func:%s, failed to drop since %s"
,
pFunc
->
name
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to drop user:%s"
,
pTrans
->
id
,
pFunc
->
name
);
SSdbRaw
*
pRedoRaw
=
mndFuncActionEncode
(
pFunc
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
);
SSdbRaw
*
pUndoRaw
=
mndFuncActionEncode
(
pFunc
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pCommitRaw
=
mndFuncActionEncode
(
pFunc
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessCreateFuncMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateFuncMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
outputLen
=
htonl
(
pCreate
->
outputLen
);
pCreate
->
bufSize
=
htonl
(
pCreate
->
bufSize
);
pCreate
->
sigature
=
htobe64
(
pCreate
->
sigature
);
pCreate
->
commentSize
=
htonl
(
pCreate
->
commentSize
);
pCreate
->
codeSize
=
htonl
(
pCreate
->
codeSize
);
mDebug
(
"func:%s, start to create"
,
pCreate
->
name
);
SFuncObj
*
pFunc
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_FUNC
,
pCreate
->
name
);
if
(
pFunc
!=
NULL
)
{
sdbRelease
(
pMnode
->
pSdb
,
pFunc
);
terrno
=
TSDB_CODE_MND_FUNC_ALREADY_EXIST
;
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
if
(
pCreate
->
name
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_FUNC_NAME
;
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
if
(
pCreate
->
commentSize
<=
0
||
pCreate
->
commentSize
>
TSDB_FUNC_COMMENT_LEN
)
{
terrno
=
TSDB_CODE_MND_INVALID_FUNC_COMMENT
;
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
if
(
pCreate
->
codeSize
<=
0
||
pCreate
->
codeSize
>
TSDB_FUNC_CODE_LEN
)
{
terrno
=
TSDB_CODE_MND_INVALID_FUNC_CODE
;
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
if
(
pCreate
->
pCont
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_FUNC_CODE
;
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
if
(
pCreate
->
bufSize
<
0
||
pCreate
->
bufSize
>
TSDB_FUNC_BUF_SIZE
)
{
terrno
=
TSDB_CODE_MND_INVALID_FUNC_BUFSIZE
;
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
int32_t
code
=
mndCreateFunc
(
pMnode
,
pMsg
,
pCreate
);
if
(
code
!=
0
)
{
mError
(
"func:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessDropFuncMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SDropFuncMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
mDebug
(
"func:%s, start to drop"
,
pDrop
->
name
);
if
(
pDrop
->
name
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_FUNC_NAME
;
mError
(
"func:%s, failed to drop since %s"
,
pDrop
->
name
,
terrstr
());
return
-
1
;
}
SFuncObj
*
pFunc
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_FUNC
,
pDrop
->
name
);
if
(
pFunc
==
NULL
)
{
terrno
=
TSDB_CODE_MND_FUNC_NOT_EXIST
;
mError
(
"func:%s, failed to drop since %s"
,
pDrop
->
name
,
terrstr
());
return
-
1
;
}
int32_t
code
=
mndDropFunc
(
pMnode
,
pMsg
,
pFunc
);
if
(
code
!=
0
)
{
mError
(
"func:%s, failed to drop since %s"
,
pDrop
->
name
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessRetrieveFuncMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SRetrieveFuncMsg
*
pRetrieve
=
pMsg
->
rpcMsg
.
pCont
;
pRetrieve
->
numOfFuncs
=
htonl
(
pRetrieve
->
numOfFuncs
);
int32_t
size
=
sizeof
(
SRetrieveFuncRsp
)
+
(
sizeof
(
SFuncInfo
)
+
TSDB_FUNC_CODE_LEN
)
*
pRetrieve
->
numOfFuncs
+
16384
;
SRetrieveFuncRsp
*
pRetrieveRsp
=
rpcMallocCont
(
size
);
pRetrieveRsp
->
numOfFuncs
=
htonl
(
pRetrieve
->
numOfFuncs
);
char
*
pOutput
=
pRetrieveRsp
->
pFuncInfos
;
for
(
int32_t
i
=
0
;
i
<
pRetrieve
->
numOfFuncs
;
++
i
)
{
char
funcName
[
TSDB_FUNC_NAME_LEN
]
=
{
0
};
memcpy
(
funcName
,
pRetrieve
->
pFuncNames
+
i
*
TSDB_FUNC_NAME_LEN
,
TSDB_FUNC_NAME_LEN
);
SFuncObj
*
pFunc
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_FUNC
,
funcName
);
if
(
pFunc
==
NULL
)
{
terrno
=
TSDB_CODE_MND_INVALID_FUNC
;
mError
(
"func:%s, failed to retrieve since %s"
,
funcName
,
terrstr
());
return
-
1
;
}
SFuncInfo
*
pFuncInfo
=
(
SFuncInfo
*
)
pOutput
;
strncpy
(
pFuncInfo
->
name
,
pFunc
->
name
,
TSDB_FUNC_NAME_LEN
);
pFuncInfo
->
funcType
=
pFunc
->
funcType
;
pFuncInfo
->
scriptType
=
pFunc
->
scriptType
;
pFuncInfo
->
outputType
=
pFunc
->
outputType
;
pFuncInfo
->
outputLen
=
htonl
(
pFunc
->
outputLen
);
pFuncInfo
->
bufSize
=
htonl
(
pFunc
->
bufSize
);
pFuncInfo
->
sigature
=
htobe64
(
pFunc
->
sigature
);
pFuncInfo
->
commentSize
=
htonl
(
pFunc
->
commentSize
);
pFuncInfo
->
codeSize
=
htonl
(
pFunc
->
codeSize
);
memcpy
(
pFuncInfo
->
pCont
,
pFunc
->
pCode
,
pFunc
->
commentSize
+
pFunc
->
codeSize
);
pOutput
+=
sizeof
(
SFuncInfo
)
+
pFunc
->
commentSize
+
pFunc
->
codeSize
;
}
pMsg
->
pCont
=
pRetrieveRsp
;
pMsg
->
contLen
=
(
int32_t
)(
pOutput
-
(
char
*
)
pRetrieveRsp
);
return
0
;
}
static
int32_t
mndGetFuncMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
TSDB_FUNC_NAME_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
PATH_MAX
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"comment"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"aggregate"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_TYPE_STR_MAX_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"outputtype"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"code_len"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"bufsize"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_FUNC
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
"show funcs"
);
return
0
;
}
static
void
*
mnodeGenTypeStr
(
char
*
buf
,
int32_t
buflen
,
uint8_t
type
,
int16_t
len
)
{
char
*
msg
=
"unknown"
;
if
(
type
>=
sizeof
(
tDataTypes
)
/
sizeof
(
tDataTypes
[
0
]))
{
return
msg
;
}
if
(
type
==
TSDB_DATA_TYPE_NCHAR
||
type
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
bytes
=
len
>
0
?
(
int
)(
len
-
VARSTR_HEADER_SIZE
)
:
len
;
snprintf
(
buf
,
buflen
-
1
,
"%s(%d)"
,
tDataTypes
[
type
].
name
,
type
==
TSDB_DATA_TYPE_NCHAR
?
bytes
/
4
:
bytes
);
buf
[
buflen
-
1
]
=
0
;
return
buf
;
}
return
tDataTypes
[
type
].
name
;
}
static
int32_t
mndRetrieveFuncs
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SFuncObj
*
pFunc
=
NULL
;
int32_t
cols
=
0
;
char
*
pWrite
;
char
buf
[
TSDB_TYPE_STR_MAX_LEN
];
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_FUNC
,
pShow
->
pIter
,
(
void
**
)
&
pFunc
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pFunc
->
name
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pFunc
->
pComment
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pFunc
->
funcType
==
TSDB_FUNC_TYPE_AGGREGATE
?
1
:
0
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
mnodeGenTypeStr
(
buf
,
TSDB_TYPE_STR_MAX_LEN
,
pFunc
->
outputType
,
pFunc
->
outputLen
),
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pFunc
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pFunc
->
codeSize
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pFunc
->
bufSize
;
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pFunc
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextFunc
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndMnode.c
浏览文件 @
7fea9e2f
...
@@ -14,10 +14,88 @@
...
@@ -14,10 +14,88 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "mndMnode.h"
#include "mndDnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndTrans.h"
#define SDB_MNODE_VER 1
#define SDB_MNODE_VER 1
static
int32_t
mndCreateDefaultMnode
(
SMnode
*
pMnode
);
static
SSdbRaw
*
mndMnodeActionEncode
(
SMnodeObj
*
pMnodeObj
);
static
SSdbRow
*
mndMnodeActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndMnodeActionInsert
(
SSdb
*
pSdb
,
SMnodeObj
*
pMnodeObj
);
static
int32_t
mndMnodeActionDelete
(
SSdb
*
pSdb
,
SMnodeObj
*
pMnodeObj
);
static
int32_t
mndMnodeActionUpdate
(
SSdb
*
pSdb
,
SMnodeObj
*
pOldMnode
,
SMnodeObj
*
pNewMnode
);
static
int32_t
mndProcessCreateMnodeMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropMnodeMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateMnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropMnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetMnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveMnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextMnode
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitMnode
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_MNODE
,
.
keyType
=
SDB_KEY_INT32
,
.
deployFp
=
(
SdbDeployFp
)
mndCreateDefaultMnode
,
.
encodeFp
=
(
SdbEncodeFp
)
mndMnodeActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndMnodeActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndMnodeActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndMnodeActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndMnodeActionDelete
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_MNODE
,
mndProcessCreateMnodeMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_MNODE
,
mndProcessDropMnodeMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP
,
mndProcessCreateMnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_MNODE_IN_RSP
,
mndProcessDropMnodeRsp
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_MNODE
,
mndGetMnodeMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_MNODE
,
mndRetrieveMnodes
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_MNODE
,
mndCancelGetNextMnode
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupMnode
(
SMnode
*
pMnode
)
{}
static
SMnodeObj
*
mndAcquireMnode
(
SMnode
*
pMnode
,
int32_t
mnodeId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbAcquire
(
pSdb
,
SDB_MNODE
,
&
mnodeId
);
}
static
void
mndReleaseMnode
(
SMnode
*
pMnode
,
SMnodeObj
*
pMnodeObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pMnodeObj
);
}
char
*
mndGetRoleStr
(
int32_t
showType
)
{
switch
(
showType
)
{
case
TAOS_SYNC_STATE_FOLLOWER
:
return
"unsynced"
;
case
TAOS_SYNC_STATE_CANDIDATE
:
return
"slave"
;
case
TAOS_SYNC_STATE_LEADER
:
return
"master"
;
default:
return
"undefined"
;
}
}
static
int32_t
mndCreateDefaultMnode
(
SMnode
*
pMnode
)
{
SMnodeObj
mnodeObj
=
{
0
};
mnodeObj
.
id
=
1
;
mnodeObj
.
createdTime
=
taosGetTimestampMs
();
mnodeObj
.
updateTime
=
mnodeObj
.
createdTime
;
SSdbRaw
*
pRaw
=
mndMnodeActionEncode
(
&
mnodeObj
);
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
mDebug
(
"mnode:%d, will be created while deploy sdb"
,
mnodeObj
.
id
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
static
SSdbRaw
*
mndMnodeActionEncode
(
SMnodeObj
*
pMnodeObj
)
{
static
SSdbRaw
*
mndMnodeActionEncode
(
SMnodeObj
*
pMnodeObj
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_MNODE
,
SDB_MNODE_VER
,
sizeof
(
SMnodeObj
));
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_MNODE
,
SDB_MNODE_VER
,
sizeof
(
SMnodeObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
if
(
pRaw
==
NULL
)
return
NULL
;
...
@@ -81,50 +159,14 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj) {
...
@@ -81,50 +159,14 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj) {
return
0
;
return
0
;
}
}
static
int32_t
mndMnodeActionUpdate
(
SSdb
*
pSdb
,
SMnodeObj
*
p
SrcMnode
,
SMnodeObj
*
pDst
Mnode
)
{
static
int32_t
mndMnodeActionUpdate
(
SSdb
*
pSdb
,
SMnodeObj
*
p
OldMnode
,
SMnodeObj
*
pNew
Mnode
)
{
mTrace
(
"mnode:%d, perform update action"
,
p
Src
Mnode
->
id
);
mTrace
(
"mnode:%d, perform update action"
,
p
Old
Mnode
->
id
);
p
SrcMnode
->
id
=
pDst
Mnode
->
id
;
p
OldMnode
->
id
=
pNew
Mnode
->
id
;
p
SrcMnode
->
createdTime
=
pDst
Mnode
->
createdTime
;
p
OldMnode
->
createdTime
=
pNew
Mnode
->
createdTime
;
p
SrcMnode
->
updateTime
=
pDst
Mnode
->
updateTime
;
p
OldMnode
->
updateTime
=
pNew
Mnode
->
updateTime
;
return
0
;
return
0
;
}
}
static
int32_t
mndCreateDefaultMnode
(
SMnode
*
pMnode
)
{
SMnodeObj
mnodeObj
=
{
0
};
mnodeObj
.
id
=
1
;
mnodeObj
.
createdTime
=
taosGetTimestampMs
();
mnodeObj
.
updateTime
=
mnodeObj
.
createdTime
;
SSdbRaw
*
pRaw
=
mndMnodeActionEncode
(
&
mnodeObj
);
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
mTrace
(
"mnode:%d, will be created while deploy sdb"
,
mnodeObj
.
id
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
static
int32_t
mndProcessCreateMnodeMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessDropMnodeMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
int32_t
mndInitMnode
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_MNODE
,
.
keyType
=
SDB_KEY_INT32
,
.
deployFp
=
(
SdbDeployFp
)
mndCreateDefaultMnode
,
.
encodeFp
=
(
SdbEncodeFp
)
mndMnodeActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndMnodeActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndMnodeActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndMnodeActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndMnodeActionDelete
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_MNODE
,
mndProcessCreateMnodeMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_MNODE
,
mndProcessDropMnodeMsg
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupMnode
(
SMnode
*
pMnode
)
{}
bool
mndIsMnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
bool
mndIsMnode
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
...
@@ -157,4 +199,271 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
...
@@ -157,4 +199,271 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
pEpSet
->
numOfEps
++
;
pEpSet
->
numOfEps
++
;
}
}
}
}
\ No newline at end of file
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateMnodeMsg
*
pCreate
)
{
SMnodeObj
mnodeObj
=
{
0
};
mnodeObj
.
id
=
1
;
// todo
mnodeObj
.
createdTime
=
taosGetTimestampMs
();
mnodeObj
.
updateTime
=
mnodeObj
.
createdTime
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"dnode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to create dnode:%d"
,
pTrans
->
id
,
pCreate
->
dnodeId
);
SSdbRaw
*
pRedoRaw
=
mndMnodeActionEncode
(
&
mnodeObj
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
);
SSdbRaw
*
pUndoRaw
=
mndMnodeActionEncode
(
&
mnodeObj
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
);
SSdbRaw
*
pCommitRaw
=
mndMnodeActionEncode
(
&
mnodeObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessCreateMnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateMnodeMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
mDebug
(
"mnode:%d, start to create"
,
pCreate
->
dnodeId
);
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"mnode:%d, dnode not exist"
,
pDnode
->
id
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
mndReleaseDnode
(
pMnode
,
pDnode
);
SMnodeObj
*
pMnodeObj
=
mndAcquireMnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pMnodeObj
!=
NULL
)
{
mError
(
"mnode:%d, mnode already exist"
,
pMnodeObj
->
id
);
terrno
=
TSDB_CODE_MND_MNODE_ALREADY_EXIST
;
return
-
1
;
}
int32_t
code
=
mndCreateMnode
(
pMnode
,
pMsg
,
pCreate
);
if
(
code
!=
0
)
{
mError
(
"mnode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndDropMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SMnodeObj
*
pMnodeObj
)
{
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"mnode:%d, failed to drop since %s"
,
pMnodeObj
->
id
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to drop user:%d"
,
pTrans
->
id
,
pMnodeObj
->
id
);
SSdbRaw
*
pRedoRaw
=
mndMnodeActionEncode
(
pMnodeObj
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
);
SSdbRaw
*
pUndoRaw
=
mndMnodeActionEncode
(
pMnodeObj
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pCommitRaw
=
mndMnodeActionEncode
(
pMnodeObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessDropMnodeMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SDropMnodeMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
mDebug
(
"mnode:%d, start to drop"
,
pDrop
->
dnodeId
);
if
(
pDrop
->
dnodeId
<=
0
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
mError
(
"mnode:%d, failed to drop since %s"
,
pDrop
->
dnodeId
,
terrstr
());
return
-
1
;
}
SMnodeObj
*
pMnodeObj
=
mndAcquireMnode
(
pMnode
,
pDrop
->
dnodeId
);
if
(
pMnodeObj
==
NULL
)
{
mError
(
"mnode:%d, not exist"
,
pDrop
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndDropMnode
(
pMnode
,
pMsg
,
pMnodeObj
);
if
(
code
!=
0
)
{
mError
(
"mnode:%d, failed to drop since %s"
,
pMnode
->
dnodeId
,
terrstr
());
return
-
1
;
}
sdbRelease
(
pMnode
->
pSdb
,
pMnode
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessCreateMnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessDropMnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndGetMnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"end point"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
12
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"role"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"role time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_MNODE
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveMnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SMnodeObj
*
pMnodeObj
=
NULL
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pShow
->
pIter
,
(
void
**
)
&
pMnodeObj
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pMnodeObj
->
id
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pMnodeObj
->
id
);
if
(
pDnode
!=
NULL
)
{
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pDnode
->
ep
,
pShow
->
bytes
[
cols
]);
}
else
{
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
"invalid ep"
,
pShow
->
bytes
[
cols
]);
}
mndReleaseDnode
(
pMnode
,
pDnode
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
roles
=
mndGetRoleStr
(
pMnodeObj
->
role
);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
roles
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pMnodeObj
->
roleTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pMnodeObj
->
createdTime
;
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pMnodeObj
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextMnode
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
source/dnode/mnode/impl/src/mndOper.c
已删除
100644 → 0
浏览文件 @
7a2a6a7c
/*
* 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 "mndInt.h"
int32_t
mndInitOper
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupOper
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mndProfile.c
浏览文件 @
7fea9e2f
...
@@ -467,7 +467,7 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
...
@@ -467,7 +467,7 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
mndReleaseUser
(
pMnode
,
pUser
);
mndReleaseUser
(
pMnode
,
pUser
);
int32_t
cols
=
0
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
s
chema
;
SSchema
*
pSchema
=
pMeta
->
pS
chema
;
pShow
->
bytes
[
cols
]
=
4
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
...
@@ -595,7 +595,7 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
...
@@ -595,7 +595,7 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
mndReleaseUser
(
pMnode
,
pUser
);
mndReleaseUser
(
pMnode
,
pUser
);
int32_t
cols
=
0
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
s
chema
;
SSchema
*
pSchema
=
pMeta
->
pS
chema
;
pShow
->
bytes
[
cols
]
=
4
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
...
@@ -811,7 +811,7 @@ static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
...
@@ -811,7 +811,7 @@ static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
mndReleaseUser
(
pMnode
,
pUser
);
mndReleaseUser
(
pMnode
,
pUser
);
int32_t
cols
=
0
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
s
chema
;
SSchema
*
pSchema
=
pMeta
->
pS
chema
;
pShow
->
bytes
[
cols
]
=
4
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
...
...
source/dnode/mnode/impl/src/mndShow.c
浏览文件 @
7fea9e2f
...
@@ -20,7 +20,6 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg);
...
@@ -20,7 +20,6 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg);
static
void
mndFreeShowObj
(
SShowObj
*
pShow
);
static
void
mndFreeShowObj
(
SShowObj
*
pShow
);
static
SShowObj
*
mndAcquireShowObj
(
SMnode
*
pMnode
,
int32_t
showId
);
static
SShowObj
*
mndAcquireShowObj
(
SMnode
*
pMnode
,
int32_t
showId
);
static
void
mndReleaseShowObj
(
SShowObj
*
pShow
,
bool
forceRemove
);
static
void
mndReleaseShowObj
(
SShowObj
*
pShow
,
bool
forceRemove
);
static
char
*
mndShowStr
(
int32_t
showType
);
static
int32_t
mndProcessShowMsg
(
SMnodeMsg
*
pMnodeMsg
);
static
int32_t
mndProcessShowMsg
(
SMnodeMsg
*
pMnodeMsg
);
static
int32_t
mndProcessRetrieveMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessRetrieveMsg
(
SMnodeMsg
*
pMsg
);
static
bool
mndCheckRetrieveFinished
(
SShowObj
*
pShow
);
static
bool
mndCheckRetrieveFinished
(
SShowObj
*
pShow
);
...
@@ -88,10 +87,6 @@ static void mndFreeShowObj(SShowObj *pShow) {
...
@@ -88,10 +87,6 @@ static void mndFreeShowObj(SShowObj *pShow) {
ShowFreeIterFp
freeFp
=
pMgmt
->
freeIterFps
[
pShow
->
type
];
ShowFreeIterFp
freeFp
=
pMgmt
->
freeIterFps
[
pShow
->
type
];
if
(
freeFp
!=
NULL
)
{
if
(
freeFp
!=
NULL
)
{
if
(
pShow
->
pVgIter
!=
NULL
)
{
// only used in 'show vnodes "ep"'
(
*
freeFp
)(
pMnode
,
pShow
->
pVgIter
);
}
if
(
pShow
->
pIter
!=
NULL
)
{
if
(
pShow
->
pIter
!=
NULL
)
{
(
*
freeFp
)(
pMnode
,
pShow
->
pIter
);
(
*
freeFp
)(
pMnode
,
pShow
->
pIter
);
}
}
...
@@ -259,7 +254,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
...
@@ -259,7 +254,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
char
*
mndShowStr
(
int32_t
showType
)
{
char
*
mndShowStr
(
int32_t
showType
)
{
switch
(
showType
)
{
switch
(
showType
)
{
case
TSDB_MGMT_TABLE_ACCT
:
case
TSDB_MGMT_TABLE_ACCT
:
return
"show accounts"
;
return
"show accounts"
;
...
@@ -275,7 +270,7 @@ static char *mndShowStr(int32_t showType) {
...
@@ -275,7 +270,7 @@ static char *mndShowStr(int32_t showType) {
return
"show mnodes"
;
return
"show mnodes"
;
case
TSDB_MGMT_TABLE_VGROUP
:
case
TSDB_MGMT_TABLE_VGROUP
:
return
"show vgroups"
;
return
"show vgroups"
;
case
TSDB_MGMT_TABLE_
METRIC
:
case
TSDB_MGMT_TABLE_
STABLE
:
return
"show stables"
;
return
"show stables"
;
case
TSDB_MGMT_TABLE_MODULE
:
case
TSDB_MGMT_TABLE_MODULE
:
return
"show modules"
;
return
"show modules"
;
...
...
source/dnode/mnode/impl/src/mndStable.c
浏览文件 @
7fea9e2f
...
@@ -14,8 +14,414 @@
...
@@ -14,8 +14,414 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndStable.h"
#include "mndInt.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "mndDb.h"
#include "tname.h"
int32_t
mndInitStable
(
SMnode
*
pMnode
)
{
return
0
;
}
#define TSDB_STABLE_VER_NUM 1
void
mndCleanupStable
(
SMnode
*
pMnode
)
{}
#define TSDB_STABLE_RESERVE_SIZE 64
\ No newline at end of file
static
SSdbRaw
*
mndStableActionEncode
(
SStableObj
*
pStb
);
static
SSdbRow
*
mndStableActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndStableActionInsert
(
SSdb
*
pSdb
,
SStableObj
*
pStb
);
static
int32_t
mndStableActionDelete
(
SSdb
*
pSdb
,
SStableObj
*
pStb
);
static
int32_t
mndStableActionUpdate
(
SSdb
*
pSdb
,
SStableObj
*
pOldStb
,
SStableObj
*
pNewStb
);
static
int32_t
mndProcessCreateStableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterStableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropStableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateStableInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterStableInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropStableInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessStableMetaMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetStableMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveStables
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextStable
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitStable
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_STABLE
,
.
keyType
=
SDB_KEY_BINARY
,
.
encodeFp
=
(
SdbEncodeFp
)
mndStableActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndStableActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndStableActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndStableActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndStableActionDelete
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_STABLE
,
mndProcessCreateStableMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_ALTER_STABLE
,
mndProcessAlterStableMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_STABLE
,
mndProcessDropStableMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP
,
mndProcessCreateStableInRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP
,
mndProcessAlterStableInRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_STABLE_IN_RSP
,
mndProcessDropStableInRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_TABLE_META
,
mndProcessStableMetaMsg
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_STABLE
,
mndGetStableMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_STABLE
,
mndRetrieveStables
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_STABLE
,
mndCancelGetNextStable
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupStable
(
SMnode
*
pMnode
)
{}
static
SSdbRaw
*
mndStableActionEncode
(
SStableObj
*
pStb
)
{
int32_t
size
=
sizeof
(
SStableObj
)
+
(
pStb
->
numOfColumns
+
pStb
->
numOfTags
)
*
sizeof
(
SSchema
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_STABLE
,
TSDB_STABLE_VER_NUM
,
size
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pStb
->
name
,
TSDB_TABLE_NAME_LEN
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
updateTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
uid
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pStb
->
version
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
numOfColumns
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pStb
->
numOfTags
)
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfColumns
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
columnSchema
[
i
];
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSchema
->
type
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
colId
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
bytes
);
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
);
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
tagSchema
[
i
];
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSchema
->
type
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
colId
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
pSchema
->
bytes
);
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
);
}
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_STABLE_RESERVE_SIZE
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
return
pRaw
;
}
static
SSdbRow
*
mndStableActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_STABLE_VER_NUM
)
{
mError
(
"failed to decode stable since %s"
,
terrstr
());
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
return
NULL
;
}
int32_t
size
=
sizeof
(
SStableObj
)
+
TSDB_MAX_COLUMNS
*
sizeof
(
SSchema
);
SSdbRow
*
pRow
=
sdbAllocRow
(
size
);
SStableObj
*
pStb
=
sdbGetRowObj
(
pRow
);
if
(
pStb
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pStb
->
name
,
TSDB_TABLE_NAME_LEN
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pStb
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pStb
->
updateTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pStb
->
uid
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pStb
->
version
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pStb
->
numOfColumns
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pStb
->
numOfTags
)
pStb
->
columnSchema
=
calloc
(
pStb
->
numOfColumns
,
sizeof
(
SSchema
));
pStb
->
tagSchema
=
calloc
(
pStb
->
numOfTags
,
sizeof
(
SSchema
));
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfColumns
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
columnSchema
[
i
];
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pSchema
->
type
);
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pSchema
->
colId
);
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pSchema
->
bytes
);
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
);
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
&
pStb
->
tagSchema
[
i
];
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pSchema
->
type
);
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pSchema
->
colId
);
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pSchema
->
bytes
);
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
);
}
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_STABLE_RESERVE_SIZE
)
return
pRow
;
}
static
int32_t
mndStableActionInsert
(
SSdb
*
pSdb
,
SStableObj
*
pStb
)
{
mTrace
(
"stable:%s, perform insert action"
,
pStb
->
name
);
return
0
;
}
static
int32_t
mndStableActionDelete
(
SSdb
*
pSdb
,
SStableObj
*
pStb
)
{
mTrace
(
"stable:%s, perform delete action"
,
pStb
->
name
);
return
0
;
}
static
int32_t
mndStableActionUpdate
(
SSdb
*
pSdb
,
SStableObj
*
pOldStb
,
SStableObj
*
pNewStb
)
{
mTrace
(
"stable:%s, perform update action"
,
pOldStb
->
name
);
atomic_exchange_32
(
&
pOldStb
->
updateTime
,
pNewStb
->
updateTime
);
atomic_exchange_32
(
&
pOldStb
->
version
,
pNewStb
->
version
);
taosWLockLatch
(
&
pOldStb
->
lock
);
int32_t
numOfTags
=
pNewStb
->
numOfTags
;
int32_t
tagSize
=
numOfTags
*
sizeof
(
SSchema
);
int32_t
numOfColumns
=
pNewStb
->
numOfColumns
;
int32_t
columnSize
=
numOfColumns
*
sizeof
(
SSchema
);
if
(
pOldStb
->
numOfTags
<
numOfTags
)
{
pOldStb
->
tagSchema
=
malloc
(
tagSize
);
}
if
(
pOldStb
->
numOfColumns
<
numOfColumns
)
{
pOldStb
->
columnSchema
=
malloc
(
columnSize
);
}
memcpy
(
pOldStb
->
tagSchema
,
pNewStb
->
tagSchema
,
tagSize
);
memcpy
(
pOldStb
->
columnSchema
,
pNewStb
->
columnSchema
,
columnSize
);
taosWUnLockLatch
(
&
pOldStb
->
lock
);
return
0
;
}
SStableObj
*
mndAcquireStb
(
SMnode
*
pMnode
,
char
*
stbName
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbAcquire
(
pSdb
,
SDB_STABLE
,
stbName
);
}
void
mndReleaseStb
(
SMnode
*
pMnode
,
SStableObj
*
pStb
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pStb
);
}
static
int32_t
mndProcessCreateStableMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessCreateStableInRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessAlterStableMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessAlterStableInRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessDropStableMsg
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessDropStableInRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
SDbObj
*
mndGetDbByStbName
(
SMnode
*
pMnode
,
char
*
stbName
)
{
SName
name
=
{
0
};
tNameFromString
(
&
name
,
stbName
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
char
db
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
&
name
,
db
);
return
mndAcquireDb
(
pMnode
,
db
);
}
static
int32_t
mndProcessStableMetaMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SStableInfoMsg
*
pInfo
=
pMsg
->
rpcMsg
.
pCont
;
mDebug
(
"stable:%s, start to retrieve meta"
,
pInfo
->
name
);
SDbObj
*
pDb
=
mndGetDbByStbName
(
pMnode
,
pInfo
->
name
);
if
(
pDb
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
mError
(
"stable:%s, failed to retrieve meta since %s"
,
pInfo
->
name
,
terrstr
());
return
-
1
;
}
SStableObj
*
pStb
=
mndAcquireStb
(
pMnode
,
pInfo
->
name
);
if
(
pStb
==
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
terrno
=
TSDB_CODE_MND_INVALID_TABLE_NAME
;
mError
(
"stable:%s, failed to get meta since %s"
,
pInfo
->
name
,
terrstr
());
return
-
1
;
}
int32_t
contLen
=
sizeof
(
STableMetaMsg
)
+
(
pStb
->
numOfColumns
+
pStb
->
numOfTags
)
*
sizeof
(
SSchema
);
STableMetaMsg
*
pMeta
=
rpcMallocCont
(
contLen
);
if
(
pMeta
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"stable:%s, failed to get meta since %s"
,
pInfo
->
name
,
terrstr
());
return
-
1
;
}
memcpy
(
pMeta
->
stableFname
,
pStb
->
name
,
TSDB_TABLE_FNAME_LEN
);
pMeta
->
numOfTags
=
htonl
(
pStb
->
numOfTags
);
pMeta
->
numOfColumns
=
htonl
(
pStb
->
numOfColumns
);
pMeta
->
precision
=
pDb
->
cfg
.
precision
;
pMeta
->
tableType
=
TSDB_SUPER_TABLE
;
pMeta
->
update
=
pDb
->
cfg
.
update
;
pMeta
->
sversion
=
htonl
(
pStb
->
version
);
pMeta
->
suid
=
htonl
(
pStb
->
uid
);
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfColumns
;
++
i
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
i
];
SSchema
*
pColumn
=
&
pStb
->
columnSchema
[
i
];
memcpy
(
pSchema
->
name
,
pColumn
->
name
,
TSDB_COL_NAME_LEN
);
pSchema
->
type
=
pColumn
->
type
;
pSchema
->
colId
=
htonl
(
pColumn
->
colId
);
pSchema
->
bytes
=
htonl
(
pColumn
->
bytes
);
}
for
(
int32_t
i
=
0
;
i
<
pStb
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
i
+
pStb
->
numOfColumns
];
SSchema
*
pTag
=
&
pStb
->
tagSchema
[
i
];
memcpy
(
pSchema
->
name
,
pTag
->
name
,
TSDB_COL_NAME_LEN
);
pSchema
->
type
=
pTag
->
type
;
pSchema
->
colId
=
htons
(
pTag
->
colId
);
pSchema
->
bytes
=
htonl
(
pTag
->
bytes
);
}
pMsg
->
pCont
=
pMeta
;
pMsg
->
contLen
=
contLen
;
mDebug
(
"stable:%s, meta is retrieved, cols:%d tags:%d"
,
pInfo
->
name
,
pStb
->
numOfColumns
,
pStb
->
numOfTags
);
return
0
;
}
static
int32_t
mndGetNumOfStables
(
SMnode
*
pMnode
,
char
*
dbName
,
int32_t
*
pNumOfStables
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
dbName
);
if
(
pDb
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
return
-
1
;
}
int32_t
numOfStables
=
0
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SStableObj
*
pStb
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pStb
);
if
(
pIter
==
NULL
)
break
;
if
(
strcmp
(
pStb
->
db
,
dbName
)
==
0
)
{
numOfStables
++
;
}
sdbRelease
(
pSdb
,
pStb
);
}
*
pNumOfStables
=
numOfStables
;
return
0
;
}
static
int32_t
mndGetStableMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
if
(
mndGetNumOfStables
(
pMnode
,
pShow
->
db
,
&
pShow
->
numOfRows
)
!=
0
)
{
return
-
1
;
}
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"columns"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"tags"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
void
mnodeExtractTableName
(
char
*
tableId
,
char
*
name
)
{
int
pos
=
-
1
;
int
num
=
0
;
for
(
pos
=
0
;
tableId
[
pos
]
!=
0
;
++
pos
)
{
if
(
tableId
[
pos
]
==
'.'
)
num
++
;
if
(
num
==
2
)
break
;
}
if
(
num
==
2
)
{
strcpy
(
name
,
tableId
+
pos
+
1
);
}
}
static
int32_t
mndRetrieveStables
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SStableObj
*
pStb
=
NULL
;
int32_t
cols
=
0
;
char
*
pWrite
;
char
prefix
[
64
]
=
{
0
};
tstrncpy
(
prefix
,
pShow
->
db
,
64
);
strcat
(
prefix
,
TS_PATH_DELIMITER
);
int32_t
prefixLen
=
(
int32_t
)
strlen
(
prefix
);
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_STABLE
,
pShow
->
pIter
,
(
void
**
)
&
pStb
);
if
(
pShow
->
pIter
==
NULL
)
break
;
if
(
strncmp
(
pStb
->
name
,
prefix
,
prefixLen
)
!=
0
)
{
sdbRelease
(
pSdb
,
pStb
);
continue
;
}
cols
=
0
;
char
stableName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
memcpy
(
stableName
,
pStb
->
name
+
prefixLen
,
TSDB_TABLE_FNAME_LEN
-
prefixLen
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_TO_VARSTR
(
pWrite
,
stableName
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pStb
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pStb
->
numOfColumns
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pStb
->
numOfTags
;
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pStb
);
}
pShow
->
numOfReads
+=
numOfRows
;
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
return
numOfRows
;
}
static
void
mndCancelGetNextStable
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
7fea9e2f
...
@@ -21,9 +21,15 @@
...
@@ -21,9 +21,15 @@
int32_t
mndInitSync
(
SMnode
*
pMnode
)
{
return
0
;
}
int32_t
mndInitSync
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupSync
(
SMnode
*
pMnode
)
{}
void
mndCleanupSync
(
SMnode
*
pMnode
)
{}
int32_t
mndSyncPropose
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
void
*
pData
)
{
int32_t
mndSyncPropose
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
STransMsg
*
pMsg
)
{
mndTransApply
(
pMnode
,
pData
,
pData
,
0
);
int32_t
code
=
0
;
free
(
pData
);
int32_t
len
=
sdbGetRawTotalSize
(
pRaw
);
SSdbRaw
*
pReceived
=
calloc
(
1
,
len
);
memcpy
(
pReceived
,
pRaw
,
len
);
mDebug
(
"trans:%d, data:%p recv from sync, code:0x%x pMsg:%p"
,
pMsg
->
id
,
pReceived
,
code
&
0xFFFF
,
pMsg
);
mndTransApply
(
pMnode
,
pReceived
,
pMsg
,
code
);
return
0
;
return
0
;
}
}
...
...
source/dnode/mnode/impl/src/mndTelem.c
浏览文件 @
7fea9e2f
...
@@ -189,12 +189,12 @@ static void mndSendTelemetryReport(SMnode* pMnode) {
...
@@ -189,12 +189,12 @@ static void mndSendTelemetryReport(SMnode* pMnode) {
char
buf
[
128
]
=
{
0
};
char
buf
[
128
]
=
{
0
};
uint32_t
ip
=
taosGetIpv4FromFqdn
(
TELEMETRY_SERVER
);
uint32_t
ip
=
taosGetIpv4FromFqdn
(
TELEMETRY_SERVER
);
if
(
ip
==
0xffffffff
)
{
if
(
ip
==
0xffffffff
)
{
m
Trace
(
"failed to get IP address of "
TELEMETRY_SERVER
" since :%s"
,
strerror
(
errno
));
m
Debug
(
"failed to get IP address of "
TELEMETRY_SERVER
" since :%s"
,
strerror
(
errno
));
return
;
return
;
}
}
SOCKET
fd
=
taosOpenTcpClientSocket
(
ip
,
TELEMETRY_PORT
,
0
);
SOCKET
fd
=
taosOpenTcpClientSocket
(
ip
,
TELEMETRY_PORT
,
0
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
m
Trace
(
"failed to create socket for telemetry, reason:%s"
,
strerror
(
errno
));
m
Debug
(
"failed to create socket for telemetry, reason:%s"
,
strerror
(
errno
));
return
;
return
;
}
}
...
@@ -228,7 +228,7 @@ static void mndSendTelemetryReport(SMnode* pMnode) {
...
@@ -228,7 +228,7 @@ static void mndSendTelemetryReport(SMnode* pMnode) {
// read something to avoid nginx error 499
// read something to avoid nginx error 499
if
(
taosReadSocket
(
fd
,
buf
,
10
)
<
0
)
{
if
(
taosReadSocket
(
fd
,
buf
,
10
)
<
0
)
{
m
Trace
(
"failed to receive response since %s"
,
strerror
(
errno
));
m
Debug
(
"failed to receive response since %s"
,
strerror
(
errno
));
}
}
taosCloseSocket
(
fd
);
taosCloseSocket
(
fd
);
...
@@ -297,7 +297,7 @@ int32_t mndInitTelem(SMnode* pMnode) {
...
@@ -297,7 +297,7 @@ int32_t mndInitTelem(SMnode* pMnode) {
int32_t
code
=
pthread_create
(
&
pMgmt
->
thread
,
&
attr
,
mndTelemThreadFp
,
pMnode
);
int32_t
code
=
pthread_create
(
&
pMgmt
->
thread
,
&
attr
,
mndTelemThreadFp
,
pMnode
);
pthread_attr_destroy
(
&
attr
);
pthread_attr_destroy
(
&
attr
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
m
Trace
(
"failed to create telemetry thread since :%s"
,
strerror
(
code
));
m
Debug
(
"failed to create telemetry thread since :%s"
,
strerror
(
code
));
}
}
mInfo
(
"mnd telemetry is initialized"
);
mInfo
(
"mnd telemetry is initialized"
);
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
7fea9e2f
...
@@ -15,13 +15,33 @@
...
@@ -15,13 +15,33 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "mndTrans.h"
#include "mndTrans.h"
#include "
trp
c.h"
#include "
mndSyn
c.h"
#define SDB_TRANS_VER 1
#define SDB_TRANS_VER 1
#define TRN_DEFAULT_ARRAY_SIZE 8
#define TRN_DEFAULT_ARRAY_SIZE 8
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
)
{
static
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
);
int32_t
rawDataLen
=
10
*
sizeof
(
int32_t
);
static
SSdbRow
*
mndTransActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
);
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
OldTrans
,
STrans
*
pOldTrans
);
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
);
int32_t
mndInitTrans
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_TRANS
,
.
keyType
=
SDB_KEY_INT32
,
.
encodeFp
=
(
SdbEncodeFp
)
mndTransActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndTransActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndTransActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndTransActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndTransActionDelete
};
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupTrans
(
SMnode
*
pMnode
)
{}
static
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
)
{
int32_t
rawDataLen
=
16
*
sizeof
(
int32_t
);
int32_t
redoLogNum
=
taosArrayGetSize
(
pTrans
->
redoLogs
);
int32_t
redoLogNum
=
taosArrayGetSize
(
pTrans
->
redoLogs
);
int32_t
undoLogNum
=
taosArrayGetSize
(
pTrans
->
undoLogs
);
int32_t
undoLogNum
=
taosArrayGetSize
(
pTrans
->
undoLogs
);
int32_t
commitLogNum
=
taosArrayGetSize
(
pTrans
->
commitLogs
);
int32_t
commitLogNum
=
taosArrayGetSize
(
pTrans
->
commitLogs
);
...
@@ -29,23 +49,23 @@ SSdbRaw *mndTransActionEncode(STrans *pTrans) {
...
@@ -29,23 +49,23 @@ SSdbRaw *mndTransActionEncode(STrans *pTrans) {
int32_t
undoActionNum
=
taosArrayGetSize
(
pTrans
->
undoActions
);
int32_t
undoActionNum
=
taosArrayGetSize
(
pTrans
->
undoActions
);
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
redoLogs
,
i
);
SSdbRaw
*
pTmp
=
taosArrayGet
P
(
pTrans
->
redoLogs
,
i
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
}
}
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
undoLogs
,
i
);
SSdbRaw
*
pTmp
=
taosArrayGet
P
(
pTrans
->
undoLogs
,
i
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
}
}
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
commitLogs
,
i
);
SSdbRaw
*
pTmp
=
taosArrayGet
P
(
pTrans
->
commitLogs
,
i
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
}
}
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_TRANS
,
SDB_TRANS_VER
,
rawDataLen
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_TRANS
,
SDB_TRANS_VER
,
rawDataLen
);
if
(
pRaw
==
NULL
)
{
if
(
pRaw
==
NULL
)
{
mError
(
"tr
n
:%d, failed to alloc raw since %s"
,
pTrans
->
id
,
terrstr
());
mError
(
"tr
ans
:%d, failed to alloc raw since %s"
,
pTrans
->
id
,
terrstr
());
return
NULL
;
return
NULL
;
}
}
...
@@ -60,31 +80,33 @@ SSdbRaw *mndTransActionEncode(STrans *pTrans) {
...
@@ -60,31 +80,33 @@ SSdbRaw *mndTransActionEncode(STrans *pTrans) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
undoActionNum
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
undoActionNum
)
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
redoLogs
,
i
);
SSdbRaw
*
pTmp
=
taosArrayGet
P
(
pTrans
->
redoLogs
,
i
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
}
}
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
undoLogs
,
i
);
SSdbRaw
*
pTmp
=
taosArrayGet
P
(
pTrans
->
undoLogs
,
i
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
}
}
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
commitLogs
,
i
);
SSdbRaw
*
pTmp
=
taosArrayGet
P
(
pTrans
->
commitLogs
,
i
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
}
}
m
Debug
(
"trn:%d, is encoded as
raw:%p, len:%d"
,
pTrans
->
id
,
pRaw
,
dataPos
);
m
Trace
(
"trans:%d, encode to
raw:%p, len:%d"
,
pTrans
->
id
,
pRaw
,
dataPos
);
return
pRaw
;
return
pRaw
;
}
}
SSdbRow
*
mndTransActionDecode
(
SSdbRaw
*
pRaw
)
{
static
SSdbRow
*
mndTransActionDecode
(
SSdbRaw
*
pRaw
)
{
int32_t
code
=
0
;
int8_t
sver
=
0
;
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
{
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
{
mError
(
"failed to get soft ver from raw:%p since %s"
,
pRaw
,
terrstr
());
mError
(
"failed to get soft ver from raw:%p since %s"
,
pRaw
,
terrstr
());
...
@@ -97,8 +119,8 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
...
@@ -97,8 +119,8 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
return
NULL
;
return
NULL
;
}
}
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
STrans
));
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
STrans
));
STrans
*
pTrans
=
sdbGetRowObj
(
pRow
);
STrans
*
pTrans
=
sdbGetRowObj
(
pRow
);
if
(
pTrans
==
NULL
)
{
if
(
pTrans
==
NULL
)
{
mError
(
"failed to alloc trans from raw:%p since %s"
,
pRaw
,
terrstr
());
mError
(
"failed to alloc trans from raw:%p since %s"
,
pRaw
,
terrstr
());
return
NULL
;
return
NULL
;
...
@@ -112,9 +134,9 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
...
@@ -112,9 +134,9 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
if
(
pTrans
->
redoLogs
==
NULL
||
pTrans
->
undoLogs
==
NULL
||
pTrans
->
commitLogs
==
NULL
||
if
(
pTrans
->
redoLogs
==
NULL
||
pTrans
->
undoLogs
==
NULL
||
pTrans
->
commitLogs
==
NULL
||
pTrans
->
redoActions
==
NULL
||
pTrans
->
undoActions
==
NULL
)
{
pTrans
->
redoActions
==
NULL
||
pTrans
->
undoActions
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mDebug
(
"trans:%d, failed to create array while parsed from raw:%p"
,
pTrans
->
id
,
pRaw
)
;
mDebug
(
"trn:%d, failed to create array while parsed from raw:%p"
,
pTrans
->
id
,
pRaw
)
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
goto
TRANS_DECODE_OVER
;
}
}
int32_t
redoLogNum
=
0
;
int32_t
redoLogNum
=
0
;
...
@@ -133,85 +155,118 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
...
@@ -133,85 +155,118 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
redoActionNum
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
redoActionNum
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
undoActionNum
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
undoActionNum
)
int32_t
code
=
0
;
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
int32_t
dataLen
=
0
;
int32_t
dataLen
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
dataLen
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
dataLen
)
char
*
pData
=
malloc
(
dataLen
);
char
*
pData
=
malloc
(
dataLen
);
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pData
,
dataLen
);
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pData
,
dataLen
);
void
*
ret
=
taosArrayPush
(
pTrans
->
redoLogs
,
pData
);
void
*
ret
=
taosArrayPush
(
pTrans
->
redoLogs
,
&
pData
);
if
(
ret
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
TRANS_DECODE_OVER
;
break
;
}
}
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
int32_t
dataLen
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
dataLen
)
char
*
pData
=
malloc
(
dataLen
);
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pData
,
dataLen
);
void
*
ret
=
taosArrayPush
(
pTrans
->
undoLogs
,
&
pData
);
if
(
ret
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
TRANS_DECODE_OVER
;
break
;
}
}
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
int32_t
dataLen
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
dataLen
)
char
*
pData
=
malloc
(
dataLen
);
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pData
,
dataLen
);
void
*
ret
=
taosArrayPush
(
pTrans
->
commitLogs
,
&
pData
);
if
(
ret
==
NULL
)
{
if
(
ret
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
TRANS_DECODE_OVER
;
break
;
break
;
}
}
}
}
TRANS_DECODE_OVER:
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
code
;
mError
(
"trans:%d, failed to parse from raw:%p since %s"
,
pTrans
->
id
,
pRaw
,
tstrerror
(
errno
));
mError
(
"trn:%d, failed to parse from raw:%p since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
mndTransDrop
(
pTrans
);
mndTransDrop
(
pTrans
);
terrno
=
code
;
return
NULL
;
return
NULL
;
}
}
m
Debug
(
"trn:%d, is parsed
from raw:%p"
,
pTrans
->
id
,
pRaw
);
m
Trace
(
"trans:%d, decode
from raw:%p"
,
pTrans
->
id
,
pRaw
);
return
pRow
;
return
pRow
;
}
}
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
mTrace
(
"trans:%d, perform insert action, stage:%d"
,
pTrans
->
id
,
pTrans
->
stage
);
SArray
*
pArray
=
pTrans
->
redoLogs
;
SArray
*
pArray
=
pTrans
->
redoLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
SSdbRaw
*
pRaw
=
taosArrayGet
P
(
pArray
,
i
);
int32_t
code
=
sdbWrite
(
pSdb
,
pRaw
);
int32_t
code
=
sdbWrite
(
pSdb
,
pRaw
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
mError
(
"tr
n
:%d, failed to write raw:%p to sdb since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
mError
(
"tr
ans
:%d, failed to write raw:%p to sdb since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
return
code
;
return
code
;
}
}
}
}
mDebug
(
"trn:%d, write to sdb"
,
pTrans
->
id
);
return
0
;
return
0
;
}
}
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
SArray
*
pArray
=
pTrans
->
redoLogs
;
mTrace
(
"trans:%d, perform delete action, stage:%d"
,
pTrans
->
id
,
pTrans
->
stage
);
SArray
*
pArray
=
pTrans
->
undoLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
SSdbRaw
*
pRaw
=
taosArrayGet
P
(
pArray
,
i
);
int32_t
code
=
sdbWrite
(
pSdb
,
pRaw
);
int32_t
code
=
sdbWrite
(
pSdb
,
pRaw
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
mError
(
"tr
n
:%d, failed to write raw:%p to sdb since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
mError
(
"tr
ans
:%d, failed to write raw:%p to sdb since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
return
code
;
return
code
;
}
}
}
}
mDebug
(
"trn:%d, delete from sdb"
,
pTrans
->
id
);
return
0
;
return
0
;
}
}
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
pTrans
,
STrans
*
pDstTrans
)
{
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
pOldTrans
,
STrans
*
pNewTrans
)
{
assert
(
true
);
mTrace
(
"trans:%d, perform update action, stage:%d"
,
pOldTrans
->
id
,
pNewTrans
->
stage
);
SArray
*
pArray
=
pTrans
->
redoLogs
;
SArray
*
pArray
=
pOldTrans
->
commitLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
SSdbRaw
*
pRaw
=
taosArrayGet
P
(
pArray
,
i
);
int32_t
code
=
sdbWrite
(
pSdb
,
pRaw
);
int32_t
code
=
sdbWrite
(
pSdb
,
pRaw
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
mError
(
"tr
n:%d, failed to write raw:%p to sdb since %s"
,
p
Trans
->
id
,
pRaw
,
terrstr
());
mError
(
"tr
ans:%d, failed to write raw:%p to sdb since %s"
,
pOld
Trans
->
id
,
pRaw
,
terrstr
());
return
code
;
return
code
;
}
}
}
}
pTrans
->
stage
=
pDstTrans
->
stage
;
pOldTrans
->
stage
=
pNewTrans
->
stage
;
mDebug
(
"trn:%d, update in sdb"
,
pTrans
->
id
);
return
0
;
return
0
;
}
}
static
int32_t
trnGenerateTransId
()
{
return
1
;
}
static
int32_t
trnGenerateTransId
()
{
static
int32_t
tmp
=
0
;
return
++
tmp
;
}
STrans
*
mndTransCreate
(
SMnode
*
pMnode
,
ETrnPolicy
policy
,
void
*
rpcHandle
)
{
STrans
*
mndTransCreate
(
SMnode
*
pMnode
,
ETrnPolicy
policy
,
void
*
rpcHandle
)
{
STrans
*
pTrans
=
calloc
(
1
,
sizeof
(
STrans
));
STrans
*
pTrans
=
calloc
(
1
,
sizeof
(
STrans
));
...
@@ -224,6 +279,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
...
@@ -224,6 +279,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
pTrans
->
id
=
trnGenerateTransId
();
pTrans
->
id
=
trnGenerateTransId
();
pTrans
->
stage
=
TRN_STAGE_PREPARE
;
pTrans
->
stage
=
TRN_STAGE_PREPARE
;
pTrans
->
policy
=
policy
;
pTrans
->
policy
=
policy
;
pTrans
->
pMnode
=
pMnode
;
pTrans
->
rpcHandle
=
rpcHandle
;
pTrans
->
rpcHandle
=
rpcHandle
;
pTrans
->
redoLogs
=
taosArrayInit
(
TRN_DEFAULT_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
redoLogs
=
taosArrayInit
(
TRN_DEFAULT_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
undoLogs
=
taosArrayInit
(
TRN_DEFAULT_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
undoLogs
=
taosArrayInit
(
TRN_DEFAULT_ARRAY_SIZE
,
sizeof
(
void
*
));
...
@@ -238,13 +294,13 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
...
@@ -238,13 +294,13 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
return
NULL
;
return
NULL
;
}
}
mDebug
(
"tr
n:%d, is created, %p
"
,
pTrans
->
id
,
pTrans
);
mDebug
(
"tr
ans:%d, data:%p is created
"
,
pTrans
->
id
,
pTrans
);
return
pTrans
;
return
pTrans
;
}
}
static
void
trnDropArray
(
SArray
*
pArray
)
{
static
void
trnDropArray
(
SArray
*
pArray
)
{
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
SSdbRaw
*
pRaw
=
taosArrayGet
P
(
pArray
,
i
);
tfree
(
pRaw
);
tfree
(
pRaw
);
}
}
...
@@ -258,13 +314,13 @@ void mndTransDrop(STrans *pTrans) {
...
@@ -258,13 +314,13 @@ void mndTransDrop(STrans *pTrans) {
trnDropArray
(
pTrans
->
redoActions
);
trnDropArray
(
pTrans
->
redoActions
);
trnDropArray
(
pTrans
->
undoActions
);
trnDropArray
(
pTrans
->
undoActions
);
mDebug
(
"tr
n:%d, is dropped, %p
"
,
pTrans
->
id
,
pTrans
);
mDebug
(
"tr
ans:%d, data:%p is dropped
"
,
pTrans
->
id
,
pTrans
);
tfree
(
pTrans
);
tfree
(
pTrans
);
}
}
void
mndTransSetRpcHandle
(
STrans
*
pTrans
,
void
*
rpcHandle
)
{
void
mndTransSetRpcHandle
(
STrans
*
pTrans
,
void
*
rpcHandle
)
{
pTrans
->
rpcHandle
=
rpcHandle
;
pTrans
->
rpcHandle
=
rpcHandle
;
mTrace
(
"tr
n
:%d, set rpc handle:%p"
,
pTrans
->
id
,
rpcHandle
);
mTrace
(
"tr
ans
:%d, set rpc handle:%p"
,
pTrans
->
id
,
rpcHandle
);
}
}
static
int32_t
mndTransAppendArray
(
SArray
*
pArray
,
SSdbRaw
*
pRaw
)
{
static
int32_t
mndTransAppendArray
(
SArray
*
pArray
,
SSdbRaw
*
pRaw
)
{
...
@@ -273,7 +329,7 @@ static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
...
@@ -273,7 +329,7 @@ static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
return
-
1
;
return
-
1
;
}
}
void
*
ptr
=
taosArrayPush
(
pArray
,
pRaw
);
void
*
ptr
=
taosArrayPush
(
pArray
,
&
pRaw
);
if
(
ptr
==
NULL
)
{
if
(
ptr
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
...
@@ -284,92 +340,92 @@ static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
...
@@ -284,92 +340,92 @@ static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
int32_t
mndTransAppendRedolog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
mndTransAppendRedolog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
mndTransAppendArray
(
pTrans
->
redoLogs
,
pRaw
);
int32_t
code
=
mndTransAppendArray
(
pTrans
->
redoLogs
,
pRaw
);
mTrace
(
"tr
n
:%d, raw:%p append to redo logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
mTrace
(
"tr
ans
:%d, raw:%p append to redo logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
return
code
;
return
code
;
}
}
int32_t
mndTransAppendUndolog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
mndTransAppendUndolog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
mndTransAppendArray
(
pTrans
->
undoLogs
,
pRaw
);
int32_t
code
=
mndTransAppendArray
(
pTrans
->
undoLogs
,
pRaw
);
mTrace
(
"tr
n
:%d, raw:%p append to undo logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
mTrace
(
"tr
ans
:%d, raw:%p append to undo logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
return
code
;
return
code
;
}
}
int32_t
mndTransAppendCommitlog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
mndTransAppendCommitlog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
mndTransAppendArray
(
pTrans
->
commitLogs
,
pRaw
);
int32_t
code
=
mndTransAppendArray
(
pTrans
->
commitLogs
,
pRaw
);
mTrace
(
"tr
n
:%d, raw:%p append to commit logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
mTrace
(
"tr
ans
:%d, raw:%p append to commit logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
return
code
;
return
code
;
}
}
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
code
=
mndTransAppendArray
(
pTrans
->
redoActions
,
pMsg
);
int32_t
code
=
mndTransAppendArray
(
pTrans
->
redoActions
,
pMsg
);
mTrace
(
"tr
n
:%d, msg:%p append to redo actions"
,
pTrans
->
id
,
pMsg
);
mTrace
(
"tr
ans
:%d, msg:%p append to redo actions"
,
pTrans
->
id
,
pMsg
);
return
code
;
return
code
;
}
}
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
code
=
mndTransAppendArray
(
pTrans
->
undoActions
,
pMsg
);
int32_t
code
=
mndTransAppendArray
(
pTrans
->
undoActions
,
pMsg
);
mTrace
(
"tr
n
:%d, msg:%p append to undo actions"
,
pTrans
->
id
,
pMsg
);
mTrace
(
"tr
ans
:%d, msg:%p append to undo actions"
,
pTrans
->
id
,
pMsg
);
return
code
;
return
code
;
}
}
int32_t
mndInitTrans
(
SMnode
*
pMnode
)
{
int32_t
mndTransPrepare
(
STrans
*
pTrans
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_TRANS
,
mDebug
(
"trans:%d, prepare transaction"
,
pTrans
->
id
);
.
keyType
=
SDB_KEY_INT32
,
.
encodeFp
=
(
SdbEncodeFp
)
mndTransActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndTransActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndTransActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndTransActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndTransActionDelete
};
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupTrans
(
SMnode
*
pMnode
)
{}
int32_t
mndTransPrepare
(
STrans
*
pTrans
,
int32_t
(
*
syncfp
)(
SSdbRaw
*
pRaw
,
void
*
pData
))
{
if
(
syncfp
==
NULL
)
return
-
1
;
SSdbRaw
*
pRaw
=
mndTransActionEncode
(
pTrans
);
SSdbRaw
*
pRaw
=
mndTransActionEncode
(
pTrans
);
if
(
pRaw
==
NULL
)
{
if
(
pRaw
==
NULL
)
{
mError
(
"tr
n
:%d, failed to decode trans since %s"
,
pTrans
->
id
,
terrstr
());
mError
(
"tr
ans
:%d, failed to decode trans since %s"
,
pTrans
->
id
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_CREATING
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_CREATING
);
if
(
sdbWrite
(
pTrans
->
pMnode
->
pSdb
,
pRaw
)
!=
0
)
{
if
(
sdbWrite
NotFree
(
pTrans
->
pMnode
->
pSdb
,
pRaw
)
!=
0
)
{
mError
(
"tr
n
:%d, failed to write trans since %s"
,
pTrans
->
id
,
terrstr
());
mError
(
"tr
ans
:%d, failed to write trans since %s"
,
pTrans
->
id
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
if
((
*
syncfp
)(
pRaw
,
pTrans
->
rpcHandle
)
!=
0
)
{
STransMsg
*
pMsg
=
calloc
(
1
,
sizeof
(
STransMsg
));
mError
(
"trn:%d, failed to sync trans since %s"
,
pTrans
->
id
,
terrstr
());
pMsg
->
id
=
pTrans
->
id
;
pMsg
->
rpcHandle
=
pTrans
->
rpcHandle
;
mDebug
(
"trans:%d, start sync, RPC:%p pMsg:%p"
,
pTrans
->
id
,
pTrans
->
rpcHandle
,
pMsg
);
if
(
mndSyncPropose
(
pTrans
->
pMnode
,
pRaw
,
pMsg
)
!=
0
)
{
mError
(
"trans:%d, failed to sync since %s"
,
pTrans
->
id
,
terrstr
());
free
(
pMsg
);
sdbFreeRaw
(
pRaw
);
return
-
1
;
return
-
1
;
}
}
sdbFreeRaw
(
pRaw
);
return
0
;
return
0
;
}
}
static
void
trnSendRpcRsp
(
void
*
rpcHandle
,
int32_t
code
)
{
static
void
trnSendRpcRsp
(
STransMsg
*
pMsg
,
int32_t
code
)
{
if
(
rpcHandle
!=
NULL
)
{
mDebug
(
"trans:%d, send rpc rsp, RPC:%p code:0x%x pMsg:%p"
,
pMsg
->
id
,
pMsg
->
rpcHandle
,
code
&
0xFFFF
,
pMsg
);
SRpcMsg
rspMsg
=
{.
handle
=
rpcHandle
,
.
code
=
terrno
};
if
(
pMsg
->
rpcHandle
!=
NULL
)
{
SRpcMsg
rspMsg
=
{.
handle
=
pMsg
->
rpcHandle
,
.
code
=
code
};
rpcSendResponse
(
&
rspMsg
);
rpcSendResponse
(
&
rspMsg
);
}
}
}
int32_t
mndTransApply
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
void
*
pData
,
int32_t
code
)
{
free
(
pMsg
);
if
(
code
!=
0
)
{
}
trnSendRpcRsp
(
pData
,
terrno
);
return
0
;
}
if
(
sdbWrite
(
pMnode
->
pSdb
,
pData
)
!=
0
)
{
void
mndTransApply
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
STransMsg
*
pMsg
,
int32_t
code
)
{
code
=
terrno
;
if
(
code
==
0
)
{
trnSendRpcRsp
(
pData
,
code
);
mDebug
(
"trans:%d, commit transaction"
,
pMsg
->
id
);
terrno
=
code
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
return
-
1
;
if
(
sdbWrite
(
pMnode
->
pSdb
,
pRaw
)
!=
0
)
{
code
=
terrno
;
mError
(
"trans:%d, failed to write sdb while commit since %s"
,
pMsg
->
id
,
terrstr
());
}
trnSendRpcRsp
(
pMsg
,
code
);
}
else
{
mDebug
(
"trans:%d, rollback transaction"
,
pMsg
->
id
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_DROPPED
);
if
(
sdbWrite
(
pMnode
->
pSdb
,
pRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to write sdb while rollback since %s"
,
pMsg
->
id
,
terrstr
());
}
trnSendRpcRsp
(
pMsg
,
code
);
}
}
return
0
;
}
}
static
int32_t
trnExecuteArray
(
SMnode
*
pMnode
,
SArray
*
pArray
)
{
static
int32_t
trnExecuteArray
(
SMnode
*
pMnode
,
SArray
*
pArray
)
{
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
7fea9e2f
...
@@ -27,11 +27,14 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser);
...
@@ -27,11 +27,14 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser);
static
SSdbRow
*
mndUserActionDecode
(
SSdbRaw
*
pRaw
);
static
SSdbRow
*
mndUserActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndUserActionInsert
(
SSdb
*
pSdb
,
SUserObj
*
pUser
);
static
int32_t
mndUserActionInsert
(
SSdb
*
pSdb
,
SUserObj
*
pUser
);
static
int32_t
mndUserActionDelete
(
SSdb
*
pSdb
,
SUserObj
*
pUser
);
static
int32_t
mndUserActionDelete
(
SSdb
*
pSdb
,
SUserObj
*
pUser
);
static
int32_t
mndUserActionUpdate
(
SSdb
*
pSdb
,
SUserObj
*
p
SrcUser
,
SUserObj
*
pDst
User
);
static
int32_t
mndUserActionUpdate
(
SSdb
*
pSdb
,
SUserObj
*
p
OldUser
,
SUserObj
*
pNew
User
);
static
int32_t
mndCreateUser
(
SMnode
*
pMnode
,
char
*
acct
,
char
*
user
,
char
*
pass
,
SMnodeMsg
*
pMsg
);
static
int32_t
mndCreateUser
(
SMnode
*
pMnode
,
char
*
acct
,
char
*
user
,
char
*
pass
,
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetUserMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveUsers
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextUser
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitUser
(
SMnode
*
pMnode
)
{
int32_t
mndInitUser
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_USER
,
SSdbTable
table
=
{.
sdbType
=
SDB_USER
,
...
@@ -47,6 +50,9 @@ int32_t mndInitUser(SMnode *pMnode) {
...
@@ -47,6 +50,9 @@ int32_t mndInitUser(SMnode *pMnode) {
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_ALTER_USER
,
mndProcessAlterUserMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_ALTER_USER
,
mndProcessAlterUserMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_USER
,
mndProcessDropUserMsg
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_USER
,
mndProcessDropUserMsg
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_USER
,
mndGetUserMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_USER
,
mndRetrieveUsers
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_USER
,
mndCancelGetNextUser
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
}
...
@@ -70,7 +76,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
...
@@ -70,7 +76,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
if
(
pRaw
==
NULL
)
return
-
1
;
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
m
Trace
(
"user:%s, will be created while deploy sdb"
,
userObj
.
user
);
m
Debug
(
"user:%s, will be created while deploy sdb"
,
userObj
.
user
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
}
...
@@ -162,16 +168,16 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
...
@@ -162,16 +168,16 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
return
0
;
return
0
;
}
}
static
int32_t
mndUserActionUpdate
(
SSdb
*
pSdb
,
SUserObj
*
p
SrcUser
,
SUserObj
*
pDst
User
)
{
static
int32_t
mndUserActionUpdate
(
SSdb
*
pSdb
,
SUserObj
*
p
OldUser
,
SUserObj
*
pNew
User
)
{
mTrace
(
"user:%s, perform update action"
,
p
Src
User
->
user
);
mTrace
(
"user:%s, perform update action"
,
p
Old
User
->
user
);
memcpy
(
p
SrcUser
->
user
,
pDst
User
->
user
,
TSDB_USER_LEN
);
memcpy
(
p
OldUser
->
user
,
pNew
User
->
user
,
TSDB_USER_LEN
);
memcpy
(
p
SrcUser
->
pass
,
pDst
User
->
pass
,
TSDB_KEY_LEN
);
memcpy
(
p
OldUser
->
pass
,
pNew
User
->
pass
,
TSDB_KEY_LEN
);
memcpy
(
p
SrcUser
->
acct
,
pDst
User
->
acct
,
TSDB_USER_LEN
);
memcpy
(
p
OldUser
->
acct
,
pNew
User
->
acct
,
TSDB_USER_LEN
);
p
SrcUser
->
createdTime
=
pDst
User
->
createdTime
;
p
OldUser
->
createdTime
=
pNew
User
->
createdTime
;
p
SrcUser
->
updateTime
=
pDst
User
->
updateTime
;
p
OldUser
->
updateTime
=
pNew
User
->
updateTime
;
p
SrcUser
->
superAuth
=
pDst
User
->
superAuth
;
p
OldUser
->
superAuth
=
pNew
User
->
superAuth
;
p
SrcUser
->
readAuth
=
pDst
User
->
readAuth
;
p
OldUser
->
readAuth
=
pNew
User
->
readAuth
;
p
SrcUser
->
writeAuth
=
pDst
User
->
writeAuth
;
p
OldUser
->
writeAuth
=
pNew
User
->
writeAuth
;
return
0
;
return
0
;
}
}
...
@@ -197,11 +203,15 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
...
@@ -197,11 +203,15 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
userObj
.
writeAuth
=
1
;
userObj
.
writeAuth
=
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
return
-
1
;
if
(
pTrans
==
NULL
)
{
mError
(
"user:%s, failed to create since %s"
,
user
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to create user:%s"
,
pTrans
->
id
,
user
);
SSdbRaw
*
pRedoRaw
=
mndUserActionEncode
(
&
userObj
);
SSdbRaw
*
pRedoRaw
=
mndUserActionEncode
(
&
userObj
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"
failed to append redo log since %s"
,
terrstr
());
mError
(
"
trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
mndTransDrop
(
pTrans
);
return
-
1
;
return
-
1
;
}
}
...
@@ -209,7 +219,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
...
@@ -209,7 +219,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
SSdbRaw
*
pUndoRaw
=
mndUserActionEncode
(
&
userObj
);
SSdbRaw
*
pUndoRaw
=
mndUserActionEncode
(
&
userObj
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"
failed to append undo log since %s"
,
terrstr
());
mError
(
"
trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
mndTransDrop
(
pTrans
);
return
-
1
;
return
-
1
;
}
}
...
@@ -217,13 +227,90 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
...
@@ -217,13 +227,90 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
SSdbRaw
*
pCommitRaw
=
mndUserActionEncode
(
&
userObj
);
SSdbRaw
*
pCommitRaw
=
mndUserActionEncode
(
&
userObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"
failed to append commit log since %s"
,
terrstr
());
mError
(
"
trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
mndTransDrop
(
pTrans
);
return
-
1
;
return
-
1
;
}
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pTrans
,
mndSyncPropose
)
!=
0
)
{
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndUpdateUser
(
SMnode
*
pMnode
,
SUserObj
*
pOldUser
,
SUserObj
*
pNewUser
,
SMnodeMsg
*
pMsg
)
{
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"user:%s, failed to update since %s"
,
pOldUser
->
user
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to update user:%s"
,
pTrans
->
id
,
pOldUser
->
user
);
SSdbRaw
*
pRedoRaw
=
mndUserActionEncode
(
pNewUser
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pUndoRaw
=
mndUserActionEncode
(
pOldUser
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndDropUser
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SUserObj
*
pUser
)
{
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
{
mError
(
"user:%s, failed to drop since %s"
,
pUser
->
user
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to drop user:%s"
,
pTrans
->
id
,
pUser
->
user
);
SSdbRaw
*
pRedoRaw
=
mndUserActionEncode
(
pUser
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append redo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
);
SSdbRaw
*
pUndoRaw
=
mndUserActionEncode
(
pUser
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append undo log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
);
SSdbRaw
*
pCommitRaw
=
mndUserActionEncode
(
pUser
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"trans:%d, failed to append commit log since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
);
if
(
mndTransPrepare
(
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
mndTransDrop
(
pTrans
);
return
-
1
;
return
-
1
;
}
}
...
@@ -236,6 +323,8 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
...
@@ -236,6 +323,8 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateUserMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
SCreateUserMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
mDebug
(
"user:%s, start to create"
,
pCreate
->
user
);
if
(
pCreate
->
user
[
0
]
==
0
)
{
if
(
pCreate
->
user
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_USER_FORMAT
;
terrno
=
TSDB_CODE_MND_INVALID_USER_FORMAT
;
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
terrstr
());
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
terrstr
());
...
@@ -275,13 +364,185 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
...
@@ -275,13 +364,185 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
}
}
static
int32_t
mndProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mndProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
)
{
terrno
=
TSDB_CODE_MND_MSG_NOT_PROCESSED
;
SMnode
*
pMnode
=
pMsg
->
pMnode
;
mError
(
"failed to process alter user msg since %s"
,
terrstr
());
SAlterUserMsg
*
pAlter
=
pMsg
->
rpcMsg
.
pCont
;
return
-
1
;
mDebug
(
"user:%s, start to alter"
,
pAlter
->
user
);
if
(
pAlter
->
user
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_USER_FORMAT
;
mError
(
"user:%s, failed to alter since %s"
,
pAlter
->
user
,
terrstr
());
return
-
1
;
}
if
(
pAlter
->
pass
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_PASS_FORMAT
;
mError
(
"user:%s, failed to alter since %s"
,
pAlter
->
user
,
terrstr
());
return
-
1
;
}
SUserObj
*
pUser
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_USER
,
pAlter
->
user
);
if
(
pUser
==
NULL
)
{
terrno
=
TSDB_CODE_MND_USER_NOT_EXIST
;
mError
(
"user:%s, failed to alter since %s"
,
pAlter
->
user
,
terrstr
());
return
-
1
;
}
SUserObj
*
pOperUser
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_USER
,
pMsg
->
user
);
if
(
pOperUser
==
NULL
)
{
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
mError
(
"user:%s, failed to alter since %s"
,
pAlter
->
user
,
terrstr
());
return
-
1
;
}
SUserObj
newUser
=
{
0
};
memcpy
(
&
newUser
,
pUser
,
sizeof
(
SUserObj
));
memset
(
pUser
->
pass
,
0
,
sizeof
(
pUser
->
pass
));
taosEncryptPass
((
uint8_t
*
)
pAlter
->
pass
,
strlen
(
pAlter
->
pass
),
pUser
->
pass
);
int32_t
code
=
mndUpdateUser
(
pMnode
,
pUser
,
&
newUser
,
pMsg
);
sdbRelease
(
pMnode
->
pSdb
,
pOperUser
);
if
(
code
!=
0
)
{
mError
(
"user:%s, failed to alter since %s"
,
pAlter
->
user
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
}
static
int32_t
mndProcessDropUserMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mndProcessDropUserMsg
(
SMnodeMsg
*
pMsg
)
{
terrno
=
TSDB_CODE_MND_MSG_NOT_PROCESSED
;
SMnode
*
pMnode
=
pMsg
->
pMnode
;
mError
(
"failed to process drop user msg since %s"
,
terrstr
());
SDropUserMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
return
-
1
;
mDebug
(
"user:%s, start to drop"
,
pDrop
->
user
);
if
(
pDrop
->
user
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_USER_FORMAT
;
mError
(
"user:%s, failed to drop since %s"
,
pDrop
->
user
,
terrstr
());
return
-
1
;
}
SUserObj
*
pUser
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_USER
,
pDrop
->
user
);
if
(
pUser
==
NULL
)
{
terrno
=
TSDB_CODE_MND_USER_NOT_EXIST
;
mError
(
"user:%s, failed to drop since %s"
,
pDrop
->
user
,
terrstr
());
return
-
1
;
}
SUserObj
*
pOperUser
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_USER
,
pMsg
->
user
);
if
(
pOperUser
==
NULL
)
{
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
mError
(
"user:%s, failed to drop since %s"
,
pDrop
->
user
,
terrstr
());
return
-
1
;
}
int32_t
code
=
mndDropUser
(
pMnode
,
pMsg
,
pUser
);
sdbRelease
(
pMnode
->
pSdb
,
pOperUser
);
if
(
code
!=
0
)
{
mError
(
"user:%s, failed to drop since %s"
,
pDrop
->
user
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndGetUserMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
10
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"privilege"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"account"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_USER
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveUsers
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SUserObj
*
pUser
=
NULL
;
int32_t
cols
=
0
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_USER
,
pShow
->
pIter
,
(
void
**
)
&
pUser
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pUser
->
user
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
if
(
pUser
->
superAuth
)
{
const
char
*
src
=
"super"
;
STR_WITH_SIZE_TO_VARSTR
(
pWrite
,
src
,
strlen
(
src
));
}
else
if
(
pUser
->
writeAuth
)
{
const
char
*
src
=
"writable"
;
STR_WITH_SIZE_TO_VARSTR
(
pWrite
,
src
,
strlen
(
src
));
}
else
{
const
char
*
src
=
"readable"
;
STR_WITH_SIZE_TO_VARSTR
(
pWrite
,
src
,
strlen
(
src
));
}
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pUser
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pUser
->
acct
,
pShow
->
bytes
[
cols
]);
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pUser
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextUser
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
7fea9e2f
...
@@ -14,8 +14,372 @@
...
@@ -14,8 +14,372 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndVgroup.h"
#include "mndInt.h"
#include "mndDb.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndShow.h"
#include "mndTrans.h"
int32_t
mndInitVgroup
(
SMnode
*
pMnode
)
{
return
0
;
}
#define TSDB_VGROUP_VER_NUM 1
void
mndCleanupVgroup
(
SMnode
*
pMnode
)
{}
#define TSDB_VGROUP_RESERVE_SIZE 64
\ No newline at end of file
static
SSdbRaw
*
mndVgroupActionEncode
(
SVgObj
*
pVgroup
);
static
SSdbRow
*
mndVgroupActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndVgroupActionInsert
(
SSdb
*
pSdb
,
SVgObj
*
pVgroup
);
static
int32_t
mndVgroupActionDelete
(
SSdb
*
pSdb
,
SVgObj
*
pVgroup
);
static
int32_t
mndVgroupActionUpdate
(
SSdb
*
pSdb
,
SVgObj
*
pOldVgroup
,
SVgObj
*
pNewVgroup
);
static
int32_t
mndProcessCreateVnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterVnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropVnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessSyncVnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCompactVnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetVgroupMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveVgroups
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextVgroup
(
SMnode
*
pMnode
,
void
*
pIter
);
static
int32_t
mndGetVnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveVnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextVnode
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitVgroup
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_VGROUP
,
.
keyType
=
SDB_KEY_BINARY
,
.
encodeFp
=
(
SdbEncodeFp
)
mndVgroupActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndVgroupActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndVgroupActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndVgroupActionDelete
,
.
deleteFp
=
(
SdbDeleteFp
)
mndVgroupActionUpdate
};
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP
,
mndProcessCreateVnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP
,
mndProcessAlterVnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_DROP_VNODE_IN_RSP
,
mndProcessDropVnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP
,
mndProcessSyncVnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP
,
mndProcessCompactVnodeRsp
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_VGROUP
,
mndGetVgroupMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_VGROUP
,
mndRetrieveVgroups
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_VGROUP
,
mndCancelGetNextVgroup
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_VNODES
,
mndGetVnodeMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_VNODES
,
mndRetrieveVnodes
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_VNODES
,
mndCancelGetNextVnode
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupVgroup
(
SMnode
*
pMnode
)
{}
static
SSdbRaw
*
mndVgroupActionEncode
(
SVgObj
*
pVgroup
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_DB
,
TSDB_VGROUP_VER_NUM
,
sizeof
(
SDbObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_INT32
(
pRaw
,
dataPos
,
pVgroup
->
vgId
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pVgroup
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pVgroup
->
updateTime
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pVgroup
->
version
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pVgroup
->
dbName
,
TSDB_FULL_DB_NAME_LEN
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pVgroup
->
replica
)
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SDB_SET_INT32
(
pRaw
,
dataPos
,
pVgid
->
dnodeId
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pVgid
->
role
)
}
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
return
pRaw
;
}
static
SSdbRow
*
mndVgroupActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_VGROUP_VER_NUM
)
{
mError
(
"failed to decode vgroup since %s"
,
terrstr
());
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
return
NULL
;
}
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
SDbObj
));
SVgObj
*
pVgroup
=
sdbGetRowObj
(
pRow
);
if
(
pVgroup
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pVgroup
->
vgId
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pVgroup
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pVgroup
->
updateTime
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pVgroup
->
version
)
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pVgroup
->
dbName
,
TSDB_FULL_DB_NAME_LEN
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pVgroup
->
replica
)
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pVgid
->
dnodeId
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
(
int8_t
*
)
&
pVgid
->
role
)
}
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
return
pRow
;
}
static
int32_t
mndVgroupActionInsert
(
SSdb
*
pSdb
,
SVgObj
*
pVgroup
)
{
mTrace
(
"vgId:%d, perform insert action"
,
pVgroup
->
vgId
);
return
0
;
}
static
int32_t
mndVgroupActionDelete
(
SSdb
*
pSdb
,
SVgObj
*
pVgroup
)
{
mTrace
(
"vgId:%d, perform delete action"
,
pVgroup
->
vgId
);
return
0
;
}
static
int32_t
mndProcessCreateVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessAlterVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessDropVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessSyncVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessCompactVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndVgroupActionUpdate
(
SSdb
*
pSdb
,
SVgObj
*
pOldVgroup
,
SVgObj
*
pNewVgroup
)
{
mTrace
(
"vgId:%d, perform update action"
,
pOldVgroup
->
vgId
);
pOldVgroup
->
vgId
=
pNewVgroup
->
vgId
;
pOldVgroup
->
createdTime
=
pNewVgroup
->
createdTime
;
pOldVgroup
->
updateTime
=
pNewVgroup
->
updateTime
;
pOldVgroup
->
version
=
pNewVgroup
->
version
;
memcpy
(
pOldVgroup
->
dbName
,
pNewVgroup
->
dbName
,
TSDB_FULL_DB_NAME_LEN
);
pOldVgroup
->
replica
=
pNewVgroup
->
replica
;
memcpy
(
pOldVgroup
->
vnodeGid
,
pNewVgroup
->
vnodeGid
,
TSDB_MAX_REPLICA
*
sizeof
(
SVnodeGid
));
return
0
;
}
SVgObj
*
mndAcquireVgroup
(
SMnode
*
pMnode
,
int32_t
vgId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbAcquire
(
pSdb
,
SDB_VGROUP
,
&
vgId
);
}
void
mndReleaseVgroup
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pVgroup
);
}
static
int32_t
mndGetVgroupMaxReplica
(
SMnode
*
pMnode
,
char
*
dbName
,
int8_t
*
pReplica
,
int32_t
*
pNumOfVgroups
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
dbName
);
if
(
pDb
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
return
-
1
;
}
int8_t
replica
=
1
;
int32_t
numOfVgroups
=
0
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SVgObj
*
pVgroup
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
if
(
strcmp
(
pVgroup
->
dbName
,
dbName
)
==
0
)
{
replica
=
MAX
(
replica
,
pVgroup
->
replica
);
numOfVgroups
++
;
}
sdbRelease
(
pSdb
,
pVgroup
);
}
*
pReplica
=
replica
;
*
pNumOfVgroups
=
numOfVgroups
;
return
0
;
}
static
int32_t
mndGetVgroupMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
if
(
mndGetVgroupMaxReplica
(
pMnode
,
pShow
->
db
,
&
pShow
->
replica
,
&
pShow
->
numOfRows
)
!=
0
)
{
return
-
1
;
}
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"vgId"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"tables"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
for
(
int32_t
i
=
0
;
i
<
pShow
->
replica
;
++
i
)
{
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
snprintf
(
pSchema
[
cols
].
name
,
TSDB_COL_NAME_LEN
,
"v%d_dnode"
,
i
+
1
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
9
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
snprintf
(
pSchema
[
cols
].
name
,
TSDB_COL_NAME_LEN
,
"v%d_status"
,
i
+
1
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
}
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveVgroups
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SVgObj
*
pVgroup
=
NULL
;
int32_t
cols
=
0
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pShow
->
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pVgroup
->
vgId
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pVgroup
->
numOfTables
;
cols
++
;
for
(
int32_t
i
=
0
;
i
<
pShow
->
replica
;
++
i
)
{
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pVgroup
->
vnodeGid
[
i
].
dnodeId
;
cols
++
;
const
char
*
role
=
mndGetRoleStr
(
pVgroup
->
vnodeGid
[
i
].
role
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
role
,
pShow
->
bytes
[
cols
]);
cols
++
;
}
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int8_t
*
)
pWrite
=
pVgroup
->
compact
;
cols
++
;
sdbRelease
(
pSdb
,
pVgroup
);
numOfRows
++
;
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextVgroup
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
static
int32_t
mndGetVnodesNum
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
if
(
dnodeId
==
0
)
{
return
0
;
}
return
0
;
}
static
int32_t
mndGetVnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"vgId"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
12
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"status"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
int32_t
dnodeId
=
0
;
if
(
pShow
->
payloadLen
>
0
)
{
dnodeId
=
atoi
(
pShow
->
payload
);
}
pShow
->
replica
=
dnodeId
;
pShow
->
numOfRows
=
mndGetVnodesNum
(
pMnode
,
dnodeId
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tableFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveVnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SVgObj
*
pVgroup
=
NULL
;
char
*
pWrite
;
int32_t
cols
=
0
;
int32_t
dnodeId
=
pShow
->
replica
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pShow
->
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pShow
->
pIter
==
NULL
)
break
;
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
replica
&&
numOfRows
<
rows
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
if
(
pVgid
->
dnodeId
!=
dnodeId
)
continue
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
uint32_t
*
)
pWrite
=
pVgroup
->
vgId
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_TO_VARSTR
(
pWrite
,
mndGetRoleStr
(
pVgid
->
role
));
cols
++
;
numOfRows
++
;
}
sdbRelease
(
pSdb
,
pVgroup
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextVnode
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
\ No newline at end of file
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
7fea9e2f
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
#include "mndDnode.h"
#include "mndDnode.h"
#include "mndFunc.h"
#include "mndFunc.h"
#include "mndMnode.h"
#include "mndMnode.h"
#include "mndOper.h"
#include "mndProfile.h"
#include "mndProfile.h"
#include "mndShow.h"
#include "mndShow.h"
#include "mndStable.h"
#include "mndStable.h"
...
@@ -333,7 +332,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
...
@@ -333,7 +332,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
if
(
pMsg
==
NULL
)
{
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"
failed to create msg since %s"
,
terrstr
());
mError
(
"
RPC:%p, app:%p failed to create msg since %s"
,
pRpcMsg
->
handle
,
pRpcMsg
->
ahandle
,
terrstr
());
return
NULL
;
return
NULL
;
}
}
...
@@ -341,7 +340,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
...
@@ -341,7 +340,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
if
(
rpcGetConnInfo
(
pRpcMsg
->
handle
,
&
connInfo
)
!=
0
)
{
if
(
rpcGetConnInfo
(
pRpcMsg
->
handle
,
&
connInfo
)
!=
0
)
{
mndCleanupMsg
(
pMsg
);
mndCleanupMsg
(
pMsg
);
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
mError
(
"
failed to create msg since %s"
,
terrstr
());
mError
(
"
RPC:%p, app:%p failed to create msg since %s"
,
pRpcMsg
->
handle
,
pRpcMsg
->
ahandle
,
terrstr
());
return
NULL
;
return
NULL
;
}
}
memcpy
(
pMsg
->
user
,
connInfo
.
user
,
TSDB_USER_LEN
);
memcpy
(
pMsg
->
user
,
connInfo
.
user
,
TSDB_USER_LEN
);
...
@@ -350,13 +349,13 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
...
@@ -350,13 +349,13 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
pMsg
->
rpcMsg
=
*
pRpcMsg
;
pMsg
->
rpcMsg
=
*
pRpcMsg
;
pMsg
->
createdTime
=
taosGetTimestampSec
();
pMsg
->
createdTime
=
taosGetTimestampSec
();
mTrace
(
"msg:%p,
is created"
,
pMsg
);
mTrace
(
"msg:%p,
app:%p is created, RPC:%p"
,
pMsg
,
pRpcMsg
->
ahandle
,
pRpcMsg
->
handle
);
return
pMsg
;
return
pMsg
;
}
}
void
mndCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
void
mndCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
mTrace
(
"msg:%p, app:%p is destroyed, RPC:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
->
rpcMsg
.
handle
);
taosFreeQitem
(
pMsg
);
taosFreeQitem
(
pMsg
);
mTrace
(
"msg:%p, is destroyed"
,
pMsg
);
}
}
void
mndSendRsp
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
void
mndSendRsp
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
...
@@ -371,7 +370,7 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
...
@@ -371,7 +370,7 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
void
*
ahandle
=
pMsg
->
rpcMsg
.
ahandle
;
void
*
ahandle
=
pMsg
->
rpcMsg
.
ahandle
;
bool
isReq
=
(
msgType
%
2
==
1
);
bool
isReq
=
(
msgType
%
2
==
1
);
mTrace
(
"msg:%p, app:%p
will be processed"
,
pMsg
,
ahandle
);
mTrace
(
"msg:%p, app:%p
type:%s will be processed"
,
pMsg
,
ahandle
,
taosMsg
[
msgType
]
);
if
(
isReq
&&
!
mndIsMaster
(
pMnode
))
{
if
(
isReq
&&
!
mndIsMaster
(
pMnode
))
{
code
=
TSDB_CODE_APP_NOT_READY
;
code
=
TSDB_CODE_APP_NOT_READY
;
...
@@ -393,7 +392,10 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
...
@@ -393,7 +392,10 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
}
}
code
=
(
*
fp
)(
pMsg
);
code
=
(
*
fp
)(
pMsg
);
if
(
code
!=
0
)
{
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mTrace
(
"msg:%p, app:%p in progressing"
,
pMsg
,
ahandle
);
return
;
}
else
if
(
code
!=
0
)
{
code
=
terrno
;
code
=
terrno
;
mError
(
"msg:%p, app:%p failed to process since %s"
,
pMsg
,
ahandle
,
terrstr
());
mError
(
"msg:%p, app:%p failed to process since %s"
,
pMsg
,
ahandle
,
terrstr
());
goto
PROCESS_RPC_END
;
goto
PROCESS_RPC_END
;
...
...
source/dnode/mnode/sdb/inc/sdbInt.h
浏览文件 @
7fea9e2f
...
@@ -71,7 +71,6 @@ typedef struct SSdb {
...
@@ -71,7 +71,6 @@ typedef struct SSdb {
}
SSdb
;
}
SSdb
;
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
int32_t
sdbWriteRaw
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
7fea9e2f
...
@@ -94,7 +94,7 @@ void sdbCleanup(SSdb *pSdb) {
...
@@ -94,7 +94,7 @@ void sdbCleanup(SSdb *pSdb) {
taosHashClear
(
hash
);
taosHashClear
(
hash
);
taosHashCleanup
(
hash
);
taosHashCleanup
(
hash
);
pSdb
->
hashObjs
[
i
]
=
NULL
;
pSdb
->
hashObjs
[
i
]
=
NULL
;
m
Trace
(
"sdb table:%d is cleaned up"
,
i
);
m
Debug
(
"sdb table:%d is cleaned up"
,
i
);
}
}
free
(
pSdb
);
free
(
pSdb
);
...
@@ -129,7 +129,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
...
@@ -129,7 +129,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
pSdb
->
hashObjs
[
sdbType
]
=
hash
;
pSdb
->
hashObjs
[
sdbType
]
=
hash
;
taosInitRWLatch
(
&
pSdb
->
locks
[
sdbType
]);
taosInitRWLatch
(
&
pSdb
->
locks
[
sdbType
]);
m
Trace
(
"sdb table:%d is initialized"
,
sdbType
);
m
Debug
(
"sdb table:%d is initialized"
,
sdbType
);
return
0
;
return
0
;
}
}
\ No newline at end of file
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
7fea9e2f
...
@@ -118,7 +118,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
...
@@ -118,7 +118,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
break
;
break
;
}
}
code
=
sdbWrite
Raw
(
pSdb
,
pRaw
);
code
=
sdbWrite
NotFree
(
pSdb
,
pRaw
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
mError
(
"failed to read file:%s since %s"
,
file
,
terrstr
());
mError
(
"failed to read file:%s since %s"
,
file
,
terrstr
());
goto
PARSE_SDB_DATA_ERROR
;
goto
PARSE_SDB_DATA_ERROR
;
...
...
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
7fea9e2f
...
@@ -52,11 +52,12 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -52,11 +52,12 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosWLockLatch
(
pLock
);
taosWLockLatch
(
pLock
);
SSdbRow
*
p
Dst
Row
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
SSdbRow
*
p
Old
Row
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
p
Dst
Row
!=
NULL
)
{
if
(
p
Old
Row
!=
NULL
)
{
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
pRow
);
return
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
return
terrno
;
}
}
pRow
->
refCount
=
1
;
pRow
->
refCount
=
1
;
...
@@ -65,7 +66,8 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -65,7 +66,8 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
if
(
taosHashPut
(
hash
,
pRow
->
pObj
,
keySize
,
&
pRow
,
sizeof
(
void
*
))
!=
0
)
{
if
(
taosHashPut
(
hash
,
pRow
->
pObj
,
keySize
,
&
pRow
,
sizeof
(
void
*
))
!=
0
)
{
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
pRow
);
return
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
return
terrno
;
}
}
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
...
@@ -78,35 +80,36 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -78,35 +80,36 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
pRow
);
return
code
;
terrno
=
code
;
return
terrno
;
}
}
}
}
return
0
;
return
0
;
}
}
static
int32_t
sdbUpdateRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
static
int32_t
sdbUpdateRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
p
New
Row
,
int32_t
keySize
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
p
New
Row
->
type
];
taosRLockLatch
(
pLock
);
taosRLockLatch
(
pLock
);
SSdbRow
**
pp
DstRow
=
taosHashGet
(
hash
,
p
Row
->
pObj
,
keySize
);
SSdbRow
**
pp
OldRow
=
taosHashGet
(
hash
,
pNew
Row
->
pObj
,
keySize
);
if
(
pp
DstRow
==
NULL
||
*
ppDst
Row
==
NULL
)
{
if
(
pp
OldRow
==
NULL
||
*
ppOld
Row
==
NULL
)
{
taosRUnLockLatch
(
pLock
);
taosRUnLockLatch
(
pLock
);
return
sdbInsertRow
(
pSdb
,
hash
,
pRaw
,
pRow
,
keySize
);
return
sdbInsertRow
(
pSdb
,
hash
,
pRaw
,
p
New
Row
,
keySize
);
}
}
SSdbRow
*
p
DstRow
=
*
ppDst
Row
;
SSdbRow
*
p
OldRow
=
*
ppOld
Row
;
pRow
->
status
=
pRaw
->
status
;
p
Old
Row
->
status
=
pRaw
->
status
;
taosRUnLockLatch
(
pLock
);
taosRUnLockLatch
(
pLock
);
SdbUpdateFp
updateFp
=
pSdb
->
updateFps
[
pRow
->
type
];
SdbUpdateFp
updateFp
=
pSdb
->
updateFps
[
p
New
Row
->
type
];
if
(
updateFp
!=
NULL
)
{
if
(
updateFp
!=
NULL
)
{
code
=
(
*
updateFp
)(
pSdb
,
p
Row
->
pObj
,
pDst
Row
->
pObj
);
code
=
(
*
updateFp
)(
pSdb
,
p
OldRow
->
pObj
,
pNew
Row
->
pObj
);
}
}
sdbFreeRow
(
pRow
);
sdbFreeRow
(
p
New
Row
);
return
code
;
return
code
;
}
}
...
@@ -116,29 +119,30 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -116,29 +119,30 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosWLockLatch
(
pLock
);
taosWLockLatch
(
pLock
);
SSdbRow
**
pp
Dst
Row
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
SSdbRow
**
pp
Old
Row
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
pp
DstRow
==
NULL
||
*
ppDst
Row
==
NULL
)
{
if
(
pp
OldRow
==
NULL
||
*
ppOld
Row
==
NULL
)
{
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
pRow
);
return
TSDB_CODE_SDB_OBJ_NOT_THERE
;
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
return
terrno
;
}
}
SSdbRow
*
p
DstRow
=
*
ppDst
Row
;
SSdbRow
*
p
OldRow
=
*
ppOld
Row
;
p
Dst
Row
->
status
=
pRaw
->
status
;
p
Old
Row
->
status
=
pRaw
->
status
;
taosHashRemove
(
hash
,
p
Dst
Row
->
pObj
,
keySize
);
taosHashRemove
(
hash
,
p
Old
Row
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
SdbDeleteFp
deleteFp
=
pSdb
->
deleteFps
[
p
Dst
Row
->
type
];
SdbDeleteFp
deleteFp
=
pSdb
->
deleteFps
[
p
Old
Row
->
type
];
if
(
deleteFp
!=
NULL
)
{
if
(
deleteFp
!=
NULL
)
{
code
=
(
*
deleteFp
)(
pSdb
,
p
Dst
Row
->
pObj
);
code
=
(
*
deleteFp
)(
pSdb
,
p
Old
Row
->
pObj
);
}
}
sdbRelease
(
pSdb
,
p
Dst
Row
->
pObj
);
sdbRelease
(
pSdb
,
p
Old
Row
->
pObj
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
pRow
);
return
code
;
return
code
;
}
}
int32_t
sdbWrite
Raw
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
)
{
int32_t
sdbWrite
NotFree
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
)
{
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
pRaw
->
type
);
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
pRaw
->
type
);
if
(
hash
==
NULL
)
return
terrno
;
if
(
hash
==
NULL
)
return
terrno
;
...
@@ -170,7 +174,7 @@ int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw) {
...
@@ -170,7 +174,7 @@ int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw) {
}
}
int32_t
sdbWrite
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
)
{
int32_t
sdbWrite
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
sdbWrite
Raw
(
pSdb
,
pRaw
);
int32_t
code
=
sdbWrite
NotFree
(
pSdb
,
pRaw
);
sdbFreeRaw
(
pRaw
);
sdbFreeRaw
(
pRaw
);
return
code
;
return
code
;
}
}
...
...
source/dnode/mnode/sdb/src/sdbRaw.c
浏览文件 @
7fea9e2f
...
@@ -26,10 +26,15 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
...
@@ -26,10 +26,15 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
pRaw
->
type
=
type
;
pRaw
->
type
=
type
;
pRaw
->
sver
=
sver
;
pRaw
->
sver
=
sver
;
pRaw
->
dataLen
=
dataLen
;
pRaw
->
dataLen
=
dataLen
;
mTrace
(
"raw:%p, is created, len:%d"
,
pRaw
,
dataLen
);
return
pRaw
;
return
pRaw
;
}
}
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
)
{
free
(
pRaw
);
}
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
)
{
mTrace
(
"raw:%p, is freed"
,
pRaw
);
free
(
pRaw
);
}
int32_t
sdbSetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
val
)
{
int32_t
sdbSetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
val
)
{
if
(
pRaw
==
NULL
)
{
if
(
pRaw
==
NULL
)
{
...
...
source/dnode/vnode/impl/CMakeLists.txt
浏览文件 @
7fea9e2f
...
@@ -18,6 +18,6 @@ target_link_libraries(
...
@@ -18,6 +18,6 @@ target_link_libraries(
)
)
# test
# test
if
(
${
BUILD_TEST
}
)
#if(${BUILD_TEST})
add_subdirectory
(
test
)
# add_subdirectory(test)
endif
(
${
BUILD_TEST
}
)
#endif(${BUILD_TEST})
\ No newline at end of file
\ No newline at end of file
source/libs/function/src/tfunction.c
浏览文件 @
7fea9e2f
...
@@ -343,7 +343,7 @@ bool isProjectionQueryOnSTable(SArray* pFunctionIdList, int32_t tableIndex) {
...
@@ -343,7 +343,7 @@ bool isProjectionQueryOnSTable(SArray* pFunctionIdList, int32_t tableIndex) {
//
//
// if (functionId < 0) {
// if (functionId < 0) {
// SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1);
// SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1);
// if (pUdfInfo->funcType == TSDB_
UDF
_TYPE_AGGREGATE) {
// if (pUdfInfo->funcType == TSDB_
FUNC
_TYPE_AGGREGATE) {
// return false;
// return false;
// }
// }
//
//
...
...
source/libs/function/src/tudf.c
浏览文件 @
7fea9e2f
...
@@ -146,7 +146,7 @@ void doInvokeUdf(struct SUdfInfo* pUdfInfo, SQLFunctionCtx *pCtx, int32_t idx, i
...
@@ -146,7 +146,7 @@ void doInvokeUdf(struct SUdfInfo* pUdfInfo, SQLFunctionCtx *pCtx, int32_t idx, i
pCtx->pOutput, interBuf, (char *)pCtx->ptsOutputBuf, &output, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes, &pUdfInfo->init);
pCtx->pOutput, interBuf, (char *)pCtx->ptsOutputBuf, &output, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes, &pUdfInfo->init);
}
}
if (pUdfInfo->funcType == TSDB_
UDF
_TYPE_AGGREGATE) {
if (pUdfInfo->funcType == TSDB_
FUNC
_TYPE_AGGREGATE) {
pCtx->resultInfo->numOfRes = output;
pCtx->resultInfo->numOfRes = output;
} else {
} else {
pCtx->resultInfo->numOfRes += output;
pCtx->resultInfo->numOfRes += output;
...
...
source/libs/index/src/index_fst.c
浏览文件 @
7fea9e2f
...
@@ -591,14 +591,14 @@ uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) {
...
@@ -591,14 +591,14 @@ uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) {
uint8_t
*
data
=
fstSliceData
(
&
t
,
&
len
);
uint8_t
*
data
=
fstSliceData
(
&
t
,
&
len
);
int
i
=
0
;
int
i
=
0
;
for
(;
i
<
len
;
i
++
)
{
for
(;
i
<
len
;
i
++
)
{
//uint8_t v = slice->data[slice->start + i];
////slice->data[slice->start + i];
uint8_t
v
=
data
[
i
];
uint8_t
v
=
data
[
i
];
if
(
v
==
b
)
{
if
(
v
==
b
)
{
fstSliceDestroy
(
&
t
);
return
node
->
nTrans
-
i
-
1
;
// bug
return
node
->
nTrans
-
i
-
1
;
// bug
}
}
}
}
if
(
i
==
len
)
{
*
null
=
true
;
}
if
(
i
==
len
)
{
*
null
=
true
;
}
fstSliceDestroy
(
&
t
);
}
}
}
}
...
@@ -634,7 +634,7 @@ FstNode *fstNodeCreate(int64_t version, CompiledAddr addr, FstSlice *slice) {
...
@@ -634,7 +634,7 @@ FstNode *fstNodeCreate(int64_t version, CompiledAddr addr, FstSlice *slice) {
}
else
if
(
st
.
state
==
OneTrans
)
{
}
else
if
(
st
.
state
==
OneTrans
)
{
FstSlice
data
=
fstSliceCopy
(
slice
,
0
,
addr
);
FstSlice
data
=
fstSliceCopy
(
slice
,
0
,
addr
);
PackSizes
sz
=
fstStateSizes
(
&
st
,
&
data
);
PackSizes
sz
=
fstStateSizes
(
&
st
,
&
data
);
n
->
data
=
fstSliceCopy
(
slice
,
0
,
addr
)
;
n
->
data
=
data
;
n
->
version
=
version
;
n
->
version
=
version
;
n
->
state
=
st
;
n
->
state
=
st
;
n
->
start
=
addr
;
n
->
start
=
addr
;
...
@@ -803,6 +803,7 @@ void fstBuilderDestroy(FstBuilder *b) {
...
@@ -803,6 +803,7 @@ void fstBuilderDestroy(FstBuilder *b) {
fstCountingWriterDestroy
(
b
->
wrt
);
fstCountingWriterDestroy
(
b
->
wrt
);
fstUnFinishedNodesDestroy
(
b
->
unfinished
);
fstUnFinishedNodesDestroy
(
b
->
unfinished
);
fstRegistryDestroy
(
b
->
registry
);
fstRegistryDestroy
(
b
->
registry
);
fstSliceDestroy
(
&
b
->
last
);
free
(
b
);
free
(
b
);
}
}
...
@@ -851,8 +852,9 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
...
@@ -851,8 +852,9 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
OrderType
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDup
)
{
OrderType
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDup
)
{
FstSlice
*
input
=
&
bs
;
FstSlice
*
input
=
&
bs
;
if
(
fstSliceIsEmpty
(
&
b
->
last
))
{
if
(
fstSliceIsEmpty
(
&
b
->
last
))
{
fstSliceDestroy
(
&
b
->
last
);
// deep copy or not
// deep copy or not
b
->
last
=
fstSliceCopy
(
&
bs
,
input
->
start
,
input
->
end
);
b
->
last
=
fstSlice
Deep
Copy
(
&
bs
,
input
->
start
,
input
->
end
);
}
else
{
}
else
{
int
comp
=
fstSliceCompare
(
&
b
->
last
,
&
bs
);
int
comp
=
fstSliceCompare
(
&
b
->
last
,
&
bs
);
if
(
comp
==
0
&&
ckDup
)
{
if
(
comp
==
0
&&
ckDup
)
{
...
@@ -862,20 +864,22 @@ OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) {
...
@@ -862,20 +864,22 @@ OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) {
}
}
// deep copy or not
// deep copy or not
fstSliceDestroy
(
&
b
->
last
);
fstSliceDestroy
(
&
b
->
last
);
b
->
last
=
fstSliceCopy
(
&
bs
,
input
->
start
,
input
->
end
);
b
->
last
=
fstSlice
Deep
Copy
(
&
bs
,
input
->
start
,
input
->
end
);
}
}
return
Ordered
;
return
Ordered
;
}
}
void
fstBuilderCompileFrom
(
FstBuilder
*
b
,
uint64_t
istate
)
{
void
fstBuilderCompileFrom
(
FstBuilder
*
b
,
uint64_t
istate
)
{
CompiledAddr
addr
=
NONE_ADDRESS
;
CompiledAddr
addr
=
NONE_ADDRESS
;
while
(
istate
+
1
<
FST_UNFINISHED_NODES_LEN
(
b
->
unfinished
))
{
while
(
istate
+
1
<
FST_UNFINISHED_NODES_LEN
(
b
->
unfinished
))
{
FstBuilderNode
*
n
=
NULL
;
FstBuilderNode
*
b
n
=
NULL
;
if
(
addr
==
NONE_ADDRESS
)
{
if
(
addr
==
NONE_ADDRESS
)
{
n
=
fstUnFinishedNodesPopEmpty
(
b
->
unfinished
);
b
n
=
fstUnFinishedNodesPopEmpty
(
b
->
unfinished
);
}
else
{
}
else
{
n
=
fstUnFinishedNodesPopFreeze
(
b
->
unfinished
,
addr
);
b
n
=
fstUnFinishedNodesPopFreeze
(
b
->
unfinished
,
addr
);
}
}
addr
=
fstBuilderCompile
(
b
,
n
);
addr
=
fstBuilderCompile
(
b
,
bn
);
fstBuilderNodeDestroy
(
bn
);
assert
(
addr
!=
NONE_ADDRESS
);
assert
(
addr
!=
NONE_ADDRESS
);
//fstBuilderNodeDestroy(n);
//fstBuilderNodeDestroy(n);
}
}
...
@@ -910,6 +914,7 @@ void* fstBuilderInsertInner(FstBuilder *b) {
...
@@ -910,6 +914,7 @@ void* fstBuilderInsertInner(FstBuilder *b) {
fstBuilderCompileFrom
(
b
,
0
);
fstBuilderCompileFrom
(
b
,
0
);
FstBuilderNode
*
rootNode
=
fstUnFinishedNodesPopRoot
(
b
->
unfinished
);
FstBuilderNode
*
rootNode
=
fstUnFinishedNodesPopRoot
(
b
->
unfinished
);
CompiledAddr
rootAddr
=
fstBuilderCompile
(
b
,
rootNode
);
CompiledAddr
rootAddr
=
fstBuilderCompile
(
b
,
rootNode
);
fstBuilderNodeDestroy
(
rootNode
);
char
buf64
[
8
]
=
{
0
};
char
buf64
[
8
]
=
{
0
};
...
@@ -1026,7 +1031,10 @@ Fst* fstCreate(FstSlice *slice) {
...
@@ -1026,7 +1031,10 @@ Fst* fstCreate(FstSlice *slice) {
fst
->
meta
->
ty
=
type
;
fst
->
meta
->
ty
=
type
;
fst
->
meta
->
len
=
fstLen
;
fst
->
meta
->
len
=
fstLen
;
fst
->
meta
->
checkSum
=
checkSum
;
fst
->
meta
->
checkSum
=
checkSum
;
fst
->
data
=
slice
;
FstSlice
*
s
=
calloc
(
1
,
sizeof
(
FstSlice
));
*
s
=
fstSliceCopy
(
slice
,
0
,
FST_SLICE_LEN
(
slice
));
fst
->
data
=
s
;
return
fst
;
return
fst
;
...
@@ -1038,7 +1046,8 @@ FST_CREAT_FAILED:
...
@@ -1038,7 +1046,8 @@ FST_CREAT_FAILED:
void
fstDestroy
(
Fst
*
fst
)
{
void
fstDestroy
(
Fst
*
fst
)
{
if
(
fst
)
{
if
(
fst
)
{
free
(
fst
->
meta
);
free
(
fst
->
meta
);
fstNodeDestroy
(
fst
->
root
);
fstSliceDestroy
(
fst
->
data
);
free
(
fst
->
data
);
}
}
free
(
fst
);
free
(
fst
);
}
}
...
@@ -1048,6 +1057,9 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
...
@@ -1048,6 +1057,9 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
Output
tOut
=
0
;
Output
tOut
=
0
;
int32_t
len
;
int32_t
len
;
uint8_t
*
data
=
fstSliceData
(
b
,
&
len
);
uint8_t
*
data
=
fstSliceData
(
b
,
&
len
);
SArray
*
nodes
=
(
SArray
*
)
taosArrayInit
(
len
,
sizeof
(
FstNode
*
));
taosArrayPush
(
nodes
,
&
root
);
for
(
uint32_t
i
=
0
;
i
<
len
;
i
++
)
{
for
(
uint32_t
i
=
0
;
i
<
len
;
i
++
)
{
uint8_t
inp
=
data
[
i
];
uint8_t
inp
=
data
[
i
];
Output
res
=
0
;
Output
res
=
0
;
...
@@ -1059,12 +1071,22 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
...
@@ -1059,12 +1071,22 @@ bool fstGet(Fst *fst, FstSlice *b, Output *out) {
fstNodeGetTransitionAt
(
root
,
res
,
&
trn
);
fstNodeGetTransitionAt
(
root
,
res
,
&
trn
);
tOut
+=
trn
.
out
;
tOut
+=
trn
.
out
;
root
=
fstGetNode
(
fst
,
trn
.
addr
);
root
=
fstGetNode
(
fst
,
trn
.
addr
);
taosArrayPush
(
nodes
,
&
root
);
//fstNodeDestroy(root);
}
}
if
(
!
FST_NODE_IS_FINAL
(
root
))
{
if
(
!
FST_NODE_IS_FINAL
(
root
))
{
return
false
;
return
false
;
}
else
{
}
else
{
tOut
=
tOut
+
FST_NODE_FINAL_OUTPUT
(
root
);
tOut
=
tOut
+
FST_NODE_FINAL_OUTPUT
(
root
);
}
}
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
nodes
);
i
++
)
{
FstNode
**
node
=
(
FstNode
**
)
taosArrayGet
(
nodes
,
i
);
fstNodeDestroy
(
*
node
);
}
taosArrayDestroy
(
nodes
);
fst
->
root
=
NULL
;
*
out
=
tOut
;
*
out
=
tOut
;
return
true
;
return
true
;
...
@@ -1228,6 +1250,7 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) {
...
@@ -1228,6 +1250,7 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) {
taosArrayPush
(
sws
->
stack
,
&
s
);
taosArrayPush
(
sws
->
stack
,
&
s
);
out
+=
trn
.
out
;
out
+=
trn
.
out
;
node
=
fstGetNode
(
sws
->
fst
,
trn
.
addr
);
node
=
fstGetNode
(
sws
->
fst
,
trn
.
addr
);
fstNodeDestroy
(
node
);
}
else
{
}
else
{
// This is a little tricky. We're in this case if the
// This is a little tricky. We're in this case if the
...
...
source/libs/parser/inc/sql.y
浏览文件 @
7fea9e2f
...
@@ -112,13 +112,13 @@ cmd ::= SHOW dbPrefix(X) TABLES LIKE ids(Y). {
...
@@ -112,13 +112,13 @@ cmd ::= SHOW dbPrefix(X) TABLES LIKE ids(Y). {
}
}
cmd ::= SHOW dbPrefix(X) STABLES. {
cmd ::= SHOW dbPrefix(X) STABLES. {
setShowOptions(pInfo, TSDB_MGMT_TABLE_
METRIC
, &X, 0);
setShowOptions(pInfo, TSDB_MGMT_TABLE_
STABLE
, &X, 0);
}
}
cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
SToken token;
SToken token;
tSetDbName(&token, &X);
tSetDbName(&token, &X);
setShowOptions(pInfo, TSDB_MGMT_TABLE_
METRIC
, &token, &Y);
setShowOptions(pInfo, TSDB_MGMT_TABLE_
STABLE
, &token, &Y);
}
}
cmd ::= SHOW dbPrefix(X) VGROUPS. {
cmd ::= SHOW dbPrefix(X) VGROUPS. {
...
...
source/libs/parser/src/astGenerator.c
浏览文件 @
7fea9e2f
...
@@ -972,13 +972,6 @@ void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) {
...
@@ -972,13 +972,6 @@ void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) {
memset
(
&
pDBInfo
->
precision
,
0
,
sizeof
(
SToken
));
memset
(
&
pDBInfo
->
precision
,
0
,
sizeof
(
SToken
));
}
}
void
setDefaultCreateTopicOption
(
SCreateDbInfo
*
pDBInfo
)
{
setDefaultCreateDbOption
(
pDBInfo
);
pDBInfo
->
dbType
=
TSDB_DB_TYPE_TOPIC
;
pDBInfo
->
partitions
=
TSDB_DEFAULT_DB_PARTITON_OPTION
;
}
// prefix show db.tables;
// prefix show db.tables;
void
tSetDbName
(
SToken
*
pCpxName
,
SToken
*
pDb
)
{
void
tSetDbName
(
SToken
*
pCpxName
,
SToken
*
pDb
)
{
pCpxName
->
type
=
pDb
->
type
;
pCpxName
->
type
=
pDb
->
type
;
...
...
source/libs/parser/src/parserUtil.c
浏览文件 @
7fea9e2f
...
@@ -1480,7 +1480,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild) {
...
@@ -1480,7 +1480,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild) {
pTableMeta
->
tversion
=
pChild
->
tversion
;
pTableMeta
->
tversion
=
pChild
->
tversion
;
pTableMeta
->
sversion
=
pChild
->
sversion
;
pTableMeta
->
sversion
=
pChild
->
sversion
;
memcpy
(
pTableMeta
->
schema
,
pChild
->
s
chema
,
sizeof
(
SSchema
)
*
total
);
memcpy
(
pTableMeta
->
schema
,
pChild
->
pS
chema
,
sizeof
(
SSchema
)
*
total
);
int32_t
num
=
pTableMeta
->
tableInfo
.
numOfColumns
;
int32_t
num
=
pTableMeta
->
tableInfo
.
numOfColumns
;
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
...
...
source/libs/parser/src/sql.c
浏览文件 @
7fea9e2f
...
@@ -2312,14 +2312,14 @@ static void yy_reduce(
...
@@ -2312,14 +2312,14 @@ static void yy_reduce(
break
;
break
;
case
26
:
/* cmd ::= SHOW dbPrefix STABLES */
case
26
:
/* cmd ::= SHOW dbPrefix STABLES */
{
{
setShowOptions
(
pInfo
,
TSDB_MGMT_TABLE_
METRIC
,
&
yymsp
[
-
1
].
minor
.
yy0
,
0
);
setShowOptions
(
pInfo
,
TSDB_MGMT_TABLE_
STABLE
,
&
yymsp
[
-
1
].
minor
.
yy0
,
0
);
}
}
break
;
break
;
case
27
:
/* cmd ::= SHOW dbPrefix STABLES LIKE ids */
case
27
:
/* cmd ::= SHOW dbPrefix STABLES LIKE ids */
{
{
SToken
token
;
SToken
token
;
tSetDbName
(
&
token
,
&
yymsp
[
-
3
].
minor
.
yy0
);
tSetDbName
(
&
token
,
&
yymsp
[
-
3
].
minor
.
yy0
);
setShowOptions
(
pInfo
,
TSDB_MGMT_TABLE_
METRIC
,
&
token
,
&
yymsp
[
0
].
minor
.
yy0
);
setShowOptions
(
pInfo
,
TSDB_MGMT_TABLE_
STABLE
,
&
token
,
&
yymsp
[
0
].
minor
.
yy0
);
}
}
break
;
break
;
case
28
:
/* cmd ::= SHOW dbPrefix VGROUPS */
case
28
:
/* cmd ::= SHOW dbPrefix VGROUPS */
...
...
source/util/src/terror.c
浏览文件 @
7fea9e2f
...
@@ -211,32 +211,41 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STABLE_NAME, "Super table does not
...
@@ -211,32 +211,41 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STABLE_NAME, "Super table does not
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG
,
"Invalid create table message"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG
,
"Invalid create table message"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES
,
"Exceed max row bytes"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES
,
"Exceed max row bytes"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_NAME
,
"Invalid func name"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_LEN
,
"Invalid func length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_CODE
,
"Invalid func code"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_FUNC_ALREADY_EXIST
,
"Func already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_FUNC_ALREADY_EXIST
,
"Func already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_FUNC_NOT_EXIST
,
"Func not exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC
,
"Invalid func"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC
,
"Invalid func"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_NAME
,
"Invalid func name"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_COMMENT
,
"Invalid func comment"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_CODE
,
"Invalid func code"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_BUFSIZE
,
"Invalid func bufSize"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_BUFSIZE
,
"Invalid func bufSize"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TAG_LENGTH
,
"invalid tag length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TAG_LENGTH
,
"invalid tag length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_COLUMN_LENGTH
,
"invalid column length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_COLUMN_LENGTH
,
"invalid column length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_NOT_SELECTED
,
"Database not specified or available"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_NOT_SELECTED
,
"Database not specified or available"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_NOT_EXIST
,
"Database not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_ALREADY_EXIST
,
"Database already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_ALREADY_EXIST
,
"Database already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_OPTION
,
"Invalid database options"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB
,
"Invalid database name"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB
,
"Invalid database name"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_MONITOR_DB_FORBIDDEN
,
"Cannot delete monitor database"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_OPTION
,
"Invalid database options"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_CACHE_SIZE
,
"Invalid database cache block size option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_TOTAL_BLOCKS
,
"Invalid database total blocks option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_DAYS
,
"Invalid database days option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_KEEP0
,
"Invalid database keep0 option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_KEEP1
,
"Invalid database keep1 option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_KEEP2
,
"Invalid database keep2 option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_MIN_ROWS
,
"Invalid database min rows option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_MAX_ROWS
,
"Invalid database max rows option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_COMMIT_TIME
,
"Invalid database commit time option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_FSYNC_PERIOD
,
"Invalid database fsync periodoptions"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_WAL_LEVEL
,
"Invalid database wal level option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_PRECISION
,
"Invalid database precisin option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_COMP
,
"Invalid database compression option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_REPLICA
,
"Invalid database replication option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_QUORUM
,
"Invalid database quorum option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_UPDATE
,
"Invalid database update option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_CACHE_LAST
,
"Invalid database cache last option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_OPTION_UNCHANGED
,
"Database options not changed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOO_MANY_DATABASES
,
"Too many databases for account"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOO_MANY_DATABASES
,
"Too many databases for account"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_IN_DROPPING
,
"Database not available"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_VGROUP_NOT_READY
,
"Database unsynced"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_OPTION_DAYS
,
"Invalid database option: days out of range"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_OPTION_KEEP
,
"Invalid database option: keep2 >= keep1 >= keep0 >= days"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TOPIC
,
"Invalid topic name"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TOPIC_OPTION
,
"Invalid topic option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TOPIC_PARTITONS
,
"Invalid topic partitons num, valid range: [1, 1000]"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOPIC_ALREADY_EXIST
,
"Topic already exists"
)
// dnode
// dnode
TAOS_DEFINE_ERROR
(
TSDB_CODE_DND_ACTION_IN_PROGRESS
,
"Action in progress"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_DND_ACTION_IN_PROGRESS
,
"Action in progress"
)
...
...
source/util/src/tutil.c
浏览文件 @
7fea9e2f
...
@@ -187,7 +187,7 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) {
...
@@ -187,7 +187,7 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) {
}
}
char
*
strtolower
(
char
*
dst
,
const
char
*
src
)
{
char
*
strtolower
(
char
*
dst
,
const
char
*
src
)
{
int
esc
=
0
;
int
32_t
esc
=
0
;
char
quote
=
0
,
*
p
=
dst
,
c
;
char
quote
=
0
,
*
p
=
dst
,
c
;
assert
(
dst
!=
NULL
);
assert
(
dst
!=
NULL
);
...
@@ -214,7 +214,7 @@ char* strtolower(char *dst, const char *src) {
...
@@ -214,7 +214,7 @@ char* strtolower(char *dst, const char *src) {
}
}
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
)
{
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
)
{
int
esc
=
0
;
int
32_t
esc
=
0
;
char
quote
=
0
,
*
p
=
dst
,
c
;
char
quote
=
0
,
*
p
=
dst
,
c
;
assert
(
dst
!=
NULL
);
assert
(
dst
!=
NULL
);
...
@@ -347,7 +347,7 @@ char *strbetween(char *string, char *begin, char *end) {
...
@@ -347,7 +347,7 @@ char *strbetween(char *string, char *begin, char *end) {
char
*
_begin
=
strstr
(
string
,
begin
);
char
*
_begin
=
strstr
(
string
,
begin
);
if
(
_begin
!=
NULL
)
{
if
(
_begin
!=
NULL
)
{
char
*
_end
=
strstr
(
_begin
+
strlen
(
begin
),
end
);
char
*
_end
=
strstr
(
_begin
+
strlen
(
begin
),
end
);
int
size
=
(
in
t
)(
_end
-
_begin
);
int
32_t
size
=
(
int32_
t
)(
_end
-
_begin
);
if
(
_end
!=
NULL
&&
size
>
0
)
{
if
(
_end
!=
NULL
&&
size
>
0
)
{
result
=
(
char
*
)
calloc
(
1
,
size
);
result
=
(
char
*
)
calloc
(
1
,
size
);
memcpy
(
result
,
_begin
+
strlen
(
begin
),
size
-
+
strlen
(
begin
));
memcpy
(
result
,
_begin
+
strlen
(
begin
),
size
-
+
strlen
(
begin
));
...
@@ -402,7 +402,7 @@ int32_t taosHexStrToByteArray(char hexstr[], char bytes[]) {
...
@@ -402,7 +402,7 @@ int32_t taosHexStrToByteArray(char hexstr[], char bytes[]) {
char
*
taosIpStr
(
uint32_t
ipInt
)
{
char
*
taosIpStr
(
uint32_t
ipInt
)
{
static
char
ipStrArray
[
3
][
30
];
static
char
ipStrArray
[
3
][
30
];
static
int
ipStrIndex
=
0
;
static
int
32_t
ipStrIndex
=
0
;
char
*
ipStr
=
ipStrArray
[(
ipStrIndex
++
)
%
3
];
char
*
ipStr
=
ipStrArray
[(
ipStrIndex
++
)
%
3
];
//sprintf(ipStr, "0x%x:%u.%u.%u.%u", ipInt, ipInt & 0xFF, (ipInt >> 8) & 0xFF, (ipInt >> 16) & 0xFF, (uint8_t)(ipInt >> 24));
//sprintf(ipStr, "0x%x:%u.%u.%u.%u", ipInt, ipInt & 0xFF, (ipInt >> 8) & 0xFF, (ipInt >> 16) & 0xFF, (uint8_t)(ipInt >> 24));
...
@@ -416,4 +416,17 @@ void taosIp2String(uint32_t ip, char *str) {
...
@@ -416,4 +416,17 @@ void taosIp2String(uint32_t ip, char *str) {
void
taosIpPort2String
(
uint32_t
ip
,
uint16_t
port
,
char
*
str
)
{
void
taosIpPort2String
(
uint32_t
ip
,
uint16_t
port
,
char
*
str
)
{
sprintf
(
str
,
"%u.%u.%u.%u:%u"
,
ip
&
0xFF
,
(
ip
>>
8
)
&
0xFF
,
(
ip
>>
16
)
&
0xFF
,
(
uint8_t
)(
ip
>>
24
),
port
);
sprintf
(
str
,
"%u.%u.%u.%u:%u"
,
ip
&
0xFF
,
(
ip
>>
8
)
&
0xFF
,
(
ip
>>
16
)
&
0xFF
,
(
uint8_t
)(
ip
>>
24
),
port
);
}
int32_t
taosGetFqdnPortFromEp
(
const
char
*
ep
,
char
*
fqdn
,
uint16_t
*
port
)
{
*
port
=
0
;
strcpy
(
fqdn
,
ep
);
char
*
temp
=
strchr
(
fqdn
,
':'
);
if
(
temp
)
{
*
temp
=
0
;
*
port
=
atoi
(
temp
+
1
);
}
return
0
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录