mndInt.h 4.7 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_INT_H_
#define _TD_MND_INT_H_
H
refact  
Hongze Cheng 已提交
18

S
Shengliang Guan 已提交
19
#include "mndDef.h"
S
Shengliang Guan 已提交
20

S
Shengliang Guan 已提交
21
#include "sdb.h"
M
Minghao Li 已提交
22
#include "sync.h"
23
#include "syncTools.h"
S
Shengliang Guan 已提交
24
#include "tcache.h"
H
Haojun Liao 已提交
25
#include "tdatablock.h"
S
monitor  
Shengliang Guan 已提交
26
#include "tglobal.h"
27
#include "tqueue.h"
S
Shengliang Guan 已提交
28
#include "ttime.h"
S
charset  
Shengliang Guan 已提交
29
#include "version.h"
S
monitor  
Shengliang Guan 已提交
30
#include "wal.h"
S
Shengliang Guan 已提交
31

H
refact  
Hongze Cheng 已提交
32 33 34 35
#ifdef __cplusplus
extern "C" {
#endif

36
// clang-format off
S
Shengliang Guan 已提交
37 38 39 40 41 42 43
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255,        __VA_ARGS__); }}
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255,        __VA_ARGS__); }}
#define mWarn(...)  { if (mDebugFlag & DEBUG_WARN)  { taosPrintLog("MND WARN ",  DEBUG_WARN,  255,        __VA_ARGS__); }}
#define mInfo(...)  { if (mDebugFlag & DEBUG_INFO)  { taosPrintLog("MND ",       DEBUG_INFO,  255,        __VA_ARGS__); }}
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ",       DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ",       DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }}

S
Shengliang Guan 已提交
44 45 46 47 48 49
#define mGFatal(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mFatal(param ", gtid:%s", __VA_ARGS__, buf);}
#define mGError(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mError(param ", gtid:%s", __VA_ARGS__, buf);}
#define mGWarn(param, ...)  { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mWarn (param ", gtid:%s", __VA_ARGS__, buf);}
#define mGInfo(param, ...)  { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mInfo (param ", gtid:%s", __VA_ARGS__, buf);}
#define mGDebug(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mDebug(param ", gtid:%s", __VA_ARGS__, buf);}
#define mGTrace(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); mTrace(param ", gtid:%s", __VA_ARGS__, buf);}
50
// clang-format on
51

D
dapan1121 已提交
52 53
#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
#define SYSTABLE_SCH_DB_NAME_LEN    ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
54
#define SYSTABLE_SCH_COL_NAME_LEN   ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
D
dapan1121 已提交
55

S
Shengliang Guan 已提交
56
typedef int32_t (*MndMsgFp)(SRpcMsg *pMsg);
57 58
typedef int32_t (*MndInitFp)(SMnode *pMnode);
typedef void (*MndCleanupFp)(SMnode *pMnode);
S
Shengliang Guan 已提交
59
typedef int32_t (*ShowRetrieveFp)(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
S
Shengliang Guan 已提交
60
typedef void (*ShowFreeIterFp)(SMnode *pMnode, void *pIter);
D
dapan1121 已提交
61
typedef struct SQWorker SQHandle;
D
dapan1121 已提交
62

63
typedef struct {
dengyihao's avatar
dengyihao 已提交
64
  const char * name;
65 66 67
  MndInitFp    initFp;
  MndCleanupFp cleanupFp;
} SMnodeStep;
S
Shengliang Guan 已提交
68

S
Shengliang Guan 已提交
69
typedef struct {
70
  int64_t        showId;
S
Shengliang Guan 已提交
71 72
  ShowRetrieveFp retrieveFps[TSDB_MGMT_TABLE_MAX];
  ShowFreeIterFp freeIterFps[TSDB_MGMT_TABLE_MAX];
dengyihao's avatar
dengyihao 已提交
73
  SCacheObj *    cache;
S
Shengliang Guan 已提交
74 75
} SShowMgmt;

S
Shengliang Guan 已提交
76
typedef struct {
D
dapan1121 已提交
77
  SCacheObj *connCache;
dengyihao's avatar
dengyihao 已提交
78
  SCacheObj *appCache;
S
Shengliang Guan 已提交
79 80
} SProfileMgmt;

S
Shengliang Guan 已提交
81
typedef struct {
S
Shengliang Guan 已提交
82 83
  SRWLatch lock;
  char     email[TSDB_FQDN_LEN];
S
Shengliang Guan 已提交
84 85
} STelemMgmt;

S
Shengliang Guan 已提交
86
typedef struct {
wafwerar's avatar
wafwerar 已提交
87
  tsem_t    syncSem;
S
Shengliang Guan 已提交
88 89 90 91 92
  int64_t  sync;
  bool     standby;
  SReplica replica;
  int32_t  errCode;
  int32_t  transId;
S
Shengliang Guan 已提交
93 94
} SSyncMgmt;

S
Shengliang Guan 已提交
95 96 97 98 99
typedef struct {
  int64_t expireTimeMS;
  int64_t timeseriesAllowed;
} SGrantInfo;

100
typedef struct SMnode {
S
Shengliang Guan 已提交
101 102 103 104
  int32_t        selfDnodeId;
  int64_t        clusterId;
  TdThread       thread;
  TdThreadRwlock lock;
S
Shengliang Guan 已提交
105 106
  int32_t        rpcRef;
  int32_t        syncRef;
S
Shengliang Guan 已提交
107 108 109
  bool           stopped;
  bool           restored;
  bool           deploy;
dengyihao's avatar
dengyihao 已提交
110
  char *         path;
S
Shengliang Guan 已提交
111
  int64_t        checkTime;
dengyihao's avatar
dengyihao 已提交
112 113 114 115 116 117
  SSdb *         pSdb;
  SArray *       pSteps;
  SQHandle *     pQuery;
  SHashObj *     infosMeta;
  SHashObj *     perfsMeta;
  SWal *         pWal;
S
Shengliang Guan 已提交
118 119 120 121 122 123 124
  SShowMgmt      showMgmt;
  SProfileMgmt   profileMgmt;
  STelemMgmt     telemMgmt;
  SSyncMgmt      syncMgmt;
  SGrantInfo     grant;
  MndMsgFp       msgFp[TDMT_MAX];
  SMsgCb         msgCb;
125
} SMnode;
S
Shengliang Guan 已提交
126

S
sma  
Shengliang Guan 已提交
127
void    mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
128
int64_t mndGenerateUid(const char *name, int32_t len);
S
Shengliang Guan 已提交
129

S
Shengliang Guan 已提交
130 131 132 133 134 135
int32_t mndAcquireRpcRef(SMnode *pMnode);
void    mndReleaseRpcRef(SMnode *pMnode);
void    mndSetRestore(SMnode *pMnode, bool restored);
void    mndSetStop(SMnode *pMnode);
bool    mndGetStop(SMnode *pMnode);

H
refact  
Hongze Cheng 已提交
136 137 138 139
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
140
#endif /*_TD_MND_INT_H_*/