Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2a0543f7
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
2a0543f7
编写于
12月 05, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add dynamic change json tag index
上级
345d92d0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
142 addition
and
76 deletion
+142
-76
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+142
-76
未找到文件。
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
2a0543f7
...
...
@@ -1196,6 +1196,7 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
int64_t
oversion
;
const
void
*
pData
=
NULL
;
int
nData
=
0
;
SDecoder
dc
=
{
0
};
if
(
pAlterTbReq
->
tagName
==
NULL
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
...
...
@@ -1208,81 +1209,146 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
terrno
=
TSDB_CODE_TDB_TABLE_NOT_EXIST
;
return
-
1
;
}
uid
=
*
(
tb_uid_t
*
)
pVal
;
tdbFree
(
pVal
);
pVal
=
NULL
;
// search uid index
TBC
*
pUidIdxc
=
NULL
;
tdbTbcOpen
(
pMeta
->
pUidIdx
,
&
pUidIdxc
,
&
pMeta
->
txn
);
tdbTbcMoveTo
(
pUidIdxc
,
&
uid
,
sizeof
(
uid
),
&
c
);
ASSERT
(
c
==
0
);
tdbTbcGet
(
pUidIdxc
,
NULL
,
NULL
,
&
pData
,
&
nData
);
oversion
=
((
SUidIdxVal
*
)
pData
)[
0
].
version
;
if
(
tdbTbGet
(
pMeta
->
pUidIdx
,
&
uid
,
sizeof
(
tb_uid_t
),
&
pVal
,
&
nVal
)
==
-
1
)
{
ret
=
-
1
;
goto
_err
;
}
// search table.db
TBC
*
pTbDbc
=
NULL
;
SDecoder
dc1
=
{
0
}
;
SDecoder
dc2
=
{
0
}
;
STbDbKey
tbDbKey
=
{
0
};
tbDbKey
.
uid
=
uid
;
tbDbKey
.
version
=
((
SUidIdxVal
*
)
pVal
)[
0
].
version
;
tdbTbGet
(
pMeta
->
pTbDb
,
&
tbDbKey
,
sizeof
(
tbDbKey
),
&
pVal
,
&
nVal
)
;
/* get ctbEntry */
tdbTbcOpen
(
pMeta
->
pTbDb
,
&
pTbDbc
,
&
pMeta
->
txn
);
tdbTbcMoveTo
(
pTbDbc
,
&
((
STbDbKey
){.
uid
=
uid
,
.
version
=
oversion
}),
sizeof
(
STbDbKey
),
&
c
);
ASSERT
(
c
==
0
)
;
tdbTbcGet
(
pTbDbc
,
NULL
,
NULL
,
&
pData
,
&
nData
);
tDecoderInit
(
&
dc
,
pVal
,
nVal
);
ret
=
metaDecodeEntry
(
&
dc
,
&
stbEntry
);
if
(
ret
<
0
)
{
goto
_err
;
}
ctbEntry
.
pBuf
=
taosMemoryMalloc
(
nData
);
memcpy
(
ctbEntry
.
pBuf
,
pData
,
nData
);
tDecoderInit
(
&
dc1
,
ctbEntry
.
pBuf
,
nData
);
metaDecodeEntry
(
&
dc1
,
&
ctbEntry
);
SSchemaWrapper
*
pTagSchema
=
&
stbEntry
.
stbEntry
.
schemaTag
;
/* get stbEntry*/
tdbTbGet
(
pMeta
->
pUidIdx
,
&
ctbEntry
.
ctbEntry
.
suid
,
sizeof
(
tb_uid_t
),
&
pVal
,
&
nVal
);
if
(
!
pVal
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
if
(
pTagSchema
->
nCols
==
1
&&
pTagSchema
->
pSchema
[
0
].
type
==
TSDB_DATA_TYPE_JSON
)
{
terrno
=
TSDB_CODE_VND_COL_ALREADY_EXISTS
;
goto
_err
;
}
tdbTbGet
(
pMeta
->
pTbDb
,
&
((
STbDbKey
){.
uid
=
ctbEntry
.
ctbEntry
.
suid
,
.
version
=
((
SUidIdxVal
*
)
pVal
)[
0
].
version
}),
sizeof
(
STbDbKey
),
(
void
**
)
&
stbEntry
.
pBuf
,
&
nVal
);
tdbFree
(
pVal
);
tDecoderInit
(
&
dc2
,
stbEntry
.
pBuf
,
nVal
);
metaDecodeEntry
(
&
dc2
,
&
stbEntry
);
SSchemaWrapper
*
pTagSchema
=
&
stbEntry
.
stbEntry
.
schemaTag
;
SSchema
*
pColumn
=
NULL
;
int32_t
iCol
=
0
;
SSchema
*
pCol
=
NULL
;
int32_t
iCol
=
0
;
for
(;;)
{
pCol
umn
=
NULL
;
pCol
=
NULL
;
if
(
iCol
>=
pTagSchema
->
nCols
)
break
;
pCol
umn
=
&
pTagSchema
->
pSchema
[
iCol
];
pCol
=
&
pTagSchema
->
pSchema
[
iCol
];
if
(
strcmp
(
pCol
umn
->
name
,
pAlterTbReq
->
tagName
)
==
0
)
break
;
if
(
strcmp
(
pCol
->
name
,
pAlterTbReq
->
tagName
)
==
0
)
break
;
iCol
++
;
}
if
(
pColumn
==
NULL
)
{
terrno
=
TSDB_CODE_VND_COL_
NOT
_EXISTS
;
if
(
iCol
==
0
)
{
terrno
=
TSDB_CODE_VND_COL_
ALREADY
_EXISTS
;
goto
_err
;
}
ctbEntry
.
version
=
version
;
if
(
pTagSchema
->
nCols
==
1
&&
pTagSchema
->
pSchema
[
0
].
type
==
TSDB_DATA_TYPE_JSON
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
if
(
pCol
==
NULL
)
{
terrno
=
TSDB_CODE_VND_COL_NOT_EXISTS
;
goto
_err
;
}
const
STag
*
pOldTag
=
(
const
STag
*
)
ctbEntry
.
ctbEntry
.
pTags
;
STag
*
pNewTag
=
NULL
;
SArray
*
pTagArray
=
taosArrayInit
(
pTagSchema
->
nCols
,
sizeof
(
STagVal
));
if
(
!
pTagArray
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
/*
* iterator all pTdDbc by uid and version
*/
// drop all child tables
TBC
*
pCtbIdxc
=
NULL
;
tdbTbcOpen
(
pMeta
->
pCtbIdx
,
&
pCtbIdxc
,
NULL
);
int
rc
=
tdbTbcMoveTo
(
pCtbIdxc
,
&
(
SCtbIdxKey
){.
suid
=
uid
,
.
uid
=
INT64_MIN
},
sizeof
(
SCtbIdxKey
),
&
c
);
if
(
rc
<
0
)
{
tdbTbcClose
(
pCtbIdxc
);
goto
_err
;
}
for
(;;)
{
void
*
pKey
,
*
pVal
;
int
nKey
,
nVal
;
rc
=
tdbTbcNext
(
pCtbIdxc
,
&
pKey
,
&
nKey
,
&
pVal
,
&
nVal
);
if
(
rc
<
0
)
break
;
if
(((
SCtbIdxKey
*
)
pKey
)
->
suid
!=
uid
)
{
tdbFree
(
pVal
);
continue
;
}
STag
*
pTag
=
pVal
;
}
// search uid index
// TBC *pUidIdxc = NULL;
// tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, pMeta->txn);
// tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
// ASSERT(c == 0);
// tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
// oversion = ((SUidIdxVal *)pData)[0].version;
// search table.db
// TBC *pTbDbc = NULL;
// SDecoder dc1 = {0};
// SDecoder dc2 = {0};
///* get ctbEntry */
// tdbTbcOpen(pMeta->pTbDb, &pTbDbc, pMeta->txn);
// tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
// ASSERT(c == 0);
// tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
// ctbEntry.pBuf = taosMemoryMalloc(nData);
// memcpy(ctbEntry.pBuf, pData, nData);
// tDecoderInit(&dc1, ctbEntry.pBuf, nData);
// metaDecodeEntry(&dc1, &ctbEntry);
/* get stbEntry*/
// tdbTbGet(pMeta->pUidIdx, &ctbEntry.ctbEntry.suid, sizeof(tb_uid_t), &pVal, &nVal);
// if (!pVal) {
// terrno = TSDB_CODE_INVALID_MSG;
// goto _err;
// }
// tdbTbGet(pMeta->pTbDb, &((STbDbKey){.uid = ctbEntry.ctbEntry.suid, .version = ((SUidIdxVal *)pVal)[0].version}),
// sizeof(STbDbKey), (void **)&stbEntry.pBuf, &nVal);
// tdbFree(pVal);
// tDecoderInit(&dc2, stbEntry.pBuf, nVal);
// metaDecodeEntry(&dc2, &stbEntry);
// SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag;
// SSchema *pColumn = NULL;
// int32_t iCol = 0;
// for (;;) {
// pColumn = NULL;
// if (iCol >= pTagSchema->nCols) break;
// pColumn = &pTagSchema->pSchema[iCol];
// if (strcmp(pColumn->name, pAlterTbReq->tagName) == 0) break;
// iCol++;
//}
// if (pColumn == NULL) {
// terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
// goto _err;
// }
// ctbEntry.version = version;
// if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
// terrno = TSDB_CODE_INVALID_MSG;
// goto _err;
// }
// const STag *pOldTag = (const STag *)ctbEntry.ctbEntry.pTags;
// STag *pNewTag = NULL;
// SArray *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal));
// if (!pTagArray) {
// terrno = TSDB_CODE_OUT_OF_MEMORY;
// goto _err;
// }
// for (int32_t i = 0; i < pTagSchema->nCols; i++) {
// SSchema *pCol = &pTagSchema->pSchema[i];
...
...
@@ -1315,43 +1381,43 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
// ctbEntry.ctbEntry.pTags = (uint8_t *)pNewTag;
// taosArrayDestroy(pTagArray);
metaWLock
(
pMeta
);
//
metaWLock(pMeta);
// save to table.db
metaSaveToTbDb
(
pMeta
,
&
ctbEntry
);
//
metaSaveToTbDb(pMeta, &ctbEntry);
// save to uid.idx
metaUpdateUidIdx
(
pMeta
,
&
ctbEntry
);
//
metaUpdateUidIdx(pMeta, &ctbEntry);
if
(
iCol
==
0
)
{
metaUpdateTagIdx
(
pMeta
,
&
ctbEntry
);
}
//
if (iCol == 0) {
//
metaUpdateTagIdx(pMeta, &ctbEntry);
//
}
ASSERT
(
ctbEntry
.
ctbEntry
.
pTags
);
SCtbIdxKey
ctbIdxKey
=
{.
suid
=
ctbEntry
.
ctbEntry
.
suid
,
.
uid
=
uid
};
tdbTbUpsert
(
pMeta
->
pCtbIdx
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
ctbEntry
.
ctbEntry
.
pTags
,
((
STag
*
)(
ctbEntry
.
ctbEntry
.
pTags
))
->
len
,
&
pMeta
->
txn
);
//
ASSERT(ctbEntry.ctbEntry.pTags);
//
SCtbIdxKey ctbIdxKey = {.suid = ctbEntry.ctbEntry.suid, .uid = uid};
//
tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags,
// ((STag *)(ctbEntry.ctbEntry.pTags))->len,
pMeta->txn);
metaUidCacheClear
(
pMeta
,
ctbEntry
.
ctbEntry
.
suid
);
//
metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid);
metaULock
(
pMeta
);
//
metaULock(pMeta);
tDecoderClear
(
&
dc1
);
tDecoderClear
(
&
dc2
);
taosMemoryFree
((
void
*
)
ctbEntry
.
ctbEntry
.
pTags
);
if
(
ctbEntry
.
pBuf
)
taosMemoryFree
(
ctbEntry
.
pBuf
);
if
(
stbEntry
.
pBuf
)
tdbFree
(
stbEntry
.
pBuf
);
tdbTbcClose
(
pTbDbc
);
tdbTbcClose
(
pUidIdxc
);
//
tDecoderClear(&dc1);
//
tDecoderClear(&dc2);
//
taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
//
if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf);
//
if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
//
tdbTbcClose(pTbDbc);
//
tdbTbcClose(pUidIdxc);
return
0
;
_err:
tDecoderClear
(
&
dc1
);
tDecoderClear
(
&
dc2
);
if
(
ctbEntry
.
pBuf
)
taosMemoryFree
(
ctbEntry
.
pBuf
);
if
(
stbEntry
.
pBuf
)
tdbFree
(
stbEntry
.
pBuf
);
tdbTbcClose
(
pTbDbc
);
tdbTbcClose
(
pUidIdxc
);
//
tDecoderClear(&dc1);
//
tDecoderClear(&dc2);
//
if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf);
//
if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
//
tdbTbcClose(pTbDbc);
//
tdbTbcClose(pUidIdxc);
return
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录