Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
681b973c
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看板
提交
681b973c
编写于
10月 13, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add index to ins_tables
上级
f82e6b41
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
139 addition
and
2 deletion
+139
-2
source/dnode/vnode/src/inc/meta.h
source/dnode/vnode/src/inc/meta.h
+16
-2
source/dnode/vnode/src/meta/metaOpen.c
source/dnode/vnode/src/meta/metaOpen.c
+56
-0
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+67
-0
未找到文件。
source/dnode/vnode/src/inc/meta.h
浏览文件 @
681b973c
...
...
@@ -86,8 +86,12 @@ struct SMeta {
TTB
*
pSuidIdx
;
// ivt idx and idx
void
*
pTagIvtIdx
;
TTB
*
pTagIdx
;
TTB
*
pTtlIdx
;
TTB
*
pTagIdx
;
TTB
*
pTtlIdx
;
TTB
*
pCtimeIdx
;
// table created time idx
TTB
*
pNcolIdx
;
// ncol of table idx, normal table only
TTB
*
pSmaIdx
;
...
...
@@ -142,6 +146,16 @@ typedef struct {
int64_t
smaUid
;
}
SSmaIdxKey
;
typedef
struct
{
int64_t
ctime
;
tb_uid_t
uid
;
}
SCtimeIdxKey
;
typedef
struct
{
int16_t
ncol
;
tb_uid_t
uid
;
}
SNcolIdxKey
;
// metaTable ==================
int
metaCreateTagIdxKey
(
tb_uid_t
suid
,
int32_t
cid
,
const
void
*
pTagData
,
int32_t
nTagData
,
int8_t
type
,
tb_uid_t
uid
,
STagIdxKey
**
ppTagIdxKey
,
int32_t
*
nTagIdxKey
);
...
...
source/dnode/vnode/src/meta/metaOpen.c
浏览文件 @
681b973c
...
...
@@ -24,6 +24,9 @@ static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
static
int
smaIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
taskIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
ctimeIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
ncolIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int32_t
metaInitLock
(
SMeta
*
pMeta
)
{
return
taosThreadRwlockInit
(
&
pMeta
->
lock
,
NULL
);
}
static
int32_t
metaDestroyLock
(
SMeta
*
pMeta
)
{
return
taosThreadRwlockDestroy
(
&
pMeta
->
lock
);
}
...
...
@@ -139,6 +142,20 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
goto
_err
;
}
// idx table create time
ret
=
tdbTbOpen
(
"ctime.idx"
,
sizeof
(
SCtimeIdxKey
),
0
,
ctimeIdxCmpr
,
pMeta
->
pEnv
,
&
pMeta
->
pCtimeIdx
);
if
(
ret
<
0
)
{
metaError
(
"vgId:%d, failed to open meta ctime index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
// idx num of col, normal table only
ret
=
tdbTbOpen
(
"ncol.idx"
,
sizeof
(
SNcolIdxKey
),
0
,
ncolIdxCmpr
,
pMeta
->
pEnv
,
&
pMeta
->
pNcolIdx
);
if
(
ret
<
0
)
{
metaError
(
"vgId:%d, failed to open meta ncol index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
ret
=
tdbTbOpen
(
"stream.task.db"
,
sizeof
(
int64_t
),
-
1
,
taskIdxKeyCmpr
,
pMeta
->
pEnv
,
&
pMeta
->
pStreamDb
);
if
(
ret
<
0
)
{
metaError
(
"vgId:%d, failed to open meta stream task index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
...
...
@@ -166,6 +183,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
_err:
if
(
pMeta
->
pIdx
)
metaCloseIdx
(
pMeta
);
if
(
pMeta
->
pStreamDb
)
tdbTbClose
(
pMeta
->
pStreamDb
);
if
(
pMeta
->
pNcolIdx
)
tdbTbClose
(
pMeta
->
pNcolIdx
);
if
(
pMeta
->
pCtimeIdx
)
tdbTbClose
(
pMeta
->
pCtimeIdx
);
if
(
pMeta
->
pSmaIdx
)
tdbTbClose
(
pMeta
->
pSmaIdx
);
if
(
pMeta
->
pTtlIdx
)
tdbTbClose
(
pMeta
->
pTtlIdx
);
if
(
pMeta
->
pTagIvtIdx
)
indexClose
(
pMeta
->
pTagIvtIdx
);
...
...
@@ -391,6 +410,43 @@ static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
return
0
;
}
static
int
ctimeIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SCtimeIdxKey
*
pCtimeIdxKey1
=
(
SCtimeIdxKey
*
)
pKey1
;
SCtimeIdxKey
*
pCtimeIdxKey2
=
(
SCtimeIdxKey
*
)
pKey2
;
if
(
pCtimeIdxKey1
->
ctime
>
pCtimeIdxKey2
->
ctime
)
{
return
1
;
}
else
if
(
pCtimeIdxKey1
->
ctime
<
pCtimeIdxKey2
->
ctime
)
{
return
-
1
;
}
if
(
pCtimeIdxKey1
->
uid
>
pCtimeIdxKey2
->
uid
)
{
return
1
;
}
else
if
(
pCtimeIdxKey1
->
uid
<
pCtimeIdxKey2
->
uid
)
{
return
-
1
;
}
return
0
;
}
static
int
ncolIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SNcolIdxKey
*
pNcolIdxKey1
=
(
SNcolIdxKey
*
)
pKey1
;
SNcolIdxKey
*
pNcolIdxKey2
=
(
SNcolIdxKey
*
)
pKey2
;
if
(
pNcolIdxKey1
->
ncol
>
pNcolIdxKey2
->
ncol
)
{
return
1
;
}
else
if
(
pNcolIdxKey1
->
ncol
<
pNcolIdxKey2
->
ncol
)
{
return
-
1
;
}
if
(
pNcolIdxKey1
->
uid
>
pNcolIdxKey2
->
uid
)
{
return
1
;
}
else
if
(
pNcolIdxKey1
->
uid
<
pNcolIdxKey2
->
uid
)
{
return
-
1
;
}
return
0
;
}
static
int
smaIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SSmaIdxKey
*
pSmaIdxKey1
=
(
SSmaIdxKey
*
)
pKey1
;
SSmaIdxKey
*
pSmaIdxKey2
=
(
SSmaIdxKey
*
)
pKey2
;
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
681b973c
...
...
@@ -26,6 +26,11 @@ static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME);
static
int
metaUpdateSuidIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateTagIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pCtbEntry
);
static
int
metaDropTableByUid
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int
*
type
);
// opt ins_tables query
static
int
metaUpdateCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaDeleteCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaDeleteNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
void
metaGetEntryInfo
(
const
SMetaEntry
*
pEntry
,
SMetaInfo
*
pInfo
)
{
pInfo
->
uid
=
pEntry
->
uid
;
...
...
@@ -547,6 +552,28 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) {
ttlKey
->
dtime
=
ctime
/
1000
+
ttlDays
*
tsTtlUnit
;
ttlKey
->
uid
=
pME
->
uid
;
}
static
int
metaBuildCtimeIdxKey
(
SCtimeIdxKey
*
ctimeKey
,
const
SMetaEntry
*
pME
)
{
int64_t
ctime
;
if
(
pME
->
type
==
TSDB_CHILD_TABLE
)
{
ctime
=
pME
->
ctbEntry
.
ctime
;
}
else
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
ctime
=
pME
->
ntbEntry
.
ctime
;
}
else
{
return
-
1
;
}
ctimeKey
->
ctime
=
ctime
;
ctimeKey
->
uid
=
pME
->
uid
;
return
0
;
}
static
int
metaBuildNColIdxKey
(
SNcolIdxKey
*
ncolKey
,
const
SMetaEntry
*
pME
)
{
if
(
pME
->
type
!=
TSDB_NORMAL_TABLE
)
return
-
1
;
ncolKey
->
ncol
=
pME
->
ntbEntry
.
schemaRow
.
nCols
;
ncolKey
->
uid
=
pME
->
uid
;
return
0
;
}
static
int
metaDeleteTtlIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
STtlIdxKey
ttlKey
=
{
0
};
...
...
@@ -602,6 +629,9 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
tdbTbDelete
(
pMeta
->
pNameIdx
,
e
.
name
,
strlen
(
e
.
name
)
+
1
,
&
pMeta
->
txn
);
tdbTbDelete
(
pMeta
->
pUidIdx
,
&
uid
,
sizeof
(
uid
),
&
pMeta
->
txn
);
if
(
e
.
type
==
TSDB_CHILD_TABLE
||
e
.
type
==
TSDB_NORMAL_TABLE
)
metaDeleteCtimeIdx
(
pMeta
,
&
e
);
if
(
e
.
type
==
TSDB_NORMAL_TABLE
)
metaDeleteNcolIdx
(
pMeta
,
&
e
);
if
(
e
.
type
!=
TSDB_SUPER_TABLE
)
metaDeleteTtlIdx
(
pMeta
,
&
e
);
if
(
e
.
type
==
TSDB_CHILD_TABLE
)
{
...
...
@@ -628,6 +658,37 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
return
0
;
}
// opt ins_tables
int
metaUpdateCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCtimeIdxKey
ctimeKey
=
{
0
};
if
(
metaBuildCtimeIdxKey
(
&
ctimeKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbInsert
(
pMeta
->
pCtimeIdx
,
&
ctimeKey
,
sizeof
(
ctimeKey
),
NULL
,
0
,
&
pMeta
->
txn
);
}
int
metaDeleteCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCtimeIdxKey
ctimeKey
=
{
0
};
if
(
metaBuildCtimeIdxKey
(
&
ctimeKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbDelete
(
pMeta
->
pCtimeIdx
,
&
ctimeKey
,
sizeof
(
ctimeKey
),
&
pMeta
->
txn
);
}
int
metaUpdateNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SNcolIdxKey
ncolKey
=
{
0
};
if
(
metaBuildNColIdxKey
(
&
ncolKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbInsert
(
pMeta
->
pNcolIdx
,
&
ncolKey
,
sizeof
(
ncolKey
),
NULL
,
0
,
&
pMeta
->
txn
);
}
int
metaDeleteNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SNcolIdxKey
ncolKey
=
{
0
};
if
(
metaBuildNColIdxKey
(
&
ncolKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbDelete
(
pMeta
->
pNcolIdx
,
&
ncolKey
,
sizeof
(
ncolKey
),
&
pMeta
->
txn
);
}
static
int
metaAlterTableColumn
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
,
STableMetaRsp
*
pMetaRsp
)
{
void
*
pVal
=
NULL
;
...
...
@@ -1325,6 +1386,12 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
}
}
if
(
metaUpdateCtimeIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
if
(
metaUpdateNcolIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
}
if
(
pME
->
type
!=
TSDB_SUPER_TABLE
)
{
if
(
metaUpdateTtlIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录