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

S
monitor  
Shengliang Guan 已提交
19
#include "monitor.h"
L
Liu Jicong 已提交
20
#include "tmsg.h"
S
Shengliang Guan 已提交
21
#include "tmsgcb.h"
L
Liu Jicong 已提交
22
#include "trpc.h"
C
cadem 已提交
23
#include "sync.h"
S
monitor  
Shengliang Guan 已提交
24

H
refact  
Hongze Cheng 已提交
25 26 27 28
#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
29
/* ------------------------ TYPES EXPOSED ------------------------ */
S
Shengliang Guan 已提交
30
typedef struct SMnode SMnode;
S
Shengliang Guan 已提交
31

32
typedef struct {
33
  int32_t  dnodeId;
S
shm  
Shengliang Guan 已提交
34
  bool     deploy;
35 36
  int8_t   selfIndex;
  int8_t   numOfReplicas;
C
cadem 已提交
37 38 39
  int8_t   numOfTotalReplicas;
  SReplica replicas[TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA];
  int32_t  nodeRoles[TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA];
S
Shengliang Guan 已提交
40
  SMsgCb   msgCb;
C
cadem 已提交
41
  int64_t  lastIndex;
S
Shengliang Guan 已提交
42
} SMnodeOpt;
S
Shengliang Guan 已提交
43 44 45 46 47

/* ------------------------ SMnode ------------------------ */
/**
 * @brief Open a mnode.
 *
S
Shengliang Guan 已提交
48 49 50
 * @param path Path of the mnode.
 * @param pOption Option of the mnode.
 * @return SMnode* The mnode object.
S
Shengliang Guan 已提交
51
 */
52
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption);
S
Shengliang Guan 已提交
53 54

/**
S
Shengliang Guan 已提交
55
 * @brief Close a mnode.
S
Shengliang Guan 已提交
56
 *
S
Shengliang Guan 已提交
57
 * @param pMnode The mnode object to close.
S
Shengliang Guan 已提交
58
 */
59
void mndClose(SMnode *pMnode);
60
void mndPreClose(SMnode *pMnode);
S
Shengliang Guan 已提交
61 62

/**
S
shm  
Shengliang Guan 已提交
63
 * @brief Start mnode
S
Shengliang Guan 已提交
64
 *
S
shm  
Shengliang Guan 已提交
65
 * @param pMnode The mnode object.
S
Shengliang Guan 已提交
66
 */
S
shm  
Shengliang Guan 已提交
67
int32_t mndStart(SMnode *pMnode);
68 69 70 71 72 73 74

/**
 * @brief Stop mnode
 *
 * @param pMnode The mnode object.
 */
void mndStop(SMnode *pMnode);
S
Shengliang Guan 已提交
75

C
cadem 已提交
76
int32_t mndIsCatchUp(SMnode *pMnode);
C
cadem 已提交
77
ESyncRole mndGetRole(SMnode *pMnode);
C
cadem 已提交
78

S
Shengliang Guan 已提交
79
/**
S
monitor  
Shengliang Guan 已提交
80
 * @brief Get mnode monitor info.
S
Shengliang Guan 已提交
81
 *
S
Shengliang Guan 已提交
82
 * @param pMnode The mnode object.
83 84
 * @param pCluster
 * @param pVgroup
S
Shengliang Guan 已提交
85
 * @param pStbInfo
86
 * @param pGrant
S
Shengliang Guan 已提交
87
 * @return int32_t 0 for success, -1 for failure.
S
Shengliang Guan 已提交
88
 */
S
Shengliang Guan 已提交
89 90
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
                          SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo);
91 92 93 94 95 96 97 98

/**
 * @brief Get mnode loads for status msg.
 *
 * @param pMnode The mnode object.
 * @param pLoad
 * @return int32_t 0 for success, -1 for failure.
 */
S
Shengliang Guan 已提交
99
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
S
Shengliang Guan 已提交
100

S
Shengliang Guan 已提交
101
/**
102
 * @brief Process the rpc, sync request.
S
Shengliang Guan 已提交
103
 *
S
Shengliang Guan 已提交
104 105
 * @param pMsg The request msg.
 * @return int32_t 0 for success, -1 for failure.
S
Shengliang Guan 已提交
106
 */
S
Shengliang Guan 已提交
107
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
M
Minghao Li 已提交
108
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
109 110
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg);
void    mndPostProcessQueryMsg(SRpcMsg *pMsg);
M
Minghao Li 已提交
111

S
Shengliang Guan 已提交
112 113 114 115 116
/**
 * @brief Generate machine code
 */
void mndGenerateMachineCode();

S
Shengliang Guan 已提交
117 118
void mndDumpSdb();

H
refact  
Hongze Cheng 已提交
119 120 121 122
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
123
#endif /*_TD_MND_H_*/