Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
38085942
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看板
提交
38085942
编写于
11月 09, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
transaction thread
上级
82ad9a91
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
203 addition
and
14 deletion
+203
-14
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+4
-4
include/dnode/mnode/transaction/trn.h
include/dnode/mnode/transaction/trn.h
+2
-0
source/dnode/mnode/transaction/inc/trnInt.h
source/dnode/mnode/transaction/inc/trnInt.h
+1
-0
source/dnode/mnode/transaction/src/trn.c
source/dnode/mnode/transaction/src/trn.c
+150
-10
source/dnode/mnode/transaction/src/trnThread.c
source/dnode/mnode/transaction/src/trnThread.c
+46
-0
未找到文件。
include/dnode/mnode/sdb/sdb.h
浏览文件 @
38085942
...
...
@@ -21,7 +21,7 @@ extern "C" {
#endif
#define SDB_GET_BINARY_VAL(pData, dataLen, val, valLen, code) \
{
\
if (code == 0) {
\
if ((dataLen) >= (valLen)) { \
memcpy((val), (char *)(pData), (valLen)); \
(dataLen) -= (valLen); \
...
...
@@ -32,7 +32,7 @@ extern "C" {
}
#define SDB_GET_INT32_VAL(pData, dataLen, val, code) \
{
\
if (code == 0) {
\
if (dataLen >= sizeof(int32_t)) { \
*(int32_t *)(pData) = (int32_t)(val); \
(dataLen) -= sizeof(int32_t); \
...
...
@@ -43,7 +43,7 @@ extern "C" {
}
#define SDB_GET_INT64_VAL(pData, dataLen, val, code) \
{
\
if (code == 0) {
\
if (dataLen >= sizeof(int64_t)) { \
*(int64_t *)(pData) = (int64_t)(val); \
(dataLen) -= sizeof(int64_t); \
...
...
@@ -87,7 +87,7 @@ typedef enum {
SDB_VGROUP
=
9
,
SDB_STABLE
=
10
,
SDB_FUNC
=
11
,
SDB_
OPER
=
12
,
SDB_
TRANS
=
12
,
SDB_MAX
=
13
}
ESdbType
;
...
...
include/dnode/mnode/transaction/trn.h
浏览文件 @
38085942
...
...
@@ -29,7 +29,9 @@ int32_t trnInit();
void
trnCleanup
();
STrans
*
trnCreate
();
int32_t
trnPrepare
(
STrans
*
);
int32_t
trnCommit
(
STrans
*
);
int32_t
trnExecute
(
STrans
*
);
void
trnDrop
(
STrans
*
);
int32_t
trnAppendRedoLog
(
STrans
*
,
SSdbRawData
*
);
...
...
source/dnode/mnode/transaction/inc/trnInt.h
浏览文件 @
38085942
...
...
@@ -41,6 +41,7 @@ typedef struct STrans {
SArray
*
undoActions
;
}
STrans
;
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mnode/transaction/src/trn.c
浏览文件 @
38085942
...
...
@@ -16,11 +16,9 @@
#define _DEFAULT_SOURCE
#include "trnInt.h"
#define TRN_VER 1
#define TRN_DEFAULT_ARRAY_SIZE 8
int32_t
trnInit
()
{
return
0
;
}
void
trnCleanup
();
STrans
*
trnCreate
()
{
STrans
*
pTrans
=
calloc
(
1
,
sizeof
(
STrans
));
if
(
pTrans
==
NULL
)
{
...
...
@@ -36,12 +34,7 @@ STrans *trnCreate() {
if
(
pTrans
->
redoLogs
==
NULL
||
pTrans
->
undoLogs
==
NULL
||
pTrans
->
commitLogs
==
NULL
||
pTrans
->
redoActions
==
NULL
||
pTrans
->
undoActions
==
NULL
)
{
taosArrayDestroy
(
pTrans
->
redoLogs
);
taosArrayDestroy
(
pTrans
->
undoLogs
);
taosArrayDestroy
(
pTrans
->
commitLogs
);
taosArrayDestroy
(
pTrans
->
redoActions
);
taosArrayDestroy
(
pTrans
->
undoActions
);
free
(
pTrans
);
trnDrop
(
pTrans
);
terrno
=
TSDB_CODE_MND_OUT_OF_MEMORY
;
return
NULL
;
}
...
...
@@ -50,7 +43,22 @@ STrans *trnCreate() {
}
int32_t
trnCommit
(
STrans
*
pTrans
)
{
return
0
;
}
void
trnDrop
(
STrans
*
pTrans
)
{}
static
void
trnDropLogs
(
SArray
*
pArray
)
{
for
(
int32_t
index
=
0
;
index
<
pArray
->
size
;
++
index
)
{
SSdbRawData
*
pRaw
=
taosArrayGetP
(
pArray
,
index
);
free
(
pRaw
);
}
taosArrayDestroy
(
pArray
);
}
void
trnDrop
(
STrans
*
pTrans
)
{
trnDropLogs
(
pTrans
->
redoLogs
);
trnDropLogs
(
pTrans
->
undoLogs
);
trnDropLogs
(
pTrans
->
commitLogs
);
free
(
pTrans
);
}
int32_t
trnAppendRedoLog
(
STrans
*
pTrans
,
SSdbRawData
*
pRaw
)
{
void
*
ptr
=
taosArrayPush
(
pTrans
->
redoLogs
,
&
pRaw
);
...
...
@@ -91,3 +99,135 @@ int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
}
return
0
;
}
static
SSdbRawData
*
trnActionEncode
(
STrans
*
pTrans
)
{
int32_t
rawDataLen
=
5
*
sizeof
(
int32_t
);
int32_t
redoLogNum
=
taosArrayGetSize
(
pTrans
->
redoLogs
);
int32_t
undoLogNum
=
taosArrayGetSize
(
pTrans
->
undoLogs
);
int32_t
commitLogNum
=
taosArrayGetSize
(
pTrans
->
commitLogs
);
int32_t
redoActionNum
=
taosArrayGetSize
(
pTrans
->
redoActions
);
int32_t
undoActionNum
=
taosArrayGetSize
(
pTrans
->
undoActions
);
for
(
int32_t
index
=
0
;
index
<
redoLogNum
;
++
index
)
{
SSdbRawData
*
pRawData
=
taosArrayGet
(
pTrans
->
redoLogs
,
index
);
rawDataLen
+=
(
sizeof
(
SSdbRawData
)
+
pRawData
->
dataLen
);
}
for
(
int32_t
index
=
0
;
index
<
undoLogNum
;
++
index
)
{
SSdbRawData
*
pRawData
=
taosArrayGet
(
pTrans
->
undoLogs
,
index
);
rawDataLen
+=
(
sizeof
(
SSdbRawData
)
+
pRawData
->
dataLen
);
}
for
(
int32_t
index
=
0
;
index
<
commitLogNum
;
++
index
)
{
SSdbRawData
*
pRawData
=
taosArrayGet
(
pTrans
->
commitLogs
,
index
);
rawDataLen
+=
(
sizeof
(
SSdbRawData
)
+
pRawData
->
dataLen
);
}
SSdbRawData
*
pRaw
=
calloc
(
1
,
rawDataLen
+
sizeof
(
SSdbRawData
));
if
(
pRaw
==
NULL
)
{
terrno
=
TSDB_CODE_MND_OUT_OF_MEMORY
;
return
NULL
;
}
int32_t
dataLen
=
0
;
char
*
pData
=
pRaw
->
data
;
SDB_SET_INT32_VAL
(
pData
,
dataLen
,
redoLogNum
)
SDB_SET_INT32_VAL
(
pData
,
dataLen
,
undoLogNum
)
SDB_SET_INT32_VAL
(
pData
,
dataLen
,
commitLogNum
)
SDB_SET_INT32_VAL
(
pData
,
dataLen
,
redoActionNum
)
SDB_SET_INT32_VAL
(
pData
,
dataLen
,
undoActionNum
)
pRaw
->
dataLen
=
dataLen
;
pRaw
->
type
=
SDB_TRANS
;
pRaw
->
sver
=
TRN_VER
;
return
pRaw
;
}
static
STrans
*
trnActionDecode
(
SSdbRawData
*
pRaw
)
{
if
(
pRaw
->
sver
!=
TRN_VER
)
{
terrno
=
TSDB_CODE_SDB_INVAID_RAW_DATA_VER
;
return
NULL
;
}
STrans
*
pTrans
=
trnCreate
();
if
(
pTrans
==
NULL
)
{
terrno
=
TSDB_CODE_MND_OUT_OF_MEMORY
;
return
NULL
;
}
int32_t
redoLogNum
=
0
;
int32_t
undoLogNum
=
0
;
int32_t
commitLogNum
=
0
;
int32_t
redoActionNum
=
0
;
int32_t
undoActionNum
=
0
;
SSdbRawData
*
pTmp
=
malloc
(
sizeof
(
SSdbRawData
));
int32_t
code
=
0
;
int32_t
dataLen
=
pRaw
->
dataLen
;
char
*
pData
=
pRaw
->
data
;
SDB_GET_INT32_VAL
(
pData
,
dataLen
,
redoLogNum
,
code
)
SDB_GET_INT32_VAL
(
pData
,
dataLen
,
undoLogNum
,
code
)
SDB_GET_INT32_VAL
(
pData
,
dataLen
,
commitLogNum
,
code
)
SDB_GET_INT32_VAL
(
pData
,
dataLen
,
redoActionNum
,
code
)
SDB_GET_INT32_VAL
(
pData
,
dataLen
,
undoActionNum
,
code
)
for
(
int32_t
index
=
0
;
index
<
redoLogNum
;
++
index
)
{
SDB_GET_BINARY_VAL
(
pData
,
dataLen
,
pTmp
,
sizeof
(
SSdbRawData
),
code
);
if
(
code
==
0
&&
pTmp
->
dataLen
>
0
)
{
SSdbRawData
*
pRead
=
malloc
(
sizeof
(
SSdbRawData
)
+
pTmp
->
dataLen
);
if
(
pRead
==
NULL
)
{
code
=
TSDB_CODE_MND_OUT_OF_MEMORY
;
break
;
}
memcpy
(
pRead
,
pTmp
,
sizeof
(
SSdbRawData
));
SDB_GET_BINARY_VAL
(
pData
,
dataLen
,
pRead
->
data
,
pRead
->
dataLen
,
code
);
void
*
ret
=
taosArrayPush
(
pTrans
->
redoLogs
,
&
pRead
);
if
(
ret
==
NULL
)
{
code
=
TSDB_CODE_MND_OUT_OF_MEMORY
;
break
;
}
}
}
if
(
code
!=
0
)
{
trnDrop
(
pTrans
);
terrno
=
code
;
return
NULL
;
}
return
pTrans
;
}
static
int32_t
trnActionInsert
(
STrans
*
pTrans
)
{
SArray
*
pArray
=
pTrans
->
redoLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
index
=
0
;
index
<
arraySize
;
++
index
)
{
SSdbRawData
*
pRaw
=
taosArrayGetP
(
pArray
,
index
);
int32_t
code
=
sdbWrite
(
pRaw
);
if
(
code
!=
0
)
{
return
code
;
}
}
return
0
;
}
static
int32_t
trnActionDelete
(
STrans
*
pTrans
)
{
SArray
*
pArray
=
pTrans
->
redoLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
index
=
0
;
index
<
arraySize
;
++
index
)
{
SSdbRawData
*
pRaw
=
taosArrayGetP
(
pArray
,
index
);
int32_t
code
=
sdbWrite
(
pRaw
);
if
(
code
!=
0
)
{
return
code
;
}
}
return
0
;
}
static
int32_t
trnActionUpdate
(
STrans
*
pSrcUser
,
STrans
*
pDstUser
)
{
return
0
;
}
source/dnode/mnode/transaction/src/trnThread.c
0 → 100644
浏览文件 @
38085942
/*
* 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 "trnInt.h"
#include "tthread.h"
static
struct
{
pthread_t
*
threadId
;
bool
threadRunning
;
}
tsTrn
;
static
void
*
trnThreadFunc
(
void
*
param
)
{
while
(
1
)
{
pthread_testcancel
();
}
return
NULL
;
}
int32_t
trnInit
()
{
tsTrn
.
threadId
=
taosCreateThread
(
trnThreadFunc
,
NULL
);
if
(
tsTrn
.
threadId
==
NULL
)
{
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
return
0
;
}
void
trnCleanup
()
{
if
(
tsTrn
.
threadId
)
{
taosDestoryThread
(
tsTrn
.
threadId
);
tsTrn
.
threadId
=
NULL
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录