vnode.h 6.3 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"
H
refact  
Hongze Cheng 已提交
24 25
#include "tq.h"
#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 34 35 36 37 38
typedef struct SVnode SVnode;
typedef struct SVnodeCfg {
  /** vnode buffer pool options */
  struct {
    /** write buffer size */
    uint64_t wsize;
H
more  
Hongze Cheng 已提交
39 40
    uint64_t ssize;
    uint64_t lsize;
H
more  
Hongze Cheng 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    /** use heap allocator or arena allocator */
    bool isHeapAllocator;
  };

  /** time to live of tables in this vnode */
  uint32_t ttl;

  /** data to keep in this vnode */
  uint32_t keep;

  /** if TS data is eventually consistency */
  bool isWeak;

  /** TSDB config */
  STsdbCfg tsdbCfg;

  /** META config */
  SMetaCfg metaCfg;

  /** TQ config */
  STqCfg tqCfg;

  /** WAL config */
  SWalCfg walCfg;
} SVnodeCfg;
H
save  
Hongze Cheng 已提交
66 67

/* ------------------------ SVnode ------------------------ */
H
more  
Hongze Cheng 已提交
68 69
/**
 * @brief Initialize the vnode module
H
more  
Hongze Cheng 已提交
70
 *
H
more  
Hongze Cheng 已提交
71 72
 * @param nthreads number of commit threads. 0 for no threads and
 *        a schedule queue should be given (TODO)
H
more  
Hongze Cheng 已提交
73 74
 * @return int 0 for success and -1 for failure
 */
H
more  
Hongze Cheng 已提交
75
int vnodeInit(uint16_t nthreads);
H
more  
Hongze Cheng 已提交
76 77 78

/**
 * @brief clear a vnode
H
more  
Hongze Cheng 已提交
79
 *
H
more  
Hongze Cheng 已提交
80 81 82
 */
void vnodeClear();

H
refact  
Hongze Cheng 已提交
83 84 85 86
/**
 * @brief Open a VNODE.
 *
 * @param path path of the vnode
H
refact  
Hongze Cheng 已提交
87
 * @param pVnodeCfg options of the vnode
H
refact  
Hongze Cheng 已提交
88 89
 * @return SVnode* The vnode object
 */
H
refact  
Hongze Cheng 已提交
90
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg);
H
refact  
Hongze Cheng 已提交
91 92 93 94

/**
 * @brief Close a VNODE
 *
H
more  
Hongze Cheng 已提交
95
 * @param pVnode The vnode object to close
H
refact  
Hongze Cheng 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
 */
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 已提交
120
 * @param pRsp The response message
H
refact  
Hongze Cheng 已提交
121 122 123 124
 * @return int 0 for success, -1 for failure
 */
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);

L
Liu Jicong 已提交
125 126 127 128 129 130 131 132 133 134
/**
 * @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 已提交
135 136 137 138 139 140 141 142 143
/**
 * @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 已提交
144

145 146 147 148 149 150 151 152
/**
 * @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
 */
153
int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
154 155 156 157 158 159 160 161 162

/**
 * @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
 */
163
int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
164 165 166 167 168 169 170 171 172

/**
 * @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
 */
173
int vnodeProcessConsumeReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
174

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

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

H
more  
Hongze Cheng 已提交
190
/* ------------------------ REQUESTS ------------------------ */
H
more  
Hongze Cheng 已提交
191 192 193 194 195
typedef STbCfg SVCreateTableReq;
typedef struct {
  tb_uid_t uid;
} SVDropTableReq;

H
more  
Hongze Cheng 已提交
196 197 198 199
typedef struct {
  // TODO
} SVSubmitReq;

H
more  
Hongze Cheng 已提交
200 201
typedef struct {
  uint64_t ver;
H
more  
Hongze Cheng 已提交
202 203 204 205
  union {
    SVCreateTableReq ctReq;
    SVDropTableReq   dtReq;
  };
H
more  
Hongze Cheng 已提交
206 207
} SVnodeReq;

H
more  
Hongze Cheng 已提交
208 209 210
typedef struct {
  int  err;
  char info[];
H
refact  
Hongze Cheng 已提交
211 212
} SVnodeRsp;

H
Hongze Cheng 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
static FORCE_INLINE void vnodeSetCreateStbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep, tb_uid_t suid,
                                              STSchema *pSchema, STSchema *pTagSchema) {
  pReq->ver = 0;

  pReq->ctReq.name = name;
  pReq->ctReq.ttl = ttl;
  pReq->ctReq.keep = keep;
  pReq->ctReq.type = META_SUPER_TABLE;
  pReq->ctReq.stbCfg.suid = suid;
  pReq->ctReq.stbCfg.pSchema = pSchema;
  pReq->ctReq.stbCfg.pTagSchema = pTagSchema;
}

static FORCE_INLINE void vnodeSetCreateCtbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep, tb_uid_t suid,
                                              SKVRow pTag) {
  pReq->ver = 0;
H
more  
Hongze Cheng 已提交
229

H
Hongze Cheng 已提交
230 231 232 233 234 235 236
  pReq->ctReq.name = name;
  pReq->ctReq.ttl = ttl;
  pReq->ctReq.keep = keep;
  pReq->ctReq.type = META_CHILD_TABLE;
  pReq->ctReq.ctbCfg.suid = suid;
  pReq->ctReq.ctbCfg.pTag = pTag;
}
H
more  
Hongze Cheng 已提交
237

H
Hongze Cheng 已提交
238 239 240 241 242 243 244 245 246 247
static FORCE_INLINE void vnodeSetCreateNtbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep,
                                              STSchema *pSchema) {
  pReq->ver = 0;

  pReq->ctReq.name = name;
  pReq->ctReq.ttl = ttl;
  pReq->ctReq.keep = keep;
  pReq->ctReq.type = META_NORMAL_TABLE;
  pReq->ctReq.ntbCfg.pSchema = pSchema;
}
H
more  
Hongze Cheng 已提交
248 249 250

int   vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type);
void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type);
H
refact  
Hongze Cheng 已提交
251

H
refact  
Hongze Cheng 已提交
252 253
/* ------------------------ FOR COMPILE ------------------------ */

S
Shengliang Guan 已提交
254 255 256
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
int32_t vnodeCompact(SVnode *pVnode);
int32_t vnodeSync(SVnode *pVnode);
S
Shengliang Guan 已提交
257
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
S
Shengliang Guan 已提交
258

S
Shengliang Guan 已提交
259 260 261 262
#ifdef __cplusplus
}
#endif

263
#endif /*_TD_VNODE_H_*/