Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
670a90e5
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看板
提交
670a90e5
编写于
5月 31, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: tsdb multi-version
上级
81ef708c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
107 addition
and
17 deletion
+107
-17
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+1
-0
source/dnode/vnode/src/tsdb/tsdbMemTable2.c
source/dnode/vnode/src/tsdb/tsdbMemTable2.c
+106
-17
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
670a90e5
...
@@ -870,6 +870,7 @@ struct SDelOp {
...
@@ -870,6 +870,7 @@ struct SDelOp {
int64_t
version
;
int64_t
version
;
TSKEY
sKey
;
// included
TSKEY
sKey
;
// included
TSKEY
eKey
;
// included
TSKEY
eKey
;
// included
SDelOp
*
pNext
;
};
};
#endif
#endif
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable2.c
浏览文件 @
670a90e5
...
@@ -26,7 +26,8 @@ struct SMemData {
...
@@ -26,7 +26,8 @@ struct SMemData {
TSDBKEY
minKey
;
TSDBKEY
minKey
;
TSDBKEY
maxKey
;
TSDBKEY
maxKey
;
int64_t
nRows
;
int64_t
nRows
;
SArray
*
aDelOp
;
// SArray<SDelOp>
SDelOp
*
delOpHead
;
SDelOp
*
delOpTail
;
};
};
struct
SMemTable
{
struct
SMemTable
{
...
@@ -38,7 +39,8 @@ struct SMemTable {
...
@@ -38,7 +39,8 @@ struct SMemTable {
SArray
*
pArray
;
// SArray<SMemData>
SArray
*
pArray
;
// SArray<SMemData>
};
};
static
int32_t
tsdbGetOrCreateTbData
(
STsdb
*
pTsdb
,
tb_uid_t
suid
,
tb_uid_t
uid
,
SMemData
**
ppMemData
);
static
int32_t
tsdbGetOrCreateMemData
(
SMemTable
*
pMemTable
,
tb_uid_t
suid
,
tb_uid_t
uid
,
SMemData
**
ppMemData
);
static
int
memDataPCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
// SMemTable ==============================================
// SMemTable ==============================================
int32_t
tsdbMemTableCreate2
(
STsdb
*
pTsdb
,
SMemTable
**
ppMemTable
)
{
int32_t
tsdbMemTableCreate2
(
STsdb
*
pTsdb
,
SMemTable
**
ppMemTable
)
{
...
@@ -52,8 +54,8 @@ int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTable) {
...
@@ -52,8 +54,8 @@ int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTable) {
}
}
pMemTable
->
pTsdb
=
pTsdb
;
pMemTable
->
pTsdb
=
pTsdb
;
pMemTable
->
nRef
=
1
;
pMemTable
->
nRef
=
1
;
pMemTable
->
minKey
=
(
TSDBKEY
){.
version
=
-
1
,
.
ts
=
TSKEY_MAX
};
pMemTable
->
minKey
=
(
TSDBKEY
){.
version
=
INT64_MAX
,
.
ts
=
TSKEY_MAX
};
pMemTable
->
maxKey
=
(
TSDBKEY
){.
version
=
INT64_MAX
,
.
ts
=
TSKEY_MIN
};
pMemTable
->
maxKey
=
(
TSDBKEY
){.
version
=
-
1
,
.
ts
=
TSKEY_MIN
};
pMemTable
->
nRows
=
0
;
pMemTable
->
nRows
=
0
;
pMemTable
->
pArray
=
taosArrayInit
(
512
,
sizeof
(
SMemData
*
));
pMemTable
->
pArray
=
taosArrayInit
(
512
,
sizeof
(
SMemData
*
));
if
(
pMemTable
->
pArray
==
NULL
)
{
if
(
pMemTable
->
pArray
==
NULL
)
{
...
@@ -76,15 +78,17 @@ void tsdbMemTableDestroy2(SMemTable *pMemTable) {
...
@@ -76,15 +78,17 @@ void tsdbMemTableDestroy2(SMemTable *pMemTable) {
}
}
int32_t
tsdbInsertTableData2
(
STsdb
*
pTsdb
,
int64_t
version
,
SVSubmitBlk
*
pSubmitBlk
)
{
int32_t
tsdbInsertTableData2
(
STsdb
*
pTsdb
,
int64_t
version
,
SVSubmitBlk
*
pSubmitBlk
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
SMemData
*
pMemData
;
SMemTable
*
pMemTable
=
(
SMemTable
*
)
pTsdb
->
mem
;
// TODO
SMemData
*
pMemData
;
ASSERT
(
pMemTable
);
// check if table exists
{
{
//
TODO
//
check if table exists (todo)
}
}
code
=
tsdbGetOrCreate
TbData
(
pTsdb
,
pSubmitBlk
->
suid
,
pSubmitBlk
->
uid
,
&
pMemData
);
code
=
tsdbGetOrCreate
MemData
(
pMemTable
,
pSubmitBlk
->
suid
,
pSubmitBlk
->
uid
,
&
pMemData
);
if
(
code
)
{
if
(
code
)
{
tsdbError
(
"vgId:%d failed to create/get table data since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbError
(
"vgId:%d failed to create/get table data since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
goto
_err
;
goto
_err
;
...
@@ -99,24 +103,90 @@ _err:
...
@@ -99,24 +103,90 @@ _err:
}
}
int32_t
tsdbDeleteTableData2
(
STsdb
*
pTsdb
,
int64_t
version
,
tb_uid_t
suid
,
tb_uid_t
uid
,
TSKEY
sKey
,
TSKEY
eKey
)
{
int32_t
tsdbDeleteTableData2
(
STsdb
*
pTsdb
,
int64_t
version
,
tb_uid_t
suid
,
tb_uid_t
uid
,
TSKEY
sKey
,
TSKEY
eKey
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
// TODO
SMemTable
*
pMemTable
=
(
SMemTable
*
)
pTsdb
->
mem
;
// TODO
SMemData
*
pMemData
;
SVBufPool
*
pPool
=
pTsdb
->
pVnode
->
inUse
;
ASSERT
(
pMemTable
);
{
// check if table exists (todo)
}
code
=
tsdbGetOrCreateMemData
(
pMemTable
,
suid
,
uid
,
&
pMemData
);
if
(
code
)
{
goto
_err
;
}
// do delete
SDelOp
*
pDelOp
=
(
SDelOp
*
)
vnodeBufPoolMalloc
(
pPool
,
sizeof
(
*
pDelOp
));
if
(
pDelOp
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
pDelOp
->
version
=
version
;
pDelOp
->
sKey
=
sKey
;
pDelOp
->
eKey
=
eKey
;
pDelOp
->
pNext
=
NULL
;
if
(
pMemData
->
delOpHead
==
NULL
)
{
ASSERT
(
pMemData
->
delOpTail
==
NULL
);
pMemData
->
delOpHead
=
pMemData
->
delOpTail
=
pDelOp
;
}
else
{
pMemData
->
delOpTail
->
pNext
=
pDelOp
;
pMemData
->
delOpTail
=
pDelOp
;
}
{
// update the state of pMemTable, pMemData, last and lastrow (todo)
}
tsdbDebug
(
"vgId:%d delete data from table suid:%"
PRId64
" uid:%"
PRId64
" sKey:%"
PRId64
" eKey:%"
PRId64
" since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
suid
,
uid
,
sKey
,
eKey
,
tstrerror
(
code
));
return
code
;
_err:
tsdbError
(
"vgId:%d failed to delete data from table suid:%"
PRId64
" uid:%"
PRId64
" sKey:%"
PRId64
" eKey:%"
PRId64
" since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
suid
,
uid
,
sKey
,
eKey
,
tstrerror
(
code
));
return
code
;
return
code
;
}
}
static
int32_t
tsdbGetOrCreate
TbData
(
STsdb
*
pTsdb
,
tb_uid_t
suid
,
tb_uid_t
uid
,
SMemData
**
ppMemData
)
{
static
int32_t
tsdbGetOrCreate
MemData
(
SMemTable
*
pMemTable
,
tb_uid_t
suid
,
tb_uid_t
uid
,
SMemData
**
ppMemData
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
idx
=
0
;
SMemData
*
pMemDataT
=
&
(
SMemData
){.
suid
=
suid
,
.
uid
=
uid
};
SMemData
*
pMemData
=
NULL
;
SMemData
*
pMemData
=
NULL
;
S
MemTable
*
pMemTable
=
(
SMemTable
*
)
pTsdb
->
mem
;
S
VBufPool
*
pPool
=
pMemTable
->
pTsdb
->
pVnode
->
inUse
;
// search
// get
pMemData
=
(
SMemData
*
)
taosbsearch
(
NULL
,
pMemTable
->
pArray
->
pData
,
taosArrayGetSize
(
pMemTable
->
pArray
),
idx
=
taosArraySearchIdx
(
pMemTable
->
pArray
,
&
pMemDataT
,
memDataPCmprFn
,
TD_GE
);
sizeof
(
SMemData
*
),
NULL
,
TD_GE
);
if
(
idx
>=
0
)
{
pMemData
=
(
SMemData
*
)
taosArrayGet
(
pMemTable
->
pArray
,
idx
);
if
(
memDataPCmprFn
(
&
pMemDataT
,
&
pMemData
)
==
0
)
goto
_exit
;
}
// create
pMemData
=
vnodeBufPoolMalloc
(
pPool
,
sizeof
(
*
pMemData
));
if
(
pMemData
==
NULL
)
{
if
(
pMemData
==
NULL
)
{
// not found, create one
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
pMemData
->
suid
=
suid
;
pMemData
->
uid
=
uid
;
pMemData
->
minKey
=
(
TSDBKEY
){.
version
=
INT64_MAX
,
.
ts
=
TSKEY_MAX
};
pMemData
->
maxKey
=
(
TSDBKEY
){.
version
=
-
1
,
.
ts
=
TSKEY_MIN
};
pMemData
->
nRows
=
0
;
pMemData
->
delOpHead
=
pMemData
->
delOpTail
=
NULL
;
if
(
idx
<
0
)
idx
=
0
;
if
(
taosArrayInsert
(
pMemTable
->
pArray
,
idx
,
&
pMemData
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
}
_exit:
*
ppMemData
=
pMemData
;
*
ppMemData
=
pMemData
;
return
code
;
return
code
;
...
@@ -125,6 +195,25 @@ _err:
...
@@ -125,6 +195,25 @@ _err:
return
code
;
return
code
;
}
}
static
int
memDataPCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
SMemData
*
pMemData1
=
*
(
SMemData
**
)
p1
;
SMemData
*
pMemData2
=
*
(
SMemData
**
)
p2
;
if
(
pMemData1
->
suid
<
pMemData2
->
suid
)
{
return
-
1
;
}
else
if
(
pMemData1
->
suid
>
pMemData2
->
suid
)
{
return
1
;
}
if
(
pMemData1
->
uid
<
pMemData2
->
uid
)
{
return
-
1
;
}
else
if
(
pMemData1
->
uid
>
pMemData2
->
uid
)
{
return
1
;
}
return
0
;
}
#if 0 //====================================================================================
#if 0 //====================================================================================
#define SL_MAX_LEVEL 5
#define SL_MAX_LEVEL 5
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录