Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1d420652
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1d420652
编写于
5月 04, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
5月 04, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12070 from taosdata/feature/dnode
fix: invalid write in multi-process mode
上级
d20d7872
e674de5b
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
232 addition
and
92 deletion
+232
-92
source/dnode/mnode/impl/inc/mndUser.h
source/dnode/mnode/impl/inc/mndUser.h
+4
-1
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+74
-74
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+2
-3
source/dnode/mnode/impl/test/trans/CMakeLists.txt
source/dnode/mnode/impl/test/trans/CMakeLists.txt
+31
-5
source/dnode/mnode/impl/test/trans/trans1.cpp
source/dnode/mnode/impl/test/trans/trans1.cpp
+9
-9
source/dnode/mnode/impl/test/trans/trans2.cpp
source/dnode/mnode/impl/test/trans/trans2.cpp
+112
-0
未找到文件。
source/dnode/mnode/impl/inc/mndUser.h
浏览文件 @
1d420652
...
...
@@ -24,9 +24,12 @@ extern "C" {
int32_t
mndInitUser
(
SMnode
*
pMnode
);
void
mndCleanupUser
(
SMnode
*
pMnode
);
SUserObj
*
mndAcquireUser
(
SMnode
*
pMnode
,
char
*
userName
);
SUserObj
*
mndAcquireUser
(
SMnode
*
pMnode
,
c
onst
c
har
*
userName
);
void
mndReleaseUser
(
SMnode
*
pMnode
,
SUserObj
*
pUser
);
// for trans test
SSdbRaw
*
mndUserActionEncode
(
SUserObj
*
pUser
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
1d420652
...
...
@@ -22,9 +22,9 @@
#include "mndSync.h"
#include "mndUser.h"
#define
MND_
TRANS_VER_NUMBER 1
#define
MND_
TRANS_ARRAY_SIZE 8
#define
MND_
TRANS_RESERVE_SIZE 64
#define TRANS_VER_NUMBER 1
#define TRANS_ARRAY_SIZE 8
#define TRANS_RESERVE_SIZE 64
static
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
);
static
SSdbRow
*
mndTransActionDecode
(
SSdbRaw
*
pRaw
);
...
...
@@ -84,7 +84,7 @@ void mndCleanupTrans(SMnode *pMnode) {}
static
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
int32_t
rawDataLen
=
sizeof
(
STrans
)
+
MND_
TRANS_RESERVE_SIZE
;
int32_t
rawDataLen
=
sizeof
(
STrans
)
+
TRANS_RESERVE_SIZE
;
int32_t
redoLogNum
=
taosArrayGetSize
(
pTrans
->
redoLogs
);
int32_t
undoLogNum
=
taosArrayGetSize
(
pTrans
->
undoLogs
);
int32_t
commitLogNum
=
taosArrayGetSize
(
pTrans
->
commitLogs
);
...
...
@@ -116,7 +116,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
rawDataLen
+=
(
sizeof
(
STransAction
)
+
pAction
->
contLen
);
}
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_TRANS
,
MND_
TRANS_VER_NUMBER
,
rawDataLen
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_TRANS
,
TRANS_VER_NUMBER
,
rawDataLen
);
if
(
pRaw
==
NULL
)
{
mError
(
"trans:%d, failed to alloc raw since %s"
,
pTrans
->
id
,
terrstr
());
return
NULL
;
...
...
@@ -182,7 +182,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pTrans
->
param
,
pTrans
->
paramLen
,
TRANS_ENCODE_OVER
)
}
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
MND_
TRANS_RESERVE_SIZE
,
TRANS_ENCODE_OVER
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TRANS_RESERVE_SIZE
,
TRANS_ENCODE_OVER
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
,
TRANS_ENCODE_OVER
)
terrno
=
0
;
...
...
@@ -214,38 +214,38 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
int32_t
dataPos
=
0
;
STransAction
action
=
{
0
};
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
goto
TRANS_DECODE
_OVER
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
goto
_OVER
;
if
(
sver
!=
MND_
TRANS_VER_NUMBER
)
{
if
(
sver
!=
TRANS_VER_NUMBER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
goto
TRANS_DECODE
_OVER
;
goto
_OVER
;
}
pRow
=
sdbAllocRow
(
sizeof
(
STrans
));
if
(
pRow
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pRow
==
NULL
)
goto
_OVER
;
pTrans
=
sdbGetRowObj
(
pRow
);
if
(
pTrans
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pTrans
==
NULL
)
goto
_OVER
;
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
id
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
id
,
_OVER
)
int16_t
type
=
0
;
int16_t
policy
=
0
;
int16_t
stage
=
0
;
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
policy
,
TRANS_DECODE
_OVER
)
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
stage
,
TRANS_DECODE
_OVER
)
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
type
,
TRANS_DECODE
_OVER
)
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
policy
,
_OVER
)
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
stage
,
_OVER
)
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
type
,
_OVER
)
pTrans
->
policy
=
policy
;
pTrans
->
stage
=
stage
;
pTrans
->
transType
=
type
;
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pTrans
->
createdTime
,
TRANS_DECODE
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pTrans
->
dbUid
,
TRANS_DECODE
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pTrans
->
dbname
,
TSDB_DB_FNAME_LEN
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
redoLogNum
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
undoLogNum
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
commitLogNum
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
redoActionNum
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
undoActionNum
,
TRANS_DECODE
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pTrans
->
createdTime
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pTrans
->
dbUid
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pTrans
->
dbname
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
redoLogNum
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
undoLogNum
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
commitLogNum
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
redoActionNum
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
undoActionNum
,
_OVER
)
pTrans
->
redoLogs
=
taosArrayInit
(
redoLogNum
,
sizeof
(
void
*
));
pTrans
->
undoLogs
=
taosArrayInit
(
undoLogNum
,
sizeof
(
void
*
));
...
...
@@ -253,79 +253,79 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
pTrans
->
redoActions
=
taosArrayInit
(
redoActionNum
,
sizeof
(
STransAction
));
pTrans
->
undoActions
=
taosArrayInit
(
undoActionNum
,
sizeof
(
STransAction
));
if
(
pTrans
->
redoLogs
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pTrans
->
undoLogs
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pTrans
->
commitLogs
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pTrans
->
redoActions
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pTrans
->
undoActions
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pTrans
->
redoLogs
==
NULL
)
goto
_OVER
;
if
(
pTrans
->
undoLogs
==
NULL
)
goto
_OVER
;
if
(
pTrans
->
commitLogs
==
NULL
)
goto
_OVER
;
if
(
pTrans
->
redoActions
==
NULL
)
goto
_OVER
;
if
(
pTrans
->
undoActions
==
NULL
)
goto
_OVER
;
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
_OVER
)
pData
=
taosMemoryMalloc
(
dataLen
);
if
(
pData
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pData
==
NULL
)
goto
_OVER
;
mTrace
(
"raw:%p, is created"
,
pData
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE
_OVER
);
if
(
taosArrayPush
(
pTrans
->
redoLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE
_OVER
;
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
_OVER
);
if
(
taosArrayPush
(
pTrans
->
redoLogs
,
&
pData
)
==
NULL
)
goto
_OVER
;
pData
=
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
_OVER
)
pData
=
taosMemoryMalloc
(
dataLen
);
if
(
pData
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pData
==
NULL
)
goto
_OVER
;
mTrace
(
"raw:%p, is created"
,
pData
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE
_OVER
);
if
(
taosArrayPush
(
pTrans
->
undoLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE
_OVER
;
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
_OVER
);
if
(
taosArrayPush
(
pTrans
->
undoLogs
,
&
pData
)
==
NULL
)
goto
_OVER
;
pData
=
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
_OVER
)
pData
=
taosMemoryMalloc
(
dataLen
);
if
(
pData
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
pData
==
NULL
)
goto
_OVER
;
mTrace
(
"raw:%p, is created"
,
pData
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE
_OVER
);
if
(
taosArrayPush
(
pTrans
->
commitLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE
_OVER
;
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
_OVER
);
if
(
taosArrayPush
(
pTrans
->
commitLogs
,
&
pData
)
==
NULL
)
goto
_OVER
;
pData
=
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
redoActionNum
;
++
i
)
{
SDB_GET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
&
action
.
epSet
,
sizeof
(
SEpSet
),
TRANS_DECODE
_OVER
);
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
action
.
msgType
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
acceptableCode
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
contLen
,
TRANS_DECODE
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
&
action
.
epSet
,
sizeof
(
SEpSet
),
_OVER
);
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
action
.
msgType
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
acceptableCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
contLen
,
_OVER
)
action
.
pCont
=
taosMemoryMalloc
(
action
.
contLen
);
if
(
action
.
pCont
==
NULL
)
goto
TRANS_DECODE
_OVER
;
SDB_GET_BINARY
(
pRaw
,
dataPos
,
action
.
pCont
,
action
.
contLen
,
TRANS_DECODE
_OVER
);
if
(
taosArrayPush
(
pTrans
->
redoActions
,
&
action
)
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
action
.
pCont
==
NULL
)
goto
_OVER
;
SDB_GET_BINARY
(
pRaw
,
dataPos
,
action
.
pCont
,
action
.
contLen
,
_OVER
);
if
(
taosArrayPush
(
pTrans
->
redoActions
,
&
action
)
==
NULL
)
goto
_OVER
;
action
.
pCont
=
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
undoActionNum
;
++
i
)
{
SDB_GET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
&
action
.
epSet
,
sizeof
(
SEpSet
),
TRANS_DECODE
_OVER
);
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
action
.
msgType
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
acceptableCode
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
contLen
,
TRANS_DECODE
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
&
action
.
epSet
,
sizeof
(
SEpSet
),
_OVER
);
SDB_GET_INT16
(
pRaw
,
dataPos
,
&
action
.
msgType
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
acceptableCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
contLen
,
_OVER
)
action
.
pCont
=
taosMemoryMalloc
(
action
.
contLen
);
if
(
action
.
pCont
==
NULL
)
goto
TRANS_DECODE
_OVER
;
SDB_GET_BINARY
(
pRaw
,
dataPos
,
action
.
pCont
,
action
.
contLen
,
TRANS_DECODE
_OVER
);
if
(
taosArrayPush
(
pTrans
->
undoActions
,
&
action
)
==
NULL
)
goto
TRANS_DECODE
_OVER
;
if
(
action
.
pCont
==
NULL
)
goto
_OVER
;
SDB_GET_BINARY
(
pRaw
,
dataPos
,
action
.
pCont
,
action
.
contLen
,
_OVER
);
if
(
taosArrayPush
(
pTrans
->
undoActions
,
&
action
)
==
NULL
)
goto
_OVER
;
action
.
pCont
=
NULL
;
}
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
startFunc
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
stopFunc
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
paramLen
,
TRANS_DECODE
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
startFunc
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
stopFunc
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
pTrans
->
paramLen
,
_OVER
)
if
(
pTrans
->
paramLen
!=
0
)
{
pTrans
->
param
=
taosMemoryMalloc
(
pTrans
->
paramLen
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pTrans
->
param
,
pTrans
->
paramLen
,
TRANS_DECODE
_OVER
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pTrans
->
param
,
pTrans
->
paramLen
,
_OVER
);
}
SDB_GET_RESERVE
(
pRaw
,
dataPos
,
MND_TRANS_RESERVE_SIZE
,
TRANS_DECODE
_OVER
)
SDB_GET_RESERVE
(
pRaw
,
dataPos
,
TRANS_RESERVE_SIZE
,
_OVER
)
terrno
=
0
;
TRANS_DECODE
_OVER:
_OVER:
if
(
terrno
!=
0
)
{
mError
(
"trans:%d, failed to parse from raw:%p since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
mndTransDropData
(
pTrans
);
...
...
@@ -545,11 +545,11 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnType type, const S
pTrans
->
rpcHandle
=
pReq
->
handle
;
pTrans
->
rpcAHandle
=
pReq
->
ahandle
;
pTrans
->
rpcRefId
=
pReq
->
refId
;
pTrans
->
redoLogs
=
taosArrayInit
(
MND_
TRANS_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
undoLogs
=
taosArrayInit
(
MND_
TRANS_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
commitLogs
=
taosArrayInit
(
MND_
TRANS_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
redoActions
=
taosArrayInit
(
MND_
TRANS_ARRAY_SIZE
,
sizeof
(
STransAction
));
pTrans
->
undoActions
=
taosArrayInit
(
MND_
TRANS_ARRAY_SIZE
,
sizeof
(
STransAction
));
pTrans
->
redoLogs
=
taosArrayInit
(
TRANS_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
undoLogs
=
taosArrayInit
(
TRANS_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
commitLogs
=
taosArrayInit
(
TRANS_ARRAY_SIZE
,
sizeof
(
void
*
));
pTrans
->
redoActions
=
taosArrayInit
(
TRANS_ARRAY_SIZE
,
sizeof
(
STransAction
));
pTrans
->
undoActions
=
taosArrayInit
(
TRANS_ARRAY_SIZE
,
sizeof
(
STransAction
));
if
(
pTrans
->
redoLogs
==
NULL
||
pTrans
->
undoLogs
==
NULL
||
pTrans
->
commitLogs
==
NULL
||
pTrans
->
redoActions
==
NULL
||
pTrans
->
undoActions
==
NULL
)
{
...
...
@@ -855,7 +855,7 @@ void mndTransProcessRsp(SNodeMsg *pRsp) {
STrans
*
pTrans
=
mndAcquireTrans
(
pMnode
,
transId
);
if
(
pTrans
==
NULL
)
{
mError
(
"trans:%d, failed to get transId from vnode rsp since %s"
,
transId
,
terrstr
());
goto
HANDLE_ACTION_RSP
_OVER
;
goto
_OVER
;
}
SArray
*
pArray
=
NULL
;
...
...
@@ -865,18 +865,18 @@ void mndTransProcessRsp(SNodeMsg *pRsp) {
pArray
=
pTrans
->
undoActions
;
}
else
{
mError
(
"trans:%d, invalid trans stage:%d while recv action rsp"
,
pTrans
->
id
,
pTrans
->
stage
);
goto
HANDLE_ACTION_RSP
_OVER
;
goto
_OVER
;
}
if
(
pArray
==
NULL
)
{
mError
(
"trans:%d, invalid trans stage:%d"
,
transId
,
pTrans
->
stage
);
goto
HANDLE_ACTION_RSP
_OVER
;
goto
_OVER
;
}
int32_t
actionNum
=
taosArrayGetSize
(
pTrans
->
redoActions
);
if
(
action
<
0
||
action
>=
actionNum
)
{
mError
(
"trans:%d, invalid action:%d"
,
transId
,
action
);
goto
HANDLE_ACTION_RSP
_OVER
;
goto
_OVER
;
}
STransAction
*
pAction
=
taosArrayGet
(
pArray
,
action
);
...
...
@@ -892,7 +892,7 @@ void mndTransProcessRsp(SNodeMsg *pRsp) {
pAction
->
acceptableCode
);
mndTransExecute
(
pMnode
,
pTrans
);
HANDLE_ACTION_RSP
_OVER:
_OVER:
mndReleaseTrans
(
pMnode
,
pTrans
);
}
...
...
@@ -1281,19 +1281,19 @@ static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
if
(
tDeserializeSKillTransReq
(
pReq
->
rpcMsg
.
pCont
,
pReq
->
rpcMsg
.
contLen
,
&
killReq
)
!=
0
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
goto
KILL
_OVER
;
goto
_OVER
;
}
mInfo
(
"trans:%d, start to kill"
,
killReq
.
transId
);
pUser
=
mndAcquireUser
(
pMnode
,
pReq
->
user
);
if
(
pUser
==
NULL
)
{
goto
KILL
_OVER
;
goto
_OVER
;
}
if
(
!
pUser
->
superUser
)
{
terrno
=
TSDB_CODE_MND_NO_RIGHTS
;
goto
KILL
_OVER
;
goto
_OVER
;
}
pTrans
=
mndAcquireTrans
(
pMnode
,
killReq
.
transId
);
...
...
@@ -1305,7 +1305,7 @@ static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
code
=
mndKillTrans
(
pMnode
,
pTrans
);
KILL
_OVER:
_OVER:
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to kill since %s"
,
killReq
.
transId
,
terrstr
());
return
-
1
;
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
1d420652
...
...
@@ -25,7 +25,6 @@
#define USER_RESERVE_SIZE 64
static
int32_t
mndCreateDefaultUsers
(
SMnode
*
pMnode
);
static
SSdbRaw
*
mndUserActionEncode
(
SUserObj
*
pUser
);
static
SSdbRow
*
mndUserActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndUserActionInsert
(
SSdb
*
pSdb
,
SUserObj
*
pUser
);
static
int32_t
mndUserActionDelete
(
SSdb
*
pSdb
,
SUserObj
*
pUser
);
...
...
@@ -90,7 +89,7 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
return
0
;
}
static
SSdbRaw
*
mndUserActionEncode
(
SUserObj
*
pUser
)
{
SSdbRaw
*
mndUserActionEncode
(
SUserObj
*
pUser
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
int32_t
numOfReadDbs
=
taosHashGetSize
(
pUser
->
readDbs
);
...
...
@@ -238,7 +237,7 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
return
0
;
}
SUserObj
*
mndAcquireUser
(
SMnode
*
pMnode
,
char
*
userName
)
{
SUserObj
*
mndAcquireUser
(
SMnode
*
pMnode
,
c
onst
c
har
*
userName
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SUserObj
*
pUser
=
sdbAcquire
(
pSdb
,
SDB_USER
,
userName
);
if
(
pUser
==
NULL
)
{
...
...
source/dnode/mnode/impl/test/trans/CMakeLists.txt
浏览文件 @
1d420652
aux_source_directory
(
. MNODE_TRANS_TEST_SRC
)
add_executable
(
transTest
${
MNODE_TRANS_TEST_SRC
}
)
add_executable
(
transTest1
""
)
target_sources
(
transTest1
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/trans1.cpp"
)
target_link_libraries
(
transTest
transTest
1
PUBLIC sut
)
target_include_directories
(
transTest1
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/dnode/mnode"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../inc"
)
add_test
(
NAME transTest1
COMMAND transTest1
)
add_executable
(
transTest2
""
)
target_sources
(
transTest2
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/trans2.cpp"
)
target_link_libraries
(
transTest2
PUBLIC dnode mnode gtest_main
)
target_include_directories
(
transTest2
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/dnode/mnode"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../inc"
)
add_test
(
NAME transTest
COMMAND transTest
NAME transTest
2
COMMAND transTest
2
)
source/dnode/mnode/impl/test/trans/trans.cpp
→
source/dnode/mnode/impl/test/trans/trans
1
.cpp
浏览文件 @
1d420652
...
...
@@ -11,10 +11,10 @@
#include "sut.h"
class
MndTestTrans
:
public
::
testing
::
Test
{
class
MndTestTrans
1
:
public
::
testing
::
Test
{
protected:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/mnode_test_trans"
,
9013
);
test
.
Init
(
"/tmp/mnode_test_trans
1
"
,
9013
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9013"
;
server2
.
Start
(
"/tmp/mnode_test_trans2"
,
fqdn
,
9020
,
firstEp
);
...
...
@@ -26,7 +26,7 @@ class MndTestTrans : public ::testing::Test {
}
static
void
KillThenRestartServer
()
{
char
file
[
PATH_MAX
]
=
"/tmp/mnode_test_trans/mnode/data/sdb.data"
;
char
file
[
PATH_MAX
]
=
"/tmp/mnode_test_trans
1
/mnode/data/sdb.data"
;
TdFilePtr
pFile
=
taosOpenFile
(
file
,
TD_FILE_READ
);
int32_t
size
=
3
*
1024
*
1024
;
void
*
buffer
=
taosMemoryMalloc
(
size
);
...
...
@@ -60,10 +60,10 @@ class MndTestTrans : public ::testing::Test {
void
TearDown
()
override
{}
};
Testbase
MndTestTrans
::
test
;
TestServer
MndTestTrans
::
server2
;
Testbase
MndTestTrans
1
::
test
;
TestServer
MndTestTrans
1
::
server2
;
TEST_F
(
MndTestTrans
,
00
_Create_User_Crash
)
{
TEST_F
(
MndTestTrans
1
,
00
_Create_User_Crash
)
{
{
test
.
SendShowReq
(
TSDB_MGMT_TABLE_TRANS
,
"trans"
,
""
);
EXPECT_EQ
(
test
.
GetShowRows
(),
0
);
...
...
@@ -83,7 +83,7 @@ TEST_F(MndTestTrans, 00_Create_User_Crash) {
}
}
TEST_F
(
MndTestTrans
,
01
_Create_User_Crash
)
{
TEST_F
(
MndTestTrans
1
,
01
_Create_User_Crash
)
{
{
SCreateUserReq
createReq
=
{
0
};
strcpy
(
createReq
.
user
,
"u1"
);
...
...
@@ -107,7 +107,7 @@ TEST_F(MndTestTrans, 01_Create_User_Crash) {
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
}
TEST_F
(
MndTestTrans
,
02
_Create_Qnode1_Crash
)
{
TEST_F
(
MndTestTrans
1
,
02
_Create_Qnode1_Crash
)
{
{
SMCreateQnodeReq
createReq
=
{
0
};
createReq
.
dnodeId
=
1
;
...
...
@@ -142,7 +142,7 @@ TEST_F(MndTestTrans, 02_Create_Qnode1_Crash) {
}
}
TEST_F
(
MndTestTrans
,
03
_Create_Qnode2_Crash
)
{
TEST_F
(
MndTestTrans
1
,
03
_Create_Qnode2_Crash
)
{
{
SCreateDnodeReq
createReq
=
{
0
};
strcpy
(
createReq
.
fqdn
,
"localhost"
);
...
...
source/dnode/mnode/impl/test/trans/trans2.cpp
0 → 100644
浏览文件 @
1d420652
/**
* @file trans.cpp
* @author slguan (slguan@taosdata.com)
* @brief MNODE module trans tests
* @version 1.0
* @date 2022-05-02
*
* @copyright Copyright (c) 2022
*
*/
#include <gtest/gtest.h>
#include "mndTrans.h"
#include "mndUser.h"
#include "tcache.h"
void
reportStartup
(
SMgmtWrapper
*
pWrapper
,
const
char
*
name
,
const
char
*
desc
)
{}
class
MndTestTrans2
:
public
::
testing
::
Test
{
protected:
static
void
SetUpTestSuite
()
{
dDebugFlag
=
143
;
vDebugFlag
=
0
;
mDebugFlag
=
143
;
cDebugFlag
=
0
;
jniDebugFlag
=
0
;
tmrDebugFlag
=
135
;
uDebugFlag
=
135
;
rpcDebugFlag
=
143
;
qDebugFlag
=
0
;
wDebugFlag
=
0
;
sDebugFlag
=
0
;
tsdbDebugFlag
=
0
;
tsLogEmbedded
=
1
;
tsAsyncLog
=
0
;
const
char
*
logpath
=
"/tmp/td"
;
taosRemoveDir
(
logpath
);
taosMkDir
(
logpath
);
tstrncpy
(
tsLogDir
,
logpath
,
PATH_MAX
);
if
(
taosInitLog
(
"taosdlog"
,
1
)
!=
0
)
{
printf
(
"failed to init log file
\n
"
);
}
walInit
();
static
SMsgCb
msgCb
=
{
0
};
msgCb
.
reportStartupFp
=
reportStartup
;
msgCb
.
pWrapper
=
(
SMgmtWrapper
*
)(
&
msgCb
);
// hack
tmsgSetDefaultMsgCb
(
&
msgCb
);
SMnodeOpt
opt
=
{
0
};
opt
.
deploy
=
1
;
opt
.
replica
=
1
;
opt
.
replicas
[
0
].
id
=
1
;
opt
.
replicas
[
0
].
port
=
9040
;
strcpy
(
opt
.
replicas
[
0
].
fqdn
,
"localhost"
);
opt
.
msgCb
=
msgCb
;
const
char
*
mnodepath
=
"/tmp/mnode_test_trans"
;
taosRemoveDir
(
mnodepath
);
pMnode
=
mndOpen
(
mnodepath
,
&
opt
);
}
static
void
TearDownTestSuite
()
{
mndClose
(
pMnode
);
walCleanUp
();
taosCloseLog
();
taosStopCacheRefreshWorker
();
}
static
SMnode
*
pMnode
;
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
void
CreateUser
(
const
char
*
user
)
{
SUserObj
userObj
=
{
0
};
taosEncryptPass_c
((
uint8_t
*
)
"taosdata"
,
strlen
(
"taosdata"
),
userObj
.
pass
);
tstrncpy
(
userObj
.
user
,
user
,
TSDB_USER_LEN
);
tstrncpy
(
userObj
.
acct
,
"root"
,
TSDB_USER_LEN
);
userObj
.
createdTime
=
taosGetTimestampMs
();
userObj
.
updateTime
=
userObj
.
createdTime
;
userObj
.
superUser
=
1
;
SRpcMsg
rpcMsg
=
{
0
};
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_TYPE_CREATE_USER
,
&
rpcMsg
);
SSdbRaw
*
pRedoRaw
=
mndUserActionEncode
(
&
userObj
);
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
);
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
);
char
*
param
=
strdup
(
"====> test param <====="
);
mndTransSetCb
(
pTrans
,
TEST_TRANS_START_FUNC
,
TEST_TRANS_STOP_FUNC
,
param
,
strlen
(
param
)
+
1
);
mndTransPrepare
(
pMnode
,
pTrans
);
mndTransDrop
(
pTrans
);
}
};
SMnode
*
MndTestTrans2
::
pMnode
;
TEST_F
(
MndTestTrans2
,
01
_CbFunc
)
{
ASSERT_NE
(
pMnode
,
nullptr
);
const
char
*
user1
=
"test1"
;
CreateUser
(
user1
);
SUserObj
*
pUser1
=
mndAcquireUser
(
pMnode
,
user1
);
ASSERT_NE
(
pUser1
,
nullptr
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录