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

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

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

#ifdef __cplusplus
extern "C" {
#endif

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

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

S
Shengliang Guan 已提交
145 146 147 148 149
typedef struct SDnode {
  EDndProcType  ptype;
  EDndNodeType  ntype;
  EDndRunStatus status;
  EDndEvent     event;
S
Shengliang Guan 已提交
150
  SStartupInfo  startup;
S
Shengliang Guan 已提交
151 152
  SDnodeTrans   trans;
  SDnodeData    data;
153
  TdThreadMutex mutex;
S
Shengliang Guan 已提交
154 155 156 157 158 159 160
  SMgmtWrapper  wrappers[NODE_END];
} SDnode;

#ifdef __cplusplus
}
#endif

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