Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0c1cde9c
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看板
提交
0c1cde9c
编写于
4月 22, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact meta 8
上级
a769c57f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
122 addition
and
72 deletion
+122
-72
source/common/src/tmsg.c
source/common/src/tmsg.c
+4
-2
source/dnode/vnode/src/inc/meta.h
source/dnode/vnode/src/inc/meta.h
+5
-5
source/dnode/vnode/src/meta/metaEntry.c
source/dnode/vnode/src/meta/metaEntry.c
+1
-1
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+88
-10
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+24
-54
未找到文件。
source/common/src/tmsg.c
浏览文件 @
0c1cde9c
...
...
@@ -3651,10 +3651,12 @@ int tDecodeSVCreateTbReq(SCoder *pCoder, SVCreateTbReq *pReq) {
}
int
tEncodeSVCreateTbBatchReq
(
SCoder
*
pCoder
,
const
SVCreateTbBatchReq
*
pReq
)
{
int32_t
nReq
=
taosArrayGetSize
(
pReq
->
pArray
);
if
(
tStartEncode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tEncodeI32v
(
pCoder
,
taosArrayGetSize
(
pReq
->
pArray
)
)
<
0
)
return
-
1
;
for
(
int
iReq
=
0
;
iReq
<
pReq
->
nReqs
;
iReq
++
)
{
if
(
tEncodeI32v
(
pCoder
,
nReq
)
<
0
)
return
-
1
;
for
(
int
iReq
=
0
;
iReq
<
nReq
;
iReq
++
)
{
if
(
tEncodeSVCreateTbReq
(
pCoder
,
(
SVCreateTbReq
*
)
taosArrayGet
(
pReq
->
pArray
,
iReq
))
<
0
)
return
-
1
;
}
...
...
source/dnode/vnode/src/inc/meta.h
浏览文件 @
0c1cde9c
...
...
@@ -48,6 +48,7 @@ int metaDecodeEntry(SCoder* pCoder, SMetaEntry* pME);
// metaTable ==================
int
metaCreateSTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateStbReq
*
pReq
);
int
metaDropSTable
(
SMeta
*
pMeta
,
int64_t
verison
,
SVDropStbReq
*
pReq
);
int
metaCreateTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateTbReq
*
pReq
);
// metaQuery ==================
typedef
struct
SMetaEntryReader
SMetaEntryReader
;
...
...
@@ -109,7 +110,6 @@ typedef struct {
#define META_CHILD_TABLE TD_CHILD_TABLE
#define META_NORMAL_TABLE TD_NORMAL_TABLE
int
metaCreateTable
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
);
int
metaDropTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
int
metaCommit
(
SMeta
*
pMeta
);
int32_t
metaCreateTSma
(
SMeta
*
pMeta
,
SSmaCfg
*
pCfg
);
...
...
@@ -142,10 +142,10 @@ struct SMetaEntry {
SSchema
*
pSchemaTg
;
}
stbEntry
;
struct
{
int64_t
ctime
;
int32_t
ttlDays
;
tb_uid_t
suid
;
SKVRow
pTags
;
int64_t
ctime
;
int32_t
ttlDays
;
tb_uid_t
suid
;
const
void
*
pTags
;
}
ctbEntry
;
struct
{
int64_t
ctime
;
...
...
source/dnode/vnode/src/meta/metaEntry.c
浏览文件 @
0c1cde9c
...
...
@@ -86,7 +86,7 @@ int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) {
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ctbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pME
->
ctbEntry
.
ttlDays
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ctbEntry
.
suid
)
<
0
)
return
-
1
;
if
(
tDecodeBinary
(
pCoder
,
pME
->
ctbEntry
.
pTags
,
NULL
)
<
0
)
return
-
1
;
// (TODO)
if
(
tDecodeBinary
(
pCoder
,
&
pME
->
ctbEntry
.
pTags
,
NULL
)
<
0
)
return
-
1
;
// (TODO)
}
else
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ntbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pME
->
ntbEntry
.
ttlDays
)
<
0
)
return
-
1
;
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
0c1cde9c
...
...
@@ -18,6 +18,9 @@
static
int
metaSaveToTbDb
(
SMeta
*
pMeta
,
int64_t
version
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateUidIdx
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int64_t
version
);
static
int
metaUpdateNameIdx
(
SMeta
*
pMeta
,
const
char
*
name
,
tb_uid_t
uid
);
static
int
metaCreateNormalTable
(
SMeta
*
pMeta
,
int64_t
version
,
SMetaEntry
*
pME
);
static
int
metaCreateChildTable
(
SMeta
*
pMeta
,
int64_t
version
,
SMetaEntry
*
pME
);
static
int
metaUpdateTtlIdx
(
SMeta
*
pMeta
,
int64_t
dtime
,
tb_uid_t
uid
);
int
metaCreateSTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateStbReq
*
pReq
)
{
SSkmDbKey
skmDbKey
=
{
0
};
...
...
@@ -51,6 +54,8 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
// save to table.db
if
(
metaSaveToTbDb
(
pMeta
,
version
,
&
me
)
<
0
)
goto
_err
;
// save to schema.db (TODO)
// update uid idx
if
(
metaUpdateUidIdx
(
pMeta
,
me
.
uid
,
version
)
<
0
)
goto
_err
;
...
...
@@ -72,20 +77,59 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
return
0
;
}
int
metaCreateTable
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
)
{
#if 0
if (metaSaveTableToDB(pMeta, pTbCfg) < 0) {
// TODO: handle error
return -1;
int
metaCreateTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateTbReq
*
pReq
)
{
SMetaEntry
me
=
{
0
};
// validate message
if
(
pReq
->
type
!=
TSDB_CHILD_TABLE
&&
pReq
->
type
!=
TSDB_NORMAL_TABLE
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
goto
_err
;
}
if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) {
// TODO: handle error
return -1;
// preprocess req
pReq
->
uid
=
tGenIdPI64
();
pReq
->
ctime
=
taosGetTimestampSec
();
{
// TODO: validate request (uid and name unique)
// for child table, also check if super table exists
}
// build SMetaEntry
me
.
type
=
pReq
->
type
;
me
.
uid
=
pReq
->
uid
;
me
.
name
=
pReq
->
name
;
if
(
me
.
type
==
TSDB_CHILD_TABLE
)
{
me
.
ctbEntry
.
ctime
=
pReq
->
ctime
;
me
.
ctbEntry
.
ttlDays
=
pReq
->
ttl
;
me
.
ctbEntry
.
suid
=
pReq
->
ctb
.
suid
;
me
.
ctbEntry
.
pTags
=
pReq
->
ctb
.
pTag
;
}
else
{
me
.
ntbEntry
.
ctime
=
pReq
->
ctime
;
me
.
ntbEntry
.
ttlDays
=
pReq
->
ttl
;
me
.
ntbEntry
.
nCols
=
pReq
->
ntb
.
nCols
;
me
.
ntbEntry
.
sver
=
pReq
->
ntb
.
sver
;
me
.
ntbEntry
.
pSchema
=
pReq
->
ntb
.
pSchema
;
}
#endif
// save table
if
(
me
.
type
==
TSDB_CHILD_TABLE
)
{
if
(
metaCreateChildTable
(
pMeta
,
version
,
&
me
)
<
0
)
{
goto
_err
;
}
}
else
{
if
(
metaCreateNormalTable
(
pMeta
,
version
,
&
me
)
<
0
)
{
goto
_err
;
}
}
metaDebug
(
"vgId:%d table %s uid %"
PRId64
" is created"
,
TD_VID
(
pMeta
->
pVnode
),
pReq
->
name
,
pReq
->
uid
);
return
0
;
_err:
metaError
(
"vgId:%d failed to create table:%s type:%s since %s"
,
TD_VID
(
pMeta
->
pVnode
),
pReq
->
name
,
pReq
->
type
==
TSDB_CHILD_TABLE
?
"child table"
:
"normal table"
,
tstrerror
(
terrno
));
return
-
1
;
}
int
metaDropTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
...
...
@@ -152,4 +196,38 @@ static int metaUpdateUidIdx(SMeta *pMeta, tb_uid_t uid, int64_t version) {
static
int
metaUpdateNameIdx
(
SMeta
*
pMeta
,
const
char
*
name
,
tb_uid_t
uid
)
{
return
tdbDbInsert
(
pMeta
->
pNameIdx
,
name
,
strlen
(
name
)
+
1
,
&
uid
,
sizeof
(
uid
),
NULL
);
}
\ No newline at end of file
}
static
int
metaUpdateTtlIdx
(
SMeta
*
pMeta
,
int64_t
dtime
,
tb_uid_t
uid
)
{
STtlIdxKey
ttlKey
=
{.
dtime
=
dtime
,
.
uid
=
uid
};
return
tdbDbInsert
(
pMeta
->
pTtlIdx
,
&
ttlKey
,
sizeof
(
ttlKey
),
NULL
,
0
,
NULL
);
}
static
int
metaCreateChildTable
(
SMeta
*
pMeta
,
int64_t
version
,
SMetaEntry
*
pME
)
{
// TODO
return
0
;
}
static
int
metaCreateNormalTable
(
SMeta
*
pMeta
,
int64_t
version
,
SMetaEntry
*
pME
)
{
int64_t
dtime
;
// save to table.db
if
(
metaSaveToTbDb
(
pMeta
,
version
,
pME
)
<
0
)
return
-
1
;
// save to schema.db
// update uid.idx
if
(
metaUpdateUidIdx
(
pMeta
,
pME
->
uid
,
version
)
<
0
)
return
-
1
;
// save to name.idx
if
(
metaUpdateNameIdx
(
pMeta
,
pME
->
name
,
pME
->
uid
)
<
0
)
return
-
1
;
// save to pTtlIdx if need
if
(
pME
->
ntbEntry
.
ttlDays
>
0
)
{
dtime
=
pME
->
ntbEntry
.
ctime
+
pME
->
ntbEntry
.
ttlDays
*
24
*
60
;
if
(
metaUpdateTtlIdx
(
pMeta
,
dtime
,
pME
->
uid
)
<
0
)
return
-
1
;
}
return
0
;
}
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
0c1cde9c
...
...
@@ -18,7 +18,7 @@
static
int
vnodeProcessCreateStbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessAlterStbReq
(
SVnode
*
pVnode
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessDropStbReq
(
SVnode
*
pVnode
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessCreateTbReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
void
*
pReq
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessCreateTbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessAlterTbReq
(
SVnode
*
pVnode
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessDropTbReq
(
SVnode
*
pVnode
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessSubmitReq
(
SVnode
*
pVnode
,
SSubmitReq
*
pSubmitReq
,
SRpcMsg
*
pRsp
);
...
...
@@ -77,7 +77,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
if
(
vnodeProcessDropStbReq
(
pVnode
,
pReq
,
len
,
pRsp
)
<
0
)
goto
_err
;
break
;
case
TDMT_VND_CREATE_TABLE
:
if
(
vnodeProcessCreateTbReq
(
pVnode
,
pMsg
,
pReq
,
pRsp
)
<
0
)
goto
_err
;
if
(
vnodeProcessCreateTbReq
(
pVnode
,
version
,
pReq
,
len
,
pRsp
)
<
0
)
goto
_err
;
break
;
case
TDMT_VND_ALTER_TABLE
:
if
(
vnodeProcessAlterTbReq
(
pVnode
,
pReq
,
len
,
pRsp
)
<
0
)
goto
_err
;
...
...
@@ -244,67 +244,37 @@ _err:
return
-
1
;
}
static
int
vnodeProcessCreateTbReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
void
*
pReq
,
SRpcMsg
*
pRsp
)
{
#if 0
SVCreateTbBatchReq vCreateTbBatchReq = {0};
SVCreateTbBatchRsp vCreateTbBatchRsp = {0};
static
int
vnodeProcessCreateTbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int
len
,
SRpcMsg
*
pRsp
)
{
SCoder
coder
=
{
0
};
int
rcode
=
0
;
SVCreateTbBatchReq
req
=
{
0
};
SVCreateTbReq
*
pCreateReq
;
pRsp
->
msgType
=
TDMT_VND_CREATE_TABLE_RSP
;
pRsp->code = TSDB_CODE_SUCCESS;
pRsp->pCont = NULL;
pRsp->contLen = 0;
tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq);
int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray);
for (int i = 0; i < reqNum; i++) {
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
char tableFName[TSDB_TABLE_FNAME_LEN];
SMsgHead *pHead = (SMsgHead *)pMsg->pCont;
sprintf(tableFName, "%s.%s", pVnode->config.dbname, pCreateTbReq->name);
int32_t code = vnodeValidateTableHash(&pVnode->config, tableFName);
if (code) {
SVCreateTbRsp rsp;
rsp.code = code;
taosArrayPush(vCreateTbBatchRsp.rspList, &rsp);
}
// decode
tCoderInit
(
&
coder
,
TD_LITTLE_ENDIAN
,
pReq
,
len
,
TD_DECODER
);
if
(
tDecodeSVCreateTbBatchReq
(
&
coder
,
&
req
)
<
0
)
{
rcode
=
-
1
;
terrno
=
TSDB_CODE_INVALID_MSG
;
goto
_exit
;
}
if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) {
// TODO: handle error
vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name);
}
// TODO: to encapsule a free API
taosMemoryFree(pCreateTbReq->name);
if (pCreateTbReq->type == TD_SUPER_TABLE) {
// taosMemoryFree(pCreateTbReq->stbCfg.pSchema);
// taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema);
// if (pCreateTbReq->stbCfg.pRSmaParam) {
// taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds);
// taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam);
// }
} else if (pCreateTbReq->type == TD_CHILD_TABLE) {
taosMemoryFree(pCreateTbReq->ctbCfg.pTag);
// loop to create table
for
(
int
iReq
=
0
;
iReq
<
req
.
nReqs
;
iReq
++
)
{
pCreateReq
=
req
.
pReqs
+
iReq
;
if
(
metaCreateTable
(
pVnode
->
pMeta
,
version
,
pCreateReq
)
<
0
)
{
// TODO: fill request
}
else
{
taosMemoryFree(pCreateTbReq->ntbCfg.pSchema);
// TODO
}
}
vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray));
taosArrayDestroy(vCreateTbBatchReq.pArray);
if (vCreateTbBatchRsp.rspList) {
int32_t contLen = tSerializeSVCreateTbBatchRsp(NULL, 0, &vCreateTbBatchRsp);
void *msg = rpcMallocCont(contLen);
tSerializeSVCreateTbBatchRsp(msg, contLen, &vCreateTbBatchRsp);
taosArrayDestroy(vCreateTbBatchRsp.rspList);
pRsp->pCont = msg;
pRsp->contLen = contLen;
}
// prepare rsp
#endif
return
0
;
_exit:
tCoderClear
(
&
coder
);
return
rcode
;
}
static
int
vnodeProcessAlterStbReq
(
SVnode
*
pVnode
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录