Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
622cdc39
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
622cdc39
编写于
11月 09, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add transaction interface
上级
79519165
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
221 addition
and
11 deletion
+221
-11
include/common/taosmsg.h
include/common/taosmsg.h
+0
-2
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+2
-2
include/dnode/mnode/transaction/trn.h
include/dnode/mnode/transaction/trn.h
+46
-0
source/dnode/mnode/impl/CMakeLists.txt
source/dnode/mnode/impl/CMakeLists.txt
+1
-0
source/dnode/mnode/impl/inc/mnodeDef.h
source/dnode/mnode/impl/inc/mnodeDef.h
+1
-1
source/dnode/mnode/impl/inc/mnodeInt.h
source/dnode/mnode/impl/inc/mnodeInt.h
+2
-0
source/dnode/mnode/impl/src/mnodeUser.c
source/dnode/mnode/impl/src/mnodeUser.c
+94
-2
source/dnode/mnode/sdb/CMakeLists.txt
source/dnode/mnode/sdb/CMakeLists.txt
+0
-1
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+1
-1
source/dnode/mnode/transaction/CMakeLists.txt
source/dnode/mnode/transaction/CMakeLists.txt
+5
-2
source/dnode/mnode/transaction/inc/trnInt.h
source/dnode/mnode/transaction/inc/trnInt.h
+39
-0
source/dnode/mnode/transaction/src/trn.c
source/dnode/mnode/transaction/src/trn.c
+30
-0
未找到文件。
include/common/taosmsg.h
浏览文件 @
622cdc39
...
...
@@ -399,8 +399,6 @@ typedef struct {
typedef
struct
{
char
user
[
TSDB_USER_LEN
];
char
pass
[
TSDB_KEY_LEN
];
int8_t
privilege
;
int8_t
flag
;
}
SCreateUserMsg
,
SAlterUserMsg
;
typedef
struct
{
...
...
include/dnode/mnode/sdb/sdb.h
浏览文件 @
622cdc39
...
...
@@ -93,7 +93,7 @@ typedef enum {
typedef
enum
{
SDB_ACTION_INSERT
=
1
,
SDB_ACTION_UPDATE
=
2
,
SDB_ACTION_DELETE
=
3
}
ESdbAction
;
typedef
enum
{
SDB_KEY_BINARY
=
1
,
SDB_KEY_INT32
=
2
,
SDB_KEY_INT64
=
3
}
EKeyType
;
typedef
enum
{
SDB_STATUS_CREATING
=
1
,
SDB_STATUS_READY
,
SDB_STATUS_DROPPING
,
SDB_STATUS_DROPPED
}
ESdbStatus
;
typedef
enum
{
SDB_STATUS_CREATING
=
1
,
SDB_STATUS_READY
=
2
,
SDB_STATUS_DROPPING
=
3
}
ESdbStatus
;
typedef
struct
{
int8_t
type
;
...
...
@@ -136,7 +136,7 @@ int32_t sdbDeploy();
void
sdbUnDeploy
();
void
*
sdbAcquire
(
ESdbType
sdb
,
void
*
pKey
);
void
sdbRelease
(
ESdbType
sdb
,
void
*
pObj
);
void
sdbRelease
(
void
*
pObj
);
void
*
sdbFetch
(
ESdbType
sdb
,
void
*
pIter
);
void
sdbCancelFetch
(
ESdbType
sdb
,
void
*
pIter
);
int32_t
sdbGetSize
(
ESdbType
sdb
);
...
...
include/dnode/mnode/transaction/trn.h
浏览文件 @
622cdc39
/*
* 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_TRANSACTION_H_
#define _TD_TRANSACTION_H_
#include "sdb.h"
#include "taosmsg.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
{
}
STrans
;
int32_t
trnInit
();
void
trnCleanup
();
STrans
*
trnCreate
();
int32_t
trnCommit
(
STrans
*
);
void
trnDrop
(
STrans
*
);
void
trnAppendRedoLog
(
STrans
*
,
SSdbRawData
*
);
void
trnAppendUndoLog
(
STrans
*
,
SSdbRawData
*
);
void
trnAppendCommitLog
(
STrans
*
,
SSdbRawData
*
);
void
trnAppendRedoAction
(
STrans
*
,
SEpSet
*
,
void
*
pMsg
);
void
trnAppendUndoAction
(
STrans
*
,
SEpSet
*
,
void
*
pMsg
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_TRANSACTION_H_*/
source/dnode/mnode/impl/CMakeLists.txt
浏览文件 @
622cdc39
...
...
@@ -8,6 +8,7 @@ target_include_directories(
target_link_libraries
(
mnode
PRIVATE sdb
PRIVATE transaction
PUBLIC transport
PUBLIC cjson
)
\ No newline at end of file
source/dnode/mnode/impl/inc/mnodeDef.h
浏览文件 @
622cdc39
...
...
@@ -24,7 +24,6 @@
#include "thash.h"
#include "cJSON.h"
#include "mnode.h"
#include "sdb.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -268,6 +267,7 @@ typedef struct {
typedef
struct
SMnMsg
{
void
(
*
fp
)(
SMnMsg
*
pMsg
,
int32_t
code
);
char
user
[
TSDB_USER_LEN
];
SUserObj
*
pUser
;
int16_t
received
;
int16_t
successed
;
...
...
source/dnode/mnode/impl/inc/mnodeInt.h
浏览文件 @
622cdc39
...
...
@@ -17,6 +17,8 @@
#define _TD_MNODE_INT_H_
#include "mnodeDef.h"
#include "sdb.h"
#include "trn.h"
#ifdef __cplusplus
extern
"C"
{
...
...
source/dnode/mnode/impl/src/mnodeUser.c
浏览文件 @
622cdc39
...
...
@@ -95,7 +95,7 @@ static int32_t mnodeUserActionDelete(SUserObj *pUser) {
}
if
(
pUser
->
acct
!=
NULL
)
{
sdbRelease
(
SDB_ACCT
,
pUser
->
pAcct
);
sdbRelease
(
pUser
->
pAcct
);
pUser
->
pAcct
=
NULL
;
}
...
...
@@ -115,7 +115,7 @@ static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
tstrncpy
(
userObj
.
acct
,
acct
,
TSDB_USER_LEN
);
taosEncryptPass
((
uint8_t
*
)
pass
,
strlen
(
pass
),
userObj
.
pass
);
userObj
.
createdTime
=
taosGetTimestampMs
();
userObj
.
updateTime
=
taosGetTimestampMs
()
;
userObj
.
updateTime
=
userObj
.
createdTime
;
if
(
strcmp
(
user
,
TSDB_DEFAULT_USER
)
==
0
)
{
userObj
.
rootAuth
=
1
;
...
...
@@ -144,6 +144,98 @@ static int32_t mnodeCreateDefaultUsers() {
return
code
;
}
static
int32_t
mnodeCreateUser
(
char
*
acct
,
char
*
user
,
char
*
pass
,
SMnMsg
*
pMsg
)
{
int32_t
code
=
0
;
STrans
*
pTrans
=
NULL
;
SSdbRawData
*
pUndoRaw
=
NULL
;
SSdbRawData
*
pRedoRaw
=
NULL
;
SUserObj
userObj
=
{
0
};
tstrncpy
(
userObj
.
user
,
user
,
TSDB_USER_LEN
);
tstrncpy
(
userObj
.
acct
,
acct
,
TSDB_USER_LEN
);
taosEncryptPass
((
uint8_t
*
)
pass
,
strlen
(
pass
),
userObj
.
pass
);
userObj
.
createdTime
=
taosGetTimestampMs
();
userObj
.
updateTime
=
userObj
.
createdTime
;
userObj
.
rootAuth
=
0
;
pRedoRaw
=
mnodeUserActionEncode
(
&
userObj
);
if
(
pRedoRaw
==
NULL
)
{
code
=
terrno
;
goto
CREATE_USER_OVER
;
}
pRedoRaw
->
status
=
SDB_STATUS_READY
;
pRedoRaw
->
action
=
SDB_ACTION_INSERT
;
pUndoRaw
=
mnodeUserActionEncode
(
&
userObj
);
if
(
pUndoRaw
==
NULL
)
{
code
=
terrno
;
goto
CREATE_USER_OVER
;
}
pUndoRaw
->
status
=
SDB_STATUS_DROPPING
;
pUndoRaw
->
action
=
SDB_ACTION_DELETE
;
pTrans
=
trnCreate
();
if
(
pTrans
==
NULL
)
{
code
=
TSDB_CODE_MND_OUT_OF_MEMORY
;
goto
CREATE_USER_OVER
;
}
trnAppendRedoLog
(
pTrans
,
pRedoRaw
);
trnAppendUndoLog
(
pTrans
,
pUndoRaw
);
code
=
trnCommit
(
pTrans
);
CREATE_USER_OVER:
if
(
code
!=
0
)
{
trnDrop
(
pTrans
);
free
(
pRedoRaw
);
free
(
pUndoRaw
);
}
return
code
;
}
static
int32_t
mnodeProcessCreateUserMsg
(
SMnMsg
*
pMsg
)
{
SCreateUserMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
pCreate
->
user
[
0
]
==
0
)
{
code
=
TSDB_CODE_MND_INVALID_USER_FORMAT
;
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
tstrerror
(
code
));
return
code
;
}
if
(
pCreate
->
pass
[
0
]
==
0
)
{
code
=
TSDB_CODE_MND_INVALID_PASS_FORMAT
;
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
tstrerror
(
code
));
return
code
;
}
SUserObj
*
pUser
=
sdbAcquire
(
SDB_USER
,
pCreate
->
user
);
if
(
pUser
!=
NULL
)
{
sdbRelease
(
pUser
);
code
=
TSDB_CODE_MND_USER_ALREADY_EXIST
;
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
tstrerror
(
code
));
return
code
;
}
SUserObj
*
pOperUser
=
sdbAcquire
(
SDB_USER
,
pMsg
->
user
);
if
(
pOperUser
==
NULL
)
{
code
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
tstrerror
(
code
));
return
code
;
}
code
=
mnodeCreateUser
(
pOperUser
->
acct
,
pCreate
->
user
,
pCreate
->
pass
,
pMsg
);
sdbRelease
(
pOperUser
);
if
(
code
!=
0
)
{
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
tstrerror
(
code
));
return
code
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
int32_t
mnodeInitUser
()
{
SSdbDesc
desc
=
{.
sdbType
=
SDB_USER
,
.
keyType
=
SDB_KEY_BINARY
,
...
...
source/dnode/mnode/sdb/CMakeLists.txt
浏览文件 @
622cdc39
...
...
@@ -10,5 +10,4 @@ target_link_libraries(
PRIVATE os
PRIVATE common
PRIVATE util
PRIVATE cjson
)
\ No newline at end of file
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
622cdc39
...
...
@@ -377,7 +377,7 @@ void *sdbAcquire(ESdbType sdb, void *pKey) {
}
}
void
sdbRelease
(
ESdbType
sdb
,
void
*
pObj
)
{
void
sdbRelease
(
void
*
pObj
)
{
SSdbRow
*
pRow
=
(
SSdbRow
*
)((
char
*
)
pObj
-
sizeof
(
SSdbRow
));
atomic_sub_fetch_32
(
&
pRow
->
refCount
,
1
);
}
...
...
source/dnode/mnode/transaction/CMakeLists.txt
浏览文件 @
622cdc39
...
...
@@ -7,5 +7,8 @@ target_include_directories(
)
target_link_libraries
(
transaction
PUBLIC transport
)
\ No newline at end of file
PRIVATE os
PRIVATE common
PRIVATE util
PRIVATE sdb
)
source/dnode/mnode/transaction/inc/trnInt.h
0 → 100644
浏览文件 @
622cdc39
/*
* 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_TRANSACTION_INT_H_
#define _TD_TRANSACTION_INT_H_
#include "os.h"
#include "trn.h"
#include "tglobal.h"
#include "tlog.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#ifdef __cplusplus
}
#endif
#endif
/*_TD_TRANSACTION_INT_H_*/
source/dnode/mnode/transaction/src/trn.c
浏览文件 @
622cdc39
/*
* 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"
int32_t
trnInit
()
{
return
0
;
}
void
trnCleanup
();
STrans
*
trnCreate
()
{
return
NULL
;
}
int32_t
trnCommit
(
STrans
*
pTrans
)
{
return
0
;
}
void
trnDrop
(
STrans
*
pTrans
)
{}
void
trnAppendRedoLog
(
STrans
*
pTrans
,
SSdbRawData
*
pRaw
)
{}
void
trnAppendUndoLog
(
STrans
*
pTrans
,
SSdbRawData
*
pRaw
)
{}
void
trnAppendCommitLog
(
STrans
*
pTrans
,
SSdbRawData
*
pRaw
)
{}
void
trnAppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{}
void
trnAppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录