Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1567fe2f
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看板
提交
1567fe2f
编写于
1月 03, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: skiplist concurrent access
上级
56601990
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
51 deletion
+50
-51
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+2
-2
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+48
-49
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
1567fe2f
...
...
@@ -772,8 +772,8 @@ static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
return
0
;
}
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
//
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
//
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
static
FORCE_INLINE
TSDBROW
*
tsdbTbDataIterGet
(
STbDataIter
*
pIter
)
{
if
(
pIter
==
NULL
)
return
NULL
;
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
1567fe2f
...
...
@@ -19,9 +19,13 @@
#define SL_MAX_LEVEL 5
// sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l) * 2
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + ((l) << 4))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + ((l) << 4))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
#define SL_GET_NODE_FORWARD(n, l) ((SMemSkipListNode *)atomic_load_64((int64_t *)&SL_NODE_FORWARD(n, l)))
#define SL_GET_NODE_BACKWARD(n, l) ((SMemSkipListNode *)atomic_load_64((int64_t *)&SL_NODE_BACKWARD(n, l)))
#define SL_SET_NODE_FORWARD(n, l, p) atomic_store_64((int64_t *)&SL_NODE_FORWARD(n, l), (int64_t)(p))
#define SL_SET_NODE_BACKWARD(n, l, p) atomic_store_64((int64_t *)&SL_NODE_BACKWARD(n, l), (int64_t)(p))
#define SL_MOVE_BACKWARD 0x1
#define SL_MOVE_FROM_POS 0x2
...
...
@@ -246,18 +250,18 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDa
if
(
pFrom
==
NULL
)
{
// create from head or tail
if
(
backward
)
{
pIter
->
pNode
=
SL_NODE_BACKWARD
(
pTbData
->
sl
.
pTail
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_BACKWARD
(
pTbData
->
sl
.
pTail
,
0
);
}
else
{
pIter
->
pNode
=
SL_NODE_FORWARD
(
pTbData
->
sl
.
pHead
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_FORWARD
(
pTbData
->
sl
.
pHead
,
0
);
}
}
else
{
// create from a key
if
(
backward
)
{
tbDataMovePosTo
(
pTbData
,
pos
,
pFrom
,
SL_MOVE_BACKWARD
);
pIter
->
pNode
=
SL_NODE_BACKWARD
(
pos
[
0
],
0
);
pIter
->
pNode
=
SL_
GET_
NODE_BACKWARD
(
pos
[
0
],
0
);
}
else
{
tbDataMovePosTo
(
pTbData
,
pos
,
pFrom
,
0
);
pIter
->
pNode
=
SL_NODE_FORWARD
(
pos
[
0
],
0
);
pIter
->
pNode
=
SL_
GET_
NODE_FORWARD
(
pos
[
0
],
0
);
}
}
}
...
...
@@ -271,7 +275,7 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) {
return
false
;
}
pIter
->
pNode
=
SL_NODE_BACKWARD
(
pIter
->
pNode
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_BACKWARD
(
pIter
->
pNode
,
0
);
if
(
pIter
->
pNode
==
pIter
->
pTbData
->
sl
.
pHead
)
{
return
false
;
}
...
...
@@ -282,7 +286,7 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) {
return
false
;
}
pIter
->
pNode
=
SL_NODE_FORWARD
(
pIter
->
pNode
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_FORWARD
(
pIter
->
pNode
,
0
);
if
(
pIter
->
pNode
==
pIter
->
pTbData
->
sl
.
pTail
)
{
return
false
;
}
...
...
@@ -335,7 +339,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid
int8_t
maxLevel
=
pMemTable
->
pTsdb
->
pVnode
->
config
.
tsdbCfg
.
slLevel
;
ASSERT
(
pPool
!=
NULL
);
pTbData
=
vnodeBufPoolMalloc
(
pPool
,
sizeof
(
*
pTbData
)
+
SL_NODE_SIZE
(
maxLevel
)
*
2
);
pTbData
=
vnodeBufPoolMalloc
Aligned
(
pPool
,
sizeof
(
*
pTbData
)
+
SL_NODE_SIZE
(
maxLevel
)
*
2
);
if
(
pTbData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
...
...
@@ -408,7 +412,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
if
(
fromPos
)
px
=
pos
[
pTbData
->
sl
.
level
-
1
];
for
(
int8_t
iLevel
=
pTbData
->
sl
.
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
pn
=
SL_NODE_BACKWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_BACKWARD
(
px
,
iLevel
);
while
(
pn
!=
pTbData
->
sl
.
pHead
)
{
tKey
.
version
=
pn
->
version
;
tKey
.
ts
=
pn
->
pTSRow
->
ts
;
...
...
@@ -418,7 +422,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
break
;
}
else
{
px
=
pn
;
pn
=
SL_NODE_BACKWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_BACKWARD
(
px
,
iLevel
);
}
}
...
...
@@ -438,7 +442,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
if
(
fromPos
)
px
=
pos
[
pTbData
->
sl
.
level
-
1
];
for
(
int8_t
iLevel
=
pTbData
->
sl
.
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
pn
=
SL_NODE_FORWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_FORWARD
(
px
,
iLevel
);
while
(
pn
!=
pTbData
->
sl
.
pTail
)
{
tKey
.
version
=
pn
->
version
;
tKey
.
ts
=
pn
->
pTSRow
->
ts
;
...
...
@@ -448,7 +452,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
break
;
}
else
{
px
=
pn
;
pn
=
SL_NODE_FORWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_FORWARD
(
px
,
iLevel
);
}
}
...
...
@@ -474,58 +478,53 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN
int8_t
level
;
SMemSkipListNode
*
pNode
;
SVBufPool
*
pPool
=
pMemTable
->
pTsdb
->
pVnode
->
inUse
;
int64_t
nSize
;
// node
//
create
node
level
=
tsdbMemSkipListRandLevel
(
&
pTbData
->
sl
);
ASSERT
(
pPool
!=
NULL
);
pNode
=
(
SMemSkipListNode
*
)
vnodeBufPoolMalloc
(
pPool
,
SL_NODE_SIZE
(
level
)
);
nSize
=
SL_NODE_SIZE
(
level
);
pNode
=
(
SMemSkipListNode
*
)
vnodeBufPoolMalloc
Aligned
(
pPool
,
nSize
+
pRow
->
len
);
if
(
pNode
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pNode
->
level
=
level
;
pNode
->
version
=
version
;
pNode
->
pTSRow
=
vnodeBufPoolMalloc
(
pPool
,
pRow
->
len
);
if
(
NULL
==
pNode
->
pTSRow
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pNode
->
pTSRow
=
(
STSRow
*
)((
char
*
)
pNode
+
nSize
);
memcpy
(
pNode
->
pTSRow
,
pRow
,
pRow
->
len
);
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pn
=
pos
[
iLevel
];
SMemSkipListNode
*
px
;
if
(
forward
)
{
px
=
SL_NODE_FORWARD
(
pn
,
iLevel
);
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
pn
;
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
px
;
}
else
{
px
=
SL_NODE_BACKWARD
(
pn
,
iLevel
);
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
px
;
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
pn
;
// set node
if
(
forward
)
{
for
(
int8_t
iLevel
=
0
;
iLevel
<
level
;
iLevel
++
)
{
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
SL_NODE_FORWARD
(
pos
[
iLevel
],
iLevel
);
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
pos
[
iLevel
];
}
}
else
{
for
(
int8_t
iLevel
=
0
;
iLevel
<
level
;
iLevel
++
)
{
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
pos
[
iLevel
];
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
SL_NODE_BACKWARD
(
pos
[
iLevel
],
iLevel
);
}
}
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pn
=
pos
[
iLevel
];
SMemSkipListNode
*
px
;
// set forward and backward
if
(
forward
)
{
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pNext
=
pos
[
iLevel
]
->
forwards
[
iLevel
];
if
(
forward
)
{
px
=
SL_NODE_FORWARD
(
pn
,
iLevel
);
SL_NODE_FORWARD
(
pn
,
iLevel
)
=
pNode
;
SL_NODE_BACKWARD
(
px
,
iLevel
)
=
pNode
;
}
else
{
px
=
SL_NODE_BACKWARD
(
pn
,
iLevel
);
SL_SET_NODE_FORWARD
(
pos
[
iLevel
],
iLevel
,
pNode
);
SL_SET_NODE_BACKWARD
(
pNext
,
iLevel
,
pNode
);
SL_NODE_FORWARD
(
px
,
iLevel
)
=
pNode
;
SL_NODE_BACKWARD
(
pn
,
iLevel
)
=
pNode
;
pos
[
iLevel
]
=
pNode
;
}
}
else
{
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pPrev
=
pos
[
iLevel
]
->
forwards
[
pos
[
iLevel
]
->
level
+
iLevel
];
SL_SET_NODE_FORWARD
(
pPrev
,
iLevel
,
pNode
);
SL_SET_NODE_BACKWARD
(
pos
[
iLevel
],
iLevel
,
pNode
);
pos
[
iLevel
]
=
pNode
;
pos
[
iLevel
]
=
pNode
;
}
}
pTbData
->
sl
.
size
++
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录