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"
|
2021-11-11 03:41:16 +00:00
|
|
|
#include "trpc.h"
|
2021-11-09 05:24:22 +00:00
|
|
|
|
|
|
|
|
#include "meta.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-09 05:24:22 +00:00
|
|
|
#include "tsdb.h"
|
2021-11-24 08:29:02 +00:00
|
|
|
#include "wal.h"
|
2021-11-01 11:49:44 +00:00
|
|
|
|
2021-09-22 12:29:24 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-11-07 07:58:32 +00:00
|
|
|
/* ------------------------ TYPES EXPOSED ------------------------ */
|
2021-11-26 05:43:38 +00:00
|
|
|
typedef struct SVnode SVnode;
|
2022-01-12 00:44:11 +00:00
|
|
|
typedef struct SDnode SDnode;
|
2022-01-12 01:07:34 +00:00
|
|
|
typedef int32_t (*PutReqToVQueryQFp)(SDnode *pDnode, struct SRpcMsg *pReq);
|
2022-01-25 07:18:56 +00:00
|
|
|
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
2022-01-12 00:44:11 +00:00
|
|
|
|
2022-01-21 08:12:02 +00:00
|
|
|
typedef struct STqCfg {
|
|
|
|
|
// TODO
|
|
|
|
|
int32_t reserved;
|
|
|
|
|
} STqCfg;
|
|
|
|
|
|
2021-11-26 05:43:38 +00:00
|
|
|
typedef struct SVnodeCfg {
|
2022-01-13 08:57:18 +00:00
|
|
|
int32_t vgId;
|
2022-01-19 05:39:32 +00:00
|
|
|
SDnode *pDnode;
|
|
|
|
|
STfs *pTfs;
|
2022-01-13 08:57:18 +00:00
|
|
|
uint64_t wsize;
|
|
|
|
|
uint64_t ssize;
|
|
|
|
|
uint64_t lsize;
|
|
|
|
|
bool isHeapAllocator;
|
2021-11-26 05:43:38 +00:00
|
|
|
uint32_t ttl;
|
|
|
|
|
uint32_t keep;
|
2022-01-13 08:57:18 +00:00
|
|
|
bool isWeak;
|
2021-11-26 05:43:38 +00:00
|
|
|
STsdbCfg tsdbCfg;
|
|
|
|
|
SMetaCfg metaCfg;
|
2022-01-13 08:57:18 +00:00
|
|
|
STqCfg tqCfg;
|
|
|
|
|
SWalCfg walCfg;
|
2021-11-26 05:43:38 +00:00
|
|
|
} SVnodeCfg;
|
2021-11-07 07:58:32 +00:00
|
|
|
|
2022-01-11 15:22:08 +00:00
|
|
|
typedef struct {
|
|
|
|
|
int32_t sver;
|
2022-01-19 06:40:28 +00:00
|
|
|
const char *timezone;
|
|
|
|
|
const char *locale;
|
|
|
|
|
const char *charset;
|
2022-01-11 15:22:08 +00:00
|
|
|
uint16_t nthreads; // number of commit threads. 0 for no threads and a schedule queue should be given (TODO)
|
2022-01-12 00:44:11 +00:00
|
|
|
PutReqToVQueryQFp putReqToVQueryQFp;
|
2022-01-25 07:18:56 +00:00
|
|
|
SendReqToDnodeFp sendReqToDnodeFp;
|
2022-01-11 15:22:08 +00:00
|
|
|
} SVnodeOpt;
|
|
|
|
|
|
2022-01-21 08:12:02 +00:00
|
|
|
typedef struct STqReadHandle {
|
2022-01-28 07:24:09 +00:00
|
|
|
int64_t ver;
|
|
|
|
|
uint64_t tbUid;
|
|
|
|
|
SHashObj *tbIdHash;
|
|
|
|
|
const SSubmitMsg *pMsg;
|
|
|
|
|
SSubmitBlk *pBlock;
|
|
|
|
|
SSubmitMsgIter msgIter;
|
|
|
|
|
SSubmitBlkIter blkIter;
|
|
|
|
|
SMeta *pVnodeMeta;
|
|
|
|
|
SArray *pColIdList; // SArray<int32_t>
|
|
|
|
|
int32_t sver;
|
|
|
|
|
SSchemaWrapper *pSchemaWrapper;
|
|
|
|
|
STSchema *pSchema;
|
2022-01-21 08:12:02 +00:00
|
|
|
} STqReadHandle;
|
|
|
|
|
|
2021-11-07 07:58:32 +00:00
|
|
|
/* ------------------------ SVnode ------------------------ */
|
2021-11-29 06:06:16 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Initialize the vnode module
|
2021-11-29 07:42:17 +00:00
|
|
|
*
|
2022-01-11 15:22:08 +00:00
|
|
|
* @param pOption Option of the vnode mnodule
|
2021-11-29 06:06:16 +00:00
|
|
|
* @return int 0 for success and -1 for failure
|
|
|
|
|
*/
|
2022-01-11 15:22:08 +00:00
|
|
|
int vnodeInit(const SVnodeOpt *pOption);
|
2021-11-29 06:06:16 +00:00
|
|
|
|
|
|
|
|
/**
|
2022-01-12 03:35:40 +00:00
|
|
|
* @brief Cleanup the vnode module
|
2021-11-29 07:42:17 +00:00
|
|
|
*
|
2021-11-29 06:06:16 +00:00
|
|
|
*/
|
2022-01-12 03:35:40 +00:00
|
|
|
void vnodeCleanup();
|
2021-11-29 06:06:16 +00:00
|
|
|
|
2021-11-11 03:41:16 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Open a VNODE.
|
|
|
|
|
*
|
|
|
|
|
* @param path path of the vnode
|
2021-11-22 07:39:05 +00:00
|
|
|
* @param pVnodeCfg options of the vnode
|
2021-11-11 03:41:16 +00:00
|
|
|
* @return SVnode* The vnode object
|
|
|
|
|
*/
|
2022-01-12 00:44:11 +00:00
|
|
|
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg);
|
2021-11-11 03:41:16 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Close a VNODE
|
|
|
|
|
*
|
2021-11-12 09:50:46 +00:00
|
|
|
* @param pVnode The vnode object to close
|
2021-11-11 03:41:16 +00:00
|
|
|
*/
|
|
|
|
|
void vnodeClose(SVnode *pVnode);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Destroy a VNODE.
|
|
|
|
|
*
|
|
|
|
|
* @param path Path of the VNODE.
|
|
|
|
|
*/
|
|
|
|
|
void vnodeDestroy(const char *path);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Process an array of write messages.
|
|
|
|
|
*
|
|
|
|
|
* @param pVnode The vnode object.
|
|
|
|
|
* @param pMsgs The array of SRpcMsg
|
|
|
|
|
* @return int 0 for success, -1 for failure
|
|
|
|
|
*/
|
|
|
|
|
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Apply a write request message.
|
|
|
|
|
*
|
|
|
|
|
* @param pVnode The vnode object.
|
|
|
|
|
* @param pMsg The request message
|
2021-11-12 02:53:52 +00:00
|
|
|
* @param pRsp The response message
|
2021-11-11 03:41:16 +00:00
|
|
|
* @return int 0 for success, -1 for failure
|
|
|
|
|
*/
|
|
|
|
|
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
|
|
|
|
|
2021-12-21 12:07:32 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Process a consume message.
|
|
|
|
|
*
|
|
|
|
|
* @param pVnode The vnode object.
|
|
|
|
|
* @param pMsg The request message
|
|
|
|
|
* @param pRsp The response message
|
|
|
|
|
* @return int 0 for success, -1 for failure
|
|
|
|
|
*/
|
|
|
|
|
int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
|
|
|
|
|
2021-11-11 03:41:16 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Process the sync request
|
|
|
|
|
*
|
|
|
|
|
* @param pVnode
|
|
|
|
|
* @param pMsg
|
|
|
|
|
* @param pRsp
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
2021-11-07 07:58:32 +00:00
|
|
|
|
2021-12-21 08:15:38 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Process a query message.
|
|
|
|
|
*
|
|
|
|
|
* @param pVnode The vnode object.
|
|
|
|
|
* @param pMsg The request message
|
|
|
|
|
* @return int 0 for success, -1 for failure
|
|
|
|
|
*/
|
2022-01-25 06:20:52 +00:00
|
|
|
int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
2021-12-21 08:15:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Process a fetch message.
|
|
|
|
|
*
|
|
|
|
|
* @param pVnode The vnode object.
|
|
|
|
|
* @param pMsg The request message
|
|
|
|
|
* @return int 0 for success, -1 for failure
|
|
|
|
|
*/
|
2022-01-25 06:20:52 +00:00
|
|
|
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
2021-12-21 08:15:38 +00:00
|
|
|
|
2021-11-22 07:02:53 +00:00
|
|
|
/* ------------------------ SVnodeCfg ------------------------ */
|
2021-11-11 03:41:16 +00:00
|
|
|
/**
|
|
|
|
|
* @brief Initialize VNODE options.
|
|
|
|
|
*
|
|
|
|
|
* @param pOptions The options object to be initialized. It should not be NULL.
|
|
|
|
|
*/
|
2021-11-22 07:02:53 +00:00
|
|
|
void vnodeOptionsInit(SVnodeCfg *pOptions);
|
2021-11-11 03:41:16 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Clear VNODE options.
|
|
|
|
|
*
|
|
|
|
|
* @param pOptions Options to clear.
|
|
|
|
|
*/
|
2021-11-22 07:02:53 +00:00
|
|
|
void vnodeOptionsClear(SVnodeCfg *pOptions);
|
2021-11-07 07:58:32 +00:00
|
|
|
|
2021-11-09 06:36:53 +00:00
|
|
|
/* ------------------------ FOR COMPILE ------------------------ */
|
|
|
|
|
|
2021-11-01 11:49:44 +00:00
|
|
|
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
|
|
|
|
int32_t vnodeCompact(SVnode *pVnode);
|
|
|
|
|
int32_t vnodeSync(SVnode *pVnode);
|
2021-11-04 10:38:07 +00:00
|
|
|
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
2021-11-04 06:06:29 +00:00
|
|
|
|
2022-01-21 08:12:02 +00:00
|
|
|
/* ------------------------- TQ QUERY -------------------------- */
|
|
|
|
|
|
2022-01-28 07:24:09 +00:00
|
|
|
STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta);
|
2022-01-21 08:12:02 +00:00
|
|
|
|
2022-01-28 07:24:09 +00:00
|
|
|
static FORCE_INLINE void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList) {
|
2022-01-21 11:00:09 +00:00
|
|
|
pReadHandle->pColIdList = pColIdList;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 07:24:09 +00:00
|
|
|
// static FORCE_INLINE void tqReadHandleSetTbUid(STqReadHandle* pHandle, const SArray* pTableIdList) {
|
|
|
|
|
// pHandle->tbUid = pTableIdList;
|
2022-01-28 05:31:46 +00:00
|
|
|
//}
|
2022-01-21 08:12:02 +00:00
|
|
|
|
2022-01-28 07:24:09 +00:00
|
|
|
static FORCE_INLINE int tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList) {
|
2022-01-27 10:05:23 +00:00
|
|
|
pHandle->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_NO_LOCK);
|
|
|
|
|
if (pHandle->tbIdHash == NULL) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < taosArrayGetSize(tbUidList); i++) {
|
2022-01-28 07:24:09 +00:00
|
|
|
int64_t *pKey = (int64_t *)taosArrayGet(tbUidList, i);
|
2022-01-27 10:05:23 +00:00
|
|
|
taosHashPut(pHandle->tbIdHash, pKey, sizeof(int64_t), NULL, 0);
|
2022-01-28 07:24:09 +00:00
|
|
|
// pHandle->tbUid = tbUid;
|
2022-01-27 10:05:23 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 07:24:09 +00:00
|
|
|
void tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitMsg *pMsg, int64_t ver);
|
|
|
|
|
bool tqNextDataBlock(STqReadHandle *pHandle);
|
|
|
|
|
int tqRetrieveDataBlockInfo(STqReadHandle *pHandle, SDataBlockInfo *pBlockInfo);
|
2022-01-21 08:12:02 +00:00
|
|
|
// return SArray<SColumnInfoData>
|
2022-01-28 07:24:09 +00:00
|
|
|
SArray *tqRetrieveDataBlock(STqReadHandle *pHandle);
|
2022-01-21 08:12:02 +00:00
|
|
|
|
2021-09-22 12:29:24 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-09-29 11:26:11 +00:00
|
|
|
#endif /*_TD_VNODE_H_*/
|