dnd.h 5.6 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
shm  
Shengliang Guan 已提交
16 17
#ifndef _TD_DND_H_
#define _TD_DND_H_
S
Shengliang Guan 已提交
18 19

#include "os.h"
S
Shengliang Guan 已提交
20 21 22 23

#include "cJSON.h"
#include "tcache.h"
#include "tcrc32c.h"
H
Haojun Liao 已提交
24 25
#include "tdatablock.h"
#include "tglobal.h"
S
Shengliang Guan 已提交
26
#include "thash.h"
S
Shengliang Guan 已提交
27
#include "tlockfree.h"
S
Shengliang Guan 已提交
28
#include "tlog.h"
S
Shengliang Guan 已提交
29
#include "tmsg.h"
S
shm  
Shengliang Guan 已提交
30
#include "tprocess.h"
S
Shengliang Guan 已提交
31
#include "tqueue.h"
S
Shengliang Guan 已提交
32 33 34
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
S
Shengliang Guan 已提交
35
#include "tworker.h"
S
shm  
Shengliang Guan 已提交
36
#include "tmsgcb.h"
S
Shengliang Guan 已提交
37 38

#include "dnode.h"
S
xshm  
Shengliang Guan 已提交
39
#include "monitor.h"
S
shm  
Shengliang Guan 已提交
40 41 42 43

#ifdef __cplusplus
extern "C" {
#endif
S
shm  
Shengliang Guan 已提交
44

45 46 47 48 49 50
#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__); }}
S
Shengliang Guan 已提交
51

S
shm  
Shengliang Guan 已提交
52
typedef enum { DNODE, VNODES, QNODE, SNODE, MNODE, BNODE, NODE_MAX } ENodeType;
S
shm  
Shengliang Guan 已提交
53
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus;
S
shm  
Shengliang Guan 已提交
54 55
typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EEnvStatus;
typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType;
S
Shengliang Guan 已提交
56

S
shm  
Shengliang Guan 已提交
57 58
typedef struct SMgmtFp      SMgmtFp;
typedef struct SMgmtWrapper SMgmtWrapper;
S
shm  
Shengliang Guan 已提交
59
typedef struct SMsgHandle   SMsgHandle;
S
shm  
Shengliang Guan 已提交
60 61 62 63 64 65
typedef struct SDnodeMgmt   SDnodeMgmt;
typedef struct SVnodesMgmt  SVnodesMgmt;
typedef struct SMnodeMgmt   SMnodeMgmt;
typedef struct SQnodeMgmt   SQnodeMgmt;
typedef struct SSnodeMgmt   SSnodeMgmt;
typedef struct SBnodeMgmt   SBnodeMgmt;
S
shm  
Shengliang Guan 已提交
66

S
Shengliang Guan 已提交
67
typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
S
shm  
Shengliang Guan 已提交
68
typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper);
S
shm  
Shengliang Guan 已提交
69
typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper);
S
shm  
Shengliang Guan 已提交
70
typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper);
S
shm  
Shengliang Guan 已提交
71 72
typedef int32_t (*CreateNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*DropNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
S
shm  
Shengliang Guan 已提交
73
typedef int32_t (*RequireNodeFp)(SMgmtWrapper *pWrapper, bool *required);
S
shm  
Shengliang Guan 已提交
74 75

typedef struct SMsgHandle {
S
Shengliang Guan 已提交
76 77
  SMgmtWrapper *pQndWrapper; 
  SMgmtWrapper *pMndWrapper;
S
shm  
Shengliang Guan 已提交
78 79
  SMgmtWrapper *pWrapper;
} SMsgHandle;
S
shm  
Shengliang Guan 已提交
80 81

typedef struct SMgmtFp {
S
shm  
Shengliang Guan 已提交
82 83
  OpenNodeFp    openFp;
  CloseNodeFp   closeFp;
S
shm  
Shengliang Guan 已提交
84
  StartNodeFp   startFp;
S
shm  
Shengliang Guan 已提交
85 86
  CreateNodeFp  createMsgFp;
  DropNodeFp    dropMsgFp;
S
shm  
Shengliang Guan 已提交
87
  RequireNodeFp requiredFp;
S
shm  
Shengliang Guan 已提交
88 89 90 91 92
} SMgmtFp;

typedef struct SMgmtWrapper {
  const char *name;
  char       *path;
S
shm  
Shengliang Guan 已提交
93
  int32_t     refCount;
S
shm  
Shengliang Guan 已提交
94
  SRWLatch    latch;
S
shm  
Shengliang Guan 已提交
95
  bool        deployed;
S
shm  
Shengliang Guan 已提交
96 97
  bool        required;
  EProcType   procType;
S
shm  
Shengliang Guan 已提交
98
  int32_t     procId;
S
shm  
Shengliang Guan 已提交
99
  SProcObj   *pProc;
S
shm  
Shengliang Guan 已提交
100
  SShm        shm;
S
shm  
Shengliang Guan 已提交
101
  void       *pMgmt;
S
Shengliang Guan 已提交
102
  SDnode     *pDnode;
S
shm  
Shengliang Guan 已提交
103
  SMgmtFp     fp;
S
shm  
Shengliang Guan 已提交
104 105
  int8_t      msgVgIds[TDMT_MAX];  // Handle the case where the same message type is distributed to qnode or vnode
  NodeMsgFp   msgFps[TDMT_MAX];
S
shm  
Shengliang Guan 已提交
106
} SMgmtWrapper;
S
Shengliang Guan 已提交
107

S
shm  
Shengliang Guan 已提交
108 109 110 111 112 113
typedef struct {
  void      *serverRpc;
  void      *clientRpc;
  SMsgHandle msgHandles[TDMT_MAX];
} STransMgmt;

S
Shengliang Guan 已提交
114
typedef struct SDnode {
S
shm  
Shengliang Guan 已提交
115 116 117
  int64_t      clusterId;
  int32_t      dnodeId;
  int32_t      numOfSupportVnodes;
S
shm  
Shengliang Guan 已提交
118
  int64_t      rebootTime;
S
shm  
Shengliang Guan 已提交
119 120 121 122 123
  char        *localEp;
  char        *localFqdn;
  char        *firstEp;
  char        *secondEp;
  char        *dataDir;
S
Shengliang Guan 已提交
124
  SDiskCfg    *disks;
S
shm  
Shengliang Guan 已提交
125 126 127
  int32_t      numOfDisks;
  uint16_t     serverPort;
  bool         dropped;
S
Shengliang Guan 已提交
128
  ENodeType    ntype;
S
Shengliang Guan 已提交
129
  EDndStatus   status;
S
shm  
Shengliang Guan 已提交
130 131
  EDndEvent    event;
  SStartupReq  startup;
S
shm  
Shengliang Guan 已提交
132
  TdFilePtr    lockfile;
S
shm  
Shengliang Guan 已提交
133
  STransMgmt   trans;
S
shm  
Shengliang Guan 已提交
134
  SMgmtWrapper wrappers[NODE_MAX];
S
Shengliang Guan 已提交
135 136
} SDnode;

S
shm  
Shengliang Guan 已提交
137 138
const char *dndNodeLogStr(ENodeType ntype);
const char *dndNodeProcStr(ENodeType ntype);
S
shm  
Shengliang Guan 已提交
139
const char *dndEventStr(EDndEvent ev);
S
shm  
Shengliang Guan 已提交
140 141
EDndStatus  dndGetStatus(SDnode *pDnode);
void        dndSetStatus(SDnode *pDnode, EDndStatus stat);
S
Shengliang Guan 已提交
142
void        dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
S
shm  
Shengliang Guan 已提交
143 144
void        dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
void        dndSendMonitorReport(SDnode *pDnode);
S
shm  
Shengliang Guan 已提交
145

S
shm  
Shengliang Guan 已提交
146 147 148 149 150
int32_t dndInitServer(SDnode *pDnode);
void    dndCleanupServer(SDnode *pDnode);
int32_t dndInitClient(SDnode *pDnode);
void    dndCleanupClient(SDnode *pDnode);
int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg);
S
shm  
Shengliang Guan 已提交
151
int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
S
shm  
Shengliang Guan 已提交
152
int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg);
S
shm  
Shengliang Guan 已提交
153
void    dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
S
Shengliang Guan 已提交
154
void    dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
S
shm  
Shengliang Guan 已提交
155
SMsgCb  dndCreateMsgcb(SMgmtWrapper *pWrapper);
S
shm  
Shengliang Guan 已提交
156

S
shm  
Shengliang Guan 已提交
157 158 159
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed);

S
Shengliang Guan 已提交
160 161 162 163
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, ENodeType nodeType);
int32_t       dndMarkWrapper(SMgmtWrapper *pWrapper);
void          dndReleaseWrapper(SMgmtWrapper *pWrapper);

S
Shengliang Guan 已提交
164 165 166 167
#ifdef __cplusplus
}
#endif

S
shm  
Shengliang Guan 已提交
168
#endif /*_TD_DND_H_*/