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

234 lines
6.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-08 06:49:07 +00:00
#include "tcompression.h"
2022-03-28 06:55:15 +00:00
#include "tdatablock.h"
2022-01-14 06:33:13 +00:00
#include "tfs.h"
2022-04-08 06:49:07 +00:00
#include "tglobal.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"
2021-12-14 05:40:41 +00:00
#include "tmacro.h"
2022-04-08 06:49:07 +00:00
#include "tmallocator.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 "vnode.h"
#include "wal.h"
2021-11-07 07:58:32 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-03-22 11:47:57 +00:00
typedef struct STQ STQ;
2022-04-08 06:49:07 +00:00
typedef struct SVState SVState;
typedef struct SVBufPool SVBufPool;
typedef struct SQWorkerMgmt SQHandle;
2022-01-14 06:33:13 +00:00
2021-12-14 05:40:41 +00:00
typedef struct SVnodeTask {
TD_DLIST_NODE(SVnodeTask);
void* arg;
int (*execute)(void*);
} SVnodeTask;
typedef struct SVnodeMgr {
td_mode_flag_t vnodeInitFlag;
// For commit
2022-03-21 07:51:32 +00:00
bool stop;
uint16_t nthreads;
TdThread* threads;
2022-03-19 16:47:45 +00:00
TdThreadMutex mutex;
TdThreadCond hasTask;
2021-12-14 05:40:41 +00:00
TD_DLIST(SVnodeTask) queue;
} SVnodeMgr;
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;
2021-12-14 05:40:41 +00:00
extern SVnodeMgr vnodeMgr;
2022-01-14 06:33:13 +00:00
// SVState
struct SVState {
int64_t processed;
int64_t committed;
int64_t applied;
};
2021-11-07 07:58:32 +00:00
struct SVnode {
2022-01-14 06:33:13 +00:00
int32_t vgId;
char* path;
SVnodeCfg config;
SVState state;
SVBufPool* pBufPool;
SMeta* pMeta;
STsdb* pTsdb;
SWal* pWal;
2022-03-24 03:34:43 +00:00
STQ* pTq;
SSink* pSink;
2022-01-14 06:33:13 +00:00
tsem_t canCommit;
SQHandle* pQuery;
2022-03-21 11:08:25 +00:00
SMsgCb msgCb;
2022-01-19 05:39:32 +00:00
STfs* pTfs;
2021-11-07 07:58:32 +00:00
};
2022-04-08 06:49:07 +00:00
int vnodeScheduleTask(SVnodeTask* task);
int vnodeQueryOpen(SVnode* pVnode);
void vnodeQueryClose(SVnode* pVnode);
2021-12-14 05:40:41 +00:00
2022-03-04 06:34:35 +00:00
#define vFatal(...) \
do { \
if (vDebugFlag & DEBUG_FATAL) { \
taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
} \
2022-01-14 06:33:13 +00:00
} while (0)
2022-03-04 06:34:35 +00:00
#define vError(...) \
do { \
if (vDebugFlag & DEBUG_ERROR) { \
taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
} \
2022-01-14 06:33:13 +00:00
} while (0)
2022-03-04 06:34:35 +00:00
#define vWarn(...) \
do { \
if (vDebugFlag & DEBUG_WARN) { \
taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
} \
2022-01-14 06:33:13 +00:00
} while (0)
2022-03-04 06:34:35 +00:00
#define vInfo(...) \
do { \
if (vDebugFlag & DEBUG_INFO) { \
taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); \
} \
2022-01-14 06:33:13 +00:00
} while (0)
2022-03-04 06:34:35 +00:00
#define vDebug(...) \
do { \
if (vDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("VND ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); \
} \
2022-01-14 06:33:13 +00:00
} while (0)
2022-03-04 06:34:35 +00:00
#define vTrace(...) \
do { \
if (vDebugFlag & DEBUG_TRACE) { \
taosPrintLog("VND ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); \
} \
2022-01-14 06:33:13 +00:00
} while (0)
// vnodeCfg.h
extern const SVnodeCfg defaultVnodeOptions;
int vnodeValidateOptions(const SVnodeCfg*);
void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc);
// For commit
#define vnodeShouldCommit vnodeBufPoolIsFull
int vnodeSyncCommit(SVnode* pVnode);
int vnodeAsyncCommit(SVnode* pVnode);
// SVBufPool
int vnodeOpenBufPool(SVnode* pVnode);
void vnodeCloseBufPool(SVnode* pVnode);
int vnodeBufPoolSwitch(SVnode* pVnode);
int vnodeBufPoolRecycle(SVnode* pVnode);
void* vnodeMalloc(SVnode* pVnode, uint64_t size);
bool vnodeBufPoolIsFull(SVnode* pVnode);
SMemAllocatorFactory* vBufPoolGetMAF(SVnode* pVnode);
// SVMemAllocator
typedef struct SVArenaNode {
TD_SLIST_NODE(SVArenaNode);
uint64_t size; // current node size
void* ptr;
char data[];
} SVArenaNode;
typedef struct SVMemAllocator {
T_REF_DECLARE()
TD_DLIST_NODE(SVMemAllocator);
uint64_t capacity;
uint64_t ssize;
uint64_t lsize;
SVArenaNode* pNode;
TD_SLIST(SVArenaNode) nlist;
} SVMemAllocator;
SVMemAllocator* vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize);
void vmaDestroy(SVMemAllocator* pVMA);
void vmaReset(SVMemAllocator* pVMA);
void* vmaMalloc(SVMemAllocator* pVMA, uint64_t size);
void vmaFree(SVMemAllocator* pVMA, void* ptr);
bool vmaIsFull(SVMemAllocator* pVMA);
2022-03-22 11:47:57 +00:00
// init once
int tqInit();
void tqCleanUp();
// open in each vnode
2022-03-23 02:44:32 +00:00
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig,
SMemAllocatorFactory* allocFac);
2022-03-22 11:47:57 +00:00
void tqClose(STQ*);
// required by vnode
2022-03-23 09:00:21 +00:00
int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version);
2022-03-22 11:47:57 +00:00
int tqCommit(STQ*);
2022-03-31 07:52:54 +00:00
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
2022-03-22 11:47:57 +00:00
int32_t tqProcessSetConnReq(STQ* pTq, char* msg);
int32_t tqProcessRebReq(STQ* pTq, char* msg);
2022-04-07 10:20:54 +00:00
int32_t tqProcessCancelConnReq(STQ* pTq, char* msg);
2022-03-29 10:58:15 +00:00
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
2022-03-22 11:47:57 +00:00
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
2022-03-29 10:58:15 +00:00
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
2022-03-22 11:47:57 +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-04-08 06:19:58 +00:00
#include "meta.h"
#include "tsdb.h"
#include "tq.h"
2022-04-13 08:02:55 +00:00
#include "tsdbSma.h"
2021-11-07 07:58:32 +00:00
#ifdef __cplusplus
}
#endif
2022-01-20 02:45:15 +00:00
#endif /*_TD_VNODE_DEF_H_*/