vnode.h 4.8 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"
S
Shengliang Guan 已提交
26

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

H
save  
Hongze Cheng 已提交
31 32 33 34 35
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SVnode        SVnode;
typedef struct SVnodeOptions SVnodeOptions;

/* ------------------------ SVnode ------------------------ */
H
refact  
Hongze Cheng 已提交
36 37 38 39 40 41 42
/**
 * @brief Open a VNODE.
 *
 * @param path path of the vnode
 * @param pVnodeOptions options of the vnode
 * @return SVnode* The vnode object
 */
H
save  
Hongze Cheng 已提交
43
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions);
H
refact  
Hongze Cheng 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

/**
 * @brief Close a VNODE
 *
 * @param pVnode The vnode object
 */
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 已提交
73
 * @param pRsp The response message
H
refact  
Hongze Cheng 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86
 * @return int 0 for success, -1 for failure
 */
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);

/**
 * @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 已提交
87 88

/* ------------------------ SVnodeOptions ------------------------ */
H
refact  
Hongze Cheng 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101
/**
 * @brief Initialize VNODE options.
 *
 * @param pOptions The options object to be initialized. It should not be NULL.
 */
void vnodeOptionsInit(SVnodeOptions *pOptions);

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

H
refact  
Hongze Cheng 已提交
103 104
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
struct SVnodeOptions {
H
refact  
Hongze Cheng 已提交
105 106
  /**
   * @brief write buffer size in BYTES
H
refact  
Hongze Cheng 已提交
107
   *
H
refact  
Hongze Cheng 已提交
108 109 110 111 112 113
   */
  uint64_t wsize;

  /**
   * @brief time to live of tables in this vnode
   * in SECONDS
H
refact  
Hongze Cheng 已提交
114
   *
H
refact  
Hongze Cheng 已提交
115 116 117 118 119
   */
  uint32_t ttl;

  /**
   * @brief if time-series requests eventual consistency
H
refact  
Hongze Cheng 已提交
120
   *
H
refact  
Hongze Cheng 已提交
121 122 123
   */
  bool isWeak;

H
refact  
Hongze Cheng 已提交
124 125 126 127 128 129
  /**
   * @brief if the allocator is heap allcator or arena allocator
   *
   */
  bool isHeapAllocator;

H
refact  
Hongze Cheng 已提交
130 131
  /**
   * @brief TSDB options
H
refact  
Hongze Cheng 已提交
132
   *
H
refact  
Hongze Cheng 已提交
133
   */
H
refact  
Hongze Cheng 已提交
134
  STsdbOptions tsdbOptions;
H
refact  
Hongze Cheng 已提交
135 136

  /**
H
refact  
Hongze Cheng 已提交
137
   * @brief META options
H
refact  
Hongze Cheng 已提交
138
   *
H
refact  
Hongze Cheng 已提交
139
   */
H
refact  
Hongze Cheng 已提交
140 141 142 143
  SMetaOptions metaOptions;
  // STqOptions   tqOptions; // TODO
};

H
refact  
Hongze Cheng 已提交
144 145
/* ------------------------ FOR COMPILE ------------------------ */

H
save  
Hongze Cheng 已提交
146 147
#if 1

H
Hongze Cheng 已提交
148
#include "taosmsg.h"
H
save  
Hongze Cheng 已提交
149
#include "trpc.h"
S
Shengliang Guan 已提交
150 151

typedef struct {
S
Shengliang Guan 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  char     db[TSDB_FULL_DB_NAME_LEN];
  int32_t  cacheBlockSize;  // MB
  int32_t  totalBlocks;
  int32_t  daysPerFile;
  int32_t  daysToKeep0;
  int32_t  daysToKeep1;
  int32_t  daysToKeep2;
  int32_t  minRowsPerFileBlock;
  int32_t  maxRowsPerFileBlock;
  int8_t   precision;  // time resolution
  int8_t   compression;
  int8_t   cacheLastRow;
  int8_t   update;
  int8_t   quorum;
  int8_t   replica;
  int8_t   selfIndex;
  int8_t   walLevel;
  int32_t  fsyncPeriod;  // millisecond
S
Shengliang Guan 已提交
170
  SReplica replicas[TSDB_MAX_REPLICA];
S
Shengliang Guan 已提交
171 172
} SVnodeCfg;

S
Shengliang Guan 已提交
173 174 175 176 177 178
typedef enum {
  VN_MSG_TYPE_WRITE = 1,
  VN_MSG_TYPE_APPLY,
  VN_MSG_TYPE_SYNC,
  VN_MSG_TYPE_QUERY,
  VN_MSG_TYPE_FETCH
S
Shengliang Guan 已提交
179
} EVnMsgType;
S
Shengliang Guan 已提交
180

S
Shengliang Guan 已提交
181
typedef struct {
S
Shengliang Guan 已提交
182 183 184
  int32_t curNum;
  int32_t allocNum;
  SRpcMsg rpcMsg[];
S
Shengliang Guan 已提交
185
} SVnodeMsg;
S
Shengliang Guan 已提交
186

S
Shengliang Guan 已提交
187 188 189 190 191 192 193
typedef struct {
  void (*SendMsgToDnode)(SEpSet *pEpSet, SRpcMsg *pMsg);
  void (*SendMsgToMnode)(SRpcMsg *pMsg);
  int32_t (*PutMsgIntoApplyQueue)(int32_t vgId, SVnodeMsg *pMsg);
} SVnodePara;

int32_t vnodeInit(SVnodePara);
S
Shengliang Guan 已提交
194
void    vnodeCleanup();
195

S
Shengliang Guan 已提交
196 197
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg);
S
Shengliang Guan 已提交
198
void    vnodeDrop(SVnode *pVnode);
S
Shengliang Guan 已提交
199 200
int32_t vnodeCompact(SVnode *pVnode);
int32_t vnodeSync(SVnode *pVnode);
S
Shengliang Guan 已提交
201

S
Shengliang Guan 已提交
202
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
S
Shengliang Guan 已提交
203 204 205 206

SVnodeMsg *vnodeInitMsg(int32_t msgNum);
int32_t    vnodeAppendMsg(SVnodeMsg *pMsg, SRpcMsg *pRpcMsg);
void       vnodeCleanupMsg(SVnodeMsg *pMsg);
S
Shengliang Guan 已提交
207
void       vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg, EVnMsgType msgType);
S
Shengliang Guan 已提交
208

H
save  
Hongze Cheng 已提交
209 210
#endif

S
Shengliang Guan 已提交
211 212 213 214
#ifdef __cplusplus
}
#endif

215
#endif /*_TD_VNODE_H_*/