dndInt.h 5.2 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_DND_INT_H_
#define _TD_DND_INT_H_
S
Shengliang Guan 已提交
18 19

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

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

#include "dnode.h"
S
Shengliang Guan 已提交
39 40

#include "bnode.h"
S
Shengliang Guan 已提交
41
#include "mnode.h"
S
Shengliang Guan 已提交
42 43
#include "qnode.h"
#include "snode.h"
S
Shengliang Guan 已提交
44
#include "tfs.h"
S
shm  
Shengliang Guan 已提交
45
#include "vnode.h"
S
shm  
Shengliang Guan 已提交
46 47 48 49 50
#include "monitor.h"

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

52 53 54 55 56 57
#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 已提交
58

S
shm  
Shengliang Guan 已提交
59
typedef enum { MNODE, VNODES, QNODE, SNODE, BNODE, DNODE, NODE_MAX } ENodeType;
S
shm  
Shengliang Guan 已提交
60
typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType;
S
shm  
Shengliang Guan 已提交
61
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus;
S
Shengliang Guan 已提交
62
typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType;
S
Shengliang Guan 已提交
63
typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EEnvStat;
S
Shengliang Guan 已提交
64

S
shm  
Shengliang Guan 已提交
65 66
typedef struct SMgmtFp      SMgmtFp;
typedef struct SMgmtWrapper SMgmtWrapper;
S
shm  
Shengliang Guan 已提交
67
typedef struct SMsgHandle   SMsgHandle;
S
shm  
Shengliang Guan 已提交
68 69 70 71 72 73
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 已提交
74

S
shm  
Shengliang Guan 已提交
75
typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
S
shm  
Shengliang Guan 已提交
76
typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper);
S
shm  
Shengliang Guan 已提交
77
typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper);
S
shm  
Shengliang Guan 已提交
78
typedef bool (*RequireNodeFp)(SMgmtWrapper *pWrapper);
S
shm  
Shengliang Guan 已提交
79 80

typedef struct SMsgHandle {
S
shm  
Shengliang Guan 已提交
81
  NodeMsgFp     msgFp;
S
shm  
Shengliang Guan 已提交
82 83
  SMgmtWrapper *pWrapper;
} SMsgHandle;
S
shm  
Shengliang Guan 已提交
84 85

typedef struct SMgmtFp {
S
shm  
Shengliang Guan 已提交
86 87 88
  OpenNodeFp     openFp;
  CloseNodeFp    closeFp;
  RequireNodeFp  requiredFp;
S
shm  
Shengliang Guan 已提交
89 90 91 92 93 94 95 96 97
} SMgmtFp;

typedef struct SMgmtWrapper {
  const char *name;
  char       *path;
  bool        required;
  EProcType   procType;
  SProcObj   *pProc;
  void       *pMgmt;
S
Shengliang Guan 已提交
98
  SDnode     *pDnode;
S
shm  
Shengliang Guan 已提交
99
  NodeMsgFp   msgFps[TDMT_MAX];
S
shm  
Shengliang Guan 已提交
100
  SMgmtFp     fp;
S
shm  
Shengliang Guan 已提交
101
} SMgmtWrapper;
S
Shengliang Guan 已提交
102

S
shm  
Shengliang Guan 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
typedef struct {
  EWorkerType type;
  const char *name;
  int32_t     minNum;
  int32_t     maxNum;
  void       *queueFp;
  SDnode     *pDnode;
  STaosQueue *queue;
  union {
    SQWorkerPool pool;
    SWWorkerPool mpool;
  };
} SDnodeWorker;

typedef struct {
  void      *serverRpc;
  void      *clientRpc;
  SMsgHandle msgHandles[TDMT_MAX];
} STransMgmt;

S
Shengliang Guan 已提交
123
typedef struct SDnode {
S
shm  
Shengliang Guan 已提交
124
  int64_t      rebootTime;
S
Shengliang Guan 已提交
125
  EDndStatus   status;
S
shm  
Shengliang Guan 已提交
126 127 128 129
  EDndEvent    event;
  EProcType    procType;
  SDndCfg      cfg;
  SStartupReq  startup;
S
Shengliang Guan 已提交
130
  TdFilePtr    pLockFile;
S
shm  
Shengliang Guan 已提交
131
  STransMgmt   trans;
S
shm  
Shengliang Guan 已提交
132
  SMgmtWrapper wrappers[NODE_MAX];
S
Shengliang Guan 已提交
133 134
} SDnode;

S
shm  
Shengliang Guan 已提交
135 136 137 138 139 140 141 142 143 144
// dndInt.h
int32_t       dndInit();
void          dndCleanup();
EDndStatus    dndGetStatus(SDnode *pDnode);
void          dndSetStatus(SDnode *pDnode, EDndStatus stat);
const char   *dndStatStr(EDndStatus stat);
void          dndReportStartup(SDnode *pDnode, char *pName, char *pDesc);
void          dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
TdFilePtr     dndCheckRunning(char *dataDir);
SMgmtWrapper *dndGetWrapper(SDnode *pDnode, ENodeType nodeType);
S
shm  
Shengliang Guan 已提交
145
void          dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp);
S
shm  
Shengliang Guan 已提交
146 147 148 149 150 151 152 153 154

// dndMonitor.h
void dndSendMonitorReport(SDnode *pDnode);

// dndNode.h
SDnode *dndCreate(SDndCfg *pCfg);
void    dndClose(SDnode *pDnode);
int32_t dndRun(SDnode *pDnode);
void    dndeHandleEvent(SDnode *pDnode, EDndEvent event);
S
shm  
Shengliang Guan 已提交
155
void    dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, SEpSet *pEpSet);
S
shm  
Shengliang Guan 已提交
156 157 158 159 160 161 162 163 164 165

// dndTransport.h
int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg);
int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg);

// dndWorker.h
int32_t dndInitWorker(SDnode *pDnode, SDnodeWorker *pWorker, EWorkerType type, const char *name, int32_t minNum,
                      int32_t maxNum, void *queueFp);
void    dndCleanupWorker(SDnodeWorker *pWorker);
int32_t dndWriteMsgToWorker(SDnodeWorker *pWorker, void *pCont, int32_t contLen);
S
shm  
Shengliang Guan 已提交
166

S
Shengliang Guan 已提交
167 168 169 170
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
171
#endif /*_TD_DND_INT_H_*/