snode.h 2.6 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
#ifdef __cplusplus
extern "C" {
#endif

L
Liu Jicong 已提交
26 27 28
#define SND_UNIQUE_THREAD_NUM 2
#define SND_SHARED_THREAD_NUM 2

S
Shengliang Guan 已提交
29 30 31
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SDnode SDnode;
typedef struct SSnode SSnode;
S
Shengliang Guan 已提交
32 33 34
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 已提交
35 36 37 38 39 40

typedef struct {
  int64_t numOfErrors;
} SSnodeLoad;

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

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

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

L
Liu Jicong 已提交
86 87 88 89
int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg);

int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg);

S
Shengliang Guan 已提交
90 91 92 93 94 95 96
/**
 * @brief Drop a snode.
 *
 * @param path Path of the snode.
 */
void sndDestroy(const char *path);

S
Shengliang Guan 已提交
97 98 99 100
#ifdef __cplusplus
}
#endif

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