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
/*
 * 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_

L
Liu Jicong 已提交
19 20 21
#include "tmsg.h"
#include "trpc.h"

S
Shengliang Guan 已提交
22 23 24 25 26 27 28
#ifdef __cplusplus
extern "C" {
#endif

/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SDnode SDnode;
typedef struct SSnode SSnode;
S
Shengliang Guan 已提交
29 30 31
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *pMsg);
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *pMsg);
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *pMsg);
S
Shengliang Guan 已提交
32 33 34 35 36 37

typedef struct {
  int64_t numOfErrors;
} SSnodeLoad;

typedef struct {
S
Shengliang Guan 已提交
38
  int32_t           sver;
S
Shengliang Guan 已提交
39 40 41
  int32_t           dnodeId;
  int64_t           clusterId;
  SDnode           *pDnode;
S
Shengliang Guan 已提交
42 43 44
  SendReqToDnodeFp  sendReqToDnodeFp;
  SendReqToMnodeFp  sendReqToMnodeFp;
  SendRedirectRspFp sendRedirectRspFp;
S
Shengliang Guan 已提交
45 46 47 48 49 50
} SSnodeOpt;

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

/**
 * @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 已提交
81
int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
S
Shengliang Guan 已提交
82

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

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

L
Liu Jicong 已提交
94
#endif /*_TD_SNODE_H_*/