dndInt.h 4.4 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 20 21

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

S
Shengliang Guan 已提交
23
#include "os.h"
S
Shengliang Guan 已提交
24 25 26 27

#include "cJSON.h"
#include "tcache.h"
#include "tcrc32c.h"
S
Shengliang Guan 已提交
28
#include "tep.h"
S
Shengliang Guan 已提交
29
#include "thash.h"
S
Shengliang Guan 已提交
30
#include "tlockfree.h"
S
Shengliang Guan 已提交
31
#include "tlog.h"
S
Shengliang Guan 已提交
32
#include "tmsg.h"
S
Shengliang Guan 已提交
33
#include "tqueue.h"
S
Shengliang Guan 已提交
34 35 36
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
S
Shengliang Guan 已提交
37
#include "tworker.h"
S
Shengliang Guan 已提交
38 39

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

#include "bnode.h"
S
Shengliang Guan 已提交
42
#include "mnode.h"
S
Shengliang Guan 已提交
43 44
#include "qnode.h"
#include "snode.h"
S
Shengliang Guan 已提交
45
#include "vnode.h"
S
Shengliang Guan 已提交
46 47 48

extern int32_t dDebugFlag;

S
Shengliang Guan 已提交
49 50 51 52 53 54
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }}
#define dWarn(...)  { if (dDebugFlag & DEBUG_WARN)  { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }}
#define dInfo(...)  { if (dDebugFlag & DEBUG_INFO)  { taosPrintLog("DND ", 255, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
S
Shengliang Guan 已提交
55

S
Shengliang Guan 已提交
56
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EStat;
S
Shengliang Guan 已提交
57
typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType;
S
Shengliang Guan 已提交
58
typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps);
S
Shengliang Guan 已提交
59

S
Shengliang Guan 已提交
60
typedef struct {
S
Shengliang Guan 已提交
61
  EWorkerType    type;
S
Shengliang Guan 已提交
62 63 64
  const char    *name;
  int32_t        minNum;
  int32_t        maxNum;
S
Shengliang Guan 已提交
65
  void          *queueFp;
S
Shengliang Guan 已提交
66
  SDnode        *pDnode;
67
  STaosQueue    *queue;
S
Shengliang Guan 已提交
68 69 70 71
  union {
    SWorkerPool  pool;
    SMWorkerPool mpool;
  };
S
Shengliang Guan 已提交
72 73
} SDnodeWorker;

S
Shengliang Guan 已提交
74 75 76
typedef struct {
  char *dnode;
  char *mnode;
S
Shengliang Guan 已提交
77 78
  char *snode;
  char *bnode;
S
Shengliang Guan 已提交
79 80 81 82
  char *vnodes;
} SDnodeDir;

typedef struct {
S
Shengliang Guan 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96
  int32_t      dnodeId;
  int32_t      dropped;
  int64_t      clusterId;
  int64_t      dver;
  int64_t      rebootTime;
  int64_t      updateTime;
  int8_t       statusSent;
  SEpSet       mnodeEpSet;
  char        *file;
  SHashObj    *dnodeHash;
  SDnodeEps   *dnodeEps;
  pthread_t   *threadId;
  SRWLatch     latch;
  SDnodeWorker mgmtWorker;
S
Shengliang Guan 已提交
97
} SDnodeMgmt;
S
Shengliang Guan 已提交
98 99

typedef struct {
S
Shengliang Guan 已提交
100 101 102 103 104 105 106 107 108 109 110
  int32_t      refCount;
  int8_t       deployed;
  int8_t       dropped;
  SMnode      *pMnode;
  SRWLatch     latch;
  SDnodeWorker readWorker;
  SDnodeWorker writeWorker;
  SDnodeWorker syncWorker;
  int8_t       replica;
  int8_t       selfIndex;
  SReplica     replicas[TSDB_MAX_REPLICA];
S
Shengliang Guan 已提交
111
} SMnodeMgmt;
S
Shengliang Guan 已提交
112

S
Shengliang Guan 已提交
113
typedef struct {
S
Shengliang Guan 已提交
114 115 116 117 118 119 120
  int32_t      refCount;
  int8_t       deployed;
  int8_t       dropped;
  SQnode      *pQnode;
  SRWLatch     latch;
  SDnodeWorker queryWorker;
  SDnodeWorker fetchWorker;
S
Shengliang Guan 已提交
121 122 123
} SQnodeMgmt;

typedef struct {
S
Shengliang Guan 已提交
124 125 126 127 128 129
  int32_t      refCount;
  int8_t       deployed;
  int8_t       dropped;
  SSnode      *pSnode;
  SRWLatch     latch;
  SDnodeWorker writeWorker;
S
Shengliang Guan 已提交
130 131 132 133 134 135 136 137
} SSnodeMgmt;

typedef struct {
  int32_t      refCount;
  int8_t       deployed;
  int8_t       dropped;
  SBnode      *pBnode;
  SRWLatch     latch;
S
Shengliang Guan 已提交
138
  SDnodeWorker writeWorker;
S
Shengliang Guan 已提交
139 140
} SBnodeMgmt;

S
Shengliang Guan 已提交
141
typedef struct {
S
Shengliang Guan 已提交
142
  SHashObj    *hash;
143 144 145
  int32_t      openVnodes;
  int32_t      totalVnodes;
  SRWLatch     latch;
S
Shengliang Guan 已提交
146 147 148 149 150
  SWorkerPool  queryPool;
  SWorkerPool  fetchPool;
  SMWorkerPool syncPool;
  SMWorkerPool writePool;
} SVnodesMgmt;
S
Shengliang Guan 已提交
151 152

typedef struct {
S
Shengliang Guan 已提交
153 154
  void    *serverRpc;
  void    *clientRpc;
H
Hongze Cheng 已提交
155
  DndMsgFp msgFp[TDMT_MAX];
S
Shengliang Guan 已提交
156
} STransMgmt;
S
Shengliang Guan 已提交
157 158

typedef struct SDnode {
S
Shengliang Guan 已提交
159 160 161
  EStat       stat;
  SDnodeOpt   opt;
  SDnodeDir   dir;
S
Shengliang Guan 已提交
162
  FileFd      lockFd;
S
Shengliang Guan 已提交
163
  SDnodeMgmt  dmgmt;
S
Shengliang Guan 已提交
164
  SMnodeMgmt  mmgmt;
S
Shengliang Guan 已提交
165 166 167
  SQnodeMgmt  qmgmt;
  SSnodeMgmt  smgmt;
  SBnodeMgmt  bmgmt;
S
Shengliang Guan 已提交
168
  SVnodesMgmt vmgmt;
S
Shengliang Guan 已提交
169
  STransMgmt  tmgmt;
S
Shengliang Guan 已提交
170
  SStartupReq startup;
S
Shengliang Guan 已提交
171 172
} SDnode;

S
Shengliang Guan 已提交
173 174 175
EStat dndGetStat(SDnode *pDnode);
void  dndSetStat(SDnode *pDnode, EStat stat);
char *dndStatStr(EStat stat);
S
Shengliang Guan 已提交
176

S
Shengliang Guan 已提交
177
void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc);
S
Shengliang Guan 已提交
178
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
S
Shengliang Guan 已提交
179 180 181 182 183

#ifdef __cplusplus
}
#endif

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