@@ -1060,7 +1060,7 @@ int32_t getCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, C
10601060 return code ;
10611061}
10621062
1063- int32_t createCountWinResultBuff (SStreamFileState * pFileState , SSessionKey * pKey , void * * pVal , int32_t * pVLen ) {
1063+ int32_t createCountWinResultBuff (SStreamFileState * pFileState , SSessionKey * pKey , COUNT_TYPE winCount , void * * pVal , int32_t * pVLen ) {
10641064 SSessionKey * pWinKey = pKey ;
10651065 const TSKEY gap = 0 ;
10661066 int32_t code = TSDB_CODE_SUCCESS ;
@@ -1082,21 +1082,27 @@ int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey
10821082 int32_t size = taosArrayGetSize (pWinStates );
10831083 if (size == 0 ) {
10841084 void * pFileStore = getStateFileStore (pFileState );
1085- void * p = NULL ;
1085+ void * pRockVal = NULL ;
10861086
1087- int32_t code_file = getCountWinStateFromDisc (pFileStore , pWinKey , & p , pVLen );
1087+ int32_t code_file = getCountWinStateFromDisc (pFileStore , pWinKey , & pRockVal , pVLen );
10881088 if (code_file == TSDB_CODE_SUCCESS && isFlushedState (pFileState , endTs , 0 )) {
1089- (* pVal ) = createSessionWinBuff (pFileState , pWinKey , p , pVLen );
1090- if (!(* pVal )) {
1091- code = TSDB_CODE_OUT_OF_MEMORY ;
1089+ int32_t valSize = * pVLen ;
1090+ COUNT_TYPE * pWinStateCount = (COUNT_TYPE * )((char * )(pRockVal ) + (valSize - sizeof (COUNT_TYPE )));
1091+ if ((* pWinStateCount ) == winCount ) {
1092+ code = addNewSessionWindow (pFileState , pWinStates , pWinKey , (SRowBuffPos * * )pVal );
10921093 QUERY_CHECK_CODE (code , lino , _end );
1093- }
1094-
1095- qDebug ("===stream===0 get state win:%" PRId64 ",%" PRId64 " from disc, res %d" , pWinKey -> win .skey ,
1094+ } else {
1095+ (* pVal ) = createSessionWinBuff (pFileState , pWinKey , pRockVal , pVLen );
1096+ if (!(* pVal )) {
1097+ code = TSDB_CODE_OUT_OF_MEMORY ;
1098+ QUERY_CHECK_CODE (code , lino , _end );
1099+ }
1100+ qDebug ("===stream===0 get state win:%" PRId64 ",%" PRId64 " from disc, res %d" , pWinKey -> win .skey ,
10961101 pWinKey -> win .ekey , code_file );
1102+ }
10971103 } else {
10981104 code = addNewSessionWindow (pFileState , pWinStates , pWinKey , (SRowBuffPos * * )pVal );
1099- taosMemoryFree (p );
1105+ taosMemoryFree (pRockVal );
11001106 QUERY_CHECK_CODE (code , lino , _end );
11011107 }
11021108 } else {
0 commit comments