Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
73cbc6f7
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
73cbc6f7
编写于
5月 31, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: vnode multi-version
上级
f0045e3f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
114 addition
and
46 deletion
+114
-46
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+21
-0
source/dnode/vnode/src/tsdb/tsdbMemTable2.c
source/dnode/vnode/src/tsdb/tsdbMemTable2.c
+93
-46
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
73cbc6f7
...
@@ -36,6 +36,8 @@ typedef struct TSDBROW TSDBROW;
...
@@ -36,6 +36,8 @@ typedef struct TSDBROW TSDBROW;
typedef
struct
TSDBKEY
TSDBKEY
;
typedef
struct
TSDBKEY
TSDBKEY
;
typedef
struct
SDelOp
SDelOp
;
typedef
struct
SDelOp
SDelOp
;
static
int
tsdbKeyCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
// tsdbMemTable2.c ==============================================================================================
// tsdbMemTable2.c ==============================================================================================
typedef
struct
SMemTable
SMemTable
;
typedef
struct
SMemTable
SMemTable
;
...
@@ -873,6 +875,25 @@ struct SDelOp {
...
@@ -873,6 +875,25 @@ struct SDelOp {
SDelOp
*
pNext
;
SDelOp
*
pNext
;
};
};
static
FORCE_INLINE
int
tsdbKeyCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
TSDBKEY
*
pKey1
=
(
TSDBKEY
*
)
p1
;
TSDBKEY
*
pKey2
=
(
TSDBKEY
*
)
p2
;
if
(
pKey1
->
ts
<
pKey2
->
ts
)
{
return
-
1
;
}
else
if
(
pKey1
->
ts
>
pKey2
->
ts
)
{
return
1
;
}
if
(
pKey1
->
version
<
pKey2
->
version
)
{
return
-
1
;
}
else
if
(
pKey1
->
version
>
pKey2
->
version
)
{
return
1
;
}
return
0
;
}
#endif
#endif
#ifdef __cplusplus
#ifdef __cplusplus
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable2.c
浏览文件 @
73cbc6f7
...
@@ -16,9 +16,22 @@
...
@@ -16,9 +16,22 @@
#include "tsdb.h"
#include "tsdb.h"
typedef
struct
SMemData
SMemData
;
typedef
struct
SMemData
SMemData
;
// typedef struct SMemSkipList SMemSkipList;
typedef
struct
SMemSkipList
SMemSkipList
;
// typedef struct SMemSkipListNode SMemSkipListNode;
typedef
struct
SMemSkipListNode
SMemSkipListNode
;
// typedef struct SMemSkipListCurosr SMemSkipListCurosr;
struct
SMemSkipListNode
{
int8_t
level
;
SMemSkipListNode
*
forwards
[
0
];
};
struct
SMemSkipList
{
uint32_t
seed
;
int32_t
size
;
int8_t
maxLevel
;
int8_t
level
;
SMemSkipListNode
*
pHead
;
SMemSkipListNode
*
pTail
;
};
struct
SMemData
{
struct
SMemData
{
tb_uid_t
suid
;
tb_uid_t
suid
;
...
@@ -28,6 +41,7 @@ struct SMemData {
...
@@ -28,6 +41,7 @@ struct SMemData {
int64_t
nRows
;
int64_t
nRows
;
SDelOp
*
delOpHead
;
SDelOp
*
delOpHead
;
SDelOp
*
delOpTail
;
SDelOp
*
delOpTail
;
SMemSkipList
sl
;
};
};
struct
SMemTable
{
struct
SMemTable
{
...
@@ -39,8 +53,17 @@ struct SMemTable {
...
@@ -39,8 +53,17 @@ struct SMemTable {
SArray
*
pArray
;
// SArray<SMemData>
SArray
*
pArray
;
// SArray<SMemData>
};
};
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2)
#define SL_NODE_HALF_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level))
static
int32_t
tsdbGetOrCreateMemData
(
SMemTable
*
pMemTable
,
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
);
static
int
memDataPCmprFn
(
const
void
*
p1
,
const
void
*
p2
);
static
int32_t
tPutTSDBRow
(
uint8_t
*
p
,
TSDBROW
*
pRow
);
static
int32_t
tGetTSDBRow
(
uint8_t
*
p
,
TSDBROW
*
pRow
);
static
int8_t
tsdbMemSkipListRandLevel
(
SMemSkipList
*
pSl
);
// SMemTable ==============================================
// SMemTable ==============================================
int32_t
tsdbMemTableCreate2
(
STsdb
*
pTsdb
,
SMemTable
**
ppMemTable
)
{
int32_t
tsdbMemTableCreate2
(
STsdb
*
pTsdb
,
SMemTable
**
ppMemTable
)
{
...
@@ -96,16 +119,41 @@ int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmit
...
@@ -96,16 +119,41 @@ int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmit
}
}
// do insert
// do insert
uint32_t
n
=
0
;
int32_t
nt
;
uint8_t
*
pt
;
int32_t
n
=
0
;
uint8_t
*
p
=
pSubmitBlk
->
pData
;
uint8_t
*
p
=
pSubmitBlk
->
pData
;
SVBufPool
*
pPool
=
pTsdb
->
pVnode
->
inUse
;
int8_t
level
;
SMemSkipListNode
*
pNode
;
while
(
n
<
pSubmitBlk
->
nData
)
{
while
(
n
<
pSubmitBlk
->
nData
)
{
n
+=
tGetTSRow
(
p
+
n
,
&
row
.
tsRow
);
nt
=
tGetTSRow
(
p
+
n
,
&
row
.
tsRow
);
n
+=
nt
;
ASSERT
(
n
<=
pSubmitBlk
->
nData
);
ASSERT
(
n
<=
pSubmitBlk
->
nData
);
// TODO
// build the node
level
=
tsdbMemSkipListRandLevel
(
&
pMemData
->
sl
);
pNode
=
(
SMemSkipListNode
*
)
vnodeBufPoolMalloc
(
pPool
,
SL_NODE_SIZE
(
level
)
+
nt
+
sizeof
(
version
));
if
(
pNode
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
pNode
->
level
=
level
;
tPutTSDBRow
((
uint8_t
*
)
SL_NODE_DATA
(
pNode
),
&
row
);
// put the node (todo)
pMemData
->
nRows
++
;
// set info
if
(
tsdbKeyCmprFn
(
&
row
,
&
pMemData
->
minKey
)
<
0
)
pMemData
->
minKey
=
*
(
TSDBKEY
*
)
&
row
;
if
(
tsdbKeyCmprFn
(
&
row
,
&
pMemData
->
maxKey
)
>
0
)
pMemData
->
maxKey
=
*
(
TSDBKEY
*
)
&
row
;
}
}
if
(
tsdbKeyCmprFn
(
&
pMemTable
->
minKey
,
&
pMemData
->
minKey
)
<
0
)
pMemTable
->
minKey
=
pMemData
->
minKey
;
if
(
tsdbKeyCmprFn
(
&
pMemTable
->
maxKey
,
&
pMemData
->
maxKey
)
>
0
)
pMemTable
->
maxKey
=
pMemData
->
maxKey
;
return
code
;
return
code
;
_err:
_err:
...
@@ -224,22 +272,39 @@ static int memDataPCmprFn(const void *p1, const void *p2) {
...
@@ -224,22 +272,39 @@ static int memDataPCmprFn(const void *p1, const void *p2) {
return
0
;
return
0
;
}
}
#if 0 //====================================================================================
static
int32_t
tPutTSDBRow
(
uint8_t
*
p
,
TSDBROW
*
pRow
)
{
int32_t
n
=
0
;
#define SL_MAX_LEVEL 5
n
+=
tPutI64
(
p
?
p
+
n
:
p
,
pRow
->
version
);
n
+=
tPutTSRow
(
p
?
p
+
n
:
p
,
&
pRow
->
tsRow
);
struct SMemSkipListNode {
return
n
;
int8_t level;
}
SMemSkipListNode *forwards[1]; // Windows does not allow 0
};
struct SMemSkipList {
static
int32_t
tGetTSDBRow
(
uint8_t
*
p
,
TSDBROW
*
pRow
)
{
uint32_t seed;
int32_t
n
=
0
;
int8_t maxLevel;
int8_t level;
n
+=
tGetI64
(
p
+
n
,
&
pRow
->
version
);
int32_t size;
n
+=
tGetTSRow
(
p
+
n
,
&
pRow
->
tsRow
);
SMemSkipListNode pHead[1]; // Windows does not allow 0
};
return
n
;
}
static
FORCE_INLINE
int8_t
tsdbMemSkipListRandLevel
(
SMemSkipList
*
pSl
)
{
int8_t
level
=
1
;
int8_t
tlevel
=
TMIN
(
pSl
->
maxLevel
,
pSl
->
level
+
1
);
const
uint32_t
factor
=
4
;
while
((
taosRandR
(
&
pSl
->
seed
)
%
factor
)
==
0
&&
level
<
tlevel
)
{
level
++
;
}
return
level
;
}
#if 0 //====================================================================================
#define SL_MAX_LEVEL 5
struct SMemSkipListCurosr {
struct SMemSkipListCurosr {
SMemSkipList *pSl;
SMemSkipList *pSl;
...
@@ -254,12 +319,6 @@ typedef struct {
...
@@ -254,12 +319,6 @@ typedef struct {
#define HASH_BUCKET(SUID, UID, NBUCKET) (TABS((SUID) + (UID)) % (NBUCKET))
#define HASH_BUCKET(SUID, UID, NBUCKET) (TABS((SUID) + (UID)) % (NBUCKET))
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2)
#define SL_NODE_HALF_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level))
#define SL_HEAD_NODE(sl) ((sl)->pHead)
#define SL_HEAD_NODE(sl) ((sl)->pHead)
#define SL_TAIL_NODE(sl) ((SMemSkipListNode *)&SL_NODE_FORWARD(SL_HEAD_NODE(sl), (sl)->maxLevel))
#define SL_TAIL_NODE(sl) ((SMemSkipListNode *)&SL_NODE_FORWARD(SL_HEAD_NODE(sl), (sl)->maxLevel))
#define SL_HEAD_NODE_FORWARD(n, l) SL_NODE_FORWARD(n, l)
#define SL_HEAD_NODE_FORWARD(n, l) SL_NODE_FORWARD(n, l)
...
@@ -390,18 +449,6 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
...
@@ -390,18 +449,6 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
return 0;
return 0;
}
}
static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
int8_t level = 1;
int8_t tlevel = TMIN(pSl->maxLevel, pSl->level + 1);
const uint32_t factor = 4;
while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) {
level++;
}
return level;
}
static FORCE_INLINE int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pRow) {
static FORCE_INLINE int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pRow) {
if (tEncodeI64(pEncoder, pRow->version) < 0) return -1;
if (tEncodeI64(pEncoder, pRow->version) < 0) return -1;
if (tEncodeBinary(pEncoder, (const uint8_t *)pRow->pRow, pRow->szRow) < 0) return -1;
if (tEncodeBinary(pEncoder, (const uint8_t *)pRow->pRow, pRow->szRow) < 0) return -1;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录