snode.h 2.5 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*
 * 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_SNODE_H_
#define _TD_SNODE_H_

#ifdef __cplusplus
extern "C" {
#endif

/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SDnode SDnode;
typedef struct SSnode SSnode;
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 struct {
  int64_t numOfErrors;
} SSnodeLoad;

typedef struct {
  int32_t sver;
} SSnodeCfg;

typedef struct {
  int32_t           dnodeId;
  int64_t           clusterId;
  SSnodeCfg         cfg;
  SDnode           *pDnode;
  SendMsgToDnodeFp  sendMsgToDnodeFp;
  SendMsgToMnodeFp  sendMsgToMnodeFp;
  SendRedirectMsgFp sendRedirectMsgFp;
} SSnodeOpt;

/* ------------------------ SSnode ------------------------ */
/**
 * @brief Start one Snode in Dnode.
 *
S
Shengliang Guan 已提交
52
 * @param path Path of the snode.
S
Shengliang Guan 已提交
53 54 55
 * @param pOption Option of the snode.
 * @return SSnode* The snode object.
 */
S
Shengliang Guan 已提交
56
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption);
S
Shengliang Guan 已提交
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

/**
 * @brief Stop Snode in Dnode.
 *
 * @param pSnode The snode object to close.
 */
void sndClose(SSnode *pSnode);

/**
 * @brief Get the statistical information of Snode
 *
 * @param pSnode The snode object.
 * @param pLoad Statistics of the snode.
 * @return int32_t 0 for success, -1 for failure.
 */
int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad);

/**
 * @brief Process a query message.
 *
 * @param pSnode The snode object.
 * @param pMsg The request message
 * @param pRsp The response message
 * @return int32_t 0 for success, -1 for failure
 */
S
Shengliang Guan 已提交
82
int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
S
Shengliang Guan 已提交
83

S
Shengliang Guan 已提交
84 85 86 87 88 89 90
/**
 * @brief Drop a snode.
 *
 * @param path Path of the snode.
 */
void sndDestroy(const char *path);

S
Shengliang Guan 已提交
91 92 93 94 95
#ifdef __cplusplus
}
#endif

#endif /*_TD_SNODE_H_*/