mnodeDnode.c 27.7 KB
Newer Older
S
slguan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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/>.
 */

#define _DEFAULT_SOURCE
17
#include "os.h"
S
slguan 已提交
18
#include "tgrant.h"
S
slguan 已提交
19
#include "tbalance.h"
S
slguan 已提交
20 21
#include "tglobal.h"
#include "tconfig.h"
S
slguan 已提交
22 23 24
#include "ttime.h"
#include "tutil.h"
#include "tsocket.h"
S
slguan 已提交
25
#include "tbalance.h"
S
slguan 已提交
26
#include "tsync.h"
27
#include "tdataformat.h"
28
#include "mnode.h"
S
slguan 已提交
29
#include "dnode.h"
S
Shengliang Guan 已提交
30 31 32 33 34
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeDnode.h"
#include "mnodeMnode.h"
#include "mnodeSdb.h"
35
#include "mnodeShow.h"
S
Shengliang Guan 已提交
36 37
#include "mnodeUser.h"
#include "mnodeVgroup.h"
38 39
#include "mnodeWrite.h"
#include "mnodePeer.h"
S
slguan 已提交
40

S
slguan 已提交
41
int32_t tsAccessSquence = 0;
42 43
static void   *tsDnodeSdb = NULL;
static int32_t tsDnodeUpdateSize = 0;
S
slguan 已提交
44
extern void *  tsMnodeSdb;
S
slguan 已提交
45 46
extern void *  tsVgroupSdb;

47
static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg);
48 49 50 51 52 53 54 55 56 57 58 59 60
static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg);
static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg);
static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg);
static void    mnodeProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) ;
static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *rpcMsg);
static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mnodeRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mnodeRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
61
static char*   mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole);
62 63

static int32_t mnodeDnodeActionDestroy(SSdbOper *pOper) {
S
slguan 已提交
64 65 66
  tfree(pOper->pObj);
  return TSDB_CODE_SUCCESS;
}
S
slguan 已提交
67

68
static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) {
S
slguan 已提交
69 70 71
  SDnodeObj *pDnode = pOper->pObj;
  if (pDnode->status != TAOS_DN_STATUS_DROPPING) {
    pDnode->status = TAOS_DN_STATUS_OFFLINE;
S
slguan 已提交
72
  }
S
slguan 已提交
73 74

  return TSDB_CODE_SUCCESS;
S
slguan 已提交
75 76
}

77
static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
S
slguan 已提交
78
  SDnodeObj *pDnode = pOper->pObj;
79
 
S
slguan 已提交
80
#ifndef _SYNC 
81
  mnodeDropAllDnodeVgroups(pDnode);
S
slguan 已提交
82
#endif  
83
  mnodeDropMnodeLocal(pDnode->dnodeId);
S
slguan 已提交
84 85
  balanceNotify();

86
  mTrace("dnode:%d, all vgroups is dropped from sdb", pDnode->dnodeId);
S
slguan 已提交
87 88 89
  return TSDB_CODE_SUCCESS;
}

90
static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
S
slguan 已提交
91
  SDnodeObj *pDnode = pOper->pObj;
92
  SDnodeObj *pSaved = mnodeGetDnode(pDnode->dnodeId);
93
  if (pDnode != pSaved && pDnode != NULL && pSaved != NULL) {
S
slguan 已提交
94 95
    memcpy(pSaved, pDnode, pOper->rowSize);
    free(pDnode);
S
slguan 已提交
96
  }
97
  mnodeDecDnodeRef(pSaved);
S
slguan 已提交
98 99 100
  return TSDB_CODE_SUCCESS;
}

101
static int32_t mnodeDnodeActionEncode(SSdbOper *pOper) {
S
slguan 已提交
102 103 104 105
  SDnodeObj *pDnode = pOper->pObj;
  memcpy(pOper->rowData, pDnode, tsDnodeUpdateSize);
  pOper->rowSize = tsDnodeUpdateSize;
  return TSDB_CODE_SUCCESS;
S
slguan 已提交
106 107
}

108
static int32_t mnodeDnodeActionDecode(SSdbOper *pOper) {
S
slguan 已提交
109
  SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj));
110
  if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
S
slguan 已提交
111

S
slguan 已提交
112 113 114 115
  memcpy(pDnode, pOper->rowData, tsDnodeUpdateSize);
  pOper->pObj = pDnode;
  return TSDB_CODE_SUCCESS;
}
S
slguan 已提交
116

117
static int32_t mnodeDnodeActionRestored() {
S
slguan 已提交
118
  int32_t numOfRows = sdbGetNumOfRows(tsDnodeSdb);
S
slguan 已提交
119
  if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
120
    mPrint("dnode first deploy, create dnode:%s", tsLocalEp);
121
    mnodeCreateDnode(tsLocalEp, NULL);
122 123 124
    SDnodeObj *pDnode = mnodeGetDnodeByEp(tsLocalEp);
    mnodeAddMnode(pDnode->dnodeId);
    mnodeDecDnodeRef(pDnode);
S
slguan 已提交
125 126
  }

