dmUtil.h 6.5 KB
Newer Older
S
Shengliang Guan 已提交
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_DM_INT_H_
#define _TD_DM_INT_H_
S
Shengliang Guan 已提交
18

S
Shengliang 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "cJSON.h"
#include "tcache.h"
#include "tcrc32c.h"
#include "tdatablock.h"
#include "tglobal.h"
#include "thash.h"
#include "tlockfree.h"
#include "tlog.h"
#include "tmsg.h"
#include "tmsgcb.h"
#include "tqueue.h"
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
#include "tworker.h"

#include "dnode.h"
#include "mnode.h"
#include "monitor.h"
dengyihao's avatar
dengyihao 已提交
38
#include "qnode.h"
S
Shengliang 已提交
39 40 41
#include "sync.h"
#include "wal.h"

H
Haojun Liao 已提交
42
#include "libs/function/tudf.h"
S
Shengliang Guan 已提交
43 44 45 46
#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
47 48 49 50 51 52 53 54 55
// clang-format off

#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255,        __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255,        __VA_ARGS__); }}
#define dWarn(...)  { if (dDebugFlag & DEBUG_WARN)  { taosPrintLog("DND WARN ",  DEBUG_WARN,  255,        __VA_ARGS__); }}
#define dInfo(...)  { if (dDebugFlag & DEBUG_INFO)  { taosPrintLog("DND ",       DEBUG_INFO,  255,        __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ",       DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ",       DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}

dengyihao's avatar
dengyihao 已提交
56 57 58 59 60
#define dGFatal(param, ...) {if (dDebugFlag & DEBUG_FATAL) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dFatal(param ", gtid:%s", __VA_ARGS__, buf);}}
#define dGError(param, ...) {if (dDebugFlag & DEBUG_ERROR) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dError(param ", gtid:%s", __VA_ARGS__, buf);}}
#define dGWarn(param, ...)  {if (dDebugFlag & DEBUG_WARN)  { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dWarn(param ", gtid:%s", __VA_ARGS__, buf);}}
#define dGInfo(param, ...)  {if (dDebugFlag & DEBUG_INFO)  { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dInfo(param ", gtid:%s", __VA_ARGS__, buf);}}
#define dGDebug(param, ...) {if (dDebugFlag & DEBUG_DEBUG) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dDebug(param ", gtid:%s", __VA_ARGS__, buf);}}
dengyihao's avatar
dengyihao 已提交
61
#define dGTrace(param, ...) {if (dDebugFlag & DEBUG_TRACE) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dTrace(param ", gtid:%s", __VA_ARGS__, buf);}}
S
Shengliang Guan 已提交
62 63

// clang-format on
S
Shengliang 已提交
64 65 66

typedef enum {
  DNODE = 0,
S
Shengliang Guan 已提交
67 68 69 70
  MNODE = 1,
  VNODE = 2,
  QNODE = 3,
  SNODE = 4,
S
Shengliang Guan 已提交
71
  NODE_END = 5,
S
Shengliang 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85
} EDndNodeType;

typedef enum {
  DND_STAT_INIT,
  DND_STAT_RUNNING,
  DND_STAT_STOPPED,
} EDndRunStatus;

typedef enum {
  DND_ENV_INIT,
  DND_ENV_READY,
  DND_ENV_CLEANUP,
} EDndEnvStatus;

