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

253 lines
8.1 KiB
C
Raw Normal View History

2021-09-22 05:21:07 +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/>.
2021-09-22 12:29:24 +00:00
*/
#ifndef _TD_VNODE_H_
#define _TD_VNODE_H_
2021-11-09 05:24:22 +00:00
#include "os.h"
2022-03-21 11:08:25 +00:00
#include "tmsgcb.h"
2022-03-29 10:58:15 +00:00
#include "tqueue.h"
#include "trpc.h"
2021-11-09 05:24:22 +00:00
2022-04-19 09:07:42 +00:00
#include "sync.h"
2021-11-11 03:41:16 +00:00
#include "tarray.h"
2022-01-19 06:04:01 +00:00
#include "tfs.h"
2021-11-24 08:29:02 +00:00
#include "wal.h"
2021-11-01 11:49:44 +00:00
2022-04-14 02:01:04 +00:00
#include "tcommon.h"
#include "tfs.h"
2022-04-08 06:09:15 +00:00
#include "tmallocator.h"
#include "tmsg.h"
#include "trow.h"
2022-04-28 07:02:49 +00:00
#include "tdb.h"
2022-04-24 06:19:12 +00:00
2021-09-22 12:29:24 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-05-01 16:30:47 +00:00
2022-04-14 02:01:04 +00:00
// vnode
2022-05-24 06:50:47 +00:00
typedef struct SVnode SVnode;
typedef struct STsdbCfg STsdbCfg; // todo: remove
typedef struct SVnodeCfg SVnodeCfg;
typedef struct SVSnapshotReader SVSnapshotReader;
2022-04-14 02:10:56 +00:00
2022-04-19 01:57:46 +00:00
extern const SVnodeCfg vnodeCfgDefault;
2022-05-20 02:30:48 +00:00
int32_t vnodeInit(int32_t nthreads);
2022-04-14 02:01:04 +00:00
void vnodeCleanup();
2022-05-20 02:30:48 +00:00
int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs);
2022-04-16 07:04:25 +00:00
void vnodeDestroy(const char *path, STfs *pTfs);
2022-04-16 07:16:10 +00:00
SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb);
2022-04-14 02:01:04 +00:00
void vnodeClose(SVnode *pVnode);
2022-05-23 08:38:05 +00:00
int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg);
2022-05-20 02:30:48 +00:00
int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp);
int32_t vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
2022-06-05 13:46:07 +00:00
int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
2022-05-20 02:30:48 +00:00
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
2022-04-14 02:01:04 +00:00
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
2022-05-20 02:30:48 +00:00
int32_t vnodeValidateTableHash(SVnode *pVnode, char *tableFName);
2022-04-25 07:39:52 +00:00
int32_t vnodeStart(SVnode *pVnode);
void vnodeStop(SVnode *pVnode);
2022-04-19 09:07:42 +00:00
int64_t vnodeGetSyncHandle(SVnode *pVnode);
2022-04-20 11:30:18 +00:00
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot);
void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId);
2022-05-24 06:50:47 +00:00
int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever);
int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader);
2022-05-24 09:21:14 +00:00
int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData);
2022-06-01 07:06:12 +00:00
int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen);
2022-04-19 09:07:42 +00:00
2022-06-08 06:44:42 +00:00
void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
2022-04-14 02:01:04 +00:00
// meta
2022-04-24 05:38:56 +00:00
typedef struct SMeta SMeta; // todo: remove
typedef struct SMetaReader SMetaReader;
typedef struct SMetaEntry SMetaEntry;
2022-05-12 11:21:44 +00:00
void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags);
void metaReaderClear(SMetaReader *pReader);
2022-05-20 02:30:48 +00:00
int32_t metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid);
int32_t metaReadNext(SMetaReader *pReader);
2022-05-31 09:49:33 +00:00
const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t type, STagVal *tagVal);
2022-04-14 02:10:56 +00:00
2022-05-31 10:34:17 +00:00
typedef struct SMetaFltParam {
tb_uid_t suid;
int16_t cid;
int16_t type;
2022-06-10 07:20:57 +00:00
char *val;
2022-05-31 10:34:17 +00:00
bool reverse;
int (*filterFunc)(void *a, void *b, int16_t type);
} SMetaFltParam;
int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *results);
2022-04-24 06:19:12 +00:00
#if 1 // refact APIs below (TODO)
2022-04-14 02:10:56 +00:00
typedef SVCreateTbReq STbCfg;
typedef SVCreateTSmaReq SSmaCfg;
2022-04-24 05:38:56 +00:00
typedef struct SMTbCursor SMTbCursor;
2022-04-14 02:53:10 +00:00
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
void metaCloseTbCursor(SMTbCursor *pTbCur);
2022-05-20 02:30:48 +00:00
int32_t metaTbCursorNext(SMTbCursor *pTbCur);
2022-04-24 05:38:56 +00:00
#endif
2022-04-08 06:09:15 +00:00
2022-04-14 02:01:04 +00:00
// tsdb
// typedef struct STsdb STsdb;
2022-05-07 06:57:31 +00:00
typedef void *tsdbReaderT;
2022-04-14 02:10:56 +00:00
#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
#define BLOCK_LOAD_TABLE_RR_ORDER 3
2022-04-14 02:53:10 +00:00
2022-06-10 07:20:57 +00:00
tsdbReaderT *tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableInfoGroup, uint64_t qId,
uint64_t taskId);
2022-05-26 08:05:27 +00:00
tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *groupList, uint64_t qId,
2022-04-14 02:01:04 +00:00
void *pMemRef);
int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo);
bool isTsdbCacheLastRow(tsdbReaderT *pReader);
2022-05-28 08:15:24 +00:00
int32_t tsdbGetAllTableList(SMeta *pMeta, uint64_t uid, SArray *list);
2022-06-02 03:01:05 +00:00
int32_t tsdbGetCtbIdList(SMeta *pMeta, int64_t suid, SArray *list);
2022-06-10 07:20:57 +00:00
void *tsdbGetIdx(SMeta *pMeta);
void *tsdbGetIvtIdx(SMeta *pMeta);
2022-04-14 02:01:04 +00:00
int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT *pHandle);
2022-05-28 08:15:24 +00:00
bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle);
void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo);
2022-05-07 06:57:31 +00:00
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg ***pBlockStatis, bool *allHave);
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond *pCond, int32_t tWinIdx);
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
2022-04-14 02:01:04 +00:00
// tq
2022-04-14 02:10:56 +00:00
typedef struct STqReadHandle STqReadHandle;
STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta);
void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList);
2022-05-20 02:30:48 +00:00
int32_t tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
int32_t tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
2022-05-23 07:47:49 +00:00
int32_t tqReadHandleRemoveTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
2022-04-14 02:10:56 +00:00
int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver);
bool tqNextDataBlock(STqReadHandle *pHandle);
bool tqNextDataBlockFilterOut(STqReadHandle *pHandle, SHashObj *filterOutUids);
2022-05-07 06:57:31 +00:00
int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *pGroupId, uint64_t *pUid,
int32_t *pNumOfRows, int16_t *pNumOfCols);
2022-04-14 02:01:04 +00:00
2022-06-01 11:06:58 +00:00
// sma
int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days);
2022-04-14 02:13:47 +00:00
// need to reposition
2022-04-08 06:09:15 +00:00
2022-04-14 02:01:04 +00:00
// structs
struct STsdbCfg {
2022-05-08 09:09:00 +00:00
int8_t precision;
int8_t update;
int8_t compression;
int8_t slLevel;
int32_t minRows;
int32_t maxRows;
int32_t days; // just for save config, don't use in tsdbRead/tsdbCommit/..., and use STsdbKeepCfg in STsdb instead
int32_t keep0; // just for save config, don't use in tsdbRead/tsdbCommit/..., and use STsdbKeepCfg in STsdb instead
int32_t keep1; // just for save config, don't use in tsdbRead/tsdbCommit/..., and use STsdbKeepCfg in STsdb instead
int32_t keep2; // just for save config, don't use in tsdbRead/tsdbCommit/..., and use STsdbKeepCfg in STsdb instead
2022-05-07 14:33:19 +00:00
SRetention retentions[TSDB_RETENTION_MAX];
};
2022-04-14 02:01:04 +00:00
struct SVnodeCfg {
2022-01-13 08:57:18 +00:00
int32_t vgId;
2022-05-08 14:20:53 +00:00
char dbname[TSDB_DB_FNAME_LEN];
2022-02-11 11:52:07 +00:00
uint64_t dbId;
2022-04-19 13:10:03 +00:00
int32_t szPage;
int32_t szCache;
2022-04-20 06:56:34 +00:00
uint64_t szBuf;
bool isHeap;
2022-01-13 08:57:18 +00:00
bool isWeak;
2022-05-31 13:07:52 +00:00
int8_t isTsma;
2022-06-01 07:06:12 +00:00
int8_t isRsma;
2022-05-31 13:07:52 +00:00
int8_t hashMethod;
int8_t standby;
2021-11-26 05:43:38 +00:00
STsdbCfg tsdbCfg;
2022-01-13 08:57:18 +00:00
SWalCfg walCfg;
2022-05-08 14:22:47 +00:00
SSyncCfg syncCfg;
2022-03-03 01:09:11 +00:00
uint32_t hashBegin;
uint32_t hashEnd;
2022-04-14 02:01:04 +00:00
};
2021-11-07 07:58:32 +00:00
2022-04-14 02:01:04 +00:00
typedef struct {
TSKEY lastKey;
uint64_t uid;
} STableKeyInfo;
2022-04-24 05:38:56 +00:00
struct SMetaEntry {
2022-05-23 07:47:49 +00:00
int64_t version;
int8_t type;
tb_uid_t uid;
2022-06-10 07:20:57 +00:00
char *name;
2022-04-24 05:38:56 +00:00
union {
struct {
2022-05-26 08:29:52 +00:00
SSchemaWrapper schemaRow;
2022-04-24 05:38:56 +00:00
SSchemaWrapper schemaTag;
} stbEntry;
struct {
2022-05-23 07:47:49 +00:00
int64_t ctime;
int32_t ttlDays;
tb_uid_t suid;
uint8_t *pTags;
2022-04-24 05:38:56 +00:00
} ctbEntry;
struct {
int64_t ctime;
int32_t ttlDays;
2022-05-16 06:17:56 +00:00
int32_t ncid; // next column id
2022-05-26 08:29:52 +00:00
SSchemaWrapper schemaRow;
2022-04-24 05:38:56 +00:00
} ntbEntry;
struct {
2022-05-15 14:03:02 +00:00
STSma *tsma;
} smaEntry;
2022-04-24 05:38:56 +00:00
};
2022-05-16 12:13:59 +00:00
uint8_t *pBuf;
2022-04-24 05:38:56 +00:00
};
struct SMetaReader {
int32_t flags;
2022-06-10 07:20:57 +00:00
SMeta *pMeta;
2022-05-07 10:03:06 +00:00
SDecoder coder;
2022-04-24 05:38:56 +00:00
SMetaEntry me;
2022-06-10 07:20:57 +00:00
void *pBuf;
2022-05-20 02:30:48 +00:00
int32_t szBuf;
2022-04-24 05:38:56 +00:00
};
2022-04-24 06:19:12 +00:00
struct SMTbCursor {
2022-06-10 07:20:57 +00:00
TBC *pDbc;
void *pKey;
void *pVal;
2022-05-20 02:30:48 +00:00
int32_t kLen;
int32_t vLen;
2022-04-24 06:19:12 +00:00
SMetaReader mr;
};
2021-09-22 12:29:24 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_H_*/