mnode.h 4.5 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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_MNODE_H_
#define _TD_MNODE_H_

#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
23 24 25
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SDnode    SDnode;
typedef struct SMnode    SMnode;
S
Shengliang Guan 已提交
26
typedef struct SMnodeMsg SMnodeMsg;
27 28 29 30
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg);
S
Shengliang Guan 已提交
31

S
Shengliang Guan 已提交
32
typedef struct SMnodeLoad {
S
Shengliang Guan 已提交
33 34 35 36 37 38 39 40 41 42
  int64_t numOfDnode;
  int64_t numOfMnode;
  int64_t numOfVgroup;
  int64_t numOfDatabase;
  int64_t numOfSuperTable;
  int64_t numOfChildTable;
  int64_t numOfColumn;
  int64_t totalPoints;
  int64_t totalStorage;
  int64_t compStorage;
S
Shengliang Guan 已提交
43
} SMnodeLoad;
S
Shengliang Guan 已提交
44

45
typedef struct {
S
Shengliang Guan 已提交
46 47
  int32_t           dnodeId;
  int64_t           clusterId;
S
Shengliang Guan 已提交
48 49 50
  int8_t            replica;
  int8_t            selfIndex;
  SReplica          replicas[TSDB_MAX_REPLICA];
S
Shengliang Guan 已提交
51
  struct SDnode    *pDnode;
S
Shengliang Guan 已提交
52 53 54 55
  PutMsgToMnodeQFp  putMsgToApplyMsgFp;
  SendMsgToDnodeFp  sendMsgToDnodeFp;
  SendMsgToMnodeFp  sendMsgToMnodeFp;
  SendRedirectMsgFp sendRedirectMsgFp;
S
Shengliang Guan 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
} SMnodeOptions;

/* ------------------------ SMnode ------------------------ */
/**
 * @brief Open a mnode.
 *
 * @param path Path of the mnode
 * @param pOptions Options of the mnode
 * @return SMnode* The mnode object
 */
SMnode *mnodeOpen(const char *path, const SMnodeOptions *pOptions);

/**
 * @brief Close a mnode
 *
 * @param pMnode The mnode object to close
 */
void mnodeClose(SMnode *pMnode);

/**
 * @brief Close a mnode
 *
 * @param pMnode The mnode object to close
 * @param pOptions Options of the mnode
 * @return int32_t 0 for success, -1 for failure
 */
int32_t mnodeAlter(SMnode *pMnode, const SMnodeOptions *pOptions);

/**
 * @brief Drop a mnode.
 *
 * @param path Path of the mnode.
 */
void mnodeDestroy(const char *path);

/**
 * @brief Get mnode statistics info
 *
 * @param pMnode The mnode object
 * @param pLoad Statistics of the mnode.
 * @return int32_t 0 for success, -1 for failure
 */
int32_t mnodeGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
S
Shengliang Guan 已提交
99

S
Shengliang Guan 已提交
100 101 102 103 104 105 106 107 108 109 110 111
/**
 * @brief Get user authentication info
 *
 * @param pMnode The mnode object
 * @param user
 * @param spi
 * @param encrypt
 * @param secret
 * @param ckey
 * @return int32_t 0 for success, -1 for failure
 */
int32_t mnodeRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
S
Shengliang Guan 已提交
112

S
Shengliang Guan 已提交
113 114 115 116 117 118 119 120
/**
 * @brief Initialize mnode msg
 *
 * @param pMnode The mnode object
 * @param pMsg The request rpc msg
 * @return int32_t The created mnode msg
 */
SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg);
S
Shengliang Guan 已提交
121

S
Shengliang Guan 已提交
122 123 124 125 126
/**
 * @brief Cleanup mnode msg
 *
 * @param pMsg The request msg
 */
S
Shengliang Guan 已提交
127 128 129 130 131 132 133 134 135
void mnodeCleanupMsg(SMnodeMsg *pMsg);

/**
 * @brief Cleanup mnode msg
 *
 * @param pMsg The request msg
 * @param code The error code
 */
void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code);
S
Shengliang Guan 已提交
136

S
Shengliang Guan 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
/**
 * @brief Process the read request
 *
 * @param pMnode The mnode object
 * @param pMsg The request msg
 * @return int32_t 0 for success, -1 for failure
 */
void mnodeProcessReadMsg(SMnode *pMnode, SMnodeMsg *pMsg);

/**
 * @brief Process the write request
 *
 * @param pMnode The mnode object
 * @param pMsg The request msg
 * @return int32_t 0 for success, -1 for failure
 */
void mnodeProcessWriteMsg(SMnode *pMnode, SMnodeMsg *pMsg);

/**
 * @brief Process the sync request
 *
 * @param pMnode The mnode object
 * @param pMsg The request msg
 * @return int32_t 0 for success, -1 for failure
 */
void mnodeProcessSyncMsg(SMnode *pMnode, SMnodeMsg *pMsg);

/**
 * @brief Process the apply request
 *
 * @param pMnode The mnode object
 * @param pMsg The request msg
 * @return int32_t 0 for success, -1 for failure
 */
void mnodeProcessApplyMsg(SMnode *pMnode, SMnodeMsg *pMsg);
172

H
refact  
Hongze Cheng 已提交
173 174 175 176
#ifdef __cplusplus
}
#endif

177
#endif /*_TD_MNODE_H_*/