86 87
typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
S
Shengliang Guan 已提交
88
typedef void (*SendMonitorReportFp)();
89 90
typedef void (*GetVnodeLoadsFp)(SMonVloadInfo *pInfo);
typedef void (*GetMnodeLoadsFp)(SMonMloadInfo *pInfo);
D
dapan1121 已提交
91
typedef void (*GetQnodeLoadsFp)(SQnodeLoad *pInfo);
C
cadem 已提交
92
typedef int32_t (*ProcessAlterNodeTypeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
S
Shengliang 已提交
93

S
Shengliang Guan 已提交
94
typedef struct {
95 96 97 98 99 100 101 102 103
  int32_t        dnodeId;
  int64_t        clusterId;
  int64_t        dnodeVer;
  int64_t        updateTime;
  int64_t        rebootTime;
  bool           dropped;
  bool           stopped;
  SEpSet         mnodeEps;
  SArray        *dnodeEps;
104
  SArray        *oldDnodeEps;
105 106 107
  SHashObj      *dnodeHash;
  TdThreadRwlock lock;
  SMsgCb         msgCb;
D
dmchen 已提交
108
  bool           validMnodeEps;
S
Shengliang Guan 已提交
109 110
} SDnodeData;

S
Shengliang 已提交
111
typedef struct {
S
Shengliang 已提交
112 113
  const char         *path;
  const char         *name;
S
Shengliang Guan 已提交
114 115
  SDnodeData         *pData;
  SMsgCb              msgCb;
S
Shengliang 已提交
116
  ProcessCreateNodeFp processCreateNodeFp;
C
cadem 已提交
117
  ProcessAlterNodeTypeFp processAlterNodeTypeFp;
S
Shengliang 已提交
118
  ProcessDropNodeFp   processDropNodeFp;
S
Shengliang Guan 已提交
119 120 121
  SendMonitorReportFp sendMonitorReportFp;
  GetVnodeLoadsFp     getVnodeLoadsFp;
  GetMnodeLoadsFp     getMnodeLoadsFp;
D
dapan1121 已提交
122
  GetQnodeLoadsFp     getQnodeLoadsFp;
S
Shengliang 已提交
123 124 125
} SMgmtInputOpt;

typedef struct {
S
Shengliang Guan 已提交
126
  void *pMgmt;
S
Shengliang 已提交
127 128
} SMgmtOutputOpt;

S
Shengliang Guan 已提交
129
typedef int32_t (*NodeMsgFp)(void *pMgmt, SRpcMsg *pMsg);
S
Shengliang Guan 已提交
130
typedef int32_t (*NodeOpenFp)(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput);
S
Shengliang 已提交
131 132 133
typedef void (*NodeCloseFp)(void *pMgmt);
typedef int32_t (*NodeStartFp)(void *pMgmt);
typedef void (*NodeStopFp)(void *pMgmt);
S
Shengliang Guan 已提交
134
typedef int32_t (*NodeCreateFp)(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
135
typedef int32_t (*NodeDropFp)(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
S
Shengliang 已提交
136 137
typedef int32_t (*NodeRequireFp)(const SMgmtInputOpt *pInput, bool *required);
typedef SArray *(*NodeGetHandlesFp)();  // array of SMgmtHandle
C
cadem 已提交
138
typedef bool (*NodeIsCatchUpFp)(void *pMgmt);
C
cadem 已提交
139
typedef bool (*NodeRole)(void *pMgmt);
S
Shengliang 已提交
140 141 142 143 144 145 146 147 148 149

typedef struct {
  NodeOpenFp       openFp;
  NodeCloseFp      closeFp;
  NodeStartFp      startFp;
  NodeStopFp       stopFp;
  NodeCreateFp     createFp;
  NodeDropFp       dropFp;
  NodeRequireFp    requiredFp;
  NodeGetHandlesFp getHandlesFp;
C
cadem 已提交
150
  NodeIsCatchUpFp  isCatchUpFp;
C
cadem 已提交
151
  NodeRole         nodeRoleFp;
S
Shengliang 已提交
152 153 154 155 156 157 158 159 160 161
} SMgmtFunc;

typedef struct {
  tmsg_t    msgType;
  bool      needCheckVgId;
  NodeMsgFp msgFp;
} SMgmtHandle;

// dmUtil.c
const char *dmStatStr(EDndRunStatus stype);
S
Shengliang 已提交
162
const char *dmNodeName(EDndNodeType ntype);
S
Shengliang 已提交
163
void       *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId);
S
Shengliang 已提交
164
void        dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
S
Shengliang Guan 已提交
165 166

// dmFile.c
S
Shengliang 已提交
167 168
int32_t   dmReadFile(const char *path, const char *name, bool *pDeployed);
int32_t   dmWriteFile(const char *path, const char *name, bool deployed);
S
Shengliang Guan 已提交
169
TdFilePtr dmCheckRunning(const char *dataDir);
S
Shengliang Guan 已提交
170

S
Shengliang Guan 已提交
171 172 173 174
// dmEps.c
int32_t dmReadEps(SDnodeData *pData);
int32_t dmWriteEps(SDnodeData *pData);
void    dmUpdateEps(SDnodeData *pData, SArray *pDnodeEps);
S
Shengliang Guan 已提交
175
void    dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
176
void    dmRotateMnodeEpSet(SDnodeData *pData);
177
void    dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet);
S
Shengliang Guan 已提交
178
void    dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
179
bool    dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
180
void    dmRemoveDnodePairs(SDnodeData *pData);
S
Shengliang 已提交
181

S
Shengliang Guan 已提交
182 183 184 185
#ifdef __cplusplus
}
#endif

D
dapan1121 已提交
186
#endif /*_TD_DM_INT_H_*/