Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ad9fd5ec
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看板
提交
ad9fd5ec
编写于
4月 23, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact more meta
上级
44dc05f3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
99 addition
and
71 deletion
+99
-71
include/common/tmsg.h
include/common/tmsg.h
+4
-4
source/dnode/vnode/src/inc/meta.h
source/dnode/vnode/src/inc/meta.h
+1
-0
source/dnode/vnode/src/meta/metaEntry.c
source/dnode/vnode/src/meta/metaEntry.c
+2
-0
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+92
-67
未找到文件。
include/common/tmsg.h
浏览文件 @
ad9fd5ec
...
...
@@ -2193,8 +2193,8 @@ static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) {
static
FORCE_INLINE
int32_t
tEncodeSSchema
(
SCoder
*
pEncoder
,
const
SSchema
*
pSchema
)
{
if
(
tEncodeI8
(
pEncoder
,
pSchema
->
type
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pSchema
->
flags
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pSchema
->
bytes
)
<
0
)
return
-
1
;
if
(
tEncodeI16
(
pEncoder
,
pSchema
->
colId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
v
(
pEncoder
,
pSchema
->
bytes
)
<
0
)
return
-
1
;
if
(
tEncodeI16
v
(
pEncoder
,
pSchema
->
colId
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pSchema
->
name
)
<
0
)
return
-
1
;
return
0
;
}
...
...
@@ -2202,8 +2202,8 @@ static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSch
static
FORCE_INLINE
int32_t
tDecodeSSchema
(
SCoder
*
pDecoder
,
SSchema
*
pSchema
)
{
if
(
tDecodeI8
(
pDecoder
,
&
pSchema
->
type
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pSchema
->
flags
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pSchema
->
bytes
)
<
0
)
return
-
1
;
if
(
tDecodeI16
(
pDecoder
,
&
pSchema
->
colId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
v
(
pDecoder
,
&
pSchema
->
bytes
)
<
0
)
return
-
1
;
if
(
tDecodeI16
v
(
pDecoder
,
&
pSchema
->
colId
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pSchema
->
name
)
<
0
)
return
-
1
;
return
0
;
}
...
...
source/dnode/vnode/src/inc/meta.h
浏览文件 @
ad9fd5ec
...
...
@@ -135,6 +135,7 @@ void metaCloseCtbCurosr(SMCtbCursor* pCtbCur);
tb_uid_t
metaCtbCursorNext
(
SMCtbCursor
*
pCtbCur
);
struct
SMetaEntry
{
int64_t
version
;
int8_t
type
;
tb_uid_t
uid
;
const
char
*
name
;
...
...
source/dnode/vnode/src/meta/metaEntry.c
浏览文件 @
ad9fd5ec
...
...
@@ -18,6 +18,7 @@
int
metaEncodeEntry
(
SCoder
*
pCoder
,
const
SMetaEntry
*
pME
)
{
if
(
tStartEncode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pME
->
version
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pCoder
,
pME
->
type
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pME
->
uid
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pCoder
,
pME
->
name
)
<
0
)
return
-
1
;
...
...
@@ -45,6 +46,7 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) {
int
metaDecodeEntry
(
SCoder
*
pCoder
,
SMetaEntry
*
pME
)
{
if
(
tStartDecode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pME
->
version
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pME
->
type
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pME
->
uid
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pCoder
,
&
pME
->
name
)
<
0
)
return
-
1
;
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
ad9fd5ec
...
...
@@ -15,13 +15,14 @@
#include "vnodeInt.h"
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
);
static
int
metaSaveToSkmDb
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
SSchemaWrapper
*
pSW
);
static
int
metaHandleEntry
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaSaveToTbDb
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateUidIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateNameIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateTtlIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaSaveToSkmDb
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateCtbIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateTagIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
int
metaCreateSTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateStbReq
*
pReq
)
{
SMetaEntry
me
=
{
0
};
...
...
@@ -39,23 +40,14 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
}
// set structs
me
.
version
=
version
;
me
.
type
=
TSDB_SUPER_TABLE
;
me
.
uid
=
pReq
->
suid
;
me
.
name
=
pReq
->
name
;
me
.
stbEntry
.
schema
=
pReq
->
schema
;
me
.
stbEntry
.
schemaTag
=
pReq
->
schemaTag
;
// save to table.db
if
(
metaSaveToTbDb
(
pMeta
,
version
,
&
me
)
<
0
)
goto
_err
;
// save to schema.db (TODO)
if
(
metaSaveToSkmDb
(
pMeta
,
pReq
->
suid
,
&
pReq
->
schema
)
<
0
)
goto
_err
;
// update uid idx
if
(
metaUpdateUidIdx
(
pMeta
,
me
.
uid
,
version
)
<
0
)
goto
_err
;
// update name.idx
if
(
metaUpdateNameIdx
(
pMeta
,
me
.
name
,
me
.
uid
)
<
0
)
goto
_err
;
if
(
metaHandleEntry
(
pMeta
,
&
me
)
<
0
)
goto
_err
;
metaDebug
(
"vgId: %d super table is created, name:%s uid: %"
PRId64
,
TD_VID
(
pMeta
->
pVnode
),
pReq
->
name
,
pReq
->
suid
);
...
...
@@ -105,16 +97,7 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
me
.
ntbEntry
.
schema
=
pReq
->
ntb
.
schema
;
}
// 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
;
}
}
if
(
metaHandleEntry
(
pMeta
,
&
me
)
<
0
)
goto
_err
;
metaDebug
(
"vgId:%d table %s uid %"
PRId64
" is created"
,
TD_VID
(
pMeta
->
pVnode
),
pReq
->
name
,
pReq
->
uid
);
return
0
;
...
...
@@ -141,7 +124,7 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid) {
return
0
;
}
static
int
metaSaveToTbDb
(
SMeta
*
pMeta
,
int64_t
version
,
const
SMetaEntry
*
pME
)
{
static
int
metaSaveToTbDb
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
STbDbKey
tbDbKey
;
void
*
pKey
=
NULL
;
void
*
pVal
=
NULL
;
...
...
@@ -150,7 +133,7 @@ static int metaSaveToTbDb(SMeta *pMeta, int64_t version, const SMetaEntry *pME)
SCoder
coder
=
{
0
};
// set key and value
tbDbKey
.
version
=
version
;
tbDbKey
.
version
=
pME
->
version
;
tbDbKey
.
uid
=
pME
->
uid
;
pKey
=
&
tbDbKey
;
...
...
@@ -187,71 +170,113 @@ _err:
return
-
1
;
}
static
int
metaUpdateUidIdx
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int64_t
version
)
{
return
tdbDbInsert
(
pMeta
->
pUidIdx
,
&
uid
,
sizeof
(
uid
),
&
version
,
sizeof
(
version
),
NULL
);
static
int
metaUpdateUidIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
return
tdbDbInsert
(
pMeta
->
pUidIdx
,
&
pME
->
uid
,
sizeof
(
tb_uid_t
),
&
pME
->
version
,
sizeof
(
int64_t
),
NULL
);
}
static
int
metaUpdateNameIdx
(
SMeta
*
pMeta
,
const
char
*
name
,
tb_uid_t
uid
)
{
return
tdbDbInsert
(
pMeta
->
pNameIdx
,
name
,
strlen
(
name
)
+
1
,
&
uid
,
sizeof
(
uid
),
NULL
);
static
int
metaUpdateNameIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
return
tdbDbInsert
(
pMeta
->
pNameIdx
,
pME
->
name
,
strlen
(
pME
->
name
)
+
1
,
&
pME
->
uid
,
sizeof
(
tb_uid_t
),
NULL
);
}
static
int
metaUpdateTtlIdx
(
SMeta
*
pMeta
,
int64_t
dtime
,
tb_uid_t
uid
)
{
STtlIdxKey
ttlKey
=
{.
dtime
=
dtime
,
.
uid
=
uid
};
static
int
metaUpdateTtlIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
int32_t
ttlDays
;
int64_t
ctime
;
STtlIdxKey
ttlKey
;
if
(
pME
->
type
==
TSDB_CHILD_TABLE
)
{
ctime
=
pME
->
ctbEntry
.
ctime
;
ttlDays
=
pME
->
ctbEntry
.
ttlDays
;
}
else
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
ctime
=
pME
->
ntbEntry
.
ctime
;
ttlDays
=
pME
->
ntbEntry
.
ttlDays
;
}
else
{
ASSERT
(
0
);
}
if
(
ttlDays
<=
0
)
return
0
;
ttlKey
.
dtime
=
ctime
+
ttlDays
*
24
*
60
*
60
;
ttlKey
.
uid
=
pME
->
uid
;
return
tdbDbInsert
(
pMeta
->
pTtlIdx
,
&
ttlKey
,
sizeof
(
ttlKey
),
NULL
,
0
,
NULL
);
}
static
int
metaCreateChildTable
(
SMeta
*
pMeta
,
int64_t
version
,
SMetaEntry
*
pME
)
{
static
int
metaUpdateCtbIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCtbIdxKey
ctbIdxKey
=
{.
suid
=
pME
->
ctbEntry
.
suid
,
.
uid
=
pME
->
uid
};
return
tdbDbInsert
(
pMeta
->
pCtbIdx
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
NULL
,
0
,
NULL
);
}
static
int
metaUpdateTagIdx
(
SMeta
*
pMeta
,
const
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
if
(
metaSaveToSkmDb
(
pMeta
,
pME
->
uid
,
&
pME
->
ntbEntry
.
schema
)
<
0
)
return
-
1
;
// 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
;
static
int
metaSaveToSkmDb
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCoder
coder
=
{
0
};
void
*
pVal
=
NULL
;
int
vLen
=
0
;
int
rcode
=
0
;
SSkmDbKey
skmDbKey
=
{
0
};
const
SSchemaWrapper
*
pSW
;
if
(
pME
->
type
==
TSDB_SUPER_TABLE
)
{
pSW
=
&
pME
->
stbEntry
.
schema
;
}
else
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
pSW
=
&
pME
->
ntbEntry
.
schema
;
}
else
{
ASSERT
(
0
);
}
return
0
;
}
static
int
metaSaveToSkmDb
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
SSchemaWrapper
*
pSW
)
{
SCoder
coder
=
{
0
};
void
*
pVal
=
NULL
;
int
vLen
=
0
;
int
rcode
=
0
;
SSkmDbKey
skmDbKey
=
{.
uid
=
uid
,
.
sver
=
pSW
->
sver
};
skmDbKey
.
uid
=
pME
->
uid
;
skmDbKey
.
sver
=
pSW
->
sver
;
// encode schema
if
(
tEncodeSize
(
tEncodeSSchemaWrapper
,
pSW
,
vLen
)
<
0
)
return
-
1
;
pVal
=
TCODER_MALLOC
(
&
coder
,
vLen
);
pVal
=
taosMemoryMalloc
(
vLen
);
if
(
pVal
==
NULL
)
{
rcode
=
-
1
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
tCoderInit
(
&
coder
,
TD_LITTLE_ENDIAN
,
pVal
,
vLen
,
TD_ENCODER
);
tEncodeSSchemaWrapper
(
&
coder
,
pSW
);
if
(
tdbDbInsert
(
pMeta
->
pSkmDb
,
&
skmDbKey
,
sizeof
(
skmDbKey
),
pVal
,
vLen
,
NULL
)
<
0
)
{
rcode
=
-
1
;
goto
_exit
;
}
_exit:
taosMemoryFree
(
pVal
);
tCoderClear
(
&
coder
);
return
rcode
;
}
static
int
metaHandleEntry
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
// save to table.db
if
(
metaSaveToTbDb
(
pMeta
,
pME
)
<
0
)
return
-
1
;
// update uid.idx
if
(
metaUpdateUidIdx
(
pMeta
,
pME
)
<
0
)
return
-
1
;
// update name.idx
if
(
metaUpdateNameIdx
(
pMeta
,
pME
)
<
0
)
return
-
1
;
if
(
pME
->
type
==
TSDB_CHILD_TABLE
)
{
// update ctb.idx
if
(
metaUpdateCtbIdx
(
pMeta
,
pME
)
<
0
)
return
-
1
;
// update tag.idx
if
(
metaUpdateTagIdx
(
pMeta
,
pME
)
<
0
)
return
-
1
;
}
else
{
// update schema.db
if
(
metaSaveToSkmDb
(
pMeta
,
pME
)
<
0
)
return
-
1
;
}
if
(
pME
->
type
!=
TSDB_SUPER_TABLE
)
{
if
(
metaUpdateTtlIdx
(
pMeta
,
pME
)
<
0
)
return
-
1
;
}
return
0
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录