Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
acf1d631
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
未验证
提交
acf1d631
编写于
6月 27, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
6月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2461 from taosdata/feature/2.0tsdb
Feature/2.0tsdb
上级
108e53f4
efe1e809
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
86 addition
and
22 deletion
+86
-22
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+86
-22
未找到文件。
src/tsdb/src/tsdbMeta.c
浏览文件 @
acf1d631
...
...
@@ -48,6 +48,8 @@ static int tsdbEncodeTable(void **buf, STable *pTable);
static
void
*
tsdbDecodeTable
(
void
*
buf
,
STable
**
pRTable
);
static
int
tsdbGetTableEncodeSize
(
int8_t
act
,
STable
*
pTable
);
static
void
*
tsdbInsertTableAct
(
STsdbRepo
*
pRepo
,
int8_t
act
,
void
*
buf
,
STable
*
pTable
);
static
int
tsdbRemoveTableFromStore
(
STsdbRepo
*
pRepo
,
STable
*
pTable
);
static
int
tsdbRmTableFromMeta
(
STsdbRepo
*
pRepo
,
STable
*
pTable
);
// ------------------ OUTER FUNCTIONS ------------------
int
tsdbCreateTable
(
TSDB_REPO_T
*
repo
,
STableCfg
*
pCfg
)
{
...
...
@@ -117,7 +119,7 @@ int tsdbDropTable(TSDB_REPO_T *repo, STableId tableId) {
STable
*
pTable
=
tsdbGetTableByUid
(
pMeta
,
uid
);
if
(
pTable
==
NULL
)
{
tsdbError
(
"vgId:%d failed to drop table since table not exists! tid:%d uid %"
PRI
d
64
,
REPO_ID
(
pRepo
),
tableId
.
tid
,
tsdbError
(
"vgId:%d failed to drop table since table not exists! tid:%d uid %"
PRI
u
64
,
REPO_ID
(
pRepo
),
tableId
.
tid
,
uid
);
terrno
=
TSDB_CODE_TDB_INVALID_TABLE_ID
;
return
-
1
;
...
...
@@ -132,30 +134,26 @@ int tsdbDropTable(TSDB_REPO_T *repo, STableId tableId) {
return
-
1
;
}
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_STREAM_TABLE
)
{
if
(
pTable
->
cqhandle
)
pRepo
->
appH
.
cqDropFunc
(
pTable
->
cqhandle
);
// Write to KV store first
if
(
tsdbRemoveTableFromStore
(
pRepo
,
pTable
)
<
0
)
{
tsdbError
(
"vgId:%d failed to drop table %s since %s"
,
REPO_ID
(
pRepo
),
tbname
,
tstrerror
(
terrno
));
goto
_err
;
}
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_SUPER_TABLE
)
{
SSkipListIterator
*
pIter
=
tSkipListCreateIter
(
pTable
->
pIndex
);
while
(
tSkipListIterNext
(
pIter
))
{
STable
*
tTable
=
*
(
STable
**
)
SL_GET_NODE_DATA
(
tSkipListIterGet
(
pIter
));
ASSERT
(
TABLE_TYPE
(
tTable
)
==
TSDB_CHILD_TABLE
);
int
tlen
=
tsdbGetTableEncodeSize
(
TSDB_DROP_META
,
tTable
);
void
*
buf
=
tsdbAllocBytes
(
pRepo
,
tlen
);
ASSERT
(
buf
!=
NULL
);
tsdbInsertTableAct
(
pRepo
,
TSDB_DROP_META
,
buf
,
tTable
);
tsdbRemoveTableFromMeta
(
pRepo
,
tTable
,
false
,
true
);
}
tSkipListDestroyIter
(
pIter
);
// Remove table from Meta
if
(
tsdbRmTableFromMeta
(
pRepo
,
pTable
)
<
0
)
{
tsdbError
(
"vgId:%d failed to drop table %s since %s"
,
REPO_ID
(
pRepo
),
tbname
,
tstrerror
(
terrno
));
goto
_err
;
}
tsdbRemoveTableFromMeta
(
pRepo
,
pTable
,
true
,
true
);
tsdbTrace
(
"vgId:%d, table %s is dropped! tid:%d, uid:%"
PRId64
,
pRepo
->
config
.
tsdbId
,
tbname
,
tid
,
uid
);
free
(
tbname
);
return
0
;
_err:
tfree
(
tbname
);
return
-
1
;
}
void
*
tsdbGetTableTagVal
(
const
void
*
pTable
,
int32_t
colId
,
int16_t
type
,
int16_t
bytes
)
{
...
...
@@ -555,15 +553,16 @@ int tsdbUnlockRepoMeta(STsdbRepo *pRepo) {
void
tsdbRefTable
(
STable
*
pTable
)
{
int16_t
ref
=
T_REF_INC
(
pTable
);
tsdbTrace
(
"ref table:%s, uid:%"
PRIu64
", tid:%d, ref:%d"
,
TABLE_CHAR_NAME
(
pTable
),
pTable
->
tableId
.
uid
,
pTable
->
tableId
.
tid
,
ref
);
UNUSED
(
ref
);
// tsdbTrace("ref table %"PRIu64", tid:%d, refCount:%d", TABLE_UID(pTable), TABLE_TID(pTable), ref);
}
void
tsdbUnRefTable
(
STable
*
pTable
)
{
int16_t
ref
=
T_REF_DEC
(
pTable
);
tsdbTrace
(
"unref table
:%s, uid:%"
PRIu64
", tid:%d, ref:%d"
,
TABLE_CHAR_NAME
(
pTable
),
pTable
->
tableId
.
uid
,
pTable
->
tableId
.
tid
,
ref
);
tsdbTrace
(
"unref table
uid:%"
PRIu64
", tid:%d, refCount:%d"
,
TABLE_UID
(
pTable
),
TABLE_TID
(
pTable
)
,
ref
);
if
(
ref
==
0
)
{
tsdbTrace
(
"destroy table:%s uid:%"
PRIu64
", tid:%d"
,
TABLE_CHAR_NAME
(
pTable
),
pTable
->
tableId
.
uid
,
pTable
->
tableId
.
tid
);
// tsdbTrace("destory table name:%s uid:%"PRIu64", tid:%d", TABLE_CHAR_NAME(pTable), TABLE_UID(pTable), TABLE_TID(pTable)
);
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_CHILD_TABLE
)
{
tsdbUnRefTable
(
pTable
->
pSuper
);
...
...
@@ -1164,8 +1163,16 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) {
}
static
int
tsdbGetTableEncodeSize
(
int8_t
act
,
STable
*
pTable
)
{
int
tlen
=
sizeof
(
SListNode
)
+
sizeof
(
SActObj
);
if
(
act
==
TSDB_UPDATE_META
)
tlen
+=
(
sizeof
(
SActCont
)
+
tsdbEncodeTable
(
NULL
,
pTable
)
+
sizeof
(
TSCKSUM
));
int
tlen
=
0
;
if
(
act
==
TSDB_UPDATE_META
)
{
tlen
=
sizeof
(
SListNode
)
+
sizeof
(
SActObj
)
+
sizeof
(
SActCont
)
+
tsdbEncodeTable
(
NULL
,
pTable
)
+
sizeof
(
TSCKSUM
);
}
else
{
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_SUPER_TABLE
)
{
tlen
=
(
sizeof
(
SListNode
)
+
sizeof
(
SActObj
))
*
(
tSkipListGetSize
(
pTable
->
pIndex
)
+
1
);
}
else
{
tlen
=
sizeof
(
SListNode
)
+
sizeof
(
SActObj
);
}
}
return
tlen
;
}
...
...
@@ -1190,4 +1197,61 @@ static void *tsdbInsertTableAct(STsdbRepo *pRepo, int8_t act, void *buf, STable
tdListAppendNode
(
pRepo
->
mem
->
actList
,
pNode
);
return
pBuf
;
}
static
int
tsdbRemoveTableFromStore
(
STsdbRepo
*
pRepo
,
STable
*
pTable
)
{
int
tlen
=
tsdbGetTableEncodeSize
(
TSDB_DROP_META
,
pTable
);
void
*
buf
=
tsdbAllocBytes
(
pRepo
,
tlen
);
ASSERT
(
buf
!=
NULL
);
void
*
pBuf
=
buf
;
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_SUPER_TABLE
)
{
SSkipListIterator
*
pIter
=
tSkipListCreateIter
(
pTable
->
pIndex
);
if
(
pIter
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
while
(
tSkipListIterNext
(
pIter
))
{
STable
*
tTable
=
*
(
STable
**
)
SL_GET_NODE_DATA
(
tSkipListIterGet
(
pIter
));
ASSERT
(
TABLE_TYPE
(
tTable
)
==
TSDB_CHILD_TABLE
);
pBuf
=
tsdbInsertTableAct
(
pRepo
,
TSDB_DROP_META
,
pBuf
,
pTable
);
}
tSkipListDestroyIter
(
pIter
);
}
pBuf
=
tsdbInsertTableAct
(
pRepo
,
TSDB_DROP_META
,
pBuf
,
pTable
);
ASSERT
(
POINTER_DISTANCE
(
pBuf
,
buf
)
==
tlen
);
return
0
;
}
static
int
tsdbRmTableFromMeta
(
STsdbRepo
*
pRepo
,
STable
*
pTable
)
{
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_SUPER_TABLE
)
{
SSkipListIterator
*
pIter
=
tSkipListCreateIter
(
pTable
->
pIndex
);
if
(
pIter
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
tsdbWLockRepoMeta
(
pRepo
);
while
(
tSkipListIterNext
(
pIter
))
{
STable
*
tTable
=
*
(
STable
**
)
SL_GET_NODE_DATA
(
tSkipListIterGet
(
pIter
));
tsdbRemoveTableFromMeta
(
pRepo
,
tTable
,
false
,
false
);
}
tsdbRemoveTableFromMeta
(
pRepo
,
pTable
,
false
,
false
);
tsdbUnlockRepoMeta
(
pRepo
);
tSkipListDestroyIter
(
pIter
);
}
else
{
if
((
TABLE_TYPE
(
pTable
)
==
TSDB_STREAM_TABLE
)
&&
pTable
->
cqhandle
)
pRepo
->
appH
.
cqDropFunc
(
pTable
->
cqhandle
);
tsdbRemoveTableFromMeta
(
pRepo
,
pTable
,
true
,
true
);
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录