You need to sign in or sign up before continuing.
dmDef.h 4.5 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 44 45 46 47

#ifdef __cplusplus
extern "C" {
#endif

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

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

146 147 148 149 150 151 152 153
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;
154
  uv_pipe_t     ctrlPipe;
S
slzhou 已提交
155
  uv_async_t    stopAsync;
S
slzhou 已提交
156
  int32_t        stopCalled;
157 158
} SUdfdData;

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

#ifdef __cplusplus
}
#endif

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