dmDef.h 4.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
Shengliang Guan 已提交
16 17
#ifndef _TD_DM_DEF_H_
#define _TD_DM_DEF_H_
S
Shengliang Guan 已提交
18

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

#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 已提交
40
#include "mnode.h"
S
Shengliang Guan 已提交
41
#include "monitor.h"
S
Shengliang Guan 已提交
42
#include "sync.h"
S
Shengliang Guan 已提交
43

S
Shengliang Guan 已提交
44 45
#include "libs/function/function.h"

S
Shengliang Guan 已提交
46 47 48 49
#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang Guan 已提交
50
typedef enum { DNODE, VNODE, QNODE, SNODE, MNODE, BNODE, NODE_END } EDndNodeType;
S
Shengliang Guan 已提交
51 52 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 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 114 115 116
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 } EDndProcType;

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;
    EDndNodeType ntype;
    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 已提交
117 118 119 120
  int32_t       unsyncedVgId;
  ESyncState    vndState;
  ESyncState    mndState;
  bool          isMnode;
S
Shengliang Guan 已提交
121
  bool          dropped;
S
Shengliang Guan 已提交
122
  SEpSet        mnodeEps;
S
Shengliang Guan 已提交
123
  SArray       *dnodeEps;
S
Shengliang Guan 已提交
124
  SHashObj     *dnodeHash;
S
Shengliang Guan 已提交
125 126
  TdThread     *statusThreadId;
  TdThread     *monitorThreadId;
S
Shengliang Guan 已提交
127 128 129 130 131
  SRWLatch      latch;
  SSingleWorker mgmtWorker;
  SMsgCb        msgCb;
  SDnode       *pDnode;
  TdFilePtr     lockfile;
S
Shengliang Guan 已提交
132 133 134 135 136 137 138 139 140
  char         *localEp;
  char         *localFqdn;
  char         *firstEp;
  char         *secondEp;
  char         *dataDir;
  SDiskCfg     *disks;
  int32_t       numOfDisks;
  int32_t       supportVnodes;
  uint16_t      serverPort;
S
Shengliang Guan 已提交
141 142
} SDnodeData;

S
Shengliang Guan 已提交
143 144 145 146 147
typedef struct {
  char name[TSDB_STEP_NAME_LEN];
  char desc[TSDB_STEP_DESC_LEN];
} SStartupInfo;

148 149 150 151 152 153 154 155
typedef struct SUdfdData {
  bool          startCalled;
  bool          needCleanUp;
  uv_loop_t     loop;
  uv_thread_t   thread;
  uv_barrier_t  barrier;
  uv_process_t  process;
  int           spawnErr;
156
  uv_pipe_t     ctrlPipe;
S
slzhou 已提交
157
  uv_async_t    stopAsync;
S
slzhou 已提交
158
  int32_t        stopCalled;
159 160

  int32_t         dnodeId;
161 162
} SUdfdData;

S
Shengliang Guan 已提交
163 164 165 166 167
typedef struct SDnode {
  EDndProcType  ptype;
  EDndNodeType  ntype;
  EDndRunStatus status;
  EDndEvent     event;
S
Shengliang Guan 已提交
168
  SStartupInfo  startup;
S
Shengliang Guan 已提交
169 170
  SDnodeTrans   trans;
  SDnodeData    data;
171
  SUdfdData     udfdData;
172
  TdThreadMutex mutex;
S
Shengliang Guan 已提交
173 174 175 176 177 178 179
  SMgmtWrapper  wrappers[NODE_END];
} SDnode;

#ifdef __cplusplus
}
#endif

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