Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2e643995
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看板
未验证
提交
2e643995
编写于
12月 15, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
12月 15, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9094 from taosdata/feature/dnode3
TD-10431 get sdbGetMaxId func
上级
3d190482
b282dfe1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
97 addition
and
64 deletion
+97
-64
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+10
-1
source/dnode/mnode/impl/src/mndDnode.c
source/dnode/mnode/impl/src/mndDnode.c
+2
-4
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+1
-6
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+52
-52
source/dnode/mnode/sdb/inc/sdbInt.h
source/dnode/mnode/sdb/inc/sdbInt.h
+1
-0
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+1
-0
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+29
-0
source/dnode/vnode/impl/CMakeLists.txt
source/dnode/vnode/impl/CMakeLists.txt
+1
-1
未找到文件。
include/dnode/mnode/sdb/sdb.h
浏览文件 @
2e643995
...
...
@@ -99,7 +99,7 @@ extern "C" {
sdbFreeRaw(pRaw); \
return NULL; \
} \
dataPos += sizeof(int16_t);
\
dataPos += sizeof(int16_t); \
}
#define SDB_SET_INT8(pRaw, dataPos, val) \
...
...
@@ -295,6 +295,15 @@ void sdbCancelFetch(SSdb *pSdb, void *pIter);
*/
int32_t
sdbGetSize
(
SSdb
*
pSdb
,
ESdbType
type
);
/**
* @brief Get the max id of the table, keyType of table should be INT32
*
* @param pSdb The sdb object.
* @param pIter The type of the table.
* @record int32_t The max id of the table
*/
int32_t
sdbGetMaxId
(
SSdb
*
pSdb
,
ESdbType
type
);
SSdbRaw
*
sdbAllocRaw
(
ESdbType
type
,
int8_t
sver
,
int32_t
dataLen
);
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
);
int32_t
sdbSetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
val
);
...
...
source/dnode/mnode/impl/src/mndDnode.c
浏览文件 @
2e643995
...
...
@@ -19,7 +19,7 @@
#include "mndShow.h"
#include "mndTrans.h"
#include "ttime.h"
#include "t
util
.h"
#include "t
ep
.h"
#define TSDB_DNODE_VER 1
#define TSDB_DNODE_RESERVE_SIZE 64
...
...
@@ -27,8 +27,6 @@
#define TSDB_CONIIG_VALUE_LEN 48
#define TSDB_CONFIG_NUMBER 8
static
int32_t
id
=
2
;
static
const
char
*
offlineReason
[]
=
{
""
,
"status msg timeout"
,
...
...
@@ -389,7 +387,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
static
int32_t
mndCreateDnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateDnodeMsg
*
pCreate
)
{
SDnodeObj
dnodeObj
=
{
0
};
dnodeObj
.
id
=
id
++
;
dnodeObj
.
id
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_DNODE
)
;
dnodeObj
.
createdTime
=
taosGetTimestampMs
();
dnodeObj
.
updateTime
=
dnodeObj
.
createdTime
;
taosGetFqdnPortFromEp
(
pCreate
->
ep
,
dnodeObj
.
fqdn
,
&
dnodeObj
.
port
);
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
2e643995
...
...
@@ -262,11 +262,6 @@ void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) {
sdbRelease
(
pSdb
,
pTrans
);
}
static
int32_t
mndGenerateTransId
()
{
static
int32_t
tmp
=
0
;
return
++
tmp
;
}
char
*
mndTransStageStr
(
ETrnStage
stage
)
{
switch
(
stage
)
{
case
TRN_STAGE_PREPARE
:
...
...
@@ -303,7 +298,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
return
NULL
;
}
pTrans
->
id
=
mndGenerateTransId
(
);
pTrans
->
id
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_TRANS
);
pTrans
->
stage
=
TRN_STAGE_PREPARE
;
pTrans
->
policy
=
policy
;
pTrans
->
rpcHandle
=
rpcHandle
;
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
2e643995
...
...
@@ -219,58 +219,6 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
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
);
if
(
mndTransPrepare
(
pMnode
,
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_DROPPED
);
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateUserMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
...
...
@@ -315,6 +263,32 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
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
);
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessAlterUserMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SAlterUserMsg
*
pAlter
=
pMsg
->
rpcMsg
.
pCont
;
...
...
@@ -363,6 +337,32 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
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_DROPPED
);
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
mndTransDrop
(
pTrans
);
return
0
;
}
static
int32_t
mndProcessDropUserMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SDropUserMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
...
...
source/dnode/mnode/sdb/inc/sdbInt.h
浏览文件 @
2e643995
...
...
@@ -59,6 +59,7 @@ typedef struct SSdb {
char
*
tmpDir
;
int64_t
lastCommitVer
;
int64_t
curVer
;
int32_t
maxId
[
SDB_MAX
];
EKeyType
keyTypes
[
SDB_MAX
];
SHashObj
*
hashObjs
[
SDB_MAX
];
SRWLatch
locks
[
SDB_MAX
];
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
2e643995
...
...
@@ -127,6 +127,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
return
-
1
;
}
pSdb
->
maxId
[
sdbType
]
=
0
;
pSdb
->
hashObjs
[
sdbType
]
=
hash
;
taosInitRWLatch
(
&
pSdb
->
locks
[
sdbType
]);
mDebug
(
"sdb table:%d is initialized"
,
sdbType
);
...
...
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
2e643995
...
...
@@ -72,6 +72,10 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
taosWUnLockLatch
(
pLock
);
if
(
pSdb
->
keyTypes
[
pRow
->
type
]
==
SDB_KEY_INT32
)
{
pSdb
->
maxId
[
pRow
->
type
]
=
MAX
(
pSdb
->
maxId
[
pRow
->
type
],
*
((
int32_t
*
)
pRow
->
pObj
));
}
SdbInsertFp
insertFp
=
pSdb
->
insertFps
[
pRow
->
type
];
if
(
insertFp
!=
NULL
)
{
code
=
(
*
insertFp
)(
pSdb
,
pRow
->
pObj
);
...
...
@@ -290,3 +294,28 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
return
size
;
}
int32_t
sdbGetMaxId
(
SSdb
*
pSdb
,
ESdbType
type
)
{
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
type
);
if
(
hash
==
NULL
)
return
-
1
;
if
(
pSdb
->
keyTypes
[
type
]
!=
SDB_KEY_INT32
)
return
-
1
;
int32_t
maxId
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
type
];
taosRLockLatch
(
pLock
);
SSdbRow
**
ppRow
=
taosHashIterate
(
hash
,
NULL
);
while
(
ppRow
!=
NULL
)
{
SSdbRow
*
pRow
=
*
ppRow
;
int32_t
id
=
*
(
int32_t
*
)
pRow
->
pObj
;
maxId
=
MAX
(
id
,
maxId
);
ppRow
=
taosHashIterate
(
hash
,
ppRow
);
}
taosRUnLockLatch
(
pLock
);
maxId
=
MAX
(
maxId
,
pSdb
->
maxId
[
type
]);
return
maxId
+
1
;
}
source/dnode/vnode/impl/CMakeLists.txt
浏览文件 @
2e643995
...
...
@@ -19,5 +19,5 @@ target_link_libraries(
# test
if
(
${
BUILD_TEST
}
)
add_subdirectory
(
test
)
#
add_subdirectory(test)
endif
(
${
BUILD_TEST
}
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录