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

#ifndef _TD_VNODE_H_
#define _TD_VNODE_H_

H
refact  
Hongze Cheng 已提交
19
#include "os.h"
H
refact  
Hongze Cheng 已提交
20
#include "trpc.h"
H
refact  
Hongze Cheng 已提交
21 22

#include "meta.h"
H
refact  
Hongze Cheng 已提交
23
#include "tarray.h"
S
Shengliang Guan 已提交
24
#include "tfs.h"
H
refact  
Hongze Cheng 已提交
25
#include "tsdb.h"
H
refact  
Hongze Cheng 已提交
26
#include "wal.h"
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28 29 30 31
#ifdef __cplusplus
extern "C" {
#endif

H
save  
Hongze Cheng 已提交
32
/* ------------------------ TYPES EXPOSED ------------------------ */
H
more  
Hongze Cheng 已提交
33
typedef struct SVnode SVnode;
S
Shengliang Guan 已提交
34
typedef struct SDnode SDnode;
S
Shengliang Guan 已提交
35
typedef int32_t (*PutReqToVQueryQFp)(SDnode *pDnode, struct SRpcMsg *pReq);
S
Shengliang Guan 已提交
36

L
Liu Jicong 已提交
37 38 39 40 41 42
typedef struct STqCfg {
  // TODO
  int32_t reserved;
} STqCfg;


H
more  
Hongze Cheng 已提交
43
typedef struct SVnodeCfg {
H
Hongze Cheng 已提交
44
  int32_t  vgId;
S
Shengliang Guan 已提交
45 46
  SDnode  *pDnode;
  STfs    *pTfs;
H
Hongze Cheng 已提交
47 48 49 50
  uint64_t wsize;
  uint64_t ssize;
  uint64_t lsize;
  bool     isHeapAllocator;
H
more  
Hongze Cheng 已提交
51 52
  uint32_t ttl;
  uint32_t keep;
H
Hongze Cheng 已提交
53
  bool     isWeak;
H
more  
Hongze Cheng 已提交
54 55
  STsdbCfg tsdbCfg;
  SMetaCfg metaCfg;
H
Hongze Cheng 已提交
56 57
  STqCfg   tqCfg;
  SWalCfg  walCfg;
H
more  
Hongze Cheng 已提交
58
} SVnodeCfg;
H
save  
Hongze Cheng 已提交
59

S
Shengliang Guan 已提交
60 61
typedef struct {
  int32_t           sver;
S
Shengliang Guan 已提交
62 63 64
  const char       *timezone;
  const char       *locale;
  const char       *charset;
S
Shengliang Guan 已提交
65
  uint16_t          nthreads;  // number of commit threads. 0 for no threads and a schedule queue should be given (TODO)
S
Shengliang Guan 已提交
66
  PutReqToVQueryQFp putReqToVQueryQFp;
S
Shengliang Guan 已提交
67 68
} SVnodeOpt;

L
Liu Jicong 已提交
69 70
typedef struct STqReadHandle {
  int64_t        ver;
L
Liu Jicong 已提交
71
  uint64_t       tbUid;
L
Liu Jicong 已提交
72 73 74 75 76
  SSubmitMsg*    pMsg;
  SSubmitBlk*    pBlock;
  SSubmitMsgIter msgIter;
  SSubmitBlkIter blkIter;
  SMeta*         pMeta;
L
Liu Jicong 已提交
77
  SArray*        pColIdList;
L
Liu Jicong 已提交
78 79
} STqReadHandle;

H
save  
Hongze Cheng 已提交
80
/* ------------------------ SVnode ------------------------ */
H
more  
Hongze Cheng 已提交
81 82
/**
 * @brief Initialize the vnode module
H
more  
Hongze Cheng 已提交
83
 *
S
Shengliang Guan 已提交
84
 * @param pOption Option of the vnode mnodule
H
more  
Hongze Cheng 已提交
85 86
 * @return int 0 for success and -1 for failure
 */
S
Shengliang Guan 已提交
87
int vnodeInit(const SVnodeOpt *pOption);
H
more  
Hongze Cheng 已提交
88 89

/**
S
Shengliang Guan 已提交
90
 * @brief Cleanup the vnode module
H
more  
Hongze Cheng 已提交
91
 *
H
more  
Hongze Cheng 已提交
92
 */
S
Shengliang Guan 已提交
93
void vnodeCleanup();
H
more  
Hongze Cheng 已提交
94

H
refact  
Hongze Cheng 已提交
95 96 97 98
/**
 * @brief Open a VNODE.
 *
 * @param path path of the vnode
H
refact  
Hongze Cheng 已提交
99
 * @param pVnodeCfg options of the vnode
H
refact  
Hongze Cheng 已提交
100 101
 * @return SVnode* The vnode object
 */
S
Shengliang Guan 已提交
102
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg);
H
refact  
Hongze Cheng 已提交
103 104 105 106

