Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c9aa59cb
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c9aa59cb
编写于
6月 08, 2023
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: do some internal refactor.
上级
6726edae
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
15 deletion
+37
-15
include/libs/executor/storageapi.h
include/libs/executor/storageapi.h
+1
-1
include/libs/stream/tstreamFileState.h
include/libs/stream/tstreamFileState.h
+1
-2
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+5
-3
source/libs/stream/src/tstreamFileState.c
source/libs/stream/src/tstreamFileState.c
+30
-9
未找到文件。
include/libs/executor/storageapi.h
浏览文件 @
c9aa59cb
...
...
@@ -367,7 +367,7 @@ typedef struct SStateStore {
SStreamStateCur
*
(
*
streamStateSessionSeekKeyCurrentNext
)(
SStreamState
*
pState
,
const
SSessionKey
*
key
);
struct
SStreamFileState
*
(
*
streamFileStateInit
)(
int64_t
memSize
,
uint32_t
keySize
,
uint32_t
rowSize
,
uint32_t
selectRowSize
,
GetTsFun
fp
,
void
*
pFile
,
TSKEY
delMark
);
uint32_t
selectRowSize
,
GetTsFun
fp
,
void
*
pFile
,
TSKEY
delMark
,
const
char
*
id
);
void
(
*
streamFileStateDestroy
)(
struct
SStreamFileState
*
pFileState
);
void
(
*
streamFileStateClear
)(
struct
SStreamFileState
*
pFileState
);
...
...
include/libs/stream/tstreamFileState.h
浏览文件 @
c9aa59cb
...
...
@@ -28,11 +28,10 @@ extern "C" {
#endif
typedef
struct
SStreamFileState
SStreamFileState
;
typedef
SList
SStreamSnapshot
;
SStreamFileState
*
streamFileStateInit
(
int64_t
memSize
,
uint32_t
keySize
,
uint32_t
rowSize
,
uint32_t
selectRowSize
,
GetTsFun
fp
,
void
*
pFile
,
TSKEY
delMark
);
GetTsFun
fp
,
void
*
pFile
,
TSKEY
delMark
,
const
char
*
id
);
void
streamFileStateDestroy
(
SStreamFileState
*
pFileState
);
void
streamFileStateClear
(
SStreamFileState
*
pFileState
);
bool
needClearDiskBuff
(
SStreamFileState
*
pFileState
);
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
c9aa59cb
...
...
@@ -2785,7 +2785,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
pInfo
->
pUpdatedMap
=
NULL
;
int32_t
funResSize
=
getMaxFunResSize
(
&
pOperator
->
exprSupp
,
numOfCols
);
pInfo
->
pState
->
pFileState
=
pAPI
->
stateStore
.
streamFileStateInit
(
tsStreamBufferSize
,
sizeof
(
SWinKey
),
pInfo
->
aggSup
.
resultRowSize
,
funResSize
,
compareTs
,
pInfo
->
pState
,
pInfo
->
twAggSup
.
deleteMark
);
compareTs
,
pInfo
->
pState
,
pInfo
->
twAggSup
.
deleteMark
,
GET_TASKID
(
pTaskInfo
)
);
pInfo
->
dataVersion
=
0
;
pInfo
->
statestore
=
pTaskInfo
->
storageAPI
.
stateStore
;
pInfo
->
recvGetAll
=
false
;
...
...
@@ -4974,8 +4974,10 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
pInfo
->
pUpdated
=
NULL
;
pInfo
->
pUpdatedMap
=
NULL
;
int32_t
funResSize
=
getMaxFunResSize
(
pSup
,
numOfCols
);
pInfo
->
pState
->
pFileState
=
pTaskInfo
->
storageAPI
.
stateStore
.
streamFileStateInit
(
tsStreamBufferSize
,
sizeof
(
SWinKey
),
pInfo
->
aggSup
.
resultRowSize
,
funResSize
,
compareTs
,
pInfo
->
pState
,
pInfo
->
twAggSup
.
deleteMark
);
pInfo
->
pState
->
pFileState
=
pTaskInfo
->
storageAPI
.
stateStore
.
streamFileStateInit
(
tsStreamBufferSize
,
sizeof
(
SWinKey
),
pInfo
->
aggSup
.
resultRowSize
,
funResSize
,
compareTs
,
pInfo
->
pState
,
pInfo
->
twAggSup
.
deleteMark
,
GET_TASKID
(
pTaskInfo
));
setOperatorInfo
(
pOperator
,
"StreamIntervalOperator"
,
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL
,
true
,
OP_NOT_OPENED
,
pInfo
,
pTaskInfo
);
...
...
source/libs/stream/src/tstreamFileState.c
浏览文件 @
c9aa59cb
...
...
@@ -43,12 +43,13 @@ struct SStreamFileState {
uint64_t
maxRowCount
;
uint64_t
curRowCount
;
GetTsFun
getTs
;
char
*
id
;
};
typedef
SRowBuffPos
SRowBuffInfo
;
SStreamFileState
*
streamFileStateInit
(
int64_t
memSize
,
uint32_t
keySize
,
uint32_t
rowSize
,
uint32_t
selectRowSize
,
GetTsFun
fp
,
void
*
pFile
,
TSKEY
delMark
)
{
GetTsFun
fp
,
void
*
pFile
,
TSKEY
delMark
,
const
char
*
idstr
)
{
if
(
memSize
<=
0
)
{
memSize
=
DEFAULT_MAX_STREAM_BUFFER_SIZE
;
}
...
...
@@ -70,6 +71,7 @@ SStreamFileState* streamFileStateInit(int64_t memSize, uint32_t keySize, uint32_
if
(
!
pFileState
->
usedBuffs
||
!
pFileState
->
freeBuffs
||
!
pFileState
->
rowBuffMap
)
{
goto
_error
;
}
pFileState
->
keyLen
=
keySize
;
pFileState
->
rowSize
=
rowSize
;
pFileState
->
selectivityRowSize
=
selectRowSize
;
...
...
@@ -81,6 +83,8 @@ SStreamFileState* streamFileStateInit(int64_t memSize, uint32_t keySize, uint32_
pFileState
->
deleteMark
=
delMark
;
pFileState
->
flushMark
=
INT64_MIN
;
pFileState
->
maxTs
=
INT64_MIN
;
pFileState
->
id
=
taosStrdup
(
idstr
);
recoverSnapshot
(
pFileState
);
return
pFileState
;
...
...
@@ -124,6 +128,8 @@ void streamFileStateDestroy(SStreamFileState* pFileState) {
if
(
!
pFileState
)
{
return
;
}
taosMemoryFree
(
pFileState
->
id
);
tdListFreeP
(
pFileState
->
usedBuffs
,
destroyRowBuffAllPosPtr
);
tdListFreeP
(
pFileState
->
freeBuffs
,
destroyRowBuff
);
tSimpleHashCleanup
(
pFileState
->
rowBuffMap
);
...
...
@@ -177,7 +183,8 @@ void popUsedBuffs(SStreamFileState* pFileState, SStreamSnapshot* pFlushList, uin
i
++
;
}
}
qInfo
(
"do stream state flush %d rows to disck. is used: %d"
,
listNEles
(
pFlushList
),
used
);
qInfo
(
"stream state flush %d rows to disk. is used:%d"
,
listNEles
(
pFlushList
),
used
);
}
int32_t
flushRowBuff
(
SStreamFileState
*
pFileState
)
{
...
...
@@ -185,13 +192,17 @@ int32_t flushRowBuff(SStreamFileState* pFileState) {
if
(
!
pFlushList
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
uint64_t
num
=
(
uint64_t
)(
pFileState
->
curRowCount
*
FLUSH_RATIO
);
num
=
TMAX
(
num
,
FLUSH_NUM
);
popUsedBuffs
(
pFileState
,
pFlushList
,
num
,
false
);
if
(
isListEmpty
(
pFlushList
))
{
popUsedBuffs
(
pFileState
,
pFlushList
,
num
,
true
);
}
flushSnapshot
(
pFileState
,
pFlushList
,
false
);
SListIter
fIter
=
{
0
};
tdListInitIter
(
pFlushList
,
&
fIter
,
TD_LIST_FORWARD
);
SListNode
*
pNode
=
NULL
;
...
...
@@ -201,6 +212,7 @@ int32_t flushRowBuff(SStreamFileState* pFileState) {
tdListAppend
(
pFileState
->
freeBuffs
,
&
pPos
->
pRowBuff
);
pPos
->
pRowBuff
=
NULL
;
}
tdListFreeP
(
pFlushList
,
destroyRowBuffPosPtr
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -269,13 +281,13 @@ int32_t getRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, voi
TSKEY
ts
=
pFileState
->
getTs
(
pKey
);
if
(
ts
>
pFileState
->
maxTs
-
pFileState
->
deleteMark
&&
ts
<
pFileState
->
flushMark
)
{
int32_t
len
=
0
;
void
*
p
Val
=
NULL
;
int32_t
code
=
streamStateGet_rocksdb
(
pFileState
->
pFileStore
,
pKey
,
&
p
Val
,
&
len
);
void
*
p
=
NULL
;
int32_t
code
=
streamStateGet_rocksdb
(
pFileState
->
pFileStore
,
pKey
,
&
p
,
&
len
);
qDebug
(
"===stream===get %"
PRId64
" from disc, res %d"
,
ts
,
code
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
memcpy
(
pNewPos
->
pRowBuff
,
p
Val
,
len
);
memcpy
(
pNewPos
->
pRowBuff
,
p
,
len
);
}
taosMemoryFree
(
p
Val
);
taosMemoryFree
(
p
);
}
tSimpleHashPut
(
pFileState
->
rowBuffMap
,
pKey
,
keyLen
,
&
pNewPos
,
POINTER_BYTES
);
...
...
@@ -348,12 +360,16 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
tdListInitIter
(
pSnapshot
,
&
iter
,
TD_LIST_FORWARD
);
const
int32_t
BATCH_LIMIT
=
256
;
SListNode
*
pNode
=
NULL
;
int64_t
st
=
taosGetTimestampMs
();
int32_t
numOfElems
=
listNEles
(
pSnapshot
);
SListNode
*
pNode
=
NULL
;
void
*
batch
=
streamStateCreateBatch
();
while
((
pNode
=
tdListNext
(
&
iter
))
!=
NULL
&&
code
==
TSDB_CODE_SUCCESS
)
{
SRowBuffPos
*
pPos
=
*
(
SRowBuffPos
**
)
pNode
->
data
;
ASSERT
(
pPos
->
pRowBuff
&&
pFileState
->
rowSize
>
0
);
if
(
streamStateGetBatchSize
(
batch
)
>=
BATCH_LIMIT
)
{
code
=
streamStatePutBatch_rocksdb
(
pFileState
->
pFileStore
,
batch
);
streamStateClearBatch
(
batch
);
...
...
@@ -361,7 +377,8 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
SStateKey
sKey
=
{.
key
=
*
((
SWinKey
*
)
pPos
->
pKey
),
.
opNum
=
((
SStreamState
*
)
pFileState
->
pFileStore
)
->
number
};
code
=
streamStatePutBatch
(
pFileState
->
pFileStore
,
"state"
,
batch
,
&
sKey
,
pPos
->
pRowBuff
,
pFileState
->
rowSize
,
0
);
qDebug
(
"===stream===put %"
PRId64
" to disc, code:%d, size:%d"
,
sKey
.
key
.
ts
,
code
,
pFileState
->
rowSize
);
// todo handle failure
// qDebug("===stream===put %" PRId64 " to disc, code:%d, size:%d", sKey.key.ts, code, pFileState->rowSize);
}
if
(
streamStateGetBatchSize
(
batch
)
>
0
)
{
...
...
@@ -370,6 +387,10 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
streamStateClearBatch
(
batch
);
int64_t
elapsed
=
taosGetTimestampMs
()
-
st
;
qDebug
(
"%s flush to disk in batch model completed, rows:%d, batch size:%d, elapsed time:%"
PRId64
"ms"
,
pFileState
->
id
,
numOfElems
,
BATCH_LIMIT
,
elapsed
);
if
(
flushState
)
{
const
char
*
taskKey
=
"streamFileState"
;
{
...
...
@@ -391,8 +412,8 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
}
streamStatePutBatch_rocksdb
(
pFileState
->
pFileStore
,
batch
);
}
streamStateDestroyBatch
(
batch
);
streamStateDestroyBatch
(
batch
);
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录