TDengine/source/dnode/mgmt/node_util/inc/dmUtil.h

186 lines
6.4 KiB
C
Raw Normal View History

2022-04-12 07:49:21 +00:00
/*
* 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/>.
*/
2022-04-13 06:00:56 +00:00
#ifndef _TD_DM_INT_H_
#define _TD_DM_INT_H_
2022-04-12 07:49:21 +00:00
2022-05-11 09:09:14 +00:00
#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"
2022-06-18 09:23:55 +00:00
#include "qnode.h"
2022-05-11 09:09:14 +00:00
#include "sync.h"
#include "wal.h"
2022-11-30 13:26:27 +00:00
#include "libs/function/tudf.h"
2022-04-12 07:49:21 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-06-21 07:05:31 +00:00
// 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__); }}
2023-02-23 09:54:51 +00:00
#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);}}
2023-02-23 10:07:48 +00:00
#define dGTrace(param, ...) {if (dDebugFlag & DEBUG_TRACE) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dTrace(param ", gtid:%s", __VA_ARGS__, buf);}}
2022-06-21 07:05:31 +00:00
// clang-format on
2022-05-11 09:09:14 +00:00
typedef enum {
DNODE = 0,
2022-05-12 13:25:32 +00:00
MNODE = 1,
VNODE = 2,
QNODE = 3,
SNODE = 4,
2022-10-18 09:34:58 +00:00
NODE_END = 5,
2022-05-11 09:09:14 +00:00
} 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;
2022-05-16 12:58:14 +00:00
typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
2022-05-19 03:10:13 +00:00
typedef void (*SendMonitorReportFp)();
2022-05-25 08:41:38 +00:00
typedef void (*GetVnodeLoadsFp)(SMonVloadInfo *pInfo);
typedef void (*GetMnodeLoadsFp)(SMonMloadInfo *pInfo);
2022-05-31 06:03:47 +00:00
typedef void (*GetQnodeLoadsFp)(SQnodeLoad *pInfo);
2023-04-18 11:03:45 +00:00
typedef int32_t (*ProcessAlterNodeTypeFp)(EDndNodeType ntype, SRpcMsg *pMsg);
2022-05-11 15:14:47 +00:00
2022-05-14 10:16:52 +00:00
typedef struct {
2022-05-19 07:19:19 +00:00
int32_t dnodeId;
int64_t clusterId;
int64_t dnodeVer;
int64_t updateTime;
int64_t rebootTime;
bool dropped;
bool stopped;
SEpSet mnodeEps;
SArray *dnodeEps;
SArray *oldDnodeEps;
2022-05-19 07:19:19 +00:00
SHashObj *dnodeHash;
TdThreadRwlock lock;
SMsgCb msgCb;
2022-05-14 10:16:52 +00:00
} SDnodeData;
2022-05-11 09:09:14 +00:00
typedef struct {
2022-05-11 15:14:47 +00:00
const char *path;
const char *name;
2022-05-14 10:16:52 +00:00
SDnodeData *pData;
SMsgCb msgCb;
2022-05-11 15:14:47 +00:00
ProcessCreateNodeFp processCreateNodeFp;
2023-04-18 11:03:45 +00:00
ProcessAlterNodeTypeFp processAlterNodeTypeFp;
2022-05-11 15:14:47 +00:00
ProcessDropNodeFp processDropNodeFp;
2022-05-19 03:10:13 +00:00
SendMonitorReportFp sendMonitorReportFp;
GetVnodeLoadsFp getVnodeLoadsFp;
GetMnodeLoadsFp getMnodeLoadsFp;
2022-05-31 06:03:47 +00:00
GetQnodeLoadsFp getQnodeLoadsFp;
2022-05-11 09:09:14 +00:00
} SMgmtInputOpt;
typedef struct {
2022-05-14 10:16:52 +00:00
void *pMgmt;
2022-05-11 09:09:14 +00:00
} SMgmtOutputOpt;
2022-05-16 06:55:31 +00:00
typedef int32_t (*NodeMsgFp)(void *pMgmt, SRpcMsg *pMsg);
2022-05-14 10:16:52 +00:00
typedef int32_t (*NodeOpenFp)(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput);
2022-05-11 09:09:14 +00:00
typedef void (*NodeCloseFp)(void *pMgmt);
typedef int32_t (*NodeStartFp)(void *pMgmt);
typedef void (*NodeStopFp)(void *pMgmt);
2022-05-16 06:55:31 +00:00
typedef int32_t (*NodeCreateFp)(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
2022-05-17 06:34:16 +00:00
typedef int32_t (*NodeDropFp)(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
2022-05-11 09:09:14 +00:00
typedef int32_t (*NodeRequireFp)(const SMgmtInputOpt *pInput, bool *required);
typedef SArray *(*NodeGetHandlesFp)(); // array of SMgmtHandle
2023-04-18 11:03:45 +00:00
typedef bool (*NodeIsCatchUpFp)(void *pMgmt);
typedef bool (*NodeRole)(void *pMgmt);
2022-05-11 09:09:14 +00:00
typedef struct {
NodeOpenFp openFp;
NodeCloseFp closeFp;
NodeStartFp startFp;
NodeStopFp stopFp;
NodeCreateFp createFp;
NodeDropFp dropFp;
NodeRequireFp requiredFp;
NodeGetHandlesFp getHandlesFp;
2023-04-18 11:03:45 +00:00
NodeIsCatchUpFp isCatchUpFp;
NodeRole nodeRoleFp;
2022-05-11 09:09:14 +00:00
} SMgmtFunc;
typedef struct {
tmsg_t msgType;
bool needCheckVgId;
NodeMsgFp msgFp;
} SMgmtHandle;
// dmUtil.c
const char *dmStatStr(EDndRunStatus stype);
2022-05-11 13:19:33 +00:00
const char *dmNodeName(EDndNodeType ntype);
2022-05-11 10:23:58 +00:00
void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId);
2022-05-11 15:14:47 +00:00
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
2022-04-13 06:00:56 +00:00
// dmFile.c
2022-05-11 09:09:14 +00:00
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
2022-04-13 06:00:56 +00:00
TdFilePtr dmCheckRunning(const char *dataDir);
2022-04-12 07:49:21 +00:00
2022-05-14 10:16:52 +00:00
// dmEps.c
int32_t dmReadEps(SDnodeData *pData);
int32_t dmWriteEps(SDnodeData *pData);
void dmUpdateEps(SDnodeData *pData, SArray *pDnodeEps);
2022-05-16 08:32:30 +00:00
void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
void dmRotateMnodeEpSet(SDnodeData *pData);
void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet);
2022-05-16 08:32:30 +00:00
void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
bool dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
void dmRemoveDnodePairs(SDnodeData *pData);
2022-05-11 15:14:47 +00:00
2022-04-12 07:49:21 +00:00
#ifdef __cplusplus
}
#endif
2022-05-31 06:03:47 +00:00
#endif /*_TD_DM_INT_H_*/