Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f2a52f08
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f2a52f08
编写于
2月 20, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
suppprt tag rename
上级
bfe0ac61
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
120 addition
and
17 deletion
+120
-17
source/dnode/mnode/impl/inc/mndIndex.h
source/dnode/mnode/impl/inc/mndIndex.h
+11
-2
source/dnode/mnode/impl/src/mndIndex.c
source/dnode/mnode/impl/src/mndIndex.c
+38
-13
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+71
-2
未找到文件。
source/dnode/mnode/impl/inc/mndIndex.h
浏览文件 @
f2a52f08
...
...
@@ -13,11 +13,20 @@ SIdxObj *mndAcquireIdx(SMnode *pMnode, char *Name);
void
mndReleaseIdx
(
SMnode
*
pMnode
,
SIdxObj
*
pSma
);
int32_t
mndDropIdxsByStb
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
SStbObj
*
pStb
);
int32_t
mndDropIdxsByDb
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
);
// int32_t mndDropIdxsByTagName(SMnode *pMnode, SStbObj *pStb, char *tagName
);
int32_t
mndGetTableIdx
(
SMnode
*
pMnode
,
char
*
tbFName
,
STableIndexRsp
*
rsp
,
bool
*
exist
);
int32_t
mndGetIdxsByTagName
(
SMnode
*
pMnode
,
SStbObj
*
pStb
,
char
*
tagName
,
SIdxObj
*
pIdx
);
int32_t
mndGetTableIdx
(
SMnode
*
pMnode
,
char
*
tbFName
,
STableIndexRsp
*
rsp
,
bool
*
exist
);
int32_t
mndRetrieveTagIdx
(
SRpcMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rows
);
int32_t
mndProcessDropTagIdxReq
(
SRpcMsg
*
pReq
);
int32_t
mndSetCreateIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
);
int32_t
mndSetCreateIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
);
int32_t
mndSetDropIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
);
int32_t
mndSetDropIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
);
int32_t
mndSetAlterIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
);
int32_t
mndSetAlterIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mnode/impl/src/mndIndex.c
浏览文件 @
f2a52f08
...
...
@@ -296,6 +296,10 @@ static int32_t mndIdxActionDelete(SSdb *pSdb, SIdxObj *pIdx) {
}
static
int32_t
mndIdxActionUpdate
(
SSdb
*
pSdb
,
SIdxObj
*
pOld
,
SIdxObj
*
pNew
)
{
// lock no not
if
(
strncmp
(
pOld
->
colName
,
pNew
->
colName
,
TSDB_COL_NAME_LEN
)
!=
0
)
{
memcpy
(
pOld
->
colName
,
pNew
->
colName
,
sizeof
(
pNew
->
colName
));
}
mTrace
(
"idx:%s, perform update action, old row:%p new row:%p"
,
pOld
->
name
,
pOld
,
pNew
);
return
0
;
}
...
...
@@ -324,7 +328,7 @@ SDbObj *mndAcquireDbByIdx(SMnode *pMnode, const char *idxName) {
return
mndAcquireDb
(
pMnode
,
db
);
}
static
int32_t
mndSetCreateIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
int32_t
mndSetCreateIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
SSdbRaw
*
pRedoRaw
=
mndIdxActionEncode
(
pIdx
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
...
...
@@ -333,7 +337,7 @@ static int32_t mndSetCreateIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *
return
0
;
}
static
int32_t
mndSetCreateIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
int32_t
mndSetCreateIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
SSdbRaw
*
pCommitRaw
=
mndIdxActionEncode
(
pIdx
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
...
...
@@ -342,6 +346,30 @@ static int32_t mndSetCreateIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj
return
0
;
}
int32_t
mndSetAlterIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
SSdbRaw
*
pRedoRaw
=
mndIdxActionEncode
(
pIdx
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
sdbFreeRaw
(
pRedoRaw
);
return
-
1
;
}
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
int32_t
mndSetAlterIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
SSdbRaw
*
pCommitRaw
=
mndIdxActionEncode
(
pIdx
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
{
sdbFreeRaw
(
pCommitRaw
);
return
-
1
;
}
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateIdxVgroupRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SVgObj
*
pVgroup
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
...
...
@@ -451,7 +479,7 @@ _OVER:
return
code
;
}
static
int32_t
mndSetDropIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
int32_t
mndSetDropIdxRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
SSdbRaw
*
pRedoRaw
=
mndIdxActionEncode
(
pIdx
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
...
...
@@ -460,7 +488,7 @@ static int32_t mndSetDropIdxRedoLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *pI
return
0
;
}
static
int32_t
mndSetDropIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
int32_t
mndSetDropIdxCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SIdxObj
*
pIdx
)
{
SSdbRaw
*
pCommitRaw
=
mndIdxActionEncode
(
pIdx
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
...
...
@@ -805,8 +833,7 @@ int32_t mndDropIdxsByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p
return
0
;
}
/*
int32_t mndDropIdxsByTagName(SMnode *pMnode, SStbObj *pStb, char *tagName) {
int32_t
mndGetIdxsByTagName
(
SMnode
*
pMnode
,
SStbObj
*
pStb
,
char
*
tagName
,
SIdxObj
*
idx
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
...
...
@@ -816,18 +843,16 @@ int32_t mndDropIdxsByTagName(SMnode *pMnode, SStbObj *pStb, char *tagName) {
if
(
pIter
==
NULL
)
break
;
if
(
pIdx
->
stbUid
==
pStb
->
uid
&&
strcasecmp
(
pIdx
->
colName
,
tagName
)
==
0
)
{
if (mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx) != 0) {
sdbRelease(pSdb, pIdx);
sdbCancelFetch(pSdb, pIdx);
return -1;
}
memcpy
((
char
*
)
idx
,
(
char
*
)
pIdx
,
sizeof
(
SIdxObj
));
sdbRelease
(
pSdb
,
pIdx
);
return
0
;
}
sdbRelease
(
pSdb
,
pIdx
);
}
return
0
;
}
*/
return
-
1
;
}
int32_t
mndDropIdxsByDb
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
f2a52f08
...
...
@@ -50,6 +50,8 @@ static void mndCancelGetNextStb(SMnode *pMnode, void *pIter);
static
int32_t
mndProcessTableCfgReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndAlterStbImp
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SDbObj
*
pDb
,
SStbObj
*
pStb
,
bool
needRsp
,
void
*
alterOriData
,
int32_t
alterOriDataLen
);
static
int32_t
mndAlterStbAndUpdateTagIdxImp
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SDbObj
*
pDb
,
SStbObj
*
pStb
,
bool
needRsp
,
void
*
alterOriData
,
int32_t
alterOriDataLen
,
const
SMAlterStbReq
*
pAlter
);
static
int32_t
mndProcessCreateIndexReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessDropIndexReq
(
SRpcMsg
*
pReq
);
...
...
@@ -1941,6 +1943,67 @@ _OVER:
return
code
;
}
static
int32_t
mndAlterStbAndUpdateTagIdxImp
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
SDbObj
*
pDb
,
SStbObj
*
pStb
,
bool
needRsp
,
void
*
alterOriData
,
int32_t
alterOriDataLen
,
const
SMAlterStbReq
*
pAlter
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
TRN_CONFLICT_DB_INSIDE
,
pReq
,
"alter-stb"
);
if
(
pTrans
==
NULL
)
goto
_OVER
;
mInfo
(
"trans:%d, used to alter stb:%s"
,
pTrans
->
id
,
pStb
->
name
);
mndTransSetDbName
(
pTrans
,
pDb
->
name
,
pStb
->
name
);
if
(
mndTrancCheckConflict
(
pMnode
,
pTrans
)
!=
0
)
goto
_OVER
;
if
(
pAlter
->
alterType
==
TSDB_ALTER_TABLE_DROP_TAG
)
{
SIdxObj
idxObj
=
{
0
};
SField
*
pField0
=
taosArrayGet
(
pAlter
->
pFields
,
0
);
bool
exist
=
false
;
if
(
mndGetIdxsByTagName
(
pMnode
,
pStb
,
pField0
->
name
,
&
idxObj
)
==
0
)
{
exist
=
true
;
}
if
(
mndSetAlterStbRedoLogs
(
pMnode
,
pTrans
,
pDb
,
pStb
)
!=
0
)
goto
_OVER
;
if
(
mndSetAlterStbCommitLogs
(
pMnode
,
pTrans
,
pDb
,
pStb
)
!=
0
)
goto
_OVER
;
if
(
exist
==
true
)
{
if
(
mndSetDropIdxRedoLogs
(
pMnode
,
pTrans
,
&
idxObj
)
!=
0
)
goto
_OVER
;
if
(
mndSetDropIdxCommitLogs
(
pMnode
,
pTrans
,
&
idxObj
)
!=
0
)
goto
_OVER
;
}
if
(
mndSetAlterStbRedoActions
(
pMnode
,
pTrans
,
pDb
,
pStb
,
alterOriData
,
alterOriDataLen
)
!=
0
)
goto
_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
_OVER
;
}
else
if
(
pAlter
->
alterType
==
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
)
{
SIdxObj
idxObj
=
{
0
};
SField
*
pField0
=
taosArrayGet
(
pAlter
->
pFields
,
0
);
SField
*
pField1
=
taosArrayGet
(
pAlter
->
pFields
,
1
);
const
char
*
oTagName
=
pField0
->
name
;
const
char
*
nTagName
=
pField1
->
name
;
bool
exist
=
false
;
if
(
mndGetIdxsByTagName
(
pMnode
,
pStb
,
pField0
->
name
,
&
idxObj
)
==
0
)
{
exist
=
true
;
}
if
(
mndSetAlterStbRedoLogs
(
pMnode
,
pTrans
,
pDb
,
pStb
)
!=
0
)
goto
_OVER
;
if
(
mndSetAlterStbCommitLogs
(
pMnode
,
pTrans
,
pDb
,
pStb
)
!=
0
)
goto
_OVER
;
if
(
exist
==
true
)
{
memcpy
(
idxObj
.
colName
,
nTagName
,
strlen
(
nTagName
));
idxObj
.
colName
[
strlen
(
nTagName
)]
=
0
;
if
(
mndSetAlterIdxRedoLogs
(
pMnode
,
pTrans
,
&
idxObj
)
!=
0
)
goto
_OVER
;
if
(
mndSetAlterIdxCommitLogs
(
pMnode
,
pTrans
,
&
idxObj
)
!=
0
)
goto
_OVER
;
}
if
(
mndSetAlterStbRedoActions
(
pMnode
,
pTrans
,
pDb
,
pStb
,
alterOriData
,
alterOriDataLen
)
!=
0
)
goto
_OVER
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
_OVER
;
}
code
=
0
;
_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
static
int32_t
mndAlterStb
(
SMnode
*
pMnode
,
SRpcMsg
*
pReq
,
const
SMAlterStbReq
*
pAlter
,
SDbObj
*
pDb
,
SStbObj
*
pOld
)
{
bool
needRsp
=
true
;
int32_t
code
=
-
1
;
...
...
@@ -1954,7 +2017,7 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p
stbObj
.
pTags
=
NULL
;
stbObj
.
updateTime
=
taosGetTimestampMs
();
stbObj
.
lock
=
0
;
bool
updateTagIndex
=
false
;
switch
(
pAlter
->
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_TAG
:
code
=
mndAddSuperTableTag
(
pOld
,
&
stbObj
,
pAlter
->
pFields
,
pAlter
->
numOfFields
);
...
...
@@ -1962,9 +2025,11 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p
case
TSDB_ALTER_TABLE_DROP_TAG
:
pField0
=
taosArrayGet
(
pAlter
->
pFields
,
0
);
code
=
mndDropSuperTableTag
(
pMnode
,
pOld
,
&
stbObj
,
pField0
->
name
);
updateTagIndex
=
true
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
:
code
=
mndAlterStbTagName
(
pMnode
,
pOld
,
&
stbObj
,
pAlter
->
pFields
);
updateTagIndex
=
true
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
:
pField0
=
taosArrayGet
(
pAlter
->
pFields
,
0
);
...
...
@@ -1992,7 +2057,11 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p
}
if
(
code
!=
0
)
goto
_OVER
;
code
=
mndAlterStbImp
(
pMnode
,
pReq
,
pDb
,
&
stbObj
,
needRsp
,
pReq
->
pCont
,
pReq
->
contLen
);
if
(
updateTagIndex
==
false
)
{
code
=
mndAlterStbImp
(
pMnode
,
pReq
,
pDb
,
&
stbObj
,
needRsp
,
pReq
->
pCont
,
pReq
->
contLen
);
}
else
{
code
=
mndAlterStbAndUpdateTagIdxImp
(
pMnode
,
pReq
,
pDb
,
&
stbObj
,
needRsp
,
pReq
->
pCont
,
pReq
->
contLen
,
pAlter
);
}
_OVER:
taosMemoryFreeClear
(
stbObj
.
pTags
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录