S
slguan 已提交
127
  return TSDB_CODE_SUCCESS;
S
slguan 已提交
128 129
}

130
int32_t mnodeInitDnodes() {
S
slguan 已提交
131 132 133 134 135 136
  SDnodeObj tObj;
  tsDnodeUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;

  SSdbTableDesc tableDesc = {
    .tableId      = SDB_TABLE_DNODE,
    .tableName    = "dnodes",
S
Shengliang Guan 已提交
137
    .hashSessions = TSDB_DEFAULT_DNODES_HASH_SIZE,
S
slguan 已提交
138 139 140
    .maxRowSize   = tsDnodeUpdateSize,
    .refCountPos  = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
    .keyType      = SDB_KEY_AUTO,
141 142 143 144 145 146 147
    .insertFp     = mnodeDnodeActionInsert,
    .deleteFp     = mnodeDnodeActionDelete,
    .updateFp     = mnodeDnodeActionUpdate,
    .encodeFp     = mnodeDnodeActionEncode,
    .decodeFp     = mnodeDnodeActionDecode,
    .destroyFp    = mnodeDnodeActionDestroy,
    .restoredFp   = mnodeDnodeActionRestored
S
slguan 已提交
148 149 150 151 152 153 154 155
  };

  tsDnodeSdb = sdbOpenTable(&tableDesc);
  if (tsDnodeSdb == NULL) {
    mError("failed to init dnodes data");
    return -1;
  }

156 157 158 159 160 161 162 163 164 165 166 167 168
  mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CREATE_DNODE, mnodeProcessCreateDnodeMsg);
  mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_DNODE, mnodeProcessDropDnodeMsg); 
  mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_CONFIG_DNODE, mnodeProcessCfgDnodeMsg);
  mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP, mnodeProcessCfgDnodeMsgRsp);
  mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_STATUS, mnodeProcessDnodeStatusMsg);
  mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_MODULE, mnodeGetModuleMeta);
  mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_MODULE, mnodeRetrieveModules);
  mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CONFIGS, mnodeGetConfigMeta);
  mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CONFIGS, mnodeRetrieveConfigs);
  mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VNODES, mnodeGetVnodeMeta);
  mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VNODES, mnodeRetrieveVnodes);
  mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_DNODE, mnodeGetDnodeMeta);
  mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_DNODE, mnodeRetrieveDnodes);
S
slguan 已提交
169
 
S
slguan 已提交
170
  mTrace("table:dnodes table is created");
S
slguan 已提交
171 172 173
  return 0;
}

S
Shengliang Guan 已提交
174
void mnodeCleanupDnodes() {
S
slguan 已提交
175 176 177
  sdbCloseTable(tsDnodeSdb);
}

178
void *mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode) { 
S
Shengliang Guan 已提交
179
  return sdbFetchRow(tsDnodeSdb, pIter, (void **)pDnode); 
S
slguan 已提交
180 181
}

182
int32_t mnodeGetDnodesNum() {
S
slguan 已提交
183 184 185
  return sdbGetNumOfRows(tsDnodeSdb);
}

186
int32_t mnodeGetOnlinDnodesNum(char *ep) {
187 188 189 190 191
  SDnodeObj *pDnode = NULL;
  void *     pIter = NULL;
  int32_t    onlineDnodes = 0;

  while (1) {
192
    pIter = mnodeGetNextDnode(pIter, &pDnode);
193 194
    if (pDnode == NULL) break;
    if (pDnode->status != TAOS_DN_STATUS_OFFLINE) onlineDnodes++;
195
    mnodeDecDnodeRef(pDnode);
196 197 198 199 200 201 202
  }

  sdbFreeIter(pIter);

  return onlineDnodes;
}

203
void *mnodeGetDnode(int32_t dnodeId) {
S
slguan 已提交
204 205 206
  return sdbGetRow(tsDnodeSdb, &dnodeId);
}

207
void *mnodeGetDnodeByEp(char *ep) {
S
slguan 已提交
208
  SDnodeObj *pDnode = NULL;
S
Shengliang Guan 已提交
209
  void *     pIter = NULL;
S
slguan 已提交
210 211

  while (1) {
212
    pIter = mnodeGetNextDnode(pIter, &pDnode);
S
slguan 已提交
213
    if (pDnode == NULL) break;
J
jtao1735 已提交
214
    if (strcmp(ep, pDnode->dnodeEp) == 0) {
S
Shengliang Guan 已提交
215
      sdbFreeIter(pIter);
S
slguan 已提交
216 217
      return pDnode;
    }
218
    mnodeDecDnodeRef(pDnode);
S
slguan 已提交
219 220
  }

S
Shengliang Guan 已提交
221 222
  sdbFreeIter(pIter);

S
slguan 已提交
223 224 225
  return NULL;
}

226
void mnodeIncDnodeRef(SDnodeObj *pDnode) {
S
slguan 已提交
227 228 229
  sdbIncRef(tsDnodeSdb, pDnode);
}

230
void mnodeDecDnodeRef(SDnodeObj *pDnode) {
S
slguan 已提交
231
  sdbDecRef(tsDnodeSdb, pDnode);
S
slguan 已提交
232 233
}

234
void mnodeUpdateDnode(SDnodeObj *pDnode) {
S
slguan 已提交
235
  SSdbOper oper = {
S
slguan 已提交
236 237
    .type = SDB_OPER_GLOBAL,
    .table = tsDnodeSdb,
238
    .pObj = pDnode
S
slguan 已提交
239 240
  };

241 242 243
  if (sdbUpdateRow(&oper) != 0) {
    mError("dnodeId:%d, failed update", pDnode->dnodeId);
  }
S
slguan 已提交
244 245
}

246
static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
S
Shengliang Guan 已提交
247
  SCMCfgDnodeMsg *pCmCfgDnode = pMsg->rpcMsg.pCont;
J
jtao1735 已提交
248 249
  if (pCmCfgDnode->ep[0] == 0) {
    strcpy(pCmCfgDnode->ep, tsLocalEp);
S
slguan 已提交
250
  } else {
sangshuduo's avatar
sangshuduo 已提交
251
    // TODO temporary disabled for compiling: strcpy(pCmCfgDnode->ep, pCmCfgDnode->ep); 
S
slguan 已提交
252
  }
S
slguan 已提交
253

S
slguan 已提交
254
  if (strcmp(pMsg->pUser->user, "root") != 0) {
255
    return TSDB_CODE_MND_NO_RIGHTS;
S
slguan 已提交
256 257
  }

258 259 260 261 262 263 264 265 266 267 268 269 270
  SRpcIpSet ipSet = mnodeGetIpSetFromIp(pCmCfgDnode->ep);
  SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg));
  strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep);
  strcpy(pMdCfgDnode->config, pCmCfgDnode->config);

  SRpcMsg rpcMdCfgDnodeMsg = {
    .handle = 0,
    .code = 0,
    .msgType = TSDB_MSG_TYPE_MD_CONFIG_DNODE,
    .pCont = pMdCfgDnode,
    .contLen = sizeof(SMDCfgDnodeMsg)
  };
  dnodeSendMsgToDnode(&ipSet, &rpcMdCfgDnodeMsg);
S
slguan 已提交
271

272 273 274
  mPrint("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user);

  return TSDB_CODE_SUCCESS;
S
slguan 已提交
275
}
S
slguan 已提交
276

277
static void mnodeProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) {
guanshengliang's avatar
guanshengliang 已提交
278
  mPrint("cfg dnode rsp is received");
S
slguan 已提交
279 280
}

H
Hui Li 已提交
281 282 283 284 285 286 287 288 289 290 291 292 293 294
static bool mnodeCheckClusterCfgPara(const SClusterCfg *clusterCfg) {
  if (clusterCfg->numOfMnodes        != tsNumOfMnodes)        return false;
  if (clusterCfg->mnodeEqualVnodeNum != tsMnodeEqualVnodeNum) return false;
  if (clusterCfg->offlineThreshold   != tsOfflineThreshold)   return false;
  if (clusterCfg->statusInterval     != tsStatusInterval)     return false;

  if (0 != strncasecmp(clusterCfg->arbitrator, tsArbitrator, strlen(tsArbitrator))) return false;
  if (0 != strncasecmp(clusterCfg->timezone, tsTimezone, strlen(tsTimezone)))       return false;
  if (0 != strncasecmp(clusterCfg->locale, tsLocale, strlen(tsLocale)))              return false;
  if (0 != strncasecmp(clusterCfg->charset, tsCharset, strlen(tsCharset)))           return false;
    
  return true;
}

295
static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
S
Shengliang Guan 已提交
296
  SDMStatusMsg *pStatus = pMsg->rpcMsg.pCont;
S
slguan 已提交
297
  pStatus->dnodeId      = htonl(pStatus->dnodeId);
S
slguan 已提交
298
  pStatus->moduleStatus = htonl(pStatus->moduleStatus);
S
slguan 已提交
299 300
  pStatus->lastReboot   = htonl(pStatus->lastReboot);
  pStatus->numOfCores   = htons(pStatus->numOfCores);
S
[TD-17]  
slguan 已提交
301
  pStatus->numOfTotalVnodes = htons(pStatus->numOfTotalVnodes);
S
slguan 已提交
302

S
slguan 已提交
303 304 305
  uint32_t version = htonl(pStatus->version);
  if (version != tsVersion) {
    mError("status msg version:%d not equal with mnode:%d", version, tsVersion);
306
    return TSDB_CODE_MND_INVALID_MSG_VERSION;
S
slguan 已提交
307 308
  }

S
slguan 已提交
309 310
  SDnodeObj *pDnode = NULL;
  if (pStatus->dnodeId == 0) {
311
    pDnode = mnodeGetDnodeByEp(pStatus->dnodeEp);
S
slguan 已提交
312
    if (pDnode == NULL) {
J
jtao1735 已提交
313
      mTrace("dnode %s not created", pStatus->dnodeEp);
314
      return TSDB_CODE_MND_DNODE_NOT_EXIST;
S
slguan 已提交
315 316
    }
  } else {
317
    pDnode = mnodeGetDnode(pStatus->dnodeId);
S
slguan 已提交
318
    if (pDnode == NULL) {
J
jtao1735 已提交
319
      mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp);
320
      return TSDB_CODE_MND_DNODE_NOT_EXIST;
S
slguan 已提交
321 322
    }
  }
J
jtao1735 已提交
323

S
[TD-17]  
slguan 已提交
324 325
  pDnode->lastReboot       = pStatus->lastReboot;
  pDnode->numOfCores       = pStatus->numOfCores;
S
slguan 已提交
326 327
  pDnode->diskAvailable    = pStatus->diskAvailable;
  pDnode->alternativeRole  = pStatus->alternativeRole;
S
slguan 已提交
328
  pDnode->totalVnodes      = pStatus->numOfTotalVnodes; 
S
slguan 已提交
329
  pDnode->moduleStatus     = pStatus->moduleStatus;
330
  
S
slguan 已提交
331
  if (pStatus->dnodeId == 0) {
J
jtao1735 已提交
332
    mTrace("dnode:%d %s, first access", pDnode->dnodeId, pDnode->dnodeEp);
S
slguan 已提交
333
  } else {
S
Shengliang Guan 已提交
334
    //mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess);
S
slguan 已提交
335 336
  }
 
337 338
  int32_t openVnodes = htons(pStatus->openVnodes);
  for (int32_t j = 0; j < openVnodes; ++j) {
339
    SVnodeLoad *pVload = &pStatus->load[j];
S
slguan 已提交
340
    pVload->vgId = htonl(pVload->vgId);
S
slguan 已提交
341
    pVload->cfgVersion = htonl(pVload->cfgVersion);
S
slguan 已提交
342

343
    SVgObj *pVgroup = mnodeGetVgroup(pVload->vgId);
344
    if (pVgroup == NULL) {
345
      SRpcIpSet ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp);
S
slguan 已提交
346
      mPrint("dnode:%d, vgId:%d not exist in mnode, drop it", pDnode->dnodeId, pVload->vgId);
347
      mnodeSendDropVnodeMsg(pVload->vgId, &ipSet, NULL);
348
    } else {
349 350
      mnodeUpdateVgroupStatus(pVgroup, pDnode, pVload);
      mnodeDecVgroupRef(pVgroup);
S
slguan 已提交
351 352 353
    }
  }

S
slguan 已提交
354
  if (pDnode->status == TAOS_DN_STATUS_OFFLINE) {
H
Hui Li 已提交
355
    // Verify whether the cluster parameters are consistent when status change from offline to ready
H
Hui Li 已提交
356
    bool ret = mnodeCheckClusterCfgPara(&(pStatus->clusterCfg));
H
Hui Li 已提交
357 358 359 360 361 362
    if (false == ret) {
      mnodeDecDnodeRef(pDnode);
      mError("dnode %s cluster cfg parameters inconsistent", pStatus->dnodeEp);
      return TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT;
    }
    
S
slguan 已提交
363
    mTrace("dnode:%d, from offline to online", pDnode->dnodeId);
S
slguan 已提交
364
    pDnode->status = TAOS_DN_STATUS_READY;
365
    balanceUpdateMnode();
S
slguan 已提交
366
    balanceNotify();
S
slguan 已提交
367 368
  }

369
  mnodeDecDnodeRef(pDnode);
S
slguan 已提交
370

S
slguan 已提交
371
  int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess);
S
slguan 已提交
372 373
  SDMStatusRsp *pRsp = rpcMallocCont(contLen);
  if (pRsp == NULL) {
374
    return TSDB_CODE_MND_OUT_OF_MEMORY;
S
slguan 已提交
375 376
  }

H
Hui Li 已提交
377 378
  pDnode->lastAccess = tsAccessSquence;

379
  mnodeGetMnodeInfos(&pRsp->mnodes);
S
slguan 已提交
380

S
slguan 已提交
381 382 383
  pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId);
  pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
  pRsp->dnodeCfg.numOfVnodes = 0;
S
slguan 已提交
384 385 386 387 388
  
  contLen = sizeof(SDMStatusRsp);

  //TODO: set vnode access
  
389 390
  pMsg->rpcRsp.len = contLen;
  pMsg->rpcRsp.rsp =  pRsp;
S
slguan 已提交
391

392
  return TSDB_CODE_SUCCESS;
S
slguan 已提交
393
}
394

395
static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) {
S
slguan 已提交
396 397 398 399 400
  int32_t grantCode = grantCheck(TSDB_GRANT_DNODE);
  if (grantCode != TSDB_CODE_SUCCESS) {
    return grantCode;
  }

401
  SDnodeObj *pDnode = mnodeGetDnodeByEp(ep);
S
slguan 已提交
402
  if (pDnode != NULL) {
403
    mnodeDecDnodeRef(pDnode);
J
jtao1735 已提交
404
    mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort);
405
    return TSDB_CODE_MND_DNODE_ALREADY_EXIST;
S
slguan 已提交
406 407 408 409 410 411
  }

  pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj));
  pDnode->createdTime = taosGetTimestampMs();
  pDnode->status = TAOS_DN_STATUS_OFFLINE; 
  pDnode->totalVnodes = TSDB_INVALID_VNODE_NUM; 
412
  tstrncpy(pDnode->dnodeEp, ep, TSDB_EP_LEN);
J
jtao1735 已提交
413
  taosGetFqdnPortFromEp(ep, pDnode->dnodeFqdn, &pDnode->dnodePort);
S
slguan 已提交
414

S
slguan 已提交
415
  SSdbOper oper = {
S
slguan 已提交
416 417 418
    .type = SDB_OPER_GLOBAL,
    .table = tsDnodeSdb,
    .pObj = pDnode,
419 420
    .rowSize = sizeof(SDnodeObj),
    .pMsg = pMsg
S
slguan 已提交
421 422 423 424
  };

  int32_t code = sdbInsertRow(&oper);
  if (code != TSDB_CODE_SUCCESS) {
S
slguan 已提交
425
    int dnodeId = pDnode->dnodeId;
S
slguan 已提交
426
    tfree(pDnode);
S
slguan 已提交
427
    mError("failed to create dnode:%d, result:%s", dnodeId, tstrerror(code));
428 429 430
  } else {
    mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code));
    if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
S
slguan 已提交
431 432 433 434 435
  }

  return code;
}

436
int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg) {
S
slguan 已提交
437
  SSdbOper oper = {
S
slguan 已提交
438 439
    .type = SDB_OPER_GLOBAL,
    .table = tsDnodeSdb,
440 441
    .pObj = pDnode,
    .pMsg = pMsg
S
slguan 已提交
442 443
  };

444 445 446 447
  int32_t code = sdbDeleteRow(&oper);
  if (code == TSDB_CODE_SUCCESS) {
    mLPrint("dnode:%d, is dropped from cluster, result:%s", pDnode->dnodeId, tstrerror(code));
    if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
S
slguan 已提交
448 449 450 451 452
  }

  return code;
}

453
static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) {
454
  SDnodeObj *pDnode = mnodeGetDnodeByEp(ep);
S
slguan 已提交
455
  if (pDnode == NULL) {
J
jtao1735 已提交
456
    mError("dnode:%s, is not exist", ep);
457
    return TSDB_CODE_MND_DNODE_NOT_EXIST;
S
slguan 已提交
458 459
  }

460
  mnodeDecDnodeRef(pDnode);
J
jtao1735 已提交
461 462
  if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) {
    mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep);
463
    return TSDB_CODE_MND_NO_REMOVE_MASTER;
S
slguan 已提交
464 465
  }

S
add log  
slguan 已提交
466
  mPrint("dnode:%d, start to drop it", pDnode->dnodeId);
S
slguan 已提交
467
#ifndef _SYNC
468
  return mnodeDropDnode(pDnode, pMsg);
S
slguan 已提交
469 470 471 472 473
#else
  return balanceDropDnode(pDnode);
#endif
}

474
static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
S
Shengliang Guan 已提交
475
  SCMCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont;
S
slguan 已提交
476

S
slguan 已提交
477
  if (strcmp(pMsg->pUser->user, "root") != 0) {
478
    return TSDB_CODE_MND_NO_RIGHTS;
S
slguan 已提交
479
  } else {
480
    return mnodeCreateDnode(pCreate->ep, pMsg);
S
slguan 已提交
481 482 483
  }
}

484
static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) {
S
Shengliang Guan 已提交
485
  SCMDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont;
J
jtao1735 已提交
486

S
slguan 已提交
487
  if (strcmp(pMsg->pUser->user, "root") != 0) {
488
    return TSDB_CODE_MND_NO_RIGHTS;
S
slguan 已提交
489
  } else {
490
    return mnodeDropDnodeByEp(pDrop->ep, pMsg);
491
  }
S
slguan 已提交
492 493
}

494 495
static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
  SUserObj *pUser = mnodeGetUserFromConn(pConn);
496 497
  if (pUser == NULL) return 0;

S
slguan 已提交
498
  if (strcmp(pUser->pAcct->user, "root") != 0) {
499
    mnodeDecUserRef(pUser);
500
    return TSDB_CODE_MND_NO_RIGHTS;
S
slguan 已提交
501
  }
