Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2f475399
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看板
提交
2f475399
编写于
9月 21, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: added memory allocators for parser and planner
上级
46b0c2c9
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
81 addition
and
13 deletion
+81
-13
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+7
-1
include/libs/scheduler/scheduler.h
include/libs/scheduler/scheduler.h
+1
-0
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+2
-1
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+2
-1
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+3
-1
source/client/src/clientMain.c
source/client/src/clientMain.c
+6
-6
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+56
-2
source/libs/scheduler/inc/schInt.h
source/libs/scheduler/inc/schInt.h
+2
-1
source/libs/scheduler/src/schJob.c
source/libs/scheduler/src/schJob.c
+2
-0
未找到文件。
include/libs/nodes/nodes.h
浏览文件 @
2f475399
...
...
@@ -278,9 +278,15 @@ typedef struct SNodeList {
typedef
struct
SNodeAllocator
SNodeAllocator
;
int32_t
nodesCreateNodeAllocator
(
int32_t
chunkSize
,
SNodeAllocator
**
pAllocator
);
void
nodesDestroyNodeAllocator
(
SNodeAllocator
*
pAllocator
);
void
nodesDestroyNodeAllocator
(
void
*
pAllocator
);
void
nodesResetThreadLevelAllocator
(
SNodeAllocator
*
pAllocator
);
int32_t
nodesAllocatorInit
();
int32_t
nodesCreateAllocator
(
int32_t
chunkSize
,
int64_t
*
pRefId
);
void
nodesDestroyAllocator
(
int64_t
refId
);
void
nodesResetAllocator
(
int64_t
refId
);
int64_t
nodesIncAllocatorRefCount
(
int64_t
refId
);
SNode
*
nodesMakeNode
(
ENodeType
type
);
void
nodesDestroyNode
(
SNode
*
pNode
);
...
...
include/libs/scheduler/scheduler.h
浏览文件 @
2f475399
...
...
@@ -67,6 +67,7 @@ typedef struct SSchedulerReq {
SRequestConnInfo
*
pConn
;
SArray
*
pNodeList
;
SQueryPlan
*
pDag
;
int64_t
allocatorRefId
;
const
char
*
sql
;
int64_t
startTs
;
schedulerExecFp
execFp
;
...
...
source/client/inc/clientInt.h
浏览文件 @
2f475399
...
...
@@ -250,7 +250,8 @@ typedef struct SRequestObj {
bool
inRetry
;
uint32_t
prevCode
;
// previous error code: todo refactor, add update flag for catalog
uint32_t
retry
;
SNodeAllocator
*
pNodeAllocator
;
// SNodeAllocator* pNodeAllocator;
int64_t
allocatorRefId
;
}
SRequestObj
;
typedef
struct
SSyncQueryParam
{
...
...
source/client/src/clientEnv.c
浏览文件 @
2f475399
...
...
@@ -349,7 +349,7 @@ void doDestroyRequest(void *p) {
taosArrayDestroy
(
pRequest
->
tableList
);
taosArrayDestroy
(
pRequest
->
dbList
);
taosArrayDestroy
(
pRequest
->
targetTableList
);
nodesDestroy
NodeAllocator
(
pRequest
->
pNodeAllocator
);
nodesDestroy
Allocator
(
pRequest
->
allocatorRefId
);
destroyQueryExecRes
(
&
pRequest
->
body
.
resInfo
.
execRes
);
...
...
@@ -412,6 +412,7 @@ void taos_init_imp(void) {
initTaskQueue
();
fmFuncMgtInit
();
nodesAllocatorInit
();
clientConnRefPool
=
taosOpenRef
(
200
,
destroyTscObj
);
clientReqRefPool
=
taosOpenRef
(
40960
,
doDestroyRequest
);
...
...
source/client/src/clientImpl.c
浏览文件 @
2f475399
...
...
@@ -194,8 +194,9 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
(
*
pRequest
)
->
allocatorRefId
=
-
1
;
if
(
tsQueryUseNodeAllocator
&&
!
qIsInsertValuesSql
((
*
pRequest
)
->
sqlstr
,
(
*
pRequest
)
->
sqlLen
))
{
if
(
TSDB_CODE_SUCCESS
!=
nodesCreate
NodeAllocator
(
tsQueryNodeChunkSize
,
&
((
*
pRequest
)
->
pNodeAllocator
)))
{
if
(
TSDB_CODE_SUCCESS
!=
nodesCreate
Allocator
(
tsQueryNodeChunkSize
,
&
((
*
pRequest
)
->
allocatorRefId
)))
{
tscError
(
"%d failed to create node allocator, reqId:0x%"
PRIx64
", conn:%d, %s"
,
(
*
pRequest
)
->
self
,
(
*
pRequest
)
->
requestId
,
pTscObj
->
id
,
sql
);
...
...
@@ -1058,6 +1059,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
.
pConn
=
&
conn
,
.
pNodeList
=
pNodeList
,
.
pDag
=
pDag
,
.
allocatorRefId
=
pRequest
->
allocatorRefId
,
.
sql
=
pRequest
->
sqlstr
,
.
startTs
=
pRequest
->
metric
.
start
,
.
execFp
=
schedulerExecCb
,
...
...
source/client/src/clientMain.c
浏览文件 @
2f475399
...
...
@@ -700,7 +700,7 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
pRequest
->
metric
.
ctgEnd
=
taosGetTimestampUs
();
nodesReset
ThreadLevelAllocator
(
pRequest
->
pNodeAllocator
);
nodesReset
Allocator
(
pRequest
->
allocatorRefId
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
code
=
qAnalyseSqlSemantic
(
pWrapper
->
pCtx
,
&
pWrapper
->
catalogReq
,
pResultMeta
,
pQuery
);
...
...
@@ -728,11 +728,11 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
pRequest
->
requestId
);
launchAsyncQuery
(
pRequest
,
pQuery
,
pResultMeta
);
qDestroyQuery
(
pQuery
);
nodesReset
ThreadLevelAllocator
(
NULL
);
nodesReset
Allocator
(
-
1
);
}
else
{
destorySqlParseWrapper
(
pWrapper
);
qDestroyQuery
(
pQuery
);
nodesReset
ThreadLevelAllocator
(
NULL
);
nodesReset
Allocator
(
-
1
);
if
(
NEED_CLIENT_HANDLE_ERROR
(
code
))
{
tscDebug
(
"0x%"
PRIx64
" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"
PRIx64
,
pRequest
->
self
,
code
,
tstrerror
(
code
),
pRequest
->
retry
,
pRequest
->
requestId
);
...
...
@@ -805,7 +805,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
}
SQuery
*
pQuery
=
NULL
;
nodesReset
ThreadLevelAllocator
(
pRequest
->
pNodeAllocator
);
nodesReset
Allocator
(
pRequest
->
allocatorRefId
);
pRequest
->
metric
.
syntaxStart
=
taosGetTimestampUs
();
...
...
@@ -849,7 +849,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
&
pRequest
->
body
.
queryJob
);
pCxt
=
NULL
;
if
(
code
==
TSDB_CODE_SUCCESS
)
{
nodesReset
ThreadLevelAllocator
(
NULL
);
nodesReset
Allocator
(
-
1
);
return
;
}
...
...
@@ -857,7 +857,7 @@ _error:
tscError
(
"0x%"
PRIx64
" error happens, code:%d - %s, reqId:0x%"
PRIx64
,
pRequest
->
self
,
code
,
tstrerror
(
code
),
pRequest
->
requestId
);
taosMemoryFree
(
pCxt
);
nodesReset
ThreadLevelAllocator
(
NULL
);
nodesReset
Allocator
(
-
1
);
terrno
=
code
;
pRequest
->
code
=
code
;
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
2f475399
...
...
@@ -21,6 +21,7 @@
#include "taoserror.h"
#include "tdatablock.h"
#include "thash.h"
#include "tref.h"
typedef
struct
SNodeMemChunk
{
int32_t
availableSize
;
...
...
@@ -30,6 +31,7 @@ typedef struct SNodeMemChunk {
}
SNodeMemChunk
;
typedef
struct
SNodeAllocator
{
int64_t
self
;
int32_t
chunkSize
;
int32_t
chunkNum
;
SNodeMemChunk
*
pCurrChunk
;
...
...
@@ -37,6 +39,22 @@ typedef struct SNodeAllocator {
}
SNodeAllocator
;
static
threadlocal
SNodeAllocator
*
pNodeAllocator
;
static
int32_t
allocatorReqRefPool
=
-
1
;
int32_t
nodesAllocatorInit
()
{
if
(
allocatorReqRefPool
>=
0
)
{
nodesWarn
(
"nodes already initialized"
);
return
TSDB_CODE_SUCCESS
;
}
allocatorReqRefPool
=
taosOpenRef
(
40960
,
nodesDestroyNodeAllocator
);
if
(
allocatorReqRefPool
<
0
)
{
nodesError
(
"init nodes failed"
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
TSDB_CODE_SUCCESS
;
}
static
SNodeMemChunk
*
callocNodeChunk
(
SNodeAllocator
*
pAllocator
)
{
SNodeMemChunk
*
pNewChunk
=
taosMemoryCalloc
(
1
,
sizeof
(
SNodeMemChunk
)
+
pAllocator
->
chunkSize
);
...
...
@@ -103,11 +121,13 @@ int32_t nodesCreateNodeAllocator(int32_t chunkSize, SNodeAllocator** pAllocator)
return
TSDB_CODE_SUCCESS
;
}
void
nodesDestroyNodeAllocator
(
SNodeAllocator
*
pAllocator
)
{
if
(
NULL
==
p
Allocator
)
{
void
nodesDestroyNodeAllocator
(
void
*
p
)
{
if
(
NULL
==
p
)
{
return
;
}
SNodeAllocator
*
pAllocator
=
p
;
nodesDebug
(
"alloc chunkNum: %d, chunkTotakSize: %d"
,
pAllocator
->
chunkNum
,
pAllocator
->
chunkNum
*
pAllocator
->
chunkSize
);
...
...
@@ -122,6 +142,40 @@ void nodesDestroyNodeAllocator(SNodeAllocator* pAllocator) {
void
nodesResetThreadLevelAllocator
(
SNodeAllocator
*
pAllocator
)
{
pNodeAllocator
=
pAllocator
;
}
int32_t
nodesCreateAllocator
(
int32_t
chunkSize
,
int64_t
*
pRefId
)
{
SNodeAllocator
*
pAllocator
=
NULL
;
int32_t
code
=
nodesCreateNodeAllocator
(
chunkSize
,
&
pAllocator
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pAllocator
->
self
=
taosAddRef
(
allocatorReqRefPool
,
pAllocator
);
*
pRefId
=
pAllocator
->
self
;
}
return
code
;
}
void
nodesDestroyAllocator
(
int64_t
refId
)
{
if
(
refId
<
0
)
{
return
;
}
taosReleaseRef
(
allocatorReqRefPool
,
refId
);
}
void
nodesResetAllocator
(
int64_t
refId
)
{
if
(
refId
<
0
)
{
pNodeAllocator
=
NULL
;
}
else
{
pNodeAllocator
=
taosAcquireRef
(
allocatorReqRefPool
,
refId
);
taosReleaseRef
(
allocatorReqRefPool
,
refId
);
}
}
int64_t
nodesIncAllocatorRefCount
(
int64_t
refId
)
{
if
(
refId
<
0
)
{
return
-
1
;
}
SNodeAllocator
*
pAllocator
=
taosAcquireRef
(
allocatorReqRefPool
,
refId
);
return
pAllocator
->
self
;
}
static
SNode
*
makeNode
(
ENodeType
type
,
int32_t
size
)
{
SNode
*
p
=
nodesCalloc
(
1
,
size
);
if
(
NULL
==
p
)
{
...
...
source/libs/scheduler/inc/schInt.h
浏览文件 @
2f475399
...
...
@@ -254,7 +254,8 @@ typedef struct SSchJob {
SRequestConnInfo
conn
;
SArray
*
nodeList
;
// qnode/vnode list, SArray<SQueryNodeLoad>
SArray
*
levels
;
// starting from 0. SArray<SSchLevel>
SQueryPlan
*
pDag
;
SQueryPlan
*
pDag
;
int64_t
allocatorRefId
;
SArray
*
dataSrcTasks
;
// SArray<SQueryTask*>
int32_t
levelIdx
;
...
...
source/libs/scheduler/src/schJob.c
浏览文件 @
2f475399
...
...
@@ -673,6 +673,7 @@ void schFreeJobImpl(void *job) {
destroyQueryExecRes
(
&
pJob
->
execRes
);
qDestroyQueryPlan
(
pJob
->
pDag
);
nodesDestroyAllocator
(
pJob
->
allocatorRefId
);
taosMemoryFreeClear
(
pJob
->
userRes
.
execRes
);
taosMemoryFreeClear
(
pJob
->
fetchRes
);
...
...
@@ -724,6 +725,7 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) {
pJob
->
sql
=
strdup
(
pReq
->
sql
);
}
pJob
->
pDag
=
pReq
->
pDag
;
pJob
->
allocatorRefId
=
nodesIncAllocatorRefCount
(
pReq
->
allocatorRefId
);
pJob
->
chkKillFp
=
pReq
->
chkKillFp
;
pJob
->
chkKillParam
=
pReq
->
chkKillParam
;
pJob
->
userRes
.
execFp
=
pReq
->
execFp
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录