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

234 lines
8.1 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 "tfs.h"
2022-05-11 09:09:14 +00:00
#include "wal.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__); }}
2024-05-21 01:57:33 +00:00
#define encryptDebug(...) { \
if (toLogFile) { \
if (dDebugFlag & DEBUG_DEBUG) {taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__);} \
} else { \
/*if (dDebugFlag & DEBUG_DEBUG) {taosPrintLog("DND ", DEBUG_SCREEN, dDebugFlag, __VA_ARGS__);}*/ \
if (dDebugFlag & DEBUG_DEBUG) {printf(__VA_ARGS__); printf("\n");} \
} \
}
#define encryptInfo(...) { \
if (toLogFile) { \
taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); \
} else { \
/*if (dDebugFlag & DEBUG_DEBUG) {taosPrintLog("DND ", DEBUG_SCREEN, dDebugFlag, __VA_ARGS__);}*/ \
printf(__VA_ARGS__); \
printf("\n"); \
} \
}
#define encryptError(...) { \
if (toLogFile) { \
taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
}\
else{ \
/*taosPrintLog("DND ", DEBUG_SCREEN, 255, __VA_ARGS__); */\
printf("ERROR: " __VA_ARGS__); \
printf("\n"); \
}\
}
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)();
2023-12-06 07:48:40 +00:00
typedef void (*SendAuditRecordsFp)();
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;
2023-09-26 03:47:53 +00:00
int32_t engineVer;
2022-05-19 07:19:19 +00:00
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;
2023-06-13 07:07:00 +00:00
bool validMnodeEps;
int64_t ipWhiteVer;
2024-02-21 01:07:38 +00:00
char machineId[TSDB_MACHINE_ID_LEN + 1];
2024-03-29 02:48:49 +00:00
EEncryptAlgor encryptAlgorigthm;
EEncryptScope encryptScope;
2022-05-14 10:16:52 +00:00
} SDnodeData;
2022-05-11 09:09:14 +00:00
typedef struct {
2024-07-16 11:00:12 +00:00
const char *path;
const char *name;
STfs *pTfs;
SDnodeData *pData;
SMsgCb msgCb;
ProcessCreateNodeFp processCreateNodeFp;
2023-04-18 11:03:45 +00:00
ProcessAlterNodeTypeFp processAlterNodeTypeFp;
2024-07-16 11:00:12 +00:00
ProcessDropNodeFp processDropNodeFp;
SendMonitorReportFp sendMonitorReportFp;
SendAuditRecordsFp sendAuditRecordFp;
GetVnodeLoadsFp getVnodeLoadsFp;
GetVnodeLoadsFp getVnodeLoadsLiteFp;
GetMnodeLoadsFp getMnodeLoadsFp;
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
2024-07-16 11:00:12 +00:00
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile);
//int32_t dmCheckRunningWrapper(const char *dataDir, TdFilePtr *pFile);
2022-04-12 07:49:21 +00:00
2023-09-26 03:47:53 +00:00
// dmodule.c
int32_t dmInitDndInfo(SDnodeData *pData);
2022-05-14 10:16:52 +00:00
// dmEps.c
2024-04-27 20:37:30 +00:00
int32_t dmGetDnodeSize(SDnodeData *pData);
2022-05-14 10:16:52 +00:00
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 dmEpSetToStr(char *buf, int32_t len, SEpSet *epSet);
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);
void dmGetDnodeEp(void *pData, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
2024-05-21 01:57:33 +00:00
int32_t dmUpdateEncryptKey(char *key, bool toLogFile);
2024-04-09 06:55:01 +00:00
int32_t dmGetEncryptKey();
2022-04-12 07:49:21 +00:00
#ifdef __cplusplus
}
#endif
2022-05-31 06:03:47 +00:00
#endif /*_TD_DM_INT_H_*/