Merge pull request #28180 from taosdata/fix/TD-32391
fix(stream):fix issue for stream count window state buff
This commit is contained in:
commit
f8b46586ed
|
@ -382,7 +382,7 @@ typedef struct SStateStore {
|
||||||
|
|
||||||
int32_t (*streamStateCountWinAddIfNotExist)(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount,
|
int32_t (*streamStateCountWinAddIfNotExist)(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount,
|
||||||
void** ppVal, int32_t* pVLen, int32_t* pWinCode);
|
void** ppVal, int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t (*streamStateCountWinAdd)(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t (*streamStateCountWinAdd)(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
int32_t (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType,
|
int32_t (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark, bool igUp, int8_t pkType,
|
||||||
int32_t pkLen, SUpdateInfo** ppInfo);
|
int32_t pkLen, SUpdateInfo** ppInfo);
|
||||||
|
|
|
@ -87,7 +87,7 @@ void streamStateFreeVal(void* val);
|
||||||
// count window
|
// count window
|
||||||
int32_t streamStateCountWinAddIfNotExist(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** ppVal,
|
int32_t streamStateCountWinAddIfNotExist(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** ppVal,
|
||||||
int32_t* pVLen, int32_t* pWinCode);
|
int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t streamStateCountWinAdd(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t streamStateCountWinAdd(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
SStreamStateCur* streamStateGetAndCheckCur(SStreamState* pState, SWinKey* key);
|
SStreamStateCur* streamStateGetAndCheckCur(SStreamState* pState, SWinKey* key);
|
||||||
SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const SWinKey* key);
|
SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const SWinKey* key);
|
||||||
|
|
|
@ -110,7 +110,7 @@ int32_t getStateWinResultBuff(SStreamFileState* pFileState, SSessionKey* key, ch
|
||||||
// count window
|
// count window
|
||||||
int32_t getCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal,
|
int32_t getCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal,
|
||||||
int32_t* pVLen, int32_t* pWinCode);
|
int32_t* pVLen, int32_t* pWinCode);
|
||||||
int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal, int32_t* pVLen);
|
||||||
|
|
||||||
// function
|
// function
|
||||||
int32_t getSessionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen,
|
int32_t getSessionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen,
|
||||||
|
|
|
@ -26,6 +26,8 @@ void setStreamOperatorState(SSteamOpBasicInfo* pBasicInfo, EStreamType type);
|
||||||
bool needSaveStreamOperatorInfo(SSteamOpBasicInfo* pBasicInfo);
|
bool needSaveStreamOperatorInfo(SSteamOpBasicInfo* pBasicInfo);
|
||||||
void saveStreamOperatorStateComplete(SSteamOpBasicInfo* pBasicInfo);
|
void saveStreamOperatorStateComplete(SSteamOpBasicInfo* pBasicInfo);
|
||||||
|
|
||||||
|
void reuseOutputBuf(void* pState, SRowBuffPos* pPos, SStateStore* pAPI);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -90,7 +90,7 @@ int32_t setCountOutputBuf(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t group
|
||||||
|
|
||||||
if (isSlidingCountWindow(pAggSup)) {
|
if (isSlidingCountWindow(pAggSup)) {
|
||||||
if (pBuffInfo->winBuffOp == CREATE_NEW_WINDOW) {
|
if (pBuffInfo->winBuffOp == CREATE_NEW_WINDOW) {
|
||||||
code = pAggSup->stateStore.streamStateCountWinAdd(pAggSup->pState, &pCurWin->winInfo.sessionWin,
|
code = pAggSup->stateStore.streamStateCountWinAdd(pAggSup->pState, &pCurWin->winInfo.sessionWin, pAggSup->windowCount,
|
||||||
(void**)&pCurWin->winInfo.pStatePos, &size);
|
(void**)&pCurWin->winInfo.pStatePos, &size);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
@ -101,9 +101,11 @@ int32_t setCountOutputBuf(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t group
|
||||||
winCode = pAggSup->stateStore.streamStateSessionGetKVByCur(pBuffInfo->pCur, &pCurWin->winInfo.sessionWin,
|
winCode = pAggSup->stateStore.streamStateSessionGetKVByCur(pBuffInfo->pCur, &pCurWin->winInfo.sessionWin,
|
||||||
(void**)&pCurWin->winInfo.pStatePos, &size);
|
(void**)&pCurWin->winInfo.pStatePos, &size);
|
||||||
if (winCode == TSDB_CODE_FAILED) {
|
if (winCode == TSDB_CODE_FAILED) {
|
||||||
code = pAggSup->stateStore.streamStateCountWinAdd(pAggSup->pState, &pCurWin->winInfo.sessionWin,
|
code = pAggSup->stateStore.streamStateCountWinAdd(pAggSup->pState, &pCurWin->winInfo.sessionWin, pAggSup->windowCount,
|
||||||
(void**)&pCurWin->winInfo.pStatePos, &size);
|
(void**)&pCurWin->winInfo.pStatePos, &size);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
} else {
|
||||||
|
reuseOutputBuf(pAggSup->pState, pCurWin->winInfo.pStatePos, &pAggSup->stateStore);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pBuffInfo->pCur = pAggSup->stateStore.streamStateCountSeekKeyPrev(pAggSup->pState, &pCurWin->winInfo.sessionWin,
|
pBuffInfo->pCur = pAggSup->stateStore.streamStateCountSeekKeyPrev(pAggSup->pState, &pCurWin->winInfo.sessionWin,
|
||||||
|
@ -111,9 +113,11 @@ int32_t setCountOutputBuf(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t group
|
||||||
winCode = pAggSup->stateStore.streamStateSessionGetKVByCur(pBuffInfo->pCur, &pCurWin->winInfo.sessionWin,
|
winCode = pAggSup->stateStore.streamStateSessionGetKVByCur(pBuffInfo->pCur, &pCurWin->winInfo.sessionWin,
|
||||||
(void**)&pCurWin->winInfo.pStatePos, &size);
|
(void**)&pCurWin->winInfo.pStatePos, &size);
|
||||||
if (winCode == TSDB_CODE_FAILED) {
|
if (winCode == TSDB_CODE_FAILED) {
|
||||||
code = pAggSup->stateStore.streamStateCountWinAdd(pAggSup->pState, &pCurWin->winInfo.sessionWin,
|
code = pAggSup->stateStore.streamStateCountWinAdd(pAggSup->pState, &pCurWin->winInfo.sessionWin, pAggSup->windowCount,
|
||||||
(void**)&pCurWin->winInfo.pStatePos, &size);
|
(void**)&pCurWin->winInfo.pStatePos, &size);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
} else {
|
||||||
|
reuseOutputBuf(pAggSup->pState, pCurWin->winInfo.pStatePos, &pAggSup->stateStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ts < pCurWin->winInfo.sessionWin.win.ekey) {
|
if (ts < pCurWin->winInfo.sessionWin.win.ekey) {
|
||||||
|
|
|
@ -1060,7 +1060,7 @@ _end:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, void** pVal, int32_t* pVLen) {
|
int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal, int32_t* pVLen) {
|
||||||
SSessionKey* pWinKey = pKey;
|
SSessionKey* pWinKey = pKey;
|
||||||
const TSKEY gap = 0;
|
const TSKEY gap = 0;
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
@ -1082,21 +1082,27 @@ int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey
|
||||||
int32_t size = taosArrayGetSize(pWinStates);
|
int32_t size = taosArrayGetSize(pWinStates);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
void* pFileStore = getStateFileStore(pFileState);
|
void* pFileStore = getStateFileStore(pFileState);
|
||||||
void* p = NULL;
|
void* pRockVal = NULL;
|
||||||
|
|
||||||
int32_t code_file = getCountWinStateFromDisc(pFileStore, pWinKey, &p, pVLen);
|
int32_t code_file = getCountWinStateFromDisc(pFileStore, pWinKey, &pRockVal, pVLen);
|
||||||
if (code_file == TSDB_CODE_SUCCESS && isFlushedState(pFileState, endTs, 0)) {
|
if (code_file == TSDB_CODE_SUCCESS && isFlushedState(pFileState, endTs, 0)) {
|
||||||
(*pVal) = createSessionWinBuff(pFileState, pWinKey, p, pVLen);
|
int32_t valSize = *pVLen;
|
||||||
if (!(*pVal)) {
|
COUNT_TYPE* pWinStateCount = (COUNT_TYPE*)((char*)(pRockVal) + (valSize - sizeof(COUNT_TYPE)));
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
if ((*pWinStateCount) == winCount) {
|
||||||
|
code = addNewSessionWindow(pFileState, pWinStates, pWinKey, (SRowBuffPos**)pVal);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
} else {
|
||||||
|
(*pVal) = createSessionWinBuff(pFileState, pWinKey, pRockVal, pVLen);
|
||||||
qDebug("===stream===0 get state win:%" PRId64 ",%" PRId64 " from disc, res %d", pWinKey->win.skey,
|
if (!(*pVal)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
}
|
||||||
|
qDebug("===stream===0 get state win:%" PRId64 ",%" PRId64 " from disc, res %d", pWinKey->win.skey,
|
||||||
pWinKey->win.ekey, code_file);
|
pWinKey->win.ekey, code_file);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
code = addNewSessionWindow(pFileState, pWinStates, pWinKey, (SRowBuffPos**)pVal);
|
code = addNewSessionWindow(pFileState, pWinStates, pWinKey, (SRowBuffPos**)pVal);
|
||||||
taosMemoryFree(p);
|
taosMemoryFree(pRockVal);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -545,6 +545,6 @@ int32_t streamStateCountWinAddIfNotExist(SStreamState* pState, SSessionKey* pKey
|
||||||
return getCountWinResultBuff(pState->pFileState, pKey, winCount, ppVal, pVLen, pWinCode);
|
return getCountWinResultBuff(pState->pFileState, pKey, winCount, ppVal, pVLen, pWinCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamStateCountWinAdd(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen) {
|
int32_t streamStateCountWinAdd(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal, int32_t* pVLen) {
|
||||||
return createCountWinResultBuff(pState->pFileState, pKey, pVal, pVLen);
|
return createCountWinResultBuff(pState->pFileState, pKey, winCount, pVal, pVLen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -445,7 +445,9 @@ _end:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t clearRowBuff(SStreamFileState* pFileState) {
|
int32_t clearRowBuff(SStreamFileState* pFileState) {
|
||||||
clearExpiredRowBuff(pFileState, pFileState->maxTs - pFileState->deleteMark, false);
|
if (pFileState->deleteMark != INT64_MAX) {
|
||||||
|
clearExpiredRowBuff(pFileState, pFileState->maxTs - pFileState->deleteMark, false);
|
||||||
|
}
|
||||||
if (isListEmpty(pFileState->freeBuffs)) {
|
if (isListEmpty(pFileState->freeBuffs)) {
|
||||||
return flushRowBuff(pFileState);
|
return flushRowBuff(pFileState);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue