dmUtil.h 5.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_INT_H_
#define _TD_DM_INT_H_
S
Shengliang Guan 已提交
18

S
Shengliang 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#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"
#include "mnode.h"
#include "monitor.h"
#include "sync.h"
#include "wal.h"

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

#ifdef __cplusplus
extern "C" {
#endif

S
Shengliang 已提交
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
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
#define dWarn(...)  { if (dDebugFlag & DEBUG_WARN)  { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
#define dInfo(...)  { if (dDebugFlag & DEBUG_INFO)  { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}

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 已提交
84 85 86 87
typedef int32_t (*ProcessCreateNodeFp)(struct SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg);
typedef int32_t (*ProcessDropNodeFp)(struct SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg);
typedef int8_t (*IsNodeDeployedFp)(struct SDnode *pDnode, EDndNodeType ntype);

S
Shengliang 已提交
88
typedef struct {
S
Shengliang 已提交
89 90 91 92 93 94 95
  const char         *path;
  const char         *name;
  SMsgCb              msgCb;
  int32_t             dnodeId;
  int64_t             clusterId;
  const char         *localEp;
  const char         *firstEp;
S
Shengliang Guan 已提交
96
  const char         *secondEp;
S
Shengliang 已提交
97 98 99 100 101 102 103 104 105 106
  const char         *localFqdn;
  uint16_t            serverPort;
  int32_t             supportVnodes;
  int32_t             numOfDisks;
  SDiskCfg           *disks;
  const char         *dataDir;
  struct SDnode      *pDnode;
  ProcessCreateNodeFp processCreateNodeFp;
  ProcessDropNodeFp   processDropNodeFp;
  IsNodeDeployedFp    isNodeDeployedFp;
S
Shengliang 已提交
107 108 109 110 111 112 113 114 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 144
} SMgmtInputOpt;

typedef struct {
  int32_t dnodeId;
  void   *pMgmt;
} SMgmtOutputOpt;

typedef int32_t (*NodeMsgFp)(void *pMgmt, SNodeMsg *pMsg);
typedef int32_t (*NodeOpenFp)(const SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput);
typedef void (*NodeCloseFp)(void *pMgmt);
typedef int32_t (*NodeStartFp)(void *pMgmt);
typedef void (*NodeStopFp)(void *pMgmt);
typedef int32_t (*NodeCreateFp)(void *pMgmt, SNodeMsg *pMsg);
typedef int32_t (*NodeDropFp)(void *pMgmt, SNodeMsg *pMsg);
typedef int32_t (*NodeRequireFp)(const SMgmtInputOpt *pInput, bool *required);
typedef SArray *(*NodeGetHandlesFp)();  // array of SMgmtHandle

typedef struct {
  NodeOpenFp       openFp;
  NodeCloseFp      closeFp;
  NodeStartFp      startFp;
  NodeStopFp       stopFp;
  NodeCreateFp     createFp;
  NodeDropFp       dropFp;
  NodeRequireFp    requiredFp;
  NodeGetHandlesFp getHandlesFp;
} SMgmtFunc;

typedef struct {
  tmsg_t    msgType;
  bool      needCheckVgId;
  NodeMsgFp msgFp;
} SMgmtHandle;

// dmUtil.c
const char *dmStatStr(EDndRunStatus stype);
const char *dmNodeLogName(EDndNodeType ntype);
const char *dmNodeProcName(EDndNodeType ntype);
S
Shengliang 已提交
145
const char *dmNodeName(EDndNodeType ntype);
S
Shengliang 已提交
146 147
const char *dmEventStr(EDndEvent etype);
const char *dmProcStr(EDndProcType ptype);
S
Shengliang 已提交
148
void       *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId);
S
Shengliang 已提交
149
void        dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
S
Shengliang Guan 已提交
150 151

// dmFile.c
S
Shengliang 已提交
152 153
int32_t   dmReadFile(const char *path, const char *name, bool *pDeployed);
int32_t   dmWriteFile(const char *path, const char *name, bool deployed);
S
Shengliang Guan 已提交
154
TdFilePtr dmCheckRunning(const char *dataDir);
S
Shengliang 已提交
155 156
int32_t   dmReadShmFile(const char *path, const char *name, SShm *pShm);
int32_t   dmWriteShmFile(const char *path, const char *name, const SShm *pShm);
S
Shengliang Guan 已提交
157

S
Shengliang 已提交
158 159
// common define
typedef struct {
S
Shengliang Guan 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
  int32_t    dnodeId;
  int64_t    clusterId;
  int64_t    dnodeVer;
  int64_t    updateTime;
  int64_t    rebootTime;
  int32_t    unsyncedVgId;
  ESyncState vndState;
  ESyncState mndState;
  bool       isMnode;
  bool       dropped;
  SEpSet     mnodeEps;
  SArray    *dnodeEps;
  SHashObj  *dnodeHash;
  SRWLatch   latch;
  SMsgCb     msgCb;
  TdFilePtr  lockfile;
  char      *localEp;
  char      *localFqdn;
  char      *firstEp;
  char      *secondEp;
  char      *dataDir;
  SDiskCfg  *disks;
  int32_t    numOfDisks;
  int32_t    supportVnodes;
  uint16_t   serverPort;
S
Shengliang 已提交
185 186
} SDnodeData;

S
Shengliang Guan 已提交
187 188 189 190
#ifdef __cplusplus
}
#endif

S
Shengliang Guan 已提交
191
#endif /*_TD_DM_INT_H_*/