/**
 * @brief Close a VNODE
 *
H
more  
Hongze Cheng 已提交
107
 * @param pVnode The vnode object to close
H
refact  
Hongze Cheng 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
 */
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
H
more  
Hongze Cheng 已提交
132
 * @param pRsp The response message
H
refact  
Hongze Cheng 已提交
133 134 135 136
 * @return int 0 for success, -1 for failure
 */
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);

L
Liu Jicong 已提交
137 138 139 140 141 142 143 144 145 146
/**
 * @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);

H
refact  
Hongze Cheng 已提交
147 148 149 150 151 152 153 154 155
/**
 * @brief Process the sync request
 *
 * @param pVnode
 * @param pMsg
 * @param pRsp
 * @return int
 */
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
H
save  
Hongze Cheng 已提交
156

157 158 159 160 161 162 163 164
/**
 * @brief Process a query message.
 *
 * @param pVnode The vnode object.
 * @param pMsg The request message
 * @param pRsp The response message
 * @return int 0 for success, -1 for failure
 */
165
int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
166 167 168 169 170 171 172 173 174

/**
 * @brief Process a fetch message.
 *
 * @param pVnode The vnode object.
 * @param pMsg The request message
 * @param pRsp The response message
 * @return int 0 for success, -1 for failure
 */
175
int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
176

H
refact  
Hongze Cheng 已提交
177
/* ------------------------ SVnodeCfg ------------------------ */
H
refact  
Hongze Cheng 已提交
178 179 180 181 182
/**
 * @brief Initialize VNODE options.
 *
 * @param pOptions The options object to be initialized. It should not be NULL.
 */
H
refact  
Hongze Cheng 已提交
183
void vnodeOptionsInit(SVnodeCfg *pOptions);
H
refact  
Hongze Cheng 已提交
184 185 186 187 188 189

/**
 * @brief Clear VNODE options.
 *
 * @param pOptions Options to clear.
 */
H
refact  
Hongze Cheng 已提交
190
void vnodeOptionsClear(SVnodeCfg *pOptions);
H
save  
Hongze Cheng 已提交
191

H
refact  
Hongze Cheng 已提交
192 193
/* ------------------------ FOR COMPILE ------------------------ */

S
Shengliang Guan 已提交
194 195 196
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
int32_t vnodeCompact(SVnode *pVnode);
int32_t vnodeSync(SVnode *pVnode);
S
Shengliang Guan 已提交
197
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
S
Shengliang Guan 已提交
198

L
Liu Jicong 已提交
199 200 201 202
/* ------------------------- TQ QUERY -------------------------- */

STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta);

L
Liu Jicong 已提交
203 204 205 206
static FORCE_INLINE void tqReadHandleSetColIdList(STqReadHandle* pReadHandle, SArray* pColIdList) {
  pReadHandle->pColIdList = pColIdList;
}

L
Liu Jicong 已提交
207
static FORCE_INLINE void tqReadHandleSetTbUid(STqReadHandle* pHandle, uint64_t tbUid) {
L
Liu Jicong 已提交
208
  pHandle->tbUid = tbUid;
L
Liu Jicong 已提交
209 210 211 212 213 214 215 216 217
}

void           tqReadHandleSetMsg(STqReadHandle* pHandle, SSubmitMsg* pMsg, int64_t ver);
bool           tqNextDataBlock(STqReadHandle* pHandle);
int            tqRetrieveDataBlockInfo(STqReadHandle* pHandle, SDataBlockInfo* pBlockInfo);
// return SArray<SColumnInfoData>
SArray*        tqRetrieveDataBlock(STqReadHandle* pHandle);


S
Shengliang Guan 已提交
218 219 220 221
#ifdef __cplusplus
}
#endif

222
#endif /*_TD_VNODE_H_*/