vnode.h 3.9 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 20 21 22 23 24
#include "os.h"
#include "trequest.h"

#include "meta.h"
#include "tq.h"
#include "tsdb.h"
S
Shengliang Guan 已提交
25

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

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

/* ------------------------ SVnode ------------------------ */
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions);
void    vnodeClose(SVnode *pVnode);
void    vnodeDestroy(const char *path);
H
refact  
Hongze Cheng 已提交
38
int     vnodeProcessWriteReqs(SVnode *pVnode, SReqBatch *pReqBatch);
H
Hongze Cheng 已提交
39
int     vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest);
H
refact  
Hongze Cheng 已提交
40 41
int     vnodeProcessReadReq(SVnode *pVnode, SRequest *pReq);
int     vnodeProcessSyncReq(SVnode *pVnode, SRequest *pReq);
H
save  
Hongze Cheng 已提交
42 43 44 45 46

/* ------------------------ SVnodeOptions ------------------------ */
void vnodeOptionsInit(SVnodeOptions *);
void vnodeOptionsClear(SVnodeOptions *);

H
refact  
Hongze Cheng 已提交
47 48
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
struct SVnodeOptions {
H
refact  
Hongze Cheng 已提交
49 50
  /**
   * @brief write buffer size in BYTES
H
refact  
Hongze Cheng 已提交
51
   *
H
refact  
Hongze Cheng 已提交
52 53 54 55 56 57
   */
  uint64_t wsize;

  /**
   * @brief time to live of tables in this vnode
   * in SECONDS
H
refact  
Hongze Cheng 已提交
58
   *
H
refact  
Hongze Cheng 已提交
59 60 61 62 63
   */
  uint32_t ttl;

  /**
   * @brief if time-series requests eventual consistency
H
refact  
Hongze Cheng 已提交
64
   *
H
refact  
Hongze Cheng 已提交
65 66 67
   */
  bool isWeak;

H
refact  
Hongze Cheng 已提交
68 69 70 71 72 73
  /**
   * @brief if the allocator is heap allcator or arena allocator
   *
   */
  bool isHeapAllocator;

H
refact  
Hongze Cheng 已提交
74 75
  /**
   * @brief TSDB options
H
refact  
Hongze Cheng 已提交
76
   *
H
refact  
Hongze Cheng 已提交
77
   */
H
refact  
Hongze Cheng 已提交
78
  STsdbOptions tsdbOptions;
H
refact  
Hongze Cheng 已提交
79 80

  /**
H
refact  
Hongze Cheng 已提交
81
   * @brief META options
H
refact  
Hongze Cheng 已提交
82
   *
H
refact  
Hongze Cheng 已提交
83
   */
H
refact  
Hongze Cheng 已提交
84 85 86 87
  SMetaOptions metaOptions;
  // STqOptions   tqOptions; // TODO
};

H
refact  
Hongze Cheng 已提交
88 89
/* ------------------------ FOR COMPILE ------------------------ */

H
save  
Hongze Cheng 已提交
90 91
#if 1

H
Hongze Cheng 已提交
92
#include "taosmsg.h"
H
save  
Hongze Cheng 已提交
93
#include "trpc.h"
S
Shengliang Guan 已提交
94 95

typedef struct {
S
Shengliang Guan 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  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 已提交
114
  SReplica replicas[TSDB_MAX_REPLICA];
S
Shengliang Guan 已提交
115 116
} SVnodeCfg;

S
Shengliang Guan 已提交
117 118 119 120 121 122
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 已提交
123
} EVnMsgType;
S
Shengliang Guan 已提交
124

S
Shengliang Guan 已提交
125
typedef struct {
S
Shengliang Guan 已提交
126 127 128
  int32_t curNum;
  int32_t allocNum;
  SRpcMsg rpcMsg[];
S
Shengliang Guan 已提交
129
} SVnodeMsg;
S
Shengliang Guan 已提交
130

S
Shengliang Guan 已提交
131 132 133 134 135 136 137
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 已提交
138
void    vnodeCleanup();
139

S
Shengliang Guan 已提交
140 141
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg);
S
Shengliang Guan 已提交
142
void    vnodeDrop(SVnode *pVnode);
S
Shengliang Guan 已提交
143 144
int32_t vnodeCompact(SVnode *pVnode);
int32_t vnodeSync(SVnode *pVnode);
S
Shengliang Guan 已提交
145

S
Shengliang Guan 已提交
146
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
S
Shengliang Guan 已提交
147 148 149 150

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

H
save  
Hongze Cheng 已提交
153 154
#endif

S
Shengliang Guan 已提交
155 156 157 158
#ifdef __cplusplus
}
#endif

159
#endif /*_TD_VNODE_H_*/