TDengine/source/libs/stream/src/tstreamFileState.c

469 lines
15 KiB
C
Raw Normal View History

2023-04-03 06:31:37 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tstreamFileState.h"
2023-04-07 07:26:15 +00:00
#include "streamBackendRocksdb.h"
2023-04-03 06:31:37 +00:00
#include "taos.h"
2023-04-10 04:51:00 +00:00
#include "tcommon.h"
2023-04-03 06:31:37 +00:00
#include "thash.h"
#include "tsimplehash.h"
2023-04-07 07:26:15 +00:00
#define FLUSH_RATIO 0.2
2023-04-07 07:38:02 +00:00
#define FLUSH_NUM 4
2023-04-03 06:31:37 +00:00
#define DEFAULT_MAX_STREAM_BUFFER_SIZE (128 * 1024 * 1024);
struct SStreamFileState {
SList* usedBuffs;
SList* freeBuffs;
SSHashObj* rowBuffMap;
void* pFileStore;
int32_t rowSize;
int32_t keyLen;
uint64_t preCheckPointVersion;
uint64_t checkPointVersion;
TSKEY maxTs;
TSKEY deleteMark;
2023-04-04 09:08:24 +00:00
TSKEY flushMark;
2023-04-03 06:31:37 +00:00
uint64_t maxRowCount;
uint64_t curRowCount;
2023-04-04 09:08:24 +00:00
GetTsFun getTs;
2023-04-03 06:31:37 +00:00
};
typedef SRowBuffPos SRowBuffInfo;
2023-04-07 07:38:02 +00:00
SStreamFileState* streamFileStateInit(int64_t memSize, uint32_t keySize, uint32_t rowSize, GetTsFun fp, void* pFile,
TSKEY delMark) {
2023-04-03 06:31:37 +00:00
if (memSize <= 0) {
memSize = DEFAULT_MAX_STREAM_BUFFER_SIZE;
}
if (rowSize == 0) {
goto _error;
}
SStreamFileState* pFileState = taosMemoryCalloc(1, sizeof(SStreamFileState));
if (!pFileState) {
goto _error;
}
2023-04-11 10:47:15 +00:00
pFileState->maxRowCount = TMAX((uint64_t)memSize / rowSize, FLUSH_NUM * 2);
2023-04-03 06:31:37 +00:00
pFileState->usedBuffs = tdListNew(POINTER_BYTES);
pFileState->freeBuffs = tdListNew(POINTER_BYTES);
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
2023-04-11 10:47:15 +00:00
int32_t cap = TMIN(10240, pFileState->maxRowCount);
2023-04-07 10:45:09 +00:00
pFileState->rowBuffMap = tSimpleHashInit(cap, hashFn);
2023-04-03 06:31:37 +00:00
if (!pFileState->usedBuffs || !pFileState->freeBuffs || !pFileState->rowBuffMap) {
goto _error;
}
2023-04-07 04:50:59 +00:00
pFileState->keyLen = keySize;
2023-04-03 06:31:37 +00:00
pFileState->rowSize = rowSize;
pFileState->preCheckPointVersion = 0;
pFileState->checkPointVersion = 1;
pFileState->pFileStore = pFile;
2023-04-04 09:08:24 +00:00
pFileState->getTs = fp;
2023-04-07 07:38:02 +00:00
pFileState->maxRowCount = TMAX((uint64_t)memSize / rowSize, FLUSH_NUM * 2);
2023-04-03 06:31:37 +00:00
pFileState->curRowCount = 0;
2023-04-04 09:08:24 +00:00
pFileState->deleteMark = delMark;
pFileState->flushMark = -1;
2023-04-06 08:33:00 +00:00
recoverSnapshot(pFileState);
2023-04-03 06:31:37 +00:00
return pFileState;
_error:
2023-04-04 09:08:24 +00:00
streamFileStateDestroy(pFileState);
2023-04-03 06:31:37 +00:00
return NULL;
}
void destroyRowBuffPos(SRowBuffPos* pPos) {
2023-04-04 09:08:24 +00:00
taosMemoryFreeClear(pPos->pKey);
2023-04-03 06:31:37 +00:00
taosMemoryFreeClear(pPos->pRowBuff);
taosMemoryFree(pPos);
}
void destroyRowBuffPosPtr(void* ptr) {
if (!ptr) {
return;
}
2023-04-04 09:08:24 +00:00
SRowBuffPos* pPos = *(SRowBuffPos**)ptr;
2023-04-07 04:50:59 +00:00
if (!pPos->beUsed) {
destroyRowBuffPos(pPos);
}
2023-04-03 06:31:37 +00:00
}
2023-04-18 01:50:13 +00:00
void destroyRowBuffAllPosPtr(void* ptr) {
if (!ptr) {
return;
}
SRowBuffPos* pPos = *(SRowBuffPos**)ptr;
destroyRowBuffPos(pPos);
}
2023-04-04 09:08:24 +00:00
void destroyRowBuff(void* ptr) {
if (!ptr) {
return;
}
taosMemoryFree(*(void**)ptr);
}
void streamFileStateDestroy(SStreamFileState* pFileState) {
if (!pFileState) {
return;
}
2023-04-18 01:50:13 +00:00
tdListFreeP(pFileState->usedBuffs, destroyRowBuffAllPosPtr);
2023-04-04 09:08:24 +00:00
tdListFreeP(pFileState->freeBuffs, destroyRowBuff);
2023-04-03 06:31:37 +00:00
tSimpleHashCleanup(pFileState->rowBuffMap);
2023-04-04 09:08:24 +00:00
taosMemoryFree(pFileState);
2023-04-03 06:31:37 +00:00
}
2023-04-04 09:08:24 +00:00
void clearExpiredRowBuff(SStreamFileState* pFileState, TSKEY ts, bool all) {
2023-04-03 06:31:37 +00:00
SListIter iter = {0};
tdListInitIter(pFileState->usedBuffs, &iter, TD_LIST_FORWARD);
SListNode* pNode = NULL;
while ((pNode = tdListNext(&iter)) != NULL) {
2023-04-04 09:08:24 +00:00
SRowBuffPos* pPos = *(SRowBuffPos**)(pNode->data);
2023-04-07 07:26:15 +00:00
if (all || (pFileState->getTs(pPos->pKey) < ts)) {
2023-04-07 04:50:59 +00:00
ASSERT(pPos->pRowBuff != NULL);
2023-04-04 09:08:24 +00:00
tdListAppend(pFileState->freeBuffs, &(pPos->pRowBuff));
2023-04-03 06:31:37 +00:00
pPos->pRowBuff = NULL;
2023-04-07 10:45:09 +00:00
if (!all) {
tSimpleHashRemove(pFileState->rowBuffMap, pPos->pKey, pFileState->keyLen);
}
2023-04-03 06:31:37 +00:00
destroyRowBuffPos(pPos);
2023-04-07 04:50:59 +00:00
tdListPopNode(pFileState->usedBuffs, pNode);
taosMemoryFreeClear(pNode);
2023-04-03 06:31:37 +00:00
}
}
}
2023-04-04 09:08:24 +00:00
void streamFileStateClear(SStreamFileState* pFileState) {
tSimpleHashClear(pFileState->rowBuffMap);
clearExpiredRowBuff(pFileState, 0, true);
}
2023-04-07 04:50:59 +00:00
void popUsedBuffs(SStreamFileState* pFileState, SStreamSnapshot* pFlushList, uint64_t max, bool used) {
2023-04-07 07:26:15 +00:00
uint64_t i = 0;
2023-04-03 06:31:37 +00:00
SListIter iter = {0};
tdListInitIter(pFileState->usedBuffs, &iter, TD_LIST_FORWARD);
SListNode* pNode = NULL;
2023-04-07 04:50:59 +00:00
while ((pNode = tdListNext(&iter)) != NULL && i < max) {
2023-04-03 06:31:37 +00:00
SRowBuffPos* pPos = *(SRowBuffPos**)pNode->data;
2023-04-07 04:50:59 +00:00
if (pPos->beUsed == used) {
2023-04-03 06:31:37 +00:00
tdListAppend(pFlushList, &pPos);
2023-04-04 09:08:24 +00:00
pFileState->flushMark = TMAX(pFileState->flushMark, pFileState->getTs(pPos->pKey));
tSimpleHashRemove(pFileState->rowBuffMap, pPos->pKey, pFileState->keyLen);
2023-04-07 04:50:59 +00:00
tdListPopNode(pFileState->usedBuffs, pNode);
taosMemoryFreeClear(pNode);
2023-04-03 06:31:37 +00:00
i++;
}
}
2023-04-07 10:45:09 +00:00
qInfo("do stream state flush %d rows to disck. is used: %d", listNEles(pFlushList), used);
2023-04-07 04:50:59 +00:00
}
int32_t flushRowBuff(SStreamFileState* pFileState) {
SStreamSnapshot* pFlushList = tdListNew(POINTER_BYTES);
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);
}
2023-04-06 08:33:00 +00:00
flushSnapshot(pFileState, pFlushList, false);
2023-04-07 04:50:59 +00:00
SListIter fIter = {0};
tdListInitIter(pFlushList, &fIter, TD_LIST_FORWARD);
SListNode* pNode = NULL;
while ((pNode = tdListNext(&fIter)) != NULL) {
SRowBuffPos* pPos = *(SRowBuffPos**)pNode->data;
ASSERT(pPos->pRowBuff != NULL);
tdListAppend(pFileState->freeBuffs, &pPos->pRowBuff);
pPos->pRowBuff = NULL;
}
tdListFreeP(pFlushList, destroyRowBuffPosPtr);
2023-04-03 06:31:37 +00:00
return TSDB_CODE_SUCCESS;
}
int32_t clearRowBuff(SStreamFileState* pFileState) {
2023-04-04 09:08:24 +00:00
clearExpiredRowBuff(pFileState, pFileState->maxTs - pFileState->deleteMark, false);
2023-04-03 06:31:37 +00:00
if (isListEmpty(pFileState->freeBuffs)) {
return flushRowBuff(pFileState);
}
return TSDB_CODE_SUCCESS;
}
2023-04-04 09:08:24 +00:00
void* getFreeBuff(SList* lists, int32_t buffSize) {
2023-04-03 06:31:37 +00:00
SListNode* pNode = tdListPopHead(lists);
if (!pNode) {
return NULL;
}
void* ptr = *(void**)pNode->data;
2023-04-04 09:08:24 +00:00
memset(ptr, 0, buffSize);
2023-04-03 06:31:37 +00:00
taosMemoryFree(pNode);
return ptr;
}
SRowBuffPos* getNewRowPos(SStreamFileState* pFileState) {
SRowBuffPos* pPos = taosMemoryCalloc(1, sizeof(SRowBuffPos));
2023-04-07 04:50:59 +00:00
pPos->pKey = taosMemoryCalloc(1, pFileState->keyLen);
2023-04-04 09:08:24 +00:00
void* pBuff = getFreeBuff(pFileState->freeBuffs, pFileState->rowSize);
2023-04-03 06:31:37 +00:00
if (pBuff) {
pPos->pRowBuff = pBuff;
2023-04-07 04:50:59 +00:00
goto _end;
2023-04-03 06:31:37 +00:00
}
if (pFileState->curRowCount < pFileState->maxRowCount) {
pBuff = taosMemoryCalloc(1, pFileState->rowSize);
if (pBuff) {
pPos->pRowBuff = pBuff;
pFileState->curRowCount++;
2023-04-07 04:50:59 +00:00
goto _end;
2023-04-03 06:31:37 +00:00
}
}
int32_t code = clearRowBuff(pFileState);
ASSERT(code == 0);
2023-04-04 09:08:24 +00:00
pPos->pRowBuff = getFreeBuff(pFileState->freeBuffs, pFileState->rowSize);
2023-04-07 04:50:59 +00:00
_end:
tdListAppend(pFileState->usedBuffs, &pPos);
ASSERT(pPos->pRowBuff != NULL);
2023-04-03 06:31:37 +00:00
return pPos;
}
int32_t getRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen) {
2023-04-04 09:08:24 +00:00
pFileState->maxTs = TMAX(pFileState->maxTs, pFileState->getTs(pKey));
2023-04-03 06:31:37 +00:00
SRowBuffPos** pos = tSimpleHashGet(pFileState->rowBuffMap, pKey, keyLen);
if (pos) {
2023-04-07 04:50:59 +00:00
*pVLen = pFileState->rowSize;
*pVal = *pos;
(*pos)->beUsed = true;
2023-04-03 06:31:37 +00:00
return TSDB_CODE_SUCCESS;
}
SRowBuffPos* pNewPos = getNewRowPos(pFileState);
2023-04-07 04:50:59 +00:00
pNewPos->beUsed = true;
ASSERT(pNewPos->pRowBuff);
2023-04-04 09:08:24 +00:00
memcpy(pNewPos->pKey, pKey, keyLen);
TSKEY ts = pFileState->getTs(pKey);
if (ts > pFileState->maxTs - pFileState->deleteMark && ts < pFileState->flushMark) {
int32_t len = 0;
2023-04-07 07:26:15 +00:00
void* pVal = NULL;
2023-04-07 04:50:59 +00:00
int32_t code = streamStateGet_rocksdb(pFileState->pFileStore, pKey, &pVal, &len);
if (code == TSDB_CODE_SUCCESS) {
memcpy(pNewPos->pRowBuff, pVal, len);
}
2023-04-04 09:08:24 +00:00
taosMemoryFree(pVal);
}
2023-04-03 06:31:37 +00:00
tSimpleHashPut(pFileState->rowBuffMap, pKey, keyLen, &pNewPos, POINTER_BYTES);
2023-04-04 09:08:24 +00:00
if (pVal) {
*pVLen = pFileState->rowSize;
*pVal = pNewPos;
}
2023-04-03 06:31:37 +00:00
return TSDB_CODE_SUCCESS;
}
2023-04-04 09:08:24 +00:00
int32_t deleteRowBuff(SStreamFileState* pFileState, const void* pKey, int32_t keyLen) {
int32_t code_buff = tSimpleHashRemove(pFileState->rowBuffMap, pKey, keyLen);
int32_t code_rocks = streamStateDel_rocksdb(pFileState->pFileStore, pKey);
return code_buff == TSDB_CODE_SUCCESS ? code_buff : code_rocks;
}
int32_t getRowBuffByPos(SStreamFileState* pFileState, SRowBuffPos* pPos, void** pVal) {
2023-04-03 06:31:37 +00:00
if (pPos->pRowBuff) {
2023-04-04 09:08:24 +00:00
(*pVal) = pPos->pRowBuff;
return TSDB_CODE_SUCCESS;
2023-04-03 06:31:37 +00:00
}
2023-04-04 09:08:24 +00:00
pPos->pRowBuff = getFreeBuff(pFileState->freeBuffs, pFileState->rowSize);
2023-04-07 04:50:59 +00:00
if (!pPos->pRowBuff) {
int32_t code = clearRowBuff(pFileState);
ASSERT(code == 0);
pPos->pRowBuff = getFreeBuff(pFileState->freeBuffs, pFileState->rowSize);
ASSERT(pPos->pRowBuff);
}
2023-04-03 06:31:37 +00:00
int32_t len = 0;
2023-04-07 07:38:02 +00:00
void* pBuff = NULL;
2023-04-07 04:50:59 +00:00
streamStateGet_rocksdb(pFileState->pFileStore, pPos->pKey, &pBuff, &len);
memcpy(pPos->pRowBuff, pBuff, len);
taosMemoryFree(pBuff);
2023-04-04 09:08:24 +00:00
(*pVal) = pPos->pRowBuff;
2023-04-07 04:50:59 +00:00
tdListPrepend(pFileState->usedBuffs, &pPos);
2023-04-04 09:08:24 +00:00
return TSDB_CODE_SUCCESS;
}
bool hasRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen) {
SRowBuffPos** pos = tSimpleHashGet(pFileState->rowBuffMap, pKey, keyLen);
if (pos) {
return true;
}
return false;
2023-04-03 06:31:37 +00:00
}
2023-04-07 07:26:15 +00:00
void releaseRowBuffPos(SRowBuffPos* pBuff) { pBuff->beUsed = false; }
2023-04-03 06:31:37 +00:00
SStreamSnapshot* getSnapshot(SStreamFileState* pFileState) {
2023-04-04 09:08:24 +00:00
clearExpiredRowBuff(pFileState, pFileState->maxTs - pFileState->deleteMark, false);
2023-04-03 06:31:37 +00:00
return pFileState->usedBuffs;
}
2023-04-11 14:04:39 +00:00
void streamFileStateDecode(TSKEY* key, void* pBuff, int32_t len) { pBuff = taosDecodeFixedI64(pBuff, key); }
void streamFileStateEncode(TSKEY* key, void** pVal, int32_t* pLen) {
2023-04-06 08:33:00 +00:00
*pLen = sizeof(TSKEY);
2023-04-06 10:26:47 +00:00
(*pVal) = taosMemoryCalloc(1, *pLen);
2023-04-07 07:26:15 +00:00
void* buff = *pVal;
2023-04-11 14:04:39 +00:00
taosEncodeFixedI64(&buff, *key);
2023-04-06 08:33:00 +00:00
}
int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot, bool flushState) {
2023-04-07 07:26:15 +00:00
int32_t code = TSDB_CODE_SUCCESS;
2023-04-03 06:31:37 +00:00
SListIter iter = {0};
tdListInitIter(pSnapshot, &iter, TD_LIST_FORWARD);
2023-04-14 14:05:59 +00:00
const int32_t BATCH_LIMIT = 256;
2023-04-07 07:26:15 +00:00
SListNode* pNode = NULL;
void* batch = streamStateCreateBatch();
2023-04-03 06:31:37 +00:00
while ((pNode = tdListNext(&iter)) != NULL && code == TSDB_CODE_SUCCESS) {
SRowBuffPos* pPos = *(SRowBuffPos**)pNode->data;
2023-04-07 04:50:59 +00:00
ASSERT(pPos->pRowBuff && pFileState->rowSize > 0);
2023-04-07 07:26:15 +00:00
if (streamStateGetBatchSize(batch) >= BATCH_LIMIT) {
code = streamStatePutBatch_rocksdb(pFileState->pFileStore, batch);
streamStateClearBatch(batch);
}
2023-04-10 04:51:00 +00:00
SStateKey sKey = {.key = *((SWinKey*)pPos->pKey), .opNum = ((SStreamState*)pFileState->pFileStore)->number};
2023-04-11 10:47:15 +00:00
code = streamStatePutBatch(pFileState->pFileStore, "state", batch, &sKey, pPos->pRowBuff, pFileState->rowSize);
2023-04-06 08:33:00 +00:00
}
2023-04-07 07:26:15 +00:00
if (streamStateGetBatchSize(batch) > 0) {
code = streamStatePutBatch_rocksdb(pFileState->pFileStore, batch);
}
2023-04-12 05:50:01 +00:00
streamStateClearBatch(batch);
2023-04-07 07:26:15 +00:00
2023-04-06 08:33:00 +00:00
if (flushState) {
2023-04-11 14:04:39 +00:00
const char* taskKey = "streamFileState";
{
char keyBuf[128] = {0};
void* valBuf = NULL;
int32_t len = 0;
sprintf(keyBuf, "%s:%" PRId64 "", taskKey, ((SStreamState*)pFileState->pFileStore)->checkPointId);
streamFileStateEncode(&pFileState->flushMark, &valBuf, &len);
2023-04-12 07:39:54 +00:00
code = streamStatePutBatch(pFileState->pFileStore, "default", batch, keyBuf, valBuf, len);
2023-04-11 14:04:39 +00:00
taosMemoryFree(valBuf);
}
{
char keyBuf[128] = {0};
char valBuf[64] = {0};
int32_t len = 0;
2023-04-12 03:03:51 +00:00
memcpy(keyBuf, taskKey, strlen(taskKey));
2023-04-12 07:39:54 +00:00
len = sprintf(valBuf, "%" PRId64 "", ((SStreamState*)pFileState->pFileStore)->checkPointId);
code = streamStatePutBatch(pFileState->pFileStore, "default", batch, keyBuf, valBuf, len);
2023-04-11 14:04:39 +00:00
}
streamStatePutBatch_rocksdb(pFileState->pFileStore, batch);
2023-04-03 06:31:37 +00:00
}
2023-04-11 10:47:15 +00:00
streamStateDestroyBatch(batch);
2023-04-12 07:39:54 +00:00
2023-04-03 06:31:37 +00:00
return code;
}
2023-04-12 09:33:58 +00:00
2023-04-12 03:03:51 +00:00
int32_t forceRemoveCheckpoint(SStreamFileState* pFileState, int64_t checkpointId) {
const char* taskKey = "streamFileState";
char keyBuf[128] = {0};
sprintf(keyBuf, "%s:%" PRId64 "", taskKey, checkpointId);
return streamDefaultDel_rocksdb(pFileState->pFileStore, keyBuf);
}
2023-04-12 09:33:58 +00:00
2023-04-12 03:03:51 +00:00
int32_t getSnapshotIdList(SStreamFileState* pFileState, SArray* list) {
const char* taskKey = "streamFileState";
2023-04-14 09:36:08 +00:00
return streamDefaultIterGet_rocksdb(pFileState->pFileStore, taskKey, NULL, list);
2023-04-12 03:03:51 +00:00
}
2023-04-12 09:33:58 +00:00
int32_t deleteExpiredCheckPoint(SStreamFileState* pFileState, TSKEY mark) {
2023-04-11 14:04:39 +00:00
int32_t code = TSDB_CODE_SUCCESS;
const char* taskKey = "streamFileState";
int64_t maxCheckPointId = 0;
{
char buf[128] = {0};
void* val = NULL;
int32_t len = 0;
2023-04-12 03:03:51 +00:00
memcpy(buf, taskKey, strlen(taskKey));
2023-04-11 14:04:39 +00:00
code = streamDefaultGet_rocksdb(pFileState->pFileStore, buf, &val, &len);
if (code != 0) {
return TSDB_CODE_FAILED;
}
sscanf(val, "%" PRId64 "", &maxCheckPointId);
}
2023-04-11 14:13:35 +00:00
for (int64_t i = maxCheckPointId; i > 0; i--) {
2023-04-11 14:04:39 +00:00
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);
2023-04-12 09:33:58 +00:00
if (ts < mark) {
2023-04-14 14:05:59 +00:00
// statekey winkey.ts < mark
2023-04-12 03:03:51 +00:00
forceRemoveCheckpoint(pFileState, i);
2023-04-11 14:04:39 +00:00
break;
2023-04-11 14:21:16 +00:00
} else {
2023-04-11 14:04:39 +00:00
}
}
2023-04-12 09:33:58 +00:00
return code;
}
2023-04-11 14:04:39 +00:00
2023-04-12 09:33:58 +00:00
int32_t recoverSnapshot(SStreamFileState* pFileState) {
int32_t code = TSDB_CODE_SUCCESS;
deleteExpiredCheckPoint(pFileState, pFileState->maxTs - pFileState->deleteMark);
2023-04-07 07:26:15 +00:00
void* pStVal = NULL;
2023-04-06 08:33:00 +00:00
int32_t len = 0;
2023-04-14 14:05:59 +00:00
SWinKey key = {.groupId = 0, .ts = 0};
SStreamStateCur* pCur = streamStateSeekToLast_rocksdb(pFileState->pFileStore, &key);
2023-04-14 09:36:08 +00:00
if (pCur == NULL) {
return -1;
2023-04-06 08:33:00 +00:00
}
2023-04-14 09:36:08 +00:00
2023-04-06 08:33:00 +00:00
while (code == TSDB_CODE_SUCCESS) {
if (pFileState->curRowCount == pFileState->maxRowCount) {
break;
}
2023-04-07 07:26:15 +00:00
void* pVal = NULL;
int32_t pVLen = 0;
2023-04-06 08:33:00 +00:00
SRowBuffPos* pNewPos = getNewRowPos(pFileState);
2023-04-07 07:26:15 +00:00
code = streamStateGetKVByCur_rocksdb(pCur, pNewPos->pKey, (const void**)&pVal, &pVLen);
2023-04-06 08:33:00 +00:00
if (code != TSDB_CODE_SUCCESS || pFileState->getTs(pNewPos->pKey) < pFileState->flushMark) {
destroyRowBuffPos(pNewPos);
2023-04-18 01:50:13 +00:00
SListNode* pNode = tdListPopTail(pFileState->usedBuffs);
taosMemoryFreeClear(pNode);
2023-04-06 08:33:00 +00:00
break;
}
memcpy(pNewPos->pRowBuff, pVal, pVLen);
code = tSimpleHashPut(pFileState->rowBuffMap, pNewPos->pKey, pFileState->rowSize, &pNewPos, POINTER_BYTES);
if (code != TSDB_CODE_SUCCESS) {
destroyRowBuffPos(pNewPos);
break;
}
code = streamStateCurPrev_rocksdb(pFileState->pFileStore, pCur);
}
2023-04-17 15:01:47 +00:00
streamStateFreeCur(pCur);
2023-04-06 08:33:00 +00:00
2023-04-03 06:31:37 +00:00
return TSDB_CODE_SUCCESS;
}