502 503 504 505 506 507 508 509 510 511

  int32_t  cols = 0;
  SSchema *pSchema = pMeta->schema;

  pShow->bytes[cols] = 2;
  pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
  strcpy(pSchema[cols].name, "id");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
512
  pShow->bytes[cols] = 40 + VARSTR_HEADER_SIZE;
513
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
514
  strcpy(pSchema[cols].name, "end_point");
515 516 517 518 519
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

  pShow->bytes[cols] = 2;
  pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
520
  strcpy(pSchema[cols].name, "open_vnodes");
521 522 523 524 525
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

  pShow->bytes[cols] = 2;
  pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
526
  strcpy(pSchema[cols].name, "total_vnodes");
527 528 529
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
530
  pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE;
531
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
S
slguan 已提交
532 533 534 535
  strcpy(pSchema[cols].name, "status");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

536 537 538 539 540 541
  pShow->bytes[cols] = 6 + VARSTR_HEADER_SIZE;
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema[cols].name, "alternativeRole");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
542 543
  pShow->bytes[cols] = 8;
  pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
544
  strcpy(pSchema[cols].name, "create_time");
545 546 547 548 549 550 551 552 553 554 555
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

  pMeta->numOfColumns = htons(cols);
  pShow->numOfColumns = cols;

  pShow->offset[0] = 0;
  for (int32_t i = 1; i < cols; ++i) {
    pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
  }

556
  pShow->numOfRows = mnodeGetDnodesNum();
557
  pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
S
Shengliang Guan 已提交
558
  pShow->pIter = NULL;
559

560
  mnodeDecUserRef(pUser);
S
slguan 已提交
561

562 563 564
  return 0;
}

565
static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
566 567 568 569 570 571
  int32_t    numOfRows = 0;
  int32_t    cols      = 0;
  SDnodeObj *pDnode   = NULL;
  char      *pWrite;

  while (numOfRows < rows) {
572
    pShow->pIter = mnodeGetNextDnode(pShow->pIter, &pDnode);
573 574 575 576 577 578 579 580 581
    if (pDnode == NULL) break;

    cols = 0;

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
    *(int16_t *)pWrite = pDnode->dnodeId;
    cols++;

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
H
Hui Li 已提交
582
    STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols]);
583 584 585 586 587 588 589
    cols++;

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
    *(int16_t *)pWrite = pDnode->openVnodes;
    cols++;

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
S
slguan 已提交
590
    *(int16_t *)pWrite = pDnode->totalVnodes;
591
    cols++;
S
slguan 已提交
592
    
593
    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;  
594
    char* status = mnodeGetDnodeStatusStr(pDnode->status);
595
    STR_TO_VARSTR(pWrite, status);
596 597
    cols++;

598 599 600 601 602
    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;  
    char* role = mnodeGetDnodeAlternativeRoleStr(pDnode->alternativeRole);
    STR_TO_VARSTR(pWrite, role);
    cols++;

S
slguan 已提交
603 604 605 606 607
    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
    *(int64_t *)pWrite = pDnode->createdTime;
    cols++;

 
608
    numOfRows++;
609
    mnodeDecDnodeRef(pDnode);
610 611 612 613 614 615
  }

  pShow->numOfReads += numOfRows;
  return numOfRows;
}

616
static bool mnodeCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) {
617 618 619 620
  uint32_t status = pDnode->moduleStatus & (1 << moduleType);
  return status > 0;
}

621
static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
622 623
  int32_t cols = 0;

624
  SUserObj *pUser = mnodeGetUserFromConn(pConn);
625 626
  if (pUser == NULL) return 0;

S
slguan 已提交
627
  if (strcmp(pUser->user, "root") != 0)  {
628
    mnodeDecUserRef(pUser);
629
    return TSDB_CODE_MND_NO_RIGHTS;
S
slguan 已提交
630
  }
631 632 633

  SSchema *pSchema = pMeta->schema;

S
slguan 已提交
634 635 636 637 638 639
  pShow->bytes[cols] = 2;
  pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
  strcpy(pSchema[cols].name, "id");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
640
  pShow->bytes[cols] = 40 + VARSTR_HEADER_SIZE;
641
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
J
jtao1735 已提交
642
  strcpy(pSchema[cols].name, "end point");
643 644 645
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
646
  pShow->bytes[cols] = 8 + VARSTR_HEADER_SIZE;
647
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
S
slguan 已提交
648
  strcpy(pSchema[cols].name, "module");
649 650 651
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
652
  pShow->bytes[cols] = 8 + VARSTR_HEADER_SIZE;
653
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
S
slguan 已提交
654
  strcpy(pSchema[cols].name, "status");
655 656 657 658 659 660 661 662 663 664 665
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

  pMeta->numOfColumns = htons(cols);
  pShow->numOfColumns = cols;

  pShow->offset[0] = 0;
  for (int32_t i = 1; i < cols; ++i) {
    pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
  }

666
  pShow->numOfRows = mnodeGetDnodesNum() * TSDB_MOD_MAX;
667
  pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
S
Shengliang Guan 已提交
668
  pShow->pIter = NULL;
669
  mnodeDecUserRef(pUser);
670 671 672 673

  return 0;
}

674
int32_t mnodeRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
S
slguan 已提交
675 676
  int32_t numOfRows = 0;
  char *  pWrite;
677 678

  while (numOfRows < rows) {
S
slguan 已提交
679
    SDnodeObj *pDnode = NULL;
680
    pShow->pIter = mnodeGetNextDnode(pShow->pIter, (SDnodeObj **)&pDnode);
681 682 683
    if (pDnode == NULL) break;

    for (int32_t moduleType = 0; moduleType < TSDB_MOD_MAX; ++moduleType) {
S
slguan 已提交
684
      int32_t cols = 0;
685

S
slguan 已提交
686 687 688
      pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
      *(int16_t *)pWrite = pDnode->dnodeId;
      cols++;
689 690

      pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
J
jtao1735 已提交
691
      strncpy(pWrite, pDnode->dnodeEp, pShow->bytes[cols]-1);
692 693 694
      cols++;

      pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
S
slguan 已提交
695
      switch (moduleType) {
S
Shengliang Guan 已提交
696 697
        case TSDB_MOD_MNODE:
          strcpy(pWrite, "mnode");
S
slguan 已提交
698 699 700 701 702 703 704 705 706 707
          break;
        case TSDB_MOD_HTTP:
          strcpy(pWrite, "http");
          break;
        case TSDB_MOD_MONITOR:
          strcpy(pWrite, "monitor");
          break;
        default:
          strcpy(pWrite, "unknown");
      }
708 709 710
      cols++;

      pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
711
      bool enable = mnodeCheckModuleInDnode(pDnode, moduleType);
S
slguan 已提交
712
      strcpy(pWrite, enable ? "enable" : "disable");
713 714 715 716
      cols++;

      numOfRows++;
    }
S
slguan 已提交
717

718
    mnodeDecDnodeRef(pDnode);
719 720 721 722 723 724
  }

  pShow->numOfReads += numOfRows;
  return numOfRows;
}

725
static bool mnodeCheckConfigShow(SGlobalCfg *cfg) {
726 727 728 729 730
  if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW))
    return false;
  return true;
}

731
static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
732 733
  int32_t cols = 0;

734
  SUserObj *pUser = mnodeGetUserFromConn(pConn);
735 736
  if (pUser == NULL) return 0;

S
slguan 已提交
737
  if (strcmp(pUser->user, "root") != 0)  {
738
    mnodeDecUserRef(pUser);
739
    return TSDB_CODE_MND_NO_RIGHTS;
S
slguan 已提交
740
  }
741 742 743

  SSchema *pSchema = pMeta->schema;

S
slguan 已提交
744
  pShow->bytes[cols] = TSDB_CFG_OPTION_LEN + VARSTR_HEADER_SIZE;
745 746 747 748 749
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema[cols].name, "config name");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
750
  pShow->bytes[cols] = TSDB_CFG_VALUE_LEN + VARSTR_HEADER_SIZE;
751 752 753 754 755 756 757 758 759 760 761 762 763
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema[cols].name, "config value");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

  pMeta->numOfColumns = htons(cols);
  pShow->numOfColumns = cols;

  pShow->offset[0] = 0;
  for (int32_t i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];

  pShow->numOfRows = 0;
  for (int32_t i = tsGlobalConfigNum - 1; i >= 0; --i) {
S
slguan 已提交
764
    SGlobalCfg *cfg = tsGlobalConfig + i;
765
    if (!mnodeCheckConfigShow(cfg)) continue;
766 767 768 769
    pShow->numOfRows++;
  }

  pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
S
Shengliang Guan 已提交
770
  pShow->pIter = NULL;
771
  mnodeDecUserRef(pUser);
772 773 774 775

  return 0;
}

776
static int32_t mnodeRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
777 778 779
  int32_t numOfRows = 0;

  for (int32_t i = tsGlobalConfigNum - 1; i >= 0 && numOfRows < rows; --i) {
S
slguan 已提交
780
    SGlobalCfg *cfg = tsGlobalConfig + i;
781
    if (!mnodeCheckConfigShow(cfg)) continue;
782 783 784 785 786 787 788 789 790 791

    char *pWrite;
    int32_t   cols = 0;

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
    snprintf(pWrite, TSDB_CFG_OPTION_LEN, "%s", cfg->option);
    cols++;

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
    switch (cfg->valType) {
S
slguan 已提交
792
      case TAOS_CFG_VTYPE_INT16:
793 794 795
        snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((int16_t *)cfg->ptr));
        numOfRows++;
        break;
S
slguan 已提交
796
      case TAOS_CFG_VTYPE_INT32:
797 798 799
        snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((int32_t *)cfg->ptr));
        numOfRows++;
        break;
S
slguan 已提交
800
      case TAOS_CFG_VTYPE_FLOAT:
801 802 803
        snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%f", *((float *)cfg->ptr));
        numOfRows++;
        break;
S
slguan 已提交
804 805 806
      case TAOS_CFG_VTYPE_STRING:
      case TAOS_CFG_VTYPE_IPSTR:
      case TAOS_CFG_VTYPE_DIRECTORY:
807 808 809 810 811 812 813 814 815 816 817 818
        snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%s", (char *)cfg->ptr);
        numOfRows++;
        break;
      default:
        break;
    }
  }

  pShow->numOfReads += numOfRows;
  return numOfRows;
}

819
static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
820
  int32_t cols = 0;
821
  SUserObj *pUser = mnodeGetUserFromConn(pConn);
822
  if (pUser == NULL) return 0;
S
slguan 已提交
823 824
  
  if (strcmp(pUser->user, "root") != 0)  {
825
    mnodeDecUserRef(pUser);
826
    return TSDB_CODE_MND_NO_RIGHTS;
S
slguan 已提交
827
  }
828 829 830 831 832 833 834 835 836

  SSchema *pSchema = pMeta->schema;

  pShow->bytes[cols] = 4;
  pSchema[cols].type = TSDB_DATA_TYPE_INT;
  strcpy(pSchema[cols].name, "vnode");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

S
slguan 已提交
837
  pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE;
838 839 840 841 842 843 844 845 846 847 848 849 850
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema[cols].name, "status");
  pSchema[cols].bytes = htons(pShow->bytes[cols]);
  cols++;

  pMeta->numOfColumns = htons(cols);
  pShow->numOfColumns = cols;

  pShow->offset[0] = 0;
  for (int32_t i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];

  SDnodeObj *pDnode = NULL;
  if (pShow->payloadLen > 0 ) {
851
    pDnode = mnodeGetDnodeByEp(pShow->payload);
852
  } else {
853
    void *pIter = mnodeGetNextDnode(NULL, (SDnodeObj **)&pDnode);
S
Shengliang Guan 已提交
854
    sdbFreeIter(pIter);
S
slguan 已提交
855
  }
856

S
slguan 已提交
857 858
  if (pDnode != NULL) {
    pShow->numOfRows += pDnode->openVnodes;
859
    mnodeDecDnodeRef(pDnode);
S
slguan 已提交
860
  }
861 862

  pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
S
Shengliang Guan 已提交
863
  pShow->pIter = pDnode;
864
  mnodeDecUserRef(pUser);
865 866 867 868

  return 0;
}

869
static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
870 871 872 873 874 875 876
  int32_t    numOfRows = 0;
  SDnodeObj *pDnode = NULL;
  char *     pWrite;
  int32_t    cols = 0;

  if (0 == rows) return 0;

S
Shengliang Guan 已提交
877
  pDnode = (SDnodeObj *)(pShow->pIter);
S
slguan 已提交
878
  if (pDnode != NULL) {
S
Shengliang Guan 已提交
879
    void *pIter = NULL;
S
slguan 已提交
880 881
    SVgObj *pVgroup;
    while (1) {
882
      pIter = mnodeGetNextVgroup(pIter, &pVgroup);
S
slguan 已提交
883 884 885 886 887 888 889 890 891 892 893 894
      if (pVgroup == NULL) break;

      for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
        SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
        if (pVgid->pDnode == pDnode) {
          cols = 0;

          pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
          *(uint32_t *)pWrite = pVgroup->vgId;
          cols++;

          pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
895
          strcpy(pWrite, mnodeGetMnodeRoleStr(pVgid->role));
S
slguan 已提交
896
          cols++;
897 898
        }
      }
S
slguan 已提交
899

900
      mnodeDecVgroupRef(pVgroup);
901
    }
S
Shengliang Guan 已提交
902
    sdbFreeIter(pIter);
903 904 905
  } else {
    numOfRows = 0;
  }
S
slguan 已提交
906

907 908
  pShow->numOfReads += numOfRows;
  return numOfRows;
S
slguan 已提交
909 910
}

911
char* mnodeGetDnodeStatusStr(int32_t dnodeStatus) {
S
slguan 已提交
912
  switch (dnodeStatus) {
S
slguan 已提交
913 914 915 916
    case TAOS_DN_STATUS_OFFLINE:   return "offline";
    case TAOS_DN_STATUS_DROPPING:  return "dropping";
    case TAOS_DN_STATUS_BALANCING: return "balancing";
    case TAOS_DN_STATUS_READY:     return "ready";
S
slguan 已提交
917 918 919
    default:                       return "undefined";
  }
}
920 921 922 923 924 925 926 927 928 929

static char* mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole) {
  switch (alternativeRole) {
    case TAOS_DN_ALTERNATIVE_ROLE_ANY: return "any";
    case TAOS_DN_ALTERNATIVE_ROLE_MNODE: return "mnode";
    case TAOS_DN_ALTERNATIVE_ROLE_VNODE: return "vnode";
    default:return "any";
  }
}