dmDef.h 4.7 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_DM_DEF_H_
#define _TD_DM_DEF_H_
S
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19
// tobe deleted
S
slzhou 已提交
20
#include "uv.h"
S
Shengliang Guan 已提交
21

S
Shengliang Guan 已提交
22
#include "dmLog.h"
S
Shengliang Guan 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

#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 "tprocess.h"
#include "tqueue.h"
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
#include "tworker.h"

#include "dnode.h"
S
Shengliang Guan 已提交
42
#include "mnode.h"
S
Shengliang Guan 已提交
43
#include "monitor.h"
S
Shengliang Guan 已提交
44
#include "sync.h"
S
Shengliang Guan 已提交
45
#include "wal.h"
S
Shengliang Guan 已提交
46

S
Shengliang Guan 已提交
47 48
#include "libs/function/function.h"

S
Shengliang Guan 已提交
49 50 51 52
#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
typedef enum {
  DNODE = 0,
  VNODE = 1,
  QNODE = 2,
  SNODE = 3,
  MNODE = 4,
  BNODE = 5,
  NODE_END = 6,
} 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;

typedef enum {
  DND_PROC_SINGLE,
  DND_PROC_CHILD,
  DND_PROC_PARENT,
  DND_PROC_TEST,
} EDndProcType;
S
Shengliang Guan 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

typedef int32_t (*NodeMsgFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*OpenNodeFp)(struct SMgmtWrapper *pWrapper);
typedef void (*CloseNodeFp)(struct SMgmtWrapper *pWrapper);
typedef int32_t (*StartNodeFp)(struct SMgmtWrapper *pWrapper);
typedef void (*StopNodeFp)(struct SMgmtWrapper *pWrapper);
typedef int32_t (*CreateNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*DropNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
typedef int32_t (*RequireNodeFp)(struct SMgmtWrapper *pWrapper, bool *required);

typedef struct {
  SMgmtWrapper *pQndWrapper;
  SMgmtWrapper *pMndWrapper;
  SMgmtWrapper *pNdWrapper;
} SMsgHandle;

typedef struct {
  OpenNodeFp    openFp;
  CloseNodeFp   closeFp;
  StartNodeFp   startFp;
  StopNodeFp    stopFp;
  CreateNodeFp  createFp;
  DropNodeFp    dropFp;
  RequireNodeFp requiredFp;
} SMgmtFp;

typedef struct SMgmtWrapper {
  SDnode *pDnode;
  struct {
    const char  *name;
    char        *path;
    int32_t      refCount;
    SRWLatch     latch;
S
Shengliang Guan 已提交
114
    EDndNodeType nodeType;
S
Shengliang Guan 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    bool         deployed;
    bool         required;
    SMgmtFp      fp;
    void        *pMgmt;
  };
  struct {
    EDndProcType procType;
    int32_t      procId;
    SProcObj    *procObj;
    SShm         procShm;
  };
  struct {
    int8_t    msgVgIds[TDMT_MAX];  // Handle the case where the same message type is distributed to qnode or vnode
    NodeMsgFp msgFps[TDMT_MAX];
  };
} SMgmtWrapper;

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

typedef struct {
  int32_t       dnodeId;
  int64_t       clusterId;
  int64_t       dnodeVer;
  int64_t       updateTime;
  int64_t       rebootTime;
S
Shengliang Guan 已提交
144 145 146 147
  int32_t       unsyncedVgId;
  ESyncState    vndState;
  ESyncState    mndState;
  bool          isMnode;
S
Shengliang Guan 已提交
148
  bool          dropped;
S
Shengliang Guan 已提交
149
  SEpSet        mnodeEps;
S
Shengliang Guan 已提交
150
  SArray       *dnodeEps;
S
Shengliang Guan 已提交
151
  SHashObj     *dnodeHash;
S
Shengliang Guan 已提交
152 153
  TdThread     *statusThreadId;
  TdThread     *monitorThreadId;
S
Shengliang Guan 已提交
154 155 156 157 158
  SRWLatch      latch;
  SSingleWorker mgmtWorker;
  SMsgCb        msgCb;
  SDnode       *pDnode;
  TdFilePtr     lockfile;
S
Shengliang Guan 已提交
159 160 161 162 163 164 165 166 167
  char         *localEp;
  char         *localFqdn;
  char         *firstEp;
  char         *secondEp;
  char         *dataDir;
  SDiskCfg     *disks;
  int32_t       numOfDisks;
  int32_t       supportVnodes;
  uint16_t      serverPort;
S
Shengliang Guan 已提交
168 169
} SDnodeData;

S
Shengliang Guan 已提交
170 171 172 173 174
typedef struct {
  char name[TSDB_STEP_NAME_LEN];
  char desc[TSDB_STEP_DESC_LEN];
} SStartupInfo;

175
typedef struct SUdfdData {
S
Shengliang Guan 已提交
176 177 178 179 180 181 182 183 184 185 186
  bool         startCalled;
  bool         needCleanUp;
  uv_loop_t    loop;
  uv_thread_t  thread;
  uv_barrier_t barrier;
  uv_process_t process;
  int          spawnErr;
  uv_pipe_t    ctrlPipe;
  uv_async_t   stopAsync;
  int32_t      stopCalled;
  int32_t      dnodeId;
187 188
} SUdfdData;

S
Shengliang Guan 已提交
189 190 191 192 193
typedef struct SDnode {
  EDndProcType  ptype;
  EDndNodeType  ntype;
  EDndRunStatus status;
  EDndEvent     event;
S
Shengliang Guan 已提交
194
  SStartupInfo  startup;
S
Shengliang Guan 已提交
195 196
  SDnodeTrans   trans;
  SDnodeData    data;
197
  SUdfdData     udfdData;
198
  TdThreadMutex mutex;
S
Shengliang Guan 已提交
199 200 201 202 203 204 205
  SMgmtWrapper  wrappers[NODE_END];
} SDnode;

#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
206
#endif /*_TD_DM_DEF_H_*/