TDengine/source/dnode/vnode/src/inc/vnodeInt.h

636 lines
25 KiB
C
Raw Normal View History

2021-11-07 07:58:32 +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/>.
*/
2022-01-14 06:55:24 +00:00
#ifndef _TD_VNODE_DEF_H_
#define _TD_VNODE_DEF_H_
2021-11-07 07:58:32 +00:00
2022-04-08 06:49:07 +00:00
#include "executor.h"
2022-04-14 02:25:49 +00:00
#include "filter.h"
#include "qworker.h"
#include "rocksdb/c.h"
2022-04-14 02:25:49 +00:00
#include "sync.h"
2022-07-04 11:24:54 +00:00
#include "tRealloc.h"
2022-04-08 06:49:07 +00:00
#include "tchecksum.h"
2021-12-13 08:31:39 +00:00
#include "tcoding.h"
2022-04-19 13:10:03 +00:00
#include "tcompare.h"
2022-04-08 06:49:07 +00:00
#include "tcompression.h"
2022-03-28 06:55:15 +00:00
#include "tdatablock.h"
2022-04-28 07:02:49 +00:00
#include "tdb.h"
2022-04-21 03:47:58 +00:00
#include "tencode.h"
2022-01-14 06:33:13 +00:00
#include "tfs.h"
2022-04-08 06:49:07 +00:00
#include "tglobal.h"
2022-04-15 06:27:04 +00:00
#include "tjson.h"
2021-12-17 06:12:01 +00:00
#include "tlist.h"
2021-11-09 09:52:06 +00:00
#include "tlockfree.h"
2022-04-14 02:25:49 +00:00
#include "tlosertree.h"
2022-06-23 03:08:19 +00:00
#include "tlrucache.h"
#include "tmsgcb.h"
2022-08-24 09:29:28 +00:00
#include "trbtree.h"
2022-07-04 05:21:02 +00:00
#include "tref.h"
2022-04-08 06:41:42 +00:00
#include "tskiplist.h"
2022-04-14 02:25:49 +00:00
#include "tstream.h"
2022-04-08 06:41:42 +00:00
#include "ttime.h"
2022-04-08 06:49:07 +00:00
#include "ttimer.h"
#include "wal.h"
2021-11-07 07:58:32 +00:00
2022-04-14 05:53:45 +00:00
#include "vnode.h"
2024-01-24 09:44:44 +00:00
#include "taos_monitor.h"
2021-11-07 07:58:32 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-08-01 11:12:37 +00:00
typedef struct SVnodeInfo SVnodeInfo;
typedef struct SMeta SMeta;
typedef struct SSma SSma;
typedef struct STsdb STsdb;
typedef struct STQ STQ;
typedef struct SVState SVState;
2022-10-10 10:20:53 +00:00
typedef struct SVStatis SVStatis;
2022-08-01 11:12:37 +00:00
typedef struct SVBufPool SVBufPool;
typedef struct SQueueWorker SQHandle;
2022-08-01 11:12:37 +00:00
typedef struct STsdbKeepCfg STsdbKeepCfg;
typedef struct SMetaSnapReader SMetaSnapReader;
typedef struct SMetaSnapWriter SMetaSnapWriter;
typedef struct STsdbSnapReader STsdbSnapReader;
typedef struct STsdbSnapWriter STsdbSnapWriter;
typedef struct STsdbSnapRAWReader STsdbSnapRAWReader;
typedef struct STsdbSnapRAWWriter STsdbSnapRAWWriter;
2022-08-01 11:12:37 +00:00
typedef struct STqSnapReader STqSnapReader;
typedef struct STqSnapWriter STqSnapWriter;
typedef struct STqOffsetReader STqOffsetReader;
typedef struct STqOffsetWriter STqOffsetWriter;
2023-09-13 10:09:47 +00:00
typedef struct STqCheckInfoReader STqCheckInfoReader;
typedef struct STqCheckInfoWriter STqCheckInfoWriter;
2022-08-01 11:12:37 +00:00
typedef struct SStreamTaskReader SStreamTaskReader;
typedef struct SStreamTaskWriter SStreamTaskWriter;
typedef struct SStreamStateReader SStreamStateReader;
typedef struct SStreamStateWriter SStreamStateWriter;
typedef struct SRSmaSnapReader SRSmaSnapReader;
typedef struct SRSmaSnapWriter SRSmaSnapWriter;
2022-08-01 11:12:37 +00:00
typedef struct SSnapDataHdr SSnapDataHdr;
2022-12-04 07:14:04 +00:00
typedef struct SCommitInfo SCommitInfo;
2023-02-10 08:24:29 +00:00
typedef struct SCompactInfo SCompactInfo;
2023-01-09 07:51:30 +00:00
typedef struct SQueryNode SQueryNode;
2022-01-14 06:33:13 +00:00
2022-04-29 10:07:50 +00:00
#define VNODE_META_DIR "meta"
#define VNODE_TSDB_DIR "tsdb"
#define VNODE_TQ_DIR "tq"
#define VNODE_WAL_DIR "wal"
#define VNODE_TSMA_DIR "tsma"
2022-06-28 06:11:44 +00:00
#define VNODE_RSMA_DIR "rsma"
2022-05-08 09:04:19 +00:00
#define VNODE_RSMA0_DIR "tsdb"
2022-04-29 10:07:50 +00:00
#define VNODE_RSMA1_DIR "rsma1"
#define VNODE_RSMA2_DIR "rsma2"
2023-06-28 09:57:08 +00:00
#define VNODE_TQ_STREAM "stream"
2022-04-16 10:17:33 +00:00
2023-12-25 08:13:30 +00:00
#if SUSPEND_RESUME_TEST // only for test purpose
#define VNODE_BUFPOOL_SEGMENTS 1
#else
2023-01-05 07:40:15 +00:00
#define VNODE_BUFPOOL_SEGMENTS 3
#endif
2023-01-05 07:40:15 +00:00
2023-08-03 08:24:50 +00:00
#define VND_INFO_FNAME "vnode.json"
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
2022-12-09 07:50:22 +00:00
2024-03-07 06:33:45 +00:00
#define VNODE_METRIC_SQL_COUNT "taosd_sql_req:count"
2024-01-24 09:44:44 +00:00
2024-03-15 10:22:57 +00:00
#define VNODE_METRIC_TAG_NAME_SQL_TYPE "sql_type"
2024-01-24 09:44:44 +00:00
#define VNODE_METRIC_TAG_NAME_CLUSTER_ID "cluster_id"
2024-03-15 10:22:57 +00:00
#define VNODE_METRIC_TAG_NAME_DNODE_ID "dnode_id"
#define VNODE_METRIC_TAG_NAME_DNODE_EP "dnode_ep"
#define VNODE_METRIC_TAG_NAME_VGROUP_ID "vgroup_id"
#define VNODE_METRIC_TAG_NAME_USERNAME "username"
#define VNODE_METRIC_TAG_NAME_RESULT "result"
2024-01-24 09:44:44 +00:00
2024-02-05 01:34:20 +00:00
#define VNODE_METRIC_TAG_VALUE_INSERT_AFFECTED_ROWS "inserted_rows"
2024-03-15 10:22:57 +00:00
// #define VNODE_METRIC_TAG_VALUE_INSERT "insert"
// #define VNODE_METRIC_TAG_VALUE_DELETE "delete"
2024-01-24 09:44:44 +00:00
2022-04-26 11:04:26 +00:00
// vnd.h
2023-01-09 07:51:30 +00:00
typedef int32_t (*_query_reseek_func_t)(void* pQHandle);
struct SQueryNode {
SQueryNode* pNext;
SQueryNode** ppNext;
void* pQHandle;
_query_reseek_func_t reseek;
};
2023-05-29 02:12:27 +00:00
#if 1 // refact APIs below (TODO)
typedef SVCreateTbReq STbCfg;
typedef SVCreateTSmaReq SSmaCfg;
SMTbCursor* metaOpenTbCursor(void* pVnode);
void metaCloseTbCursor(SMTbCursor* pTbCur);
void metaPauseTbCursor(SMTbCursor* pTbCur);
2024-03-22 02:33:46 +00:00
void metaResumeTbCursor(SMTbCursor* pTbCur, int8_t first, int8_t move);
int32_t metaTbCursorNext(SMTbCursor* pTbCur, ETableType jumpTableType);
int32_t metaTbCursorPrev(SMTbCursor* pTbCur, ETableType jumpTableType);
2023-05-29 02:12:27 +00:00
#endif
2022-07-04 12:04:40 +00:00
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
void* vnodeBufPoolMallocAligned(SVBufPool* pPool, int size);
2022-07-04 12:04:40 +00:00
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
2022-07-19 08:30:49 +00:00
void vnodeBufPoolRef(SVBufPool* pPool);
2023-01-10 03:36:40 +00:00
void vnodeBufPoolUnRef(SVBufPool* pPool, bool proactive);
2022-12-09 07:50:22 +00:00
int vnodeDecodeInfo(uint8_t* pData, SVnodeInfo* pInfo);
2022-04-26 11:04:26 +00:00
2023-01-09 11:03:09 +00:00
int32_t vnodeBufPoolRegisterQuery(SVBufPool* pPool, SQueryNode* pQNode);
2023-01-10 03:36:40 +00:00
void vnodeBufPoolDeregisterQuery(SVBufPool* pPool, SQueryNode* pQNode, bool proactive);
2023-01-09 07:51:30 +00:00
2022-04-26 11:04:26 +00:00
// meta
typedef struct SMCtbCursor SMCtbCursor;
2022-06-26 10:44:49 +00:00
typedef struct SMStbCursor SMStbCursor;
2022-04-26 11:04:26 +00:00
typedef struct STbUidStore STbUidStore;
#define META_BEGIN_HEAP_BUFFERPOOL 0
#define META_BEGIN_HEAP_OS 1
#define META_BEGIN_HEAP_NIL 2
2022-10-18 05:38:26 +00:00
int metaOpen(SVnode* pVnode, SMeta** ppMeta, int8_t rollback);
2023-07-05 07:58:09 +00:00
int metaUpgrade(SVnode* pVnode, SMeta** ppMeta);
int metaClose(SMeta** pMeta);
int metaBegin(SMeta* pMeta, int8_t fromSys);
TXN* metaGetTxn(SMeta* pMeta);
int metaCommit(SMeta* pMeta, TXN* txn);
int metaFinishCommit(SMeta* pMeta, TXN* txn);
int metaPrepareAsyncCommit(SMeta* pMeta);
int metaAbort(SMeta* pMeta);
2022-04-26 11:04:26 +00:00
int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
2022-05-14 14:29:04 +00:00
int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq, SArray* tbUidList);
2022-09-02 07:34:16 +00:00
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq, STableMetaRsp** pMetaRsp);
2022-09-07 03:05:00 +00:00
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids, int64_t* tbUid);
2023-06-01 00:13:32 +00:00
int32_t metaTrimTables(SMeta* pMeta);
void metaDropTables(SMeta* pMeta, SArray* tbUids);
int metaTtlFindExpired(SMeta* pMeta, int64_t timePointMs, SArray* tbUids, int32_t ttlDropMaxCount);
2022-06-04 07:38:27 +00:00
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
int metaUpdateChangeTimeWithLock(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs);
2022-10-10 03:00:55 +00:00
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
2022-07-04 08:26:16 +00:00
int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema);
2022-04-26 11:04:26 +00:00
int metaGetTableEntryByName(SMetaReader* pReader, const char* name);
2022-10-09 07:01:20 +00:00
int metaAlterCache(SMeta* pMeta, int32_t nPage);
2022-09-29 03:07:32 +00:00
int32_t metaUidCacheClear(SMeta* pMeta, uint64_t suid);
int32_t metaTbGroupCacheClear(SMeta* pMeta, uint64_t suid);
2023-05-29 02:12:27 +00:00
2023-01-06 13:33:42 +00:00
int metaAddIndexToSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
2023-02-04 13:02:06 +00:00
int metaDropIndexFromSTable(SMeta* pMeta, int64_t version, SDropIndexReq* pReq);
2023-01-06 13:33:42 +00:00
2023-09-15 06:33:35 +00:00
int64_t metaGetTimeSeriesNum(SMeta* pMeta, int type);
void metaUpdTimeSeriesNum(SMeta* pMeta);
2023-08-10 09:30:01 +00:00
SMCtbCursor* metaOpenCtbCursor(void* pVnode, tb_uid_t uid, int lock);
int32_t metaResumeCtbCursor(SMCtbCursor* pCtbCur, int8_t first);
void metaPauseCtbCursor(SMCtbCursor* pCtbCur);
void metaCloseCtbCursor(SMCtbCursor* pCtbCur);
2022-09-29 03:07:32 +00:00
tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
SMStbCursor* metaOpenStbCursor(SMeta* pMeta, tb_uid_t uid);
void metaCloseStbCursor(SMStbCursor* pStbCur);
tb_uid_t metaStbCursorNext(SMStbCursor* pStbCur);
STSma* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid);
STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid, bool deepCopy);
SArray* metaGetSmaIdsByTable(SMeta* pMeta, tb_uid_t uid);
SArray* metaGetSmaTbUids(SMeta* pMeta);
void* metaGetIdx(SMeta* pMeta);
void* metaGetIvtIdx(SMeta* pMeta);
2022-05-16 15:55:17 +00:00
2023-07-14 05:46:01 +00:00
int64_t metaGetTbNum(SMeta* pMeta);
void metaReaderDoInit(SMetaReader* pReader, SMeta* pMeta, int32_t flags);
int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg);
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
2022-04-26 11:04:26 +00:00
2022-08-16 06:22:55 +00:00
typedef struct SMetaInfo {
int64_t uid;
int64_t suid;
int64_t version;
int32_t skmVer;
} SMetaInfo;
int32_t metaGetInfo(SMeta* pMeta, int64_t uid, SMetaInfo* pInfo, SMetaReader* pReader);
2022-08-16 06:22:55 +00:00
2022-04-26 11:04:26 +00:00
// tsdb
int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback, bool force);
int tsdbClose(STsdb** pTsdb);
int32_t tsdbBegin(STsdb* pTsdb);
2023-07-14 05:46:01 +00:00
// int32_t tsdbPrepareCommit(STsdb* pTsdb);
// int32_t tsdbCommit(STsdb* pTsdb, SCommitInfo* pInfo);
int32_t tsdbCacheCommit(STsdb* pTsdb);
int32_t tsdbCacheNewTable(STsdb* pTsdb, int64_t uid, tb_uid_t suid, SSchemaWrapper* pSchemaRow);
int32_t tsdbCacheDropTable(STsdb* pTsdb, int64_t uid, tb_uid_t suid, SSchemaWrapper* pSchemaRow);
int32_t tsdbCacheDropSubTables(STsdb* pTsdb, SArray* uids, tb_uid_t suid);
int32_t tsdbCacheNewSTableColumn(STsdb* pTsdb, SArray* uids, int16_t cid, int8_t col_type);
2024-04-03 01:34:56 +00:00
int32_t tsdbCacheDropSTableColumn(STsdb* pTsdb, SArray* uids, int16_t cid, bool hasPrimayKey);
int32_t tsdbCacheNewNTableColumn(STsdb* pTsdb, int64_t uid, int16_t cid, int8_t col_type);
2024-04-03 01:34:56 +00:00
int32_t tsdbCacheDropNTableColumn(STsdb* pTsdb, int64_t uid, int16_t cid, bool hasPrimayKey);
int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq2* pMsg);
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq2* pMsg, SSubmitRsp2* pRsp);
2022-11-29 09:29:49 +00:00
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitTbData* pSubmitTbData, int32_t* affectedRows);
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg);
int64_t tsdbGetEarliestTs(STsdb* pTsdb);
2022-04-26 11:04:26 +00:00
// tq
2023-06-07 14:32:48 +00:00
STQ* tqOpen(const char* path, SVnode* pVnode);
void tqNotifyClose(STQ*);
void tqClose(STQ*);
int tqPushMsg(STQ*, tmsg_t msgType);
2023-06-07 14:32:48 +00:00
int tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg);
int tqUnregisterPushHandle(STQ* pTq, void* pHandle);
2023-08-31 03:01:53 +00:00
int tqScanWalAsync(STQ* pTq, bool ckPause);
int32_t tqStopStreamTasksAsync(STQ* pTq);
int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp);
2023-09-26 04:15:12 +00:00
int32_t tqProcessTaskCheckpointReadyMsg(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskRetrieveTriggerReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskRetrieveTriggerRsp(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskUpdateReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskResetReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessStreamHbRsp(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessStreamReqCheckpointRsp(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskChkptReportRsp(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskCheckpointReadyRsp(STQ* pTq, SRpcMsg* pMsg);
int32_t tqBuildStreamTask(void* pTq, SStreamTask* pTask, int64_t ver);
int32_t tqScanWal(STQ* pTq);
2022-04-26 11:04:26 +00:00
int tqCommit(STQ*);
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
2022-07-22 08:05:28 +00:00
int32_t tqCheckColModifiable(STQ* pTq, int64_t tbUid, int32_t colId);
// tq-mq
int32_t tqProcessAddCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
2022-10-31 10:37:28 +00:00
int32_t tqProcessSubscribeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
int32_t tqProcessSeekReq(STQ* pTq, SRpcMsg* pMsg);
2022-07-21 12:15:52 +00:00
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessPollPush(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessVgCommittedInfoReq(STQ* pTq, SRpcMsg* pMsg);
// tq-stream
int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
int32_t tqProcessTaskDropReq(STQ* pTq, char* msg, int32_t msgLen);
2023-03-28 11:39:38 +00:00
int32_t tqProcessTaskPauseReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
int32_t tqProcessTaskResumeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
2023-09-26 04:15:12 +00:00
int32_t tqProcessTaskCheckReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskCheckRsp(STQ* pTq, SRpcMsg* pMsg);
2022-05-20 10:53:21 +00:00
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg);
2022-05-20 10:53:21 +00:00
int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg);
2022-06-22 09:56:46 +00:00
int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg);
2023-06-12 14:48:23 +00:00
int32_t tqProcessTaskScanHistory(STQ* pTq, SRpcMsg* pMsg);
2024-02-07 03:40:47 +00:00
int32_t tqStreamProgressRetrieveReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskUpdateCheckpointReq(STQ* pTq, char* msg, int32_t msgLen);
2022-04-26 11:04:26 +00:00
2022-04-27 11:49:04 +00:00
// sma
2022-07-09 07:44:37 +00:00
int32_t smaInit();
void smaCleanUp();
int32_t smaOpen(SVnode* pVnode, int8_t rollback, bool force);
int32_t smaClose(SSma* pSma);
2022-07-02 07:17:41 +00:00
int32_t smaBegin(SSma* pSma);
2022-12-04 12:26:58 +00:00
int32_t smaPrepareAsyncCommit(SSma* pSma);
2022-12-04 07:14:04 +00:00
int32_t smaCommit(SSma* pSma, SCommitInfo* pInfo);
2022-10-19 09:18:41 +00:00
int32_t smaFinishCommit(SSma* pSma);
int32_t smaPostCommit(SSma* pSma);
2023-10-31 12:26:42 +00:00
int32_t smaRetention(SSma* pSma, int64_t now);
2022-04-27 11:49:04 +00:00
2022-05-16 15:55:17 +00:00
int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg);
int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg);
int32_t tdProcessRSmaCreate(SSma* pSma, SVCreateStbReq* pReq);
2023-11-09 11:51:01 +00:00
int32_t tdProcessRSmaSubmit(SSma* pSma, int64_t version, void* pReq, void* pMsg, int32_t len);
int32_t tdProcessRSmaDelete(SSma* pSma, int64_t version, void* pReq, void* pMsg, int32_t len);
int32_t tdProcessRSmaDrop(SSma* pSma, SVDropStbReq* pReq);
int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore, bool isAdd);
void* tdUidStoreFree(STbUidStore* pStore);
2022-07-04 12:04:40 +00:00
// SMetaSnapReader ========================================
int32_t metaSnapReaderOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapReader** ppReader);
int32_t metaSnapReaderClose(SMetaSnapReader** ppReader);
2022-07-04 12:24:34 +00:00
int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData);
2022-07-04 12:04:40 +00:00
// SMetaSnapWriter ========================================
2022-07-05 11:55:07 +00:00
int32_t metaSnapWriterOpen(SMeta* pMeta, int64_t sver, int64_t ever, SMetaSnapWriter** ppWriter);
int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback);
2022-07-04 12:04:40 +00:00
// STsdbSnapReader ========================================
int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type, void* pRanges,
STsdbSnapReader** ppReader);
2022-07-04 12:04:40 +00:00
int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader);
2022-07-04 13:07:13 +00:00
int32_t tsdbSnapRead(STsdbSnapReader* pReader, uint8_t** ppData);
2022-07-04 12:04:40 +00:00
// STsdbSnapWriter ========================================
int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, void* pRanges, STsdbSnapWriter** ppWriter);
2023-01-18 06:59:02 +00:00
int32_t tsdbSnapWrite(STsdbSnapWriter* pWriter, SSnapDataHdr* pHdr);
2022-12-09 08:19:49 +00:00
int32_t tsdbSnapWriterPrepareClose(STsdbSnapWriter* pWriter);
2022-07-05 11:55:07 +00:00
int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback);
// STsdbSnapRAWReader ========================================
int32_t tsdbSnapRAWReaderOpen(STsdb* pTsdb, int64_t ever, int8_t type, STsdbSnapRAWReader** ppReader);
int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** ppReader);
int32_t tsdbSnapRAWRead(STsdbSnapRAWReader* pReader, uint8_t** ppData);
// STsdbSnapRAWWriter ========================================
int32_t tsdbSnapRAWWriterOpen(STsdb* pTsdb, int64_t ever, STsdbSnapRAWWriter** ppWriter);
int32_t tsdbSnapRAWWrite(STsdbSnapRAWWriter* pWriter, SSnapDataHdr* pHdr);
int32_t tsdbSnapRAWWriterPrepareClose(STsdbSnapRAWWriter* pWriter);
int32_t tsdbSnapRAWWriterClose(STsdbSnapRAWWriter** ppWriter, int8_t rollback);
2022-08-01 11:12:37 +00:00
// STqSnapshotReader ==
int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapReader** ppReader);
int32_t tqSnapReaderClose(STqSnapReader** ppReader);
int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData);
// STqSnapshotWriter ======================================
int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** ppWriter);
int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback);
int32_t tqSnapWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
2023-09-13 10:09:47 +00:00
// STqCheckInfoshotReader ==
int32_t tqCheckInfoReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqCheckInfoReader** ppReader);
int32_t tqCheckInfoReaderClose(STqCheckInfoReader** ppReader);
int32_t tqCheckInfoRead(STqCheckInfoReader* pReader, uint8_t** ppData);
// STqCheckInfoshotWriter ======================================
int32_t tqCheckInfoWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqCheckInfoWriter** ppWriter);
int32_t tqCheckInfoWriterClose(STqCheckInfoWriter** ppWriter, int8_t rollback);
int32_t tqCheckInfoWrite(STqCheckInfoWriter* pWriter, uint8_t* pData, uint32_t nData);
2022-08-01 11:12:37 +00:00
// STqOffsetReader ========================================
int32_t tqOffsetReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqOffsetReader** ppReader);
int32_t tqOffsetReaderClose(STqOffsetReader** ppReader);
int32_t tqOffsetSnapRead(STqOffsetReader* pReader, uint8_t** ppData);
// STqOffsetWriter ========================================
int32_t tqOffsetWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqOffsetWriter** ppWriter);
int32_t tqOffsetWriterClose(STqOffsetWriter** ppWriter, int8_t rollback);
int32_t tqOffsetSnapWrite(STqOffsetWriter* pWriter, uint8_t* pData, uint32_t nData);
// SStreamTaskWriter ======================================
2023-06-28 07:02:20 +00:00
int32_t streamTaskSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTaskReader** ppReader);
int32_t streamTaskSnapReaderClose(SStreamTaskReader* pReader);
int32_t streamTaskSnapRead(SStreamTaskReader* pReader, uint8_t** ppData);
int32_t streamTaskSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTaskWriter** ppWriter);
int32_t streamTaskSnapWriterClose(SStreamTaskWriter* ppWriter, int8_t rollback);
int32_t streamTaskSnapWrite(SStreamTaskWriter* pWriter, uint8_t* pData, uint32_t nData);
int32_t streamStateSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamStateReader** ppReader);
int32_t streamStateSnapReaderClose(SStreamStateReader* pReader);
int32_t streamStateSnapRead(SStreamStateReader* pReader, uint8_t** ppData);
int32_t streamStateSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamStateWriter** ppWriter);
int32_t streamStateSnapWriterClose(SStreamStateWriter* pWriter, int8_t rollback);
int32_t streamStateSnapWrite(SStreamStateWriter* pWriter, uint8_t* pData, uint32_t nData);
2023-08-14 02:03:41 +00:00
int32_t streamStateRebuildFromSnap(SStreamStateWriter* pWriter, int64_t chkpId);
2023-08-03 08:24:50 +00:00
2023-08-07 08:51:01 +00:00
int32_t streamStateLoadTasks(SStreamStateWriter* pWriter);
2022-08-01 11:12:37 +00:00
// SStreamTaskReader ======================================
// SStreamStateWriter =====================================
// SStreamStateReader =====================================
// SRSmaSnapReader ========================================
int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapReader** ppReader);
int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader);
int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData);
// SRSmaSnapWriter ========================================
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, void** ppRanges, SRSmaSnapWriter** ppWriter);
int32_t rsmaSnapWrite(SRSmaSnapWriter* pWriter, uint8_t* pData, uint32_t nData);
2023-10-08 09:03:07 +00:00
int32_t rsmaSnapWriterPrepareClose(SRSmaSnapWriter* pWriter);
int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback);
2022-07-05 11:55:07 +00:00
2022-03-24 03:34:43 +00:00
typedef struct {
int8_t streamType; // sma or other
int8_t dstType;
int16_t padding;
int32_t smaId;
int64_t tbUid;
int64_t lastReceivedVer;
int64_t lastCommittedVer;
} SStreamSinkInfo;
typedef struct {
SVnode* pVnode;
SHashObj* pHash; // streamId -> SStreamSinkInfo
} SSink;
2022-01-14 06:33:13 +00:00
// SVState
struct SVState {
int64_t committed;
int64_t applied;
2022-07-06 09:46:14 +00:00
int64_t applyTerm;
2022-06-23 03:08:19 +00:00
int64_t commitID;
2022-07-06 09:46:14 +00:00
int64_t commitTerm;
2022-01-14 06:33:13 +00:00
};
2022-10-10 10:20:53 +00:00
struct SVStatis {
2022-10-11 09:47:23 +00:00
int64_t nInsert; // delta
int64_t nInsertSuccess; // delta
int64_t nBatchInsert; // delta
int64_t nBatchInsertSuccess; // delta
2022-10-10 10:20:53 +00:00
};
2022-04-15 05:47:57 +00:00
struct SVnodeInfo {
SVnodeCfg config;
SVState state;
2022-10-10 10:20:53 +00:00
SVStatis statis;
2022-04-15 05:47:57 +00:00
};
2022-05-08 09:04:19 +00:00
typedef enum {
TSDB_TYPE_TSDB = 0, // TSDB
TSDB_TYPE_TSMA = 1, // TSMA
TSDB_TYPE_RSMA_L0 = 2, // RSMA Level 0
TSDB_TYPE_RSMA_L1 = 3, // RSMA Level 1
TSDB_TYPE_RSMA_L2 = 4, // RSMA Level 2
} ETsdbType;
2022-05-16 20:26:37 +00:00
struct STsdbKeepCfg {
2022-05-08 09:04:19 +00:00
int8_t precision; // precision always be used with below keep cfgs
int32_t days;
int32_t keep0;
int32_t keep1;
int32_t keep2;
int32_t keepTimeOffset;
};
2022-05-08 09:04:19 +00:00
typedef struct SVCommitSched {
int64_t commitMs;
int64_t maxWaitMs;
} SVCommitSched;
2024-03-15 10:22:57 +00:00
typedef struct SVMonitorObj {
char strClusterId[TSDB_CLUSTER_ID_LEN];
char strDnodeId[TSDB_NODE_ID_LEN];
char strVgId[TSDB_VGROUP_ID_LEN];
taos_counter_t* insertCounter;
} SVMonitorObj;
2024-01-24 09:44:44 +00:00
2024-05-23 09:57:07 +00:00
typedef struct {
int64_t async;
int64_t id;
} SVAChannelID;
typedef struct {
int64_t async;
int64_t id;
} SVATaskID;
2021-11-07 07:58:32 +00:00
struct SVnode {
2023-01-05 07:40:15 +00:00
char* path;
SVnodeCfg config;
SVState state;
SVStatis statis;
STfs* pTfs;
int32_t diskPrimary;
2023-01-05 07:40:15 +00:00
SMsgCb msgCb;
// Buffer Pool
2022-07-19 08:30:49 +00:00
TdThreadMutex mutex;
TdThreadCond poolNotEmpty;
2023-01-05 07:40:15 +00:00
SVBufPool* aBufPool[VNODE_BUFPOOL_SEGMENTS];
SVBufPool* freeList;
2022-07-19 08:30:49 +00:00
SVBufPool* inUse;
2023-01-09 01:24:26 +00:00
SVBufPool* onCommit;
SVBufPool* recycleHead;
SVBufPool* recycleTail;
2023-01-09 06:54:49 +00:00
SVBufPool* onRecycle;
2023-01-05 07:40:15 +00:00
2023-11-29 10:01:31 +00:00
// commit variables
2024-05-23 09:57:07 +00:00
SVAChannelID commitChannel;
SVATaskID commitTask;
2023-11-29 10:01:31 +00:00
2022-07-19 08:30:49 +00:00
SMeta* pMeta;
SSma* pSma;
STsdb* pTsdb;
SWal* pWal;
STQ* pTq;
SSink* pSink;
int64_t sync;
TdThreadMutex lock;
bool blocked;
bool restored;
2022-07-19 08:30:49 +00:00
tsem_t syncSem;
int32_t blockSec;
int64_t blockSeq;
2022-07-19 08:30:49 +00:00
SQHandle* pQuery;
2024-01-24 09:44:44 +00:00
SVMonitorObj monitor;
2021-11-07 07:58:32 +00:00
};
2022-06-09 12:02:55 +00:00
#define TD_VID(PVNODE) ((PVNODE)->config.vgId)
2022-05-08 09:04:19 +00:00
#define VND_TSDB(vnd) ((vnd)->pTsdb)
#define VND_RSMA0(vnd) ((vnd)->pTsdb)
2022-07-19 09:57:59 +00:00
#define VND_RSMA1(vnd) ((vnd)->pSma->pRSmaTsdb[TSDB_RETENTION_L0])
#define VND_RSMA2(vnd) ((vnd)->pSma->pRSmaTsdb[TSDB_RETENTION_L1])
2022-05-08 09:04:19 +00:00
#define VND_RETENTIONS(vnd) (&(vnd)->config.tsdbCfg.retentions)
2022-06-01 07:06:12 +00:00
#define VND_IS_RSMA(v) ((v)->config.isRsma == 1)
#define VND_IS_TSMA(v) ((v)->config.isTsma == 1)
2022-04-29 10:07:50 +00:00
#define TSDB_CACHE_NO(c) ((c).cacheLast == 0)
#define TSDB_CACHE_LAST_ROW(c) (((c).cacheLast & 1) > 0)
#define TSDB_CACHE_LAST(c) (((c).cacheLast & 2) > 0)
2022-04-26 11:04:26 +00:00
struct STbUidStore {
tb_uid_t suid;
SArray* tbUids;
SHashObj* uidHash;
};
struct SSma {
bool locked;
TdThreadMutex mutex;
SVnode* pVnode;
2022-07-19 09:57:59 +00:00
STsdb* pRSmaTsdb[TSDB_RETENTION_L2];
void* pTSmaEnv;
void* pRSmaEnv;
};
2023-11-29 10:01:31 +00:00
#define SMA_CFG(s) (&(s)->pVnode->config)
#define SMA_TSDB_CFG(s) (&(s)->pVnode->config.tsdbCfg)
#define SMA_RETENTION(s) ((SRetention*)&(s)->pVnode->config.tsdbCfg.retentions)
#define SMA_LOCKED(s) ((s)->locked)
#define SMA_META(s) ((s)->pVnode->pMeta)
#define SMA_VID(s) TD_VID((s)->pVnode)
#define SMA_TFS(s) ((s)->pVnode->pTfs)
#define SMA_TSMA_ENV(s) ((s)->pTSmaEnv)
#define SMA_RSMA_ENV(s) ((s)->pRSmaEnv)
#define SMA_RSMA_TSDB0(s) ((s)->pVnode->pTsdb)
#define SMA_RSMA_TSDB1(s) ((s)->pRSmaTsdb[TSDB_RETENTION_L0])
#define SMA_RSMA_TSDB2(s) ((s)->pRSmaTsdb[TSDB_RETENTION_L1])
#define SMA_RSMA_GET_TSDB(pVnode, level) ((level == 0) ? pVnode->pTsdb : pVnode->pSma->pRSmaTsdb[level - 1])
2022-04-16 07:50:05 +00:00
2022-03-28 06:40:22 +00:00
// sma
2022-03-28 06:55:15 +00:00
void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
2022-03-28 06:40:22 +00:00
2022-07-29 16:38:11 +00:00
enum {
2022-08-18 07:29:42 +00:00
SNAP_DATA_CFG = 0,
2022-08-02 08:13:36 +00:00
SNAP_DATA_META = 1,
SNAP_DATA_TSDB = 2,
SNAP_DATA_DEL = 3,
SNAP_DATA_RSMA1 = 4,
SNAP_DATA_RSMA2 = 5,
SNAP_DATA_QTASK = 6,
SNAP_DATA_TQ_HANDLE = 7,
SNAP_DATA_TQ_OFFSET = 8,
SNAP_DATA_STREAM_TASK = 9,
2023-06-28 02:39:01 +00:00
SNAP_DATA_STREAM_TASK_CHECKPOINT = 10,
SNAP_DATA_STREAM_STATE = 11,
SNAP_DATA_STREAM_STATE_BACKEND = 12,
2023-09-13 10:09:47 +00:00
SNAP_DATA_TQ_CHECKINFO = 13,
SNAP_DATA_RAW = 14,
2022-07-29 16:38:11 +00:00
};
2022-07-04 12:24:34 +00:00
struct SSnapDataHdr {
int8_t type;
2022-12-25 13:54:09 +00:00
int8_t flag;
2022-07-12 12:16:40 +00:00
int64_t index;
2022-07-04 12:24:34 +00:00
int64_t size;
uint8_t data[];
};
2022-12-04 07:14:04 +00:00
struct SCommitInfo {
SVnodeInfo info;
SVnode* pVnode;
TXN* txn;
2023-02-10 08:24:29 +00:00
};
2022-12-04 07:14:04 +00:00
2023-02-10 08:24:29 +00:00
struct SCompactInfo {
2023-03-07 13:46:34 +00:00
SVnode* pVnode;
int32_t flag;
int64_t commitID;
STimeWindow tw;
2022-12-21 06:36:12 +00:00
};
2023-02-10 08:24:29 +00:00
void initStorageAPI(SStorageAPI* pAPI);
2024-05-23 09:57:07 +00:00
// a simple hash table impl
typedef struct SVHashTable SVHashTable;
struct SVHashTable {
uint32_t (*hash)(const void*);
int32_t (*compare)(const void*, const void*);
int32_t numEntries;
uint32_t numBuckets;
struct SVHashEntry** buckets;
};
#define vHashNumEntries(ht) ((ht)->numEntries)
int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*));
int32_t vHashDestroy(SVHashTable** ht);
int32_t vHashPut(SVHashTable* ht, void* obj);
int32_t vHashGet(SVHashTable* ht, const void* obj, void** retObj);
int32_t vHashDrop(SVHashTable* ht, const void* obj);
2021-11-07 07:58:32 +00:00
#ifdef __cplusplus
}
#endif
2022-01-20 02:45:15 +00:00
#endif /*_TD_VNODE_DEF_H_*/