Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Tonvia
TDengine
提交
f0a8c81f
T
TDengine
项目概览
Tonvia
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f0a8c81f
编写于
3月 18, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
3月 18, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5484 from taosdata/hotfix/TD-3353
[TD-3353]<hotfix>: solve race condition coredump
上级
ccf61636
e4e46768
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
82 deletion
+81
-82
src/inc/tsdb.h
src/inc/tsdb.h
+27
-3
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-1
src/tsdb/inc/tsdbMemTable.h
src/tsdb/inc/tsdbMemTable.h
+4
-19
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+41
-49
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+8
-10
未找到文件。
src/inc/tsdb.h
浏览文件 @
f0a8c81f
...
...
@@ -25,6 +25,8 @@
#include "tdataformat.h"
#include "tname.h"
#include "hash.h"
#include "tlockfree.h"
#include "tlist.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -172,10 +174,32 @@ typedef struct STsdbQueryCond {
int32_t
type
;
// data block load type:
}
STsdbQueryCond
;
typedef
struct
STableData
STableData
;
typedef
struct
{
T_REF_DECLARE
()
SRWLatch
latch
;
TSKEY
keyFirst
;
TSKEY
keyLast
;
int64_t
numOfRows
;
int32_t
maxTables
;
STableData
**
tData
;
SList
*
actList
;
SList
*
extraBuffList
;
SList
*
bufBlockList
;
int64_t
pointsAdd
;
// TODO
int64_t
storageAdd
;
// TODO
}
SMemTable
;
typedef
struct
{
SMemTable
*
mem
;
SMemTable
*
imem
;
SMemTable
mtable
;
SMemTable
*
omem
;
}
SMemSnapshot
;
typedef
struct
SMemRef
{
int32_t
ref
;
void
*
mem
;
void
*
imem
;
int32_t
ref
;
SMemSnapshot
snapshot
;
}
SMemRef
;
typedef
struct
SDataBlockInfo
{
...
...
src/query/src/qExecutor.c
浏览文件 @
f0a8c81f
...
...
@@ -1840,7 +1840,7 @@ static void doFreeQueryHandle(SQueryRuntimeEnv* pRuntimeEnv) {
pRuntimeEnv
->
pQueryHandle
=
NULL
;
SMemRef
*
pMemRef
=
&
pQuery
->
memRef
;
assert
(
pMemRef
->
ref
==
0
&&
pMemRef
->
imem
==
NULL
&&
pMemRef
->
mem
==
NULL
);
assert
(
pMemRef
->
ref
==
0
&&
pMemRef
->
snapshot
.
imem
==
NULL
&&
pMemRef
->
snapshot
.
mem
==
NULL
);
}
static
void
teardownQueryRuntimeEnv
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
...
...
src/tsdb/inc/tsdbMemTable.h
浏览文件 @
f0a8c81f
...
...
@@ -31,29 +31,14 @@ typedef struct {
SSkipListIterator
*
pIter
;
}
SCommitIter
;
typedef
struct
{
struct
STableData
{
uint64_t
uid
;
TSKEY
keyFirst
;
TSKEY
keyLast
;
int64_t
numOfRows
;
SSkipList
*
pData
;
T_REF_DECLARE
()
}
STableData
;
typedef
struct
{
T_REF_DECLARE
()
SRWLatch
latch
;
TSKEY
keyFirst
;
TSKEY
keyLast
;
int64_t
numOfRows
;
int32_t
maxTables
;
STableData
**
tData
;
SList
*
actList
;
SList
*
extraBuffList
;
SList
*
bufBlockList
;
int64_t
pointsAdd
;
// TODO
int64_t
storageAdd
;
// TODO
}
SMemTable
;
};
enum
{
TSDB_UPDATE_META
,
TSDB_DROP_META
};
...
...
@@ -77,8 +62,8 @@ typedef struct {
int
tsdbRefMemTable
(
STsdbRepo
*
pRepo
,
SMemTable
*
pMemTable
);
int
tsdbUnRefMemTable
(
STsdbRepo
*
pRepo
,
SMemTable
*
pMemTable
);
int
tsdbTakeMemSnapshot
(
STsdbRepo
*
pRepo
,
SMem
Table
**
pMem
,
SMemTable
**
pIMem
,
SArray
*
pATable
);
void
tsdbUnTakeMemSnapShot
(
STsdbRepo
*
pRepo
,
SMem
Table
*
pMem
,
SMemTable
*
pIMem
);
int
tsdbTakeMemSnapshot
(
STsdbRepo
*
pRepo
,
SMem
Snapshot
*
pSnapshot
,
SArray
*
pATable
);
void
tsdbUnTakeMemSnapShot
(
STsdbRepo
*
pRepo
,
SMem
Snapshot
*
pSnapshot
);
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
);
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
);
int
tsdbLoadDataFromCache
(
STable
*
pTable
,
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
SDataCols
*
pCols
,
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
f0a8c81f
...
...
@@ -124,88 +124,80 @@ int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
return
0
;
}
int
tsdbTakeMemSnapshot
(
STsdbRepo
*
pRepo
,
SMem
Table
**
pMem
,
SMemTable
**
pIMem
,
SArray
*
pATable
)
{
SMemTable
*
tmem
;
int
tsdbTakeMemSnapshot
(
STsdbRepo
*
pRepo
,
SMem
Snapshot
*
pSnapshot
,
SArray
*
pATable
)
{
memset
(
pSnapshot
,
0
,
sizeof
(
*
pSnapshot
))
;
// Get snap object
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
-
1
;
t
mem
=
pRepo
->
mem
;
*
pIM
em
=
pRepo
->
imem
;
tsdbRefMemTable
(
pRepo
,
t
mem
);
tsdbRefMemTable
(
pRepo
,
*
pIM
em
);
pSnapshot
->
o
mem
=
pRepo
->
mem
;
pSnapshot
->
im
em
=
pRepo
->
imem
;
tsdbRefMemTable
(
pRepo
,
pRepo
->
mem
);
tsdbRefMemTable
(
pRepo
,
pRepo
->
im
em
);
if
(
tsdbUnlockRepo
(
pRepo
)
<
0
)
return
-
1
;
// Copy mem objects and ref needed STableData
if
(
tmem
)
{
taosRLockLatch
(
&
(
tmem
->
latch
));
if
(
pSnapshot
->
omem
)
{
taosRLockLatch
(
&
(
pSnapshot
->
omem
->
latch
));
*
pMem
=
(
SMemTable
*
)
calloc
(
1
,
sizeof
(
**
pMem
));
if
(
*
pMem
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
taosRUnLockLatch
(
&
(
tmem
->
latch
));
tsdbUnRefMemTable
(
pRepo
,
tmem
);
tsdbUnRefMemTable
(
pRepo
,
*
pIMem
);
*
pMem
=
NULL
;
*
pIMem
=
NULL
;
return
-
1
;
}
pSnapshot
->
mem
=
&
(
pSnapshot
->
mtable
);
(
*
pMem
)
->
tData
=
(
STableData
**
)
calloc
(
t
mem
->
maxTables
,
sizeof
(
STableData
*
));
if
(
(
*
pMem
)
->
tData
==
NULL
)
{
pSnapshot
->
mem
->
tData
=
(
STableData
**
)
calloc
(
pSnapshot
->
o
mem
->
maxTables
,
sizeof
(
STableData
*
));
if
(
pSnapshot
->
mem
->
tData
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
taosRUnLockLatch
(
&
(
t
mem
->
latch
));
free
(
*
pM
em
);
tsdbUnRefMemTable
(
pRepo
,
t
mem
);
tsdbUnRefMemTable
(
pRepo
,
*
pIMem
)
;
*
pM
em
=
NULL
;
*
pIM
em
=
NULL
;
taosRUnLockLatch
(
&
(
pSnapshot
->
o
mem
->
latch
));
tsdbUnRefMemTable
(
pRepo
,
pSnapshot
->
om
em
);
tsdbUnRefMemTable
(
pRepo
,
pSnapshot
->
i
mem
);
pSnapshot
->
mem
=
NULL
;
pSnapshot
->
im
em
=
NULL
;
pSnapshot
->
om
em
=
NULL
;
return
-
1
;
}
(
*
pMem
)
->
keyFirst
=
t
mem
->
keyFirst
;
(
*
pMem
)
->
keyLast
=
t
mem
->
keyLast
;
(
*
pMem
)
->
numOfRows
=
t
mem
->
numOfRows
;
(
*
pMem
)
->
maxTables
=
t
mem
->
maxTables
;
pSnapshot
->
mem
->
keyFirst
=
pSnapshot
->
o
mem
->
keyFirst
;
pSnapshot
->
mem
->
keyLast
=
pSnapshot
->
o
mem
->
keyLast
;
pSnapshot
->
mem
->
numOfRows
=
pSnapshot
->
o
mem
->
numOfRows
;
pSnapshot
->
mem
->
maxTables
=
pSnapshot
->
o
mem
->
maxTables
;
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
pATable
);
i
++
)
{
STable
*
pTable
=
*
(
STable
**
)
taosArrayGet
(
pATable
,
i
);
int32_t
tid
=
TABLE_TID
(
pTable
);
STableData
*
pTableData
=
(
tid
<
tmem
->
maxTables
)
?
t
mem
->
tData
[
tid
]
:
NULL
;
STableData
*
pTableData
=
(
tid
<
pSnapshot
->
omem
->
maxTables
)
?
pSnapshot
->
o
mem
->
tData
[
tid
]
:
NULL
;
if
((
pTableData
==
NULL
)
||
(
TABLE_UID
(
pTable
)
!=
pTableData
->
uid
))
continue
;
(
*
pMem
)
->
tData
[
tid
]
=
tmem
->
tData
[
tid
]
;
T_REF_INC
(
tmem
->
tData
[
tid
]
);
pSnapshot
->
mem
->
tData
[
tid
]
=
pTableData
;
T_REF_INC
(
pTableData
);
}
taosRUnLockLatch
(
&
(
t
mem
->
latch
));
taosRUnLockLatch
(
&
(
pSnapshot
->
o
mem
->
latch
));
}
tsdbUnRefMemTable
(
pRepo
,
tmem
);
tsdbDebug
(
"vgId:%d take memory snapshot, pMem %p pIMem %p"
,
REPO_ID
(
pRepo
),
*
pMem
,
*
pIMem
);
tsdbDebug
(
"vgId:%d take memory snapshot, pMem %p pIMem %p"
,
REPO_ID
(
pRepo
),
pSnapshot
->
omem
,
pSnapshot
->
imem
);
return
0
;
}
void
tsdbUnTakeMemSnapShot
(
STsdbRepo
*
pRepo
,
SMem
Table
*
pMem
,
SMemTable
*
pIMem
)
{
tsdbDebug
(
"vgId:%d untake memory snapshot, pMem %p pIMem %p"
,
REPO_ID
(
pRepo
),
p
Mem
,
pIM
em
);
void
tsdbUnTakeMemSnapShot
(
STsdbRepo
*
pRepo
,
SMem
Snapshot
*
pSnapshot
)
{
tsdbDebug
(
"vgId:%d untake memory snapshot, pMem %p pIMem %p"
,
REPO_ID
(
pRepo
),
p
Snapshot
->
omem
,
pSnapshot
->
im
em
);
if
(
pMem
!=
NULL
)
{
for
(
size_t
i
=
0
;
i
<
pMem
->
maxTables
;
i
++
)
{
STableData
*
pTableData
=
pMem
->
tData
[
i
];
if
(
pSnapshot
->
mem
)
{
ASSERT
(
pSnapshot
->
omem
!=
NULL
);
for
(
size_t
i
=
0
;
i
<
pSnapshot
->
mem
->
maxTables
;
i
++
)
{
STableData
*
pTableData
=
pSnapshot
->
mem
->
tData
[
i
];
if
(
pTableData
)
{
tsdbFreeTableData
(
pTableData
);
}
}
free
(
pMem
->
tData
);
free
(
pMem
);
}
tfree
(
pSnapshot
->
mem
->
tData
);
if
(
pIMem
!=
NULL
)
{
tsdbUnRefMemTable
(
pRepo
,
pIMem
);
tsdbUnRefMemTable
(
pRepo
,
pSnapshot
->
omem
);
}
tsdbUnRefMemTable
(
pRepo
,
pSnapshot
->
imem
);
pSnapshot
->
mem
=
NULL
;
pSnapshot
->
imem
=
NULL
;
pSnapshot
->
omem
=
NULL
;
}
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
)
{
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
f0a8c81f
...
...
@@ -194,7 +194,7 @@ static void tsdbMayTakeMemSnapshot(STsdbQueryHandle* pQueryHandle, SArray* psTab
SMemRef
*
pMemRef
=
pQueryHandle
->
pMemRef
;
if
(
pQueryHandle
->
pMemRef
->
ref
++
==
0
)
{
tsdbTakeMemSnapshot
(
pQueryHandle
->
pTsdb
,
(
SMemTable
**
)
&
(
pMemRef
->
mem
),
(
SMemTable
**
)
&
(
pMemRef
->
imem
),
psTable
);
tsdbTakeMemSnapshot
(
pQueryHandle
->
pTsdb
,
&
(
pMemRef
->
snapshot
),
psTable
);
}
taosArrayDestroy
(
psTable
);
...
...
@@ -208,9 +208,7 @@ static void tsdbMayUnTakeMemSnapshot(STsdbQueryHandle* pQueryHandle) {
}
if
(
--
pMemRef
->
ref
==
0
)
{
tsdbUnTakeMemSnapShot
(
pQueryHandle
->
pTsdb
,
pMemRef
->
mem
,
pMemRef
->
imem
);
pMemRef
->
mem
=
NULL
;
pMemRef
->
imem
=
NULL
;
tsdbUnTakeMemSnapShot
(
pQueryHandle
->
pTsdb
,
&
(
pMemRef
->
snapshot
));
}
pQueryHandle
->
pMemRef
=
NULL
;
...
...
@@ -229,10 +227,10 @@ int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle) {
if
(
pMemRef
==
NULL
)
{
return
rows
;
}
STableData
*
pMem
=
NULL
;
STableData
*
pIMem
=
NULL
;
STableData
*
pIMem
=
NULL
;
SMemTable
*
pMemT
=
(
SMemTable
*
)(
pMemRef
->
mem
);
SMemTable
*
pIMemT
=
(
SMemTable
*
)(
pMemRef
->
imem
)
;
SMemTable
*
pMemT
=
pMemRef
->
snapshot
.
mem
;
SMemTable
*
pIMemT
=
pMemRef
->
snapshot
.
imem
;
if
(
pMemT
&&
pCheckInfo
->
tableId
.
tid
<
pMemT
->
maxTables
)
{
pMem
=
pMemT
->
tData
[
pCheckInfo
->
tableId
.
tid
];
...
...
@@ -605,7 +603,7 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
int32_t
order
=
pHandle
->
order
;
// no data in buffer, abort
if
(
pHandle
->
pMemRef
->
mem
==
NULL
&&
pHandle
->
pMemRef
->
imem
==
NULL
)
{
if
(
pHandle
->
pMemRef
->
snapshot
.
mem
==
NULL
&&
pHandle
->
pMemRef
->
snapshot
.
imem
==
NULL
)
{
return
false
;
}
...
...
@@ -614,8 +612,8 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
STableData
*
pMem
=
NULL
;
STableData
*
pIMem
=
NULL
;
SMemTable
*
pMemT
=
pHandle
->
pMemRef
->
mem
;
SMemTable
*
pIMemT
=
pHandle
->
pMemRef
->
imem
;
SMemTable
*
pMemT
=
pHandle
->
pMemRef
->
snapshot
.
mem
;
SMemTable
*
pIMemT
=
pHandle
->
pMemRef
->
snapshot
.
imem
;
if
(
pMemT
&&
pCheckInfo
->
tableId
.
tid
<
pMemT
->
maxTables
)
{
pMem
=
pMemT
->
tData
[
pCheckInfo
->
tableId
.
tid
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录