TDengine/include/libs/stream/streamState.h

148 lines
6.9 KiB
C
Raw Normal View History

/*
* 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_STATE_H_
#define _STREAM_STATE_H_
#include "tdatablock.h"
2023-03-18 07:36:55 +00:00
#include "rocksdb/c.h"
#include "tdbInt.h"
2023-04-07 10:45:09 +00:00
#include "tsimplehash.h"
2023-04-03 06:31:37 +00:00
#include "tstreamFileState.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "storageapi.h"
2024-06-19 02:29:01 +00:00
SStreamState* streamStateOpen(const char* path, void* pTask, int64_t streamId, int32_t taskId);
2023-04-27 14:38:33 +00:00
void streamStateClose(SStreamState* pState, bool remove);
int32_t streamStateBegin(SStreamState* pState);
2024-07-17 11:35:35 +00:00
void streamStateCommit(SStreamState* pState);
2023-04-27 14:38:33 +00:00
void streamStateDestroy(SStreamState* pState, bool remove);
2023-04-12 09:33:58 +00:00
int32_t streamStateDeleteCheckPoint(SStreamState* pState, TSKEY mark);
2023-10-31 12:59:24 +00:00
int32_t streamStateDelTaskDb(SStreamState* pState);
2023-05-15 08:26:24 +00:00
int32_t streamStateFuncPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
int32_t streamStateFuncGet(SStreamState* pState, const SWinKey* key, void** ppVal, int32_t* pVLen);
int32_t streamStatePut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
2024-07-17 11:35:35 +00:00
int32_t streamStateGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen, int32_t* pWinCode);
2023-04-07 07:26:15 +00:00
bool streamStateCheck(SStreamState* pState, const SWinKey* key);
2023-04-04 09:08:24 +00:00
int32_t streamStateGetByPos(SStreamState* pState, void* pos, void** pVal);
2024-07-17 11:35:35 +00:00
void streamStateDel(SStreamState* pState, const SWinKey* key);
void streamStateClear(SStreamState* pState);
2024-04-10 07:35:25 +00:00
void streamStateSetNumber(SStreamState* pState, int32_t number, int32_t tsIdex);
2024-07-17 11:35:35 +00:00
void streamStateSaveInfo(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
2023-04-14 09:35:17 +00:00
int32_t streamStateGetInfo(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
2022-09-27 10:11:44 +00:00
2023-12-05 09:09:03 +00:00
// session window
2024-07-17 11:35:35 +00:00
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, int32_t* pVLen,
int32_t* pWinCode);
2023-09-20 07:06:08 +00:00
int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, void* value, int32_t vLen);
2024-07-18 02:37:14 +00:00
int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen, int32_t* pWinCode);
2024-07-17 11:35:35 +00:00
void streamStateSessionDel(SStreamState* pState, const SSessionKey* key);
void streamStateSessionReset(SStreamState* pState, void* pVal);
void streamStateSessionClear(SStreamState* pState);
int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
int32_t streamStateSessionGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
2024-02-04 08:04:23 +00:00
int32_t streamStateCountGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
2023-10-25 09:50:16 +00:00
int32_t streamStateSessionAllocWinBuffByNextPosition(SStreamState* pState, SStreamStateCur* pCur,
const SSessionKey* pKey, void** pVal, int32_t* pVLen);
2022-10-18 09:44:00 +00:00
SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key);
2024-02-04 08:04:23 +00:00
SStreamStateCur* streamStateCountSeekKeyPrev(SStreamState* pState, const SSessionKey* pKey, COUNT_TYPE count);
SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, const SSessionKey* key);
SStreamStateCur* streamStateSessionSeekKeyCurrentNext(SStreamState* pState, const SSessionKey* key);
2022-10-18 09:44:00 +00:00
2023-12-05 09:09:03 +00:00
// state window
2023-09-20 07:06:08 +00:00
int32_t streamStateStateAddIfNotExist(SStreamState* pState, 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
2023-10-25 09:50:16 +00:00
// fill
2022-09-27 10:11:44 +00:00
int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
2024-07-17 11:35:35 +00:00
void streamStateFillDel(SStreamState* pState, const SWinKey* key);
2022-09-27 10:11:44 +00:00
2024-07-17 11:35:35 +00:00
int32_t streamStateAddIfNotExist(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen,
int32_t* pWinCode);
void streamStateReleaseBuf(SStreamState* pState, void* pVal, bool used);
void streamStateClearBuff(SStreamState* pState, void* pVal);
void streamStateFreeVal(void* val);
2024-01-17 06:22:19 +00:00
// count window
2024-04-17 02:20:11 +00:00
int32_t streamStateCountWinAddIfNotExist(SStreamState* pState, SSessionKey* pKey, COUNT_TYPE winCount, void** ppVal,
2024-07-17 11:35:35 +00:00
int32_t* pVLen, int32_t* pWinCode);
2024-02-04 08:04:23 +00:00
int32_t streamStateCountWinAdd(SStreamState* pState, SSessionKey* pKey, void** pVal, int32_t* pVLen);
2024-01-17 06:22:19 +00:00
2022-09-27 10:11:44 +00:00
SStreamStateCur* streamStateGetAndCheckCur(SStreamState* pState, SWinKey* key);
SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const SWinKey* key);
2022-09-27 10:11:44 +00:00
SStreamStateCur* streamStateFillSeekKeyNext(SStreamState* pState, const SWinKey* key);
SStreamStateCur* streamStateFillSeekKeyPrev(SStreamState* pState, const SWinKey* key);
void streamStateFreeCur(SStreamStateCur* pCur);
2023-09-22 07:00:26 +00:00
void streamStateResetCur(SStreamStateCur* pCur);
2022-09-27 10:11:44 +00:00
int32_t streamStateGetGroupKVByCur(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
int32_t streamStateGetKVByCur(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
2024-07-17 11:35:35 +00:00
void streamStateCurNext(SStreamState* pState, SStreamStateCur* pCur);
void streamStateCurPrev(SStreamState* pState, SStreamStateCur* pCur);
int32_t streamStatePutParName(SStreamState* pState, int64_t groupId, const char* tbname);
2024-07-17 11:35:35 +00:00
int32_t streamStateGetParName(SStreamState* pState, int64_t groupId, void** pVal, bool onlyCache, int32_t* pWinCode);
2023-06-15 06:13:17 +00:00
void streamStateReloadInfo(SStreamState* pState, TSKEY ts);
2023-12-05 09:09:03 +00:00
void streamStateCopyBackend(SStreamState* src, SStreamState* dst);
2023-09-20 07:06:08 +00:00
SStreamStateCur* createStreamStateCursor();
2023-06-15 06:13:17 +00:00
2023-03-21 12:28:16 +00:00
/***compare func **/
2023-04-11 10:47:15 +00:00
typedef struct SStateChekpoint {
char* taskName;
int64_t checkpointId;
} SStateChekpoint;
2023-03-21 12:28:16 +00:00
// todo refactor
typedef struct SStateKey {
SWinKey key;
int64_t opNum;
} SStateKey;
typedef struct SStateSessionKey {
SSessionKey key;
int64_t opNum;
} SStateSessionKey;
2023-04-23 13:29:18 +00:00
typedef struct SStreamValue {
2023-04-20 04:05:35 +00:00
int64_t unixTimestamp;
int32_t len;
2024-04-17 02:20:11 +00:00
int32_t rawLen;
int8_t compress;
2023-04-23 13:29:18 +00:00
char* data;
} SStreamValue;
2023-04-20 04:05:35 +00:00
2023-03-21 12:28:16 +00:00
int sessionRangeKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2);
int sessionWinKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2);
int stateSessionKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2);
int stateKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2);
2022-10-27 07:51:04 +00:00
#ifdef __cplusplus
}
#endif
2023-10-31 12:59:24 +00:00
#endif /* ifndef _STREAM_STATE_H_ */