fix invalid free
This commit is contained in:
parent
a3836b2363
commit
29d80b1c76
|
@ -13,7 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "executorimpl.h"
|
||||
#include "tglobal.h"
|
||||
#include "filter.h"
|
||||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
|
@ -21,6 +20,7 @@
|
|||
#include "tcompare.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tfill.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
#include "ttime.h"
|
||||
|
||||
|
@ -2096,12 +2096,11 @@ void compactFunctions(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx, int3
|
|||
}
|
||||
}
|
||||
|
||||
bool hasIntervalWindow(SStreamState* pState, SWinKey* pKey) {
|
||||
return streamStateCheck(pState, pKey);
|
||||
}
|
||||
bool hasIntervalWindow(SStreamState* pState, SWinKey* pKey) { return streamStateCheck(pState, pKey); }
|
||||
|
||||
int32_t setIntervalOutputBuf(SStreamState* pState, STimeWindow* win, SRowBuffPos** pResult, int64_t groupId,
|
||||
SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup) {
|
||||
SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset,
|
||||
SAggSupporter* pAggSup) {
|
||||
SWinKey key = {
|
||||
.ts = win->skey,
|
||||
.groupId = groupId,
|
||||
|
@ -2148,20 +2147,19 @@ static void rebuildIntervalWindow(SOperatorInfo* pOperator, SArray* pWinArray, S
|
|||
continue;
|
||||
}
|
||||
if (num == 0) {
|
||||
int32_t code = setIntervalOutputBuf(pInfo->pState, &parentWin, &pCurResPos, pWinRes->groupId, pSup->pCtx, numOfOutput,
|
||||
pSup->rowEntryInfoOffset, &pInfo->aggSup);
|
||||
int32_t code = setIntervalOutputBuf(pInfo->pState, &parentWin, &pCurResPos, pWinRes->groupId, pSup->pCtx,
|
||||
numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup);
|
||||
ASSERT(pCurResPos != NULL);
|
||||
pCurResult = (SResultRow*)pCurResPos->pRowBuff;
|
||||
if (code != TSDB_CODE_SUCCESS || pCurResult == NULL) {
|
||||
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
}
|
||||
num++;
|
||||
SRowBuffPos* pChResPos = NULL;
|
||||
SResultRow* pChResult = NULL;
|
||||
setIntervalOutputBuf(pChInfo->pState, &parentWin, &pChResPos, pWinRes->groupId, pChildSup->pCtx, pChildSup->numOfExprs,
|
||||
pChildSup->rowEntryInfoOffset, &pChInfo->aggSup);
|
||||
setIntervalOutputBuf(pChInfo->pState, &parentWin, &pChResPos, pWinRes->groupId, pChildSup->pCtx,
|
||||
pChildSup->numOfExprs, pChildSup->rowEntryInfoOffset, &pChInfo->aggSup);
|
||||
pChResult = (SResultRow*)pChResPos->pRowBuff;
|
||||
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &parentWin, true);
|
||||
compactFunctions(pSup->pCtx, pChildSup->pCtx, numOfOutput, pTaskInfo, &pInfo->twAggSup.timeWindowData);
|
||||
|
@ -2786,7 +2784,8 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
|||
.deleteMarkSaved = 0,
|
||||
.calTriggerSaved = 0,
|
||||
.checkPointTs = 0,
|
||||
.checkPointInterval = convertTimePrecision(tsCheckpointInterval, TSDB_TIME_PRECISION_MILLI, pInfo->interval.precision),
|
||||
.checkPointInterval =
|
||||
convertTimePrecision(tsCheckpointInterval, TSDB_TIME_PRECISION_MILLI, pInfo->interval.precision),
|
||||
};
|
||||
ASSERTS(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY, "trigger type should not be max delay");
|
||||
pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId;
|
||||
|
@ -2869,8 +2868,8 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
|||
pInfo->numOfDatapack = 0;
|
||||
pInfo->pUpdated = NULL;
|
||||
pInfo->pUpdatedMap = NULL;
|
||||
pInfo->pState->pFileState = streamFileStateInit(tsStreamBufferSize, sizeof(SWinKey), pInfo->aggSup.resultRowSize, compareTs,
|
||||
pInfo->pState, pInfo->twAggSup.deleteMark);
|
||||
pInfo->pState->pFileState = streamFileStateInit(tsStreamBufferSize, sizeof(SWinKey), pInfo->aggSup.resultRowSize,
|
||||
compareTs, pInfo->pState, pInfo->twAggSup.deleteMark);
|
||||
pInfo->dataVersion = 0;
|
||||
|
||||
pOperator->operatorType = pPhyNode->type;
|
||||
|
@ -4985,7 +4984,8 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
|
|||
.minTs = INT64_MAX,
|
||||
.deleteMark = getDeleteMark(pIntervalPhyNode),
|
||||
.checkPointTs = 0,
|
||||
.checkPointInterval = convertTimePrecision(tsCheckpointInterval, TSDB_TIME_PRECISION_MILLI, pInfo->interval.precision),
|
||||
.checkPointInterval =
|
||||
convertTimePrecision(tsCheckpointInterval, TSDB_TIME_PRECISION_MILLI, pInfo->interval.precision),
|
||||
};
|
||||
|
||||
ASSERTS(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY, "trigger type should not be max delay");
|
||||
|
@ -5042,8 +5042,8 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
|
|||
pInfo->numOfDatapack = 0;
|
||||
pInfo->pUpdated = NULL;
|
||||
pInfo->pUpdatedMap = NULL;
|
||||
pInfo->pState->pFileState = streamFileStateInit(tsStreamBufferSize, sizeof(SWinKey), pInfo->aggSup.resultRowSize, compareTs,
|
||||
pInfo->pState, pInfo->twAggSup.deleteMark);
|
||||
pInfo->pState->pFileState = streamFileStateInit(tsStreamBufferSize, sizeof(SWinKey), pInfo->aggSup.resultRowSize,
|
||||
compareTs, pInfo->pState, pInfo->twAggSup.deleteMark);
|
||||
|
||||
setOperatorInfo(pOperator, "StreamIntervalOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL, true, OP_NOT_OPENED,
|
||||
pInfo, pTaskInfo);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "rocksdb/c.h"
|
||||
#include "streamBackendRocksdb.h"
|
||||
#include "tcommon.h"
|
||||
#include "tlog.h"
|
||||
|
||||
int defaultKeyComp(void* state, const char* aBuf, size_t aLen, const char* bBuf, size_t bLen) {
|
||||
//
|
||||
|
|
|
@ -313,15 +313,23 @@ SStreamSnapshot* getSnapshot(SStreamFileState* pFileState) {
|
|||
return pFileState->usedBuffs;
|
||||
}
|
||||
|
||||
void streamFileStateDecode(SStreamFileState* pFileState, void* pBuff, int32_t len) {
|
||||
pBuff = taosDecodeFixedI64(pBuff, &pFileState->flushMark);
|
||||
}
|
||||
// void streamFileStateDecode(SStreamFileState* pFileState, void* pBuff, int32_t len) {
|
||||
// pBuff = taosDecodeFixedI64(pBuff, &pFileState->flushMark);
|
||||
// }
|
||||
|
||||
void streamFileStateEncode(SStreamFileState* pFileState, void** pVal, int32_t* pLen) {
|
||||
// void streamFileStateEncode(SStreamFileState* pFileState, void** pVal, int32_t* pLen) {
|
||||
// *pLen = sizeof(TSKEY);
|
||||
// (*pVal) = taosMemoryCalloc(1, *pLen);
|
||||
// void* buff = *pVal;
|
||||
// taosEncodeFixedI64(&buff, pFileState->flushMark);
|
||||
// }
|
||||
void streamFileStateDecode(TSKEY* key, void* pBuff, int32_t len) { pBuff = taosDecodeFixedI64(pBuff, key); }
|
||||
|
||||
void streamFileStateEncode(TSKEY* key, void** pVal, int32_t* pLen) {
|
||||
*pLen = sizeof(TSKEY);
|
||||
(*pVal) = taosMemoryCalloc(1, *pLen);
|
||||
void* buff = *pVal;
|
||||
taosEncodeFixedI64(&buff, pFileState->flushMark);
|
||||
taosEncodeFixedI64(&buff, *key);
|
||||
}
|
||||
|
||||
int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot, bool flushState) {
|
||||
|
@ -349,12 +357,26 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
|
|||
}
|
||||
|
||||
if (flushState) {
|
||||
const char* taskKey = "streamFileState";
|
||||
{
|
||||
char keyBuf[128] = {0};
|
||||
void* valBuf = NULL;
|
||||
int32_t len = 0;
|
||||
void* buff = NULL;
|
||||
streamFileStateEncode(pFileState, &buff, &len);
|
||||
SWinKey key = {.ts = -1, .groupId = 0}; // dengyihao
|
||||
streamStatePut_rocksdb(pFileState->pFileStore, &key, buff, len);
|
||||
taosMemoryFree(buff);
|
||||
sprintf(keyBuf, "%s:%" PRId64 "", taskKey, ((SStreamState*)pFileState->pFileStore)->checkPointId);
|
||||
streamFileStateEncode(&pFileState->flushMark, &valBuf, &len);
|
||||
streamStatePutBatch(pFileState->pFileStore, "default", batch, keyBuf, valBuf, len);
|
||||
taosMemoryFree(valBuf);
|
||||
}
|
||||
{
|
||||
char keyBuf[128] = {0};
|
||||
char valBuf[64] = {0};
|
||||
int32_t len = 0;
|
||||
sprintf(keyBuf, "%s:%" PRId64 "", taskKey, INT64_MIN);
|
||||
sprintf(valBuf, "%" PRId64 "", ((SStreamState*)pFileState->pFileStore)->checkPointId);
|
||||
|
||||
streamStatePutBatch(pFileState->pFileStore, "default", batch, keyBuf, valBuf, strlen(valBuf));
|
||||
}
|
||||
streamStatePutBatch_rocksdb(pFileState->pFileStore, batch);
|
||||
}
|
||||
|
||||
streamStateDestroyBatch(batch);
|
||||
|
@ -363,15 +385,41 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
|
|||
|
||||
int32_t recoverSnapshot(SStreamFileState* pFileState) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SWinKey stkey = {.ts = -1, .groupId = 0}; // dengyihao
|
||||
void* pStVal = NULL;
|
||||
const char* taskKey = "streamFileState";
|
||||
int64_t maxCheckPointId = 0;
|
||||
{
|
||||
char buf[128] = {0};
|
||||
void* val = NULL;
|
||||
int32_t len = 0;
|
||||
code = streamStateGet_rocksdb(pFileState->pFileStore, &stkey, &pStVal, &len);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
streamFileStateDecode(pFileState, pStVal, len);
|
||||
} else {
|
||||
sprintf(buf, "%s:%" PRId64 "", taskKey, INT64_MIN);
|
||||
code = streamDefaultGet_rocksdb(pFileState->pFileStore, buf, &val, &len);
|
||||
if (code != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
sscanf(val, "%" PRId64 "", &maxCheckPointId);
|
||||
taosMemoryFree(val);
|
||||
}
|
||||
for (int64_t i = maxCheckPointId; i > 0; i++) {
|
||||
char buf[128] = {0};
|
||||
void* val = 0;
|
||||
int32_t len = 0;
|
||||
sprintf(buf, "%s:%" PRId64 "", taskKey, i);
|
||||
code = streamDefaultGet_rocksdb(pFileState->pFileStore, buf, &val, &len);
|
||||
if (code != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
TSKEY ts;
|
||||
sscanf(val, "%" PRId64 "", &ts);
|
||||
taosMemoryFree(val);
|
||||
if (ts < pFileState->flushMark) {
|
||||
// forceRemoveCheckPoint(pFileState->pFileStore, i);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void* pStVal = NULL;
|
||||
int32_t len = 0;
|
||||
|
||||
SWinKey key = {.groupId = 0, .ts = 0};
|
||||
SStreamStateCur* pCur = streamStateGetCur_rocksdb(pFileState->pFileStore, &key);
|
||||
|
|
Loading…
Reference in New Issue