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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _STREAM_FILE_STATE_H_
|
|
|
|
|
#define _STREAM_FILE_STATE_H_
|
|
|
|
|
|
2024-07-17 11:35:35 +00:00
|
|
|
#include "storageapi.h"
|
2023-04-12 03:03:51 +00:00
|
|
|
#include "tarray.h"
|
2023-04-03 06:31:37 +00:00
|
|
|
#include "tdef.h"
|
|
|
|
|
#include "tlist.h"
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
typedef struct SStreamFileState SStreamFileState;
|
2023-09-20 07:06:08 +00:00
|
|
|
typedef SList SStreamSnapshot;
|
|
|
|
|
|
2024-07-17 11:35:35 +00:00
|
|
|
typedef void* (*_state_buff_get_fn)(void* pRowBuff, const void* pKey, size_t keyLen);
|
2023-10-07 09:43:50 +00:00
|
|
|
typedef int32_t (*_state_buff_remove_fn)(void* pRowBuff, const void* pKey, size_t keyLen);
|
2024-07-18 02:09:15 +00:00
|
|
|
typedef void (*_state_buff_remove_by_pos_fn)(SStreamFileState* pState, SRowBuffPos* pPos);
|
2024-07-17 11:35:35 +00:00
|
|
|
typedef void (*_state_buff_cleanup_fn)(void* pRowBuff);
|
|
|
|
|
typedef void* (*_state_buff_create_statekey_fn)(SRowBuffPos* pPos, int64_t num);
|
2023-09-20 07:06:08 +00:00
|
|
|
|
|
|
|
|
typedef int32_t (*_state_file_remove_fn)(SStreamFileState* pFileState, const void* pKey);
|
2024-07-12 03:03:45 +00:00
|
|
|
typedef int32_t (*_state_file_get_fn)(SStreamFileState* pFileState, void* pKey, void** data, int32_t* pDataLen);
|
2023-09-20 07:06:08 +00:00
|
|
|
typedef int32_t (*_state_file_clear_fn)(SStreamState* pState);
|
2023-04-03 06:31:37 +00:00
|
|
|
|
2024-07-17 11:35:35 +00:00
|
|
|
typedef int32_t (*_state_fun_get_fn)(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal,
|
|
|
|
|
int32_t* pVLen, int32_t* pWinCode);
|
2024-04-10 09:41:59 +00:00
|
|
|
|
2024-02-04 08:04:23 +00:00
|
|
|
typedef int32_t (*range_cmpr_fn)(const SSessionKey* pWin1, const SSessionKey* pWin2);
|
|
|
|
|
|
2024-07-12 03:03:45 +00:00
|
|
|
typedef int (*__session_compare_fn_t)(const void* pWin, const void* pDatas, int pos);
|
|
|
|
|
|
2024-09-14 02:51:57 +00:00
|
|
|
int32_t streamFileStateInit(int64_t memSize, uint32_t keySize, uint32_t rowSize, uint32_t selectRowSize, GetTsFun fp,
|
|
|
|
|
void* pFile, TSKEY delMark, const char* taskId, int64_t checkpointId, int8_t type,
|
|
|
|
|
struct SStreamFileState** ppFileState);
|
2023-04-04 09:08:24 +00:00
|
|
|
void streamFileStateDestroy(SStreamFileState* pFileState);
|
|
|
|
|
void streamFileStateClear(SStreamFileState* pFileState);
|
2023-04-26 10:58:19 +00:00
|
|
|
bool needClearDiskBuff(SStreamFileState* pFileState);
|
2023-09-20 07:06:08 +00:00
|
|
|
void streamFileStateReleaseBuff(SStreamFileState* pFileState, SRowBuffPos* pPos, bool used);
|
2024-07-17 11:35:35 +00:00
|
|
|
void streamFileStateClearBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
2025-03-28 10:10:57 +00:00
|
|
|
int32_t getFileStateRowSize(SStreamFileState* pFileState);
|
2023-04-03 06:31:37 +00:00
|
|
|
|
2024-08-06 08:14:15 +00:00
|
|
|
int32_t addRowBuffIfNotExist(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen,
|
|
|
|
|
int32_t* pWinCode);
|
2025-03-14 12:14:01 +00:00
|
|
|
int32_t createRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen);
|
|
|
|
|
|
2024-07-17 11:35:35 +00:00
|
|
|
int32_t getRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen,
|
|
|
|
|
int32_t* pWinCode);
|
|
|
|
|
void deleteRowBuff(SStreamFileState* pFileState, const void* pKey, int32_t keyLen);
|
2025-02-20 03:52:04 +00:00
|
|
|
void deleteRowBuffByGroupId(SStreamFileState* pFileState, uint64_t groupId);
|
2023-04-04 09:08:24 +00:00
|
|
|
int32_t getRowBuffByPos(SStreamFileState* pFileState, SRowBuffPos* pPos, void** pVal);
|
2025-03-14 12:14:01 +00:00
|
|
|
bool hasRowBuff(SStreamFileState* pFileState, const SWinKey* pKey, bool hasLimit, bool* pIsLast);
|
2024-07-18 02:37:14 +00:00
|
|
|
int32_t putFreeBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
2023-04-03 06:31:37 +00:00
|
|
|
|
|
|
|
|
SStreamSnapshot* getSnapshot(SStreamFileState* pFileState);
|
2024-07-17 11:35:35 +00:00
|
|
|
void flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot, bool flushState);
|
2024-09-14 02:51:57 +00:00
|
|
|
int32_t recoverSnapshot(SStreamFileState* pFileState, int64_t ckId);
|
2023-04-12 03:03:51 +00:00
|
|
|
|
2023-04-12 09:33:58 +00:00
|
|
|
int32_t deleteExpiredCheckPoint(SStreamFileState* pFileState, TSKEY mark);
|
2024-04-10 09:41:59 +00:00
|
|
|
int32_t streamFileStateGetSelectRowSize(SStreamFileState* pFileState);
|
2023-06-15 06:13:17 +00:00
|
|
|
void streamFileStateReloadInfo(SStreamFileState* pFileState, TSKEY ts);
|
2023-04-03 06:31:37 +00:00
|
|
|
|
2024-07-17 11:35:35 +00:00
|
|
|
void* getRowStateBuff(SStreamFileState* pFileState);
|
2024-07-26 08:44:18 +00:00
|
|
|
void* getSearchBuff(SStreamFileState* pFileState);
|
2024-07-17 11:35:35 +00:00
|
|
|
void* getStateFileStore(SStreamFileState* pFileState);
|
|
|
|
|
bool isDeteled(SStreamFileState* pFileState, TSKEY ts);
|
|
|
|
|
bool isFlushedState(SStreamFileState* pFileState, TSKEY ts, TSKEY gap);
|
2024-07-26 08:44:18 +00:00
|
|
|
TSKEY getFlushMark(SStreamFileState* pFileState);
|
2023-09-20 07:06:08 +00:00
|
|
|
SRowBuffPos* getNewRowPosForWrite(SStreamFileState* pFileState);
|
2024-07-17 11:35:35 +00:00
|
|
|
int32_t getRowStateRowSize(SStreamFileState* pFileState);
|
2025-03-14 12:14:01 +00:00
|
|
|
void freeArrayPtr(void* ptr);
|
2023-09-20 07:06:08 +00:00
|
|
|
|
|
|
|
|
// session window
|
2024-07-17 11:35:35 +00:00
|
|
|
int32_t getSessionWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, TSKEY gap, void** pVal, int32_t* pVLen,
|
|
|
|
|
int32_t* pWinCode);
|
2023-09-22 11:25:19 +00:00
|
|
|
int32_t putSessionWinResultBuff(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
2024-07-18 02:37:14 +00:00
|
|
|
int32_t getSessionFlushedBuff(SStreamFileState* pFileState, SSessionKey* pKey, void** pVal, int32_t* pVLen,
|
|
|
|
|
int32_t* pWinCode);
|
2023-10-25 09:50:16 +00:00
|
|
|
int32_t deleteSessionWinStateBuffFn(void* pBuff, const void* key, size_t keyLen);
|
2024-07-18 02:09:15 +00:00
|
|
|
void deleteSessionWinStateBuffByPosFn(SStreamFileState* pFileState, SRowBuffPos* pPos);
|
2023-10-25 09:50:16 +00:00
|
|
|
int32_t allocSessioncWinBuffByNextPosition(SStreamFileState* pFileState, SStreamStateCur* pCur,
|
|
|
|
|
const SSessionKey* pWinKey, void** ppVal, int32_t* pVLen);
|
2023-09-20 07:06:08 +00:00
|
|
|
|
2023-10-13 03:32:35 +00:00
|
|
|
SRowBuffPos* createSessionWinBuff(SStreamFileState* pFileState, SSessionKey* pKey, void* p, int32_t* pVLen);
|
2024-11-27 00:40:19 +00:00
|
|
|
int32_t recoverSession(SStreamFileState* pFileState, int64_t ckId);
|
2023-10-13 03:32:35 +00:00
|
|
|
|
2023-09-20 07:06:08 +00:00
|
|
|
void sessionWinStateClear(SStreamFileState* pFileState);
|
|
|
|
|
void sessionWinStateCleanup(void* pBuff);
|
|
|
|
|
|
2024-08-06 08:14:15 +00:00
|
|
|
SStreamStateCur* createStateCursor(SStreamFileState* pFileState);
|
2023-09-20 07:06:08 +00:00
|
|
|
SStreamStateCur* sessionWinStateSeekKeyCurrentPrev(SStreamFileState* pFileState, const SSessionKey* pWinKey);
|
|
|
|
|
SStreamStateCur* sessionWinStateSeekKeyCurrentNext(SStreamFileState* pFileState, const SSessionKey* pWinKey);
|
2025-02-12 15:33:15 +00:00
|
|
|
SStreamStateCur* sessionWinStateSeekKeyPrev(SStreamFileState* pFileState, const SSessionKey* pWinKey);
|
2023-09-20 07:06:08 +00:00
|
|
|
SStreamStateCur* sessionWinStateSeekKeyNext(SStreamFileState* pFileState, const SSessionKey* pWinKey);
|
2024-02-04 08:04:23 +00:00
|
|
|
SStreamStateCur* countWinStateSeekKeyPrev(SStreamFileState* pFileState, const SSessionKey* pWinKey, COUNT_TYPE count);
|
2024-07-17 11:35:35 +00:00
|
|
|
int32_t sessionWinStateGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
|
|
|
|
void sessionWinStateMoveToNext(SStreamStateCur* pCur);
|
2025-02-12 15:33:15 +00:00
|
|
|
void sessionWinStateMoveToPrev(SStreamStateCur* pCur);
|
2024-07-17 11:35:35 +00:00
|
|
|
int32_t sessionWinStateGetKeyByRange(SStreamFileState* pFileState, const SSessionKey* key, SSessionKey* curKey,
|
|
|
|
|
range_cmpr_fn cmpFn);
|
2023-09-20 07:06:08 +00:00
|
|
|
|
2024-07-12 03:03:45 +00:00
|
|
|
int32_t binarySearch(void* keyList, int num, const void* key, __session_compare_fn_t cmpFn);
|
|
|
|
|
|
2023-09-20 07:06:08 +00:00
|
|
|
// state window
|
|
|
|
|
int32_t getStateWinResultBuff(SStreamFileState* pFileState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
2024-07-17 11:35:35 +00:00
|
|
|
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen, int32_t* pWinCode);
|
2023-09-20 07:06:08 +00:00
|
|
|
|
2024-01-17 06:22:19 +00:00
|
|
|
// count window
|
2024-07-17 11:35:35 +00:00
|
|
|
int32_t getCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal,
|
|
|
|
|
int32_t* pVLen, int32_t* pWinCode);
|
2024-09-29 06:16:16 +00:00
|
|
|
int32_t createCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, COUNT_TYPE winCount, void** pVal, int32_t* pVLen);
|
2024-01-17 06:22:19 +00:00
|
|
|
|
2024-07-17 11:35:35 +00:00
|
|
|
// function
|
|
|
|
|
int32_t getSessionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen,
|
|
|
|
|
int32_t* pWinCode);
|
2024-04-10 09:41:59 +00:00
|
|
|
int32_t getFunctionRowBuff(SStreamFileState* pFileState, void* pKey, int32_t keyLen, void** pVal, int32_t* pVLen);
|
|
|
|
|
|
2024-07-30 08:06:40 +00:00
|
|
|
// time slice
|
2024-08-02 05:22:14 +00:00
|
|
|
int32_t getHashSortRowBuff(SStreamFileState* pFileState, const SWinKey* pKey, void** pVal, int32_t* pVLen,
|
|
|
|
|
int32_t* pWinCode);
|
2024-07-12 03:03:45 +00:00
|
|
|
int32_t hashSortFileGetFn(SStreamFileState* pFileState, void* pKey, void** data, int32_t* pDataLen);
|
|
|
|
|
int32_t hashSortFileRemoveFn(SStreamFileState* pFileState, const void* pKey);
|
|
|
|
|
void clearSearchBuff(SStreamFileState* pFileState);
|
2024-07-26 08:44:18 +00:00
|
|
|
int32_t getHashSortNextRow(SStreamFileState* pFileState, const SWinKey* pKey, SWinKey* pResKey, void** pVal,
|
2024-08-02 05:22:14 +00:00
|
|
|
int32_t* pVLen, int32_t* pWinCode);
|
2024-08-14 07:22:42 +00:00
|
|
|
int32_t getHashSortPrevRow(SStreamFileState* pFileState, const SWinKey* pKey, SWinKey* pResKey, void** ppVal,
|
2024-08-02 05:22:14 +00:00
|
|
|
int32_t* pVLen, int32_t* pWinCode);
|
2024-07-12 03:03:45 +00:00
|
|
|
int32_t recoverFillSnapshot(SStreamFileState* pFileState, int64_t ckId);
|
2024-07-30 08:06:40 +00:00
|
|
|
void deleteHashSortRowBuff(SStreamFileState* pFileState, const SWinKey* pKey);
|
2024-07-12 03:03:45 +00:00
|
|
|
|
2024-08-06 08:14:15 +00:00
|
|
|
//group
|
|
|
|
|
int32_t streamFileStateGroupPut(SStreamFileState* pFileState, int64_t groupId, void* value, int32_t vLen);
|
|
|
|
|
void streamFileStateGroupCurNext(SStreamStateCur* pCur);
|
|
|
|
|
int32_t streamFileStateGroupGetKVByCur(SStreamStateCur* pCur, int64_t* pKey, void** pVal, int32_t* pVLen);
|
2024-09-24 08:58:46 +00:00
|
|
|
SSHashObj* getGroupIdCache(SStreamFileState* pFileState);
|
2024-10-16 04:16:59 +00:00
|
|
|
int fillStateKeyCompare(const void* pWin1, const void* pDatas, int pos);
|
|
|
|
|
int32_t getRowStatePrevRow(SStreamFileState* pFileState, const SWinKey* pKey, SWinKey* pResKey, void** ppVal,
|
|
|
|
|
int32_t* pVLen, int32_t* pWinCode);
|
2025-03-14 12:14:01 +00:00
|
|
|
int32_t addSearchItem(SStreamFileState* pFileState, SArray* pWinStates, const SWinKey* pKey, bool* pIsEnd);
|
|
|
|
|
int32_t getRowStateAllPrevRow(SStreamFileState* pFileState, const SWinKey* pKey, SArray* pResArray, int32_t maxNum);
|
2024-10-16 04:16:59 +00:00
|
|
|
|
|
|
|
|
//twa
|
2024-10-17 06:55:07 +00:00
|
|
|
void setFillInfo(SStreamFileState* pFileState);
|
2025-03-14 12:14:01 +00:00
|
|
|
void clearExpiredState(SStreamFileState* pFileState, int32_t numOfKeep, TSKEY minTs);
|
2024-10-17 06:55:07 +00:00
|
|
|
int32_t addArrayBuffIfNotExist(SSHashObj* pSearchBuff, uint64_t groupId, SArray** ppResStates);
|
2025-03-14 12:14:01 +00:00
|
|
|
int32_t recoverHashSortBuff(SStreamFileState* pFileState, SArray* pWinStates, uint64_t groupId);
|
|
|
|
|
|
|
|
|
|
int32_t getAndSetTsData(STableTsDataState* pTsDataState, uint64_t tableUid, TSKEY* pCurTs, void** ppCurPkVal,
|
|
|
|
|
TSKEY lastTs, void* pLastPkVal, int32_t lastPkLen, int32_t* pWinCode);
|
|
|
|
|
int32_t doTsDataCommit(STableTsDataState* pTsDataState);
|
|
|
|
|
int32_t doRangeDataCommit(STableTsDataState* pTsDataState);
|
|
|
|
|
int32_t initTsDataState(STableTsDataState** ppTsDataState, int8_t pkType, int32_t pkLen, void* pState,
|
|
|
|
|
void* pOtherState);
|
|
|
|
|
void destroyTsDataState(STableTsDataState* pTsDataState);
|
|
|
|
|
int32_t recoverTsData(STableTsDataState* pTsDataState);
|
|
|
|
|
int32_t mergeAndSaveScanRange(STableTsDataState* pTsDataState, STimeWindow* pWin, uint64_t gpId, SRecDataInfo* pRecData,
|
|
|
|
|
int32_t len);
|
|
|
|
|
int32_t mergeAllScanRange(STableTsDataState* pTsDataState);
|
|
|
|
|
int32_t popScanRange(STableTsDataState* pTsDataState, SScanRange* pRange);
|
|
|
|
|
|
|
|
|
|
// continuous
|
|
|
|
|
typedef void* (*getStateBuffFn)(SStreamFileState* pFileState);
|
|
|
|
|
SStreamStateCur* getLastStateCur(SStreamFileState* pFileState, getStateBuffFn fn);
|
|
|
|
|
void moveLastStateCurNext(SStreamStateCur* pCur, getStateBuffFn fn);
|
|
|
|
|
void moveOneStateCurNext(SStreamStateCur* pCur);
|
|
|
|
|
int32_t getNLastStateKVByCur(SStreamStateCur* pCur, int32_t num, SArray* pRes);
|
|
|
|
|
int32_t getNLastSessionStateKVByCur(SStreamStateCur* pCur, int32_t num, SArray* pRes);
|
|
|
|
|
int32_t reloadTsDataState(STableTsDataState* pTsDataState);
|
|
|
|
|
int32_t setStateRecFlag(SStreamFileState* pState, const void* pKey, int32_t keyLen, int32_t mode);
|
|
|
|
|
int32_t getStateRecFlag(SStreamFileState* pFileState, const void* pKey, int32_t keyLen, int32_t* pMode);
|
|
|
|
|
void clearExpiredSessionState(struct SStreamFileState* pFileState, int32_t numOfKeep, TSKEY minTs,
|
|
|
|
|
SSHashObj* pFlushGroup);
|
|
|
|
|
bool hasSessionState(SStreamFileState* pFileState, SSessionKey* pKey, TSKEY gap, bool* pIsLast);
|
|
|
|
|
int32_t saveRecInfoToDisk(STableTsDataState* pTsDataState, SSessionKey* pKey, SRecDataInfo* pVal, int32_t vLen);
|
|
|
|
|
int32_t flushRemainRecInfoToDisk(STableTsDataState* pTsDataState);
|
2024-08-06 08:14:15 +00:00
|
|
|
|
2023-04-03 06:31:37 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif // _STREAM_FILE_STATE_H_
|