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

266 lines
8.8 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 "sync.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-04-08 06:49:07 +00:00
#include "tmallocator.h"
#include "tmsgcb.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"
2021-11-07 07:58:32 +00:00
#ifdef __cplusplus
extern "C" {
#endif
typedef struct SVnodeInfo SVnodeInfo;
typedef struct SMeta SMeta;
typedef struct SSma SSma;
typedef struct STsdb STsdb;
typedef struct STQ STQ;
typedef struct SVState SVState;
typedef struct SVBufPool SVBufPool;
typedef struct SQWorker SQHandle;
typedef struct STsdbKeepCfg STsdbKeepCfg;
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-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"
2022-04-16 10:17:33 +00:00
2022-04-26 11:04:26 +00:00
// vnd.h
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
// meta
typedef struct SMCtbCursor SMCtbCursor;
typedef struct STbUidStore STbUidStore;
int metaOpen(SVnode* pVnode, SMeta** ppMeta);
int metaClose(SMeta* pMeta);
int metaBegin(SMeta* pMeta);
int metaCommit(SMeta* pMeta);
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);
2022-04-28 06:20:00 +00:00
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
2022-04-26 11:04:26 +00:00
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq);
2022-05-04 03:57:16 +00:00
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq);
2022-04-26 11:04:26 +00:00
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver);
int metaGetTableEntryByName(SMetaReader* pReader, const char* name);
int metaGetTbNum(SMeta* pMeta);
SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid);
void metaCloseCtbCurosr(SMCtbCursor* pCtbCur);
tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
SArray* metaGetSmaTbUids(SMeta* pMeta, bool isDup);
void* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid, bool isDecode);
STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid);
int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg);
2022-04-26 11:04:26 +00:00
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
// tsdb
int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg *pKeepCfg);
int tsdbClose(STsdb** pTsdb);
int tsdbBegin(STsdb* pTsdb);
int tsdbCommit(STsdb* pTsdb);
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp);
2022-05-10 05:57:31 +00:00
int tsdbInsertTableData(STsdb* pTsdb, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkRsp* pRsp);
2022-04-29 08:46:01 +00:00
tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
2022-05-04 03:57:16 +00:00
uint64_t taskId);
tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
void* pMemRef);
int32_t tsdbGetTableGroupFromIdListT(STsdb* tsdb, SArray* pTableIdList, STableGroupInfo* pGroupInfo);
2022-04-26 11:04:26 +00:00
// tq
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal);
void tqClose(STQ*);
int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver);
int tqCommit(STQ*);
int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen);
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
2022-04-27 11:49:04 +00:00
// sma
int32_t smaOpen(SVnode* pVnode);
int32_t smaClose(SSma* pSma);
2022-04-27 11:49:04 +00:00
int32_t tdUpdateExpireWindow(SSma* pSma, SSubmitReq* pMsg, int64_t version);
int32_t tdProcessTSmaCreate(SSma* pSma, char* pMsg);
int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg);
int32_t tdProcessRSmaCreate(SSma* pSma, SMeta* pMeta, SVCreateStbReq* pReq, SMsgCb* pMsgCb);
int32_t tdProcessRSmaSubmit(SSma* pSma, void* pMsg, int32_t inputType);
int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore);
void tdUidStoreDestory(STbUidStore* pStore);
void* tdUidStoreFree(STbUidStore* pStore);
#if 0
int32_t tsdbUpdateSmaWindow(STsdb* pTsdb, SSubmitReq* pMsg, int64_t version);
int32_t tsdbCreateTSma(STsdb* pTsdb, char* pMsg);
int32_t tsdbInsertTSmaData(STsdb* pTsdb, int64_t indexUid, const char* msg);
int32_t tsdbRegisterRSma(STsdb* pTsdb, SMeta* pMeta, SVCreateStbReq* pReq, SMsgCb* pMsgCb);
2022-04-27 11:49:04 +00:00
int32_t tsdbFetchTbUidList(STsdb* pTsdb, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
int32_t tsdbUpdateTbUidList(STsdb* pTsdb, STbUidStore* pUidStore);
void tsdbUidStoreDestory(STbUidStore* pStore);
void* tsdbUidStoreFree(STbUidStore* pStore);
2022-05-01 04:18:54 +00:00
int32_t tsdbTriggerRSma(STsdb* pTsdb, void* pMsg, int32_t inputType);
#endif
2022-04-27 11:49:04 +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 {
2022-04-20 11:30:18 +00:00
// int64_t processed;
2022-01-14 06:33:13 +00:00
int64_t committed;
int64_t applied;
};
2022-04-15 05:47:57 +00:00
struct SVnodeInfo {
SVnodeCfg config;
SVState state;
};
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;
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;
};
2022-05-08 09:04:19 +00:00
2021-11-07 07:58:32 +00:00
struct SVnode {
2022-01-14 06:33:13 +00:00
char* path;
SVnodeCfg config;
SVState state;
2022-04-16 08:19:21 +00:00
STfs* pTfs;
SMsgCb msgCb;
2022-04-20 06:56:34 +00:00
SVBufPool* pPool;
SVBufPool* inUse;
SVBufPool* onCommit;
SVBufPool* onRecycle;
2022-01-14 06:33:13 +00:00
SMeta* pMeta;
SSma* pSma;
2022-01-14 06:33:13 +00:00
STsdb* pTsdb;
SWal* pWal;
2022-03-24 03:34:43 +00:00
STQ* pTq;
SSink* pSink;
int64_t sync;
2022-01-14 06:33:13 +00:00
tsem_t canCommit;
SQHandle* pQuery;
2021-11-07 07:58:32 +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)
#define VND_RSMA1(vnd) ((vnd)->pSma->pRSmaTsdb1)
#define VND_RSMA2(vnd) ((vnd)->pSma->pRSmaTsdb2)
2022-05-08 09:04:19 +00:00
#define VND_RETENTIONS(vnd) (&(vnd)->config.tsdbCfg.retentions)
2022-04-29 10:07:50 +00:00
2022-04-26 11:04:26 +00:00
struct STbUidStore {
tb_uid_t suid;
2022-05-01 16:30:47 +00:00
tb_uid_t uid; // TODO: just for debugging, remove when uid provided in SSDataBlock
2022-04-26 11:04:26 +00:00
SArray* tbUids;
SHashObj* uidHash;
};
struct SSma {
int16_t nTSma;
bool locked;
TdThreadMutex mutex;
SVnode* pVnode;
STsdb* pRSmaTsdb1;
STsdb* pRSmaTsdb2;
void* pTSmaEnv;
void* pRSmaEnv;
};
#define SMA_CFG(s) (&(s)->pVnode->config)
#define SMA_TSDB_CFG(s) (&(s)->pVnode->config.tsdbCfg)
#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_NUM(s) ((s)->nTSma)
#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)->pRSmaTsdb1)
#define SMA_RSMA_TSDB2(s) ((s)->pRSmaTsdb2)
2022-04-16 07:50:05 +00:00
2022-05-01 02:50:23 +00:00
static FORCE_INLINE bool vnodeIsRollup(SVnode* pVnode) {
2022-04-29 10:07:50 +00:00
SRetention* pRetention = &(pVnode->config.tsdbCfg.retentions[0]);
return (pRetention->freq > 0 && pRetention->keep > 0);
}
2022-04-23 11:15:20 +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
2021-11-07 07:58:32 +00:00
#ifdef __cplusplus
}
#endif
2022-01-20 02:45:15 +00:00
#endif /*_TD_VNODE_DEF_H_*/