vnd.h 4.8 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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/>.
 */

#ifndef _TD_VND_H_
#define _TD_VND_H_

H
Hongze Cheng 已提交
19
#include "sync.h"
dengyihao's avatar
dengyihao 已提交
20
#include "ttrace.h"
H
Hongze Cheng 已提交
21 22
#include "vnodeInt.h"

H
Hongze Cheng 已提交
23 24 25 26 27 28 29 30 31 32 33
#ifdef __cplusplus
extern "C" {
#endif

// clang-format off
#define vFatal(...) do { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}     while(0)
#define vError(...) do { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}     while(0)
#define vWarn(...)  do { if (vDebugFlag & DEBUG_WARN)  { taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}       while(0)
#define vInfo(...)  do { if (vDebugFlag & DEBUG_INFO)  { taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); }}            while(0)
#define vDebug(...) do { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", DEBUG_DEBUG, vDebugFlag, __VA_ARGS__); }}    while(0)
#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }}    while(0)
S
Shengliang Guan 已提交
34

dengyihao's avatar
dengyihao 已提交
35 36 37 38 39 40
#define vGTrace(param, ...) do { if (vDebugFlag & DEBUG_TRACE) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vTrace(param ", gtid:%s", __VA_ARGS__, buf);}} while(0)
#define vGFatal(param, ...) do { if (vDebugFlag & DEBUG_FATAL) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vFatal(param ", gtid:%s", __VA_ARGS__, buf);}} while(0)
#define vGError(param, ...) do { if (vDebugFlag & DEBUG_ERROR) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vError(param ", gtid:%s", __VA_ARGS__, buf);}} while(0)
#define vGWarn(param, ...)  do { if (vDebugFlag & DEBUG_WARN)  { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vWarn(param ", gtid:%s", __VA_ARGS__, buf);}} while(0)
#define vGInfo(param, ...)  do { if (vDebugFlag & DEBUG_INFO)  { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vInfo(param ", gtid:%s", __VA_ARGS__, buf);}} while(0)
#define vGDebug(param, ...) do { if (vDebugFlag & DEBUG_DEBUG) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vDebug(param ", gtid:%s", __VA_ARGS__, buf);}}    while(0)
S
Shengliang Guan 已提交
41

H
Hongze Cheng 已提交
42 43
// clang-format on

44
// vnodeCfg.c
H
Hongze Cheng 已提交
45 46
extern const SVnodeCfg vnodeCfgDefault;

47 48 49
int32_t vnodeCheckCfg(const SVnodeCfg*);
int32_t vnodeEncodeConfig(const void* pObj, SJson* pJson);
int32_t vnodeDecodeConfig(const SJson* pJson, void* pObj);
H
Hongze Cheng 已提交
50

51 52
// vnodeModule.c
int32_t vnodeScheduleTask(int32_t (*execute)(void*), void* arg);
H
Hongze Cheng 已提交
53

54
// vnodeBufPool.c
H
Hongze Cheng 已提交
55 56 57 58 59 60 61 62 63
typedef struct SVBufPoolNode SVBufPoolNode;
struct SVBufPoolNode {
  SVBufPoolNode*  prev;
  SVBufPoolNode** pnext;
  int64_t         size;
  uint8_t         data[];
};

struct SVBufPool {
H
Hongze Cheng 已提交
64 65 66 67
  SVBufPool* freeNext;
  SVBufPool* recycleNext;
  SVBufPool* recyclePrev;

H
Hongze Cheng 已提交
68 69 70 71 72
  // query handle list
  TdThreadMutex mutex;
  int32_t       nQuery;
  SQueryNode    qList;

C
Cary Xu 已提交
73
  SVnode*           pVnode;
H
Hongze Cheng 已提交
74
  int32_t           id;
C
Cary Xu 已提交
75
  volatile int32_t  nRef;
H
Hongze Cheng 已提交
76
  TdThreadSpinlock* lock;
C
Cary Xu 已提交
77 78 79 80
  int64_t           size;
  uint8_t*          ptr;
  SVBufPoolNode*    pTail;
  SVBufPoolNode     node;
H
Hongze Cheng 已提交
81 82
};

H
Hongze Cheng 已提交
83
int32_t vnodeOpenBufPool(SVnode* pVnode);
84 85
int32_t vnodeCloseBufPool(SVnode* pVnode);
void    vnodeBufPoolReset(SVBufPool* pPool);
H
Hongze Cheng 已提交
86

87 88
// vnodeQuery.c
int32_t vnodeQueryOpen(SVnode* pVnode);
H
Hongze Cheng 已提交
89
void    vnodeQueryPreClose(SVnode* pVnode);
90
void    vnodeQueryClose(SVnode* pVnode);
D
dapan1121 已提交
91 92
int32_t vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg, bool direct);
int     vnodeGetTableCfg(SVnode* pVnode, SRpcMsg* pMsg, bool direct);
93
int32_t vnodeGetBatchMeta(SVnode* pVnode, SRpcMsg* pMsg);
H
Hongze Cheng 已提交
94

95 96 97
// vnodeCommit.c
int32_t vnodeBegin(SVnode* pVnode);
int32_t vnodeShouldCommit(SVnode* pVnode);
98
void    vnodeUpdCommitSched(SVnode* pVnode);
H
Hongze Cheng 已提交
99
void    vnodeRollback(SVnode* pVnode);
100 101 102 103 104
int32_t vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
int32_t vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
int32_t vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo);
int32_t vnodeSyncCommit(SVnode* pVnode);
int32_t vnodeAsyncCommit(SVnode* pVnode);
H
Hongze Cheng 已提交
105
bool    vnodeShouldRollback(SVnode* pVnode);
H
Hongze Cheng 已提交
106

107
// vnodeSync.c
108
int32_t vnodeSyncOpen(SVnode* pVnode, char* path);
B
Benguang Zhao 已提交
109
int32_t vnodeSyncStart(SVnode* pVnode);
S
Shengliang Guan 已提交
110
void    vnodeSyncPreClose(SVnode* pVnode);
111
void    vnodeSyncPostClose(SVnode* pVnode);
112
void    vnodeSyncClose(SVnode* pVnode);
113
void    vnodeRedirectRpcMsg(SVnode* pVnode, SRpcMsg* pMsg, int32_t code);
114
bool    vnodeIsLeader(SVnode* pVnode);
115
bool    vnodeIsRoleLeader(SVnode* pVnode);
B
Benguang Zhao 已提交
116
int     vnodeShouldCommit(SVnode* pVnode);
H
Hongze Cheng 已提交
117

H
Hongze Cheng 已提交
118 119 120 121
#ifdef __cplusplus
}
#endif

dengyihao's avatar
dengyihao 已提交
122
#endif /*_TD_VND_H_*/