mndDnode.c 25.3 KB
Newer Older
H
refact  
Hongze Cheng 已提交
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
#define _DEFAULT_SOURCE
S
Shengliang Guan 已提交
17
#include "mndDnode.h"
S
Shengliang Guan 已提交
18
#include "mndAuth.h"
S
Shengliang Guan 已提交
19
#include "mndMnode.h"
S
Shengliang Guan 已提交
20
#include "mndShow.h"
S
Shengliang Guan 已提交
21
#include "mndTrans.h"
S
Shengliang Guan 已提交
22
#include "mndUser.h"
S
Shengliang Guan 已提交
23
#include "mndVgroup.h"
S
Shengliang Guan 已提交
24

S
Shengliang Guan 已提交
25
#define TSDB_DNODE_VER_NUMBER   1
26
#define TSDB_DNODE_RESERVE_SIZE 64
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28
static const char *offlineReason[] = {
S
Shengliang Guan 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41
    "",
    "status msg timeout",
    "status not received",
    "version not match",
    "dnodeId not match",
    "clusterId not match",
    "interval not match",
    "timezone not match",
    "locale not match",
    "charset not match",
    "unknown",
};

S
Shengliang Guan 已提交
42 43 44 45 46
static int32_t  mndCreateDefaultDnode(SMnode *pMnode);
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode);
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw);
static int32_t  mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode);
static int32_t  mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode);
47
static int32_t  mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew);
S
Shengliang Guan 已提交
48

S
Shengliang Guan 已提交
49 50 51 52 53
static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq);
static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq);
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq);
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp);
static int32_t mndProcessStatusReq(SRpcMsg *pReq);
S
Shengliang Guan 已提交
54

S
Shengliang Guan 已提交
55
static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
S
Shengliang Guan 已提交
56
static void    mndCancelGetNextConfig(SMnode *pMnode, void *pIter);
S
Shengliang Guan 已提交
57
static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
S
Shengliang Guan 已提交
58
static void    mndCancelGetNextDnode(SMnode *pMnode, void *pIter);
S
Shengliang Guan 已提交
59 60

int32_t mndInitDnode(SMnode *pMnode) {
61 62 63 64 65 66 67 68 69 70
  SSdbTable table = {
      .sdbType = SDB_DNODE,
      .keyType = SDB_KEY_INT32,
      .deployFp = (SdbDeployFp)mndCreateDefaultDnode,
      .encodeFp = (SdbEncodeFp)mndDnodeActionEncode,
      .decodeFp = (SdbDecodeFp)mndDnodeActionDecode,
      .insertFp = (SdbInsertFp)mndDnodeActionInsert,
      .updateFp = (SdbUpdateFp)mndDnodeActionUpdate,
      .deleteFp = (SdbDeleteFp)mndDnodeActionDelete,
  };
S
Shengliang Guan 已提交
71

S
Shengliang Guan 已提交
72 73 74
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DNODE, mndProcessCreateDnodeReq);
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeReq);
  mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
H
Hongze Cheng 已提交
75
  mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp);
S
Shengliang Guan 已提交
76
  mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusReq);
S
Shengliang Guan 已提交
77

78 79
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndRetrieveConfigs);
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndCancelGetNextConfig);
S
Shengliang Guan 已提交
80 81 82
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndRetrieveDnodes);
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndCancelGetNextDnode);

S
Shengliang Guan 已提交
83 84 85 86 87 88 89 90 91 92 93 94
  return sdbSetTable(pMnode->pSdb, table);
}

void mndCleanupDnode(SMnode *pMnode) {}

static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
  SDnodeObj dnodeObj = {0};
  dnodeObj.id = 1;
  dnodeObj.createdTime = taosGetTimestampMs();
  dnodeObj.updateTime = dnodeObj.createdTime;
  dnodeObj.port = pMnode->replicas[0].port;
  memcpy(&dnodeObj.fqdn, pMnode->replicas[0].fqdn, TSDB_FQDN_LEN);
95
  snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port);
S
Shengliang Guan 已提交
96 97 98

  SSdbRaw *pRaw = mndDnodeActionEncode(&dnodeObj);
  if (pRaw == NULL) return -1;
S
Shengliang Guan 已提交
99
  if (sdbSetRawStatus(pRaw, SDB_STATUS_READY) != 0) return -1;
S
Shengliang Guan 已提交
100

101
  mDebug("dnode:%d, will be created while deploy sdb, raw:%p", dnodeObj.id, pRaw);
102 103

#if 0
S
Shengliang Guan 已提交
104
  return sdbWrite(pMnode->pSdb, pRaw);
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
#else
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_DNODE, NULL);
  if (pTrans == NULL) {
    mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr());
    return -1;
  }
  mDebug("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep);

  if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
    mndTransDrop(pTrans);
    return -1;
  }
  sdbSetRawStatus(pRaw, SDB_STATUS_READY);

  if (mndTransPrepare(pMnode, pTrans) != 0) {
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
    mndTransDrop(pTrans);
    return -1;
  }

  mndTransDrop(pTrans);
  return 0;
#endif
S
Shengliang Guan 已提交
129 130
}

S
Shengliang Guan 已提交
131
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
132 133
  terrno = TSDB_CODE_OUT_OF_MEMORY;

S
Shengliang Guan 已提交
134
  SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
135
  if (pRaw == NULL) goto DNODE_ENCODE_OVER;
S
Shengliang Guan 已提交
136 137

  int32_t dataPos = 0;
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  SDB_SET_INT32(pRaw, dataPos, pDnode->id, DNODE_ENCODE_OVER)
  SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime, DNODE_ENCODE_OVER)
  SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, DNODE_ENCODE_OVER)
  SDB_SET_INT16(pRaw, dataPos, pDnode->port, DNODE_ENCODE_OVER)
  SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_ENCODE_OVER)
  SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_ENCODE_OVER)
  SDB_SET_DATALEN(pRaw, dataPos, DNODE_ENCODE_OVER);

  terrno = 0;

DNODE_ENCODE_OVER:
  if (terrno != 0) {
    mError("dnode:%d, failed to encode to raw:%p since %s", pDnode->id, pRaw, terrstr());
    sdbFreeRaw(pRaw);
    return NULL;
  }
S
Shengliang Guan 已提交
154

155
  mTrace("dnode:%d, encode to raw:%p, row:%p", pDnode->id, pRaw, pDnode);
S
Shengliang Guan 已提交
156 157 158 159
  return pRaw;
}

static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
160 161
  terrno = TSDB_CODE_OUT_OF_MEMORY;

S
Shengliang Guan 已提交
162
  int8_t sver = 0;
163
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DNODE_DECODE_OVER;
S
Shengliang Guan 已提交
164

S
Shengliang Guan 已提交
165
  if (sver != TSDB_DNODE_VER_NUMBER) {
S
Shengliang Guan 已提交
166
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
167
    goto DNODE_DECODE_OVER;
S
Shengliang Guan 已提交
168 169
  }

170 171 172
  SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj));
  if (pRow == NULL) goto DNODE_DECODE_OVER;

S
Shengliang Guan 已提交
173
  SDnodeObj *pDnode = sdbGetRowObj(pRow);
174
  if (pDnode == NULL) goto DNODE_DECODE_OVER;
S
Shengliang Guan 已提交
175 176

  int32_t dataPos = 0;
177 178 179 180 181 182 183 184 185 186 187 188
  SDB_GET_INT32(pRaw, dataPos, &pDnode->id, DNODE_DECODE_OVER)
  SDB_GET_INT64(pRaw, dataPos, &pDnode->createdTime, DNODE_DECODE_OVER)
  SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, DNODE_DECODE_OVER)
  SDB_GET_INT16(pRaw, dataPos, &pDnode->port, DNODE_DECODE_OVER)
  SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_DECODE_OVER)
  SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_DECODE_OVER)

  terrno = 0;

DNODE_DECODE_OVER:
  if (terrno != 0) {
    mError("dnode:%d, failed to decode from raw:%p since %s", pDnode->id, pRaw, terrstr());
wafwerar's avatar
wafwerar 已提交
189
    taosMemoryFreeClear(pRow);
190 191
    return NULL;
  }
S
Shengliang Guan 已提交
192

193
  mTrace("dnode:%d, decode from raw:%p, row:%p", pDnode->id, pRaw, pDnode);
S
Shengliang Guan 已提交
194 195 196
  return pRow;
}

197
static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) {
198
  mTrace("dnode:%d, perform insert action, row:%p", pDnode->id, pDnode);
S
Shengliang Guan 已提交
199
  pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED;
S
Shengliang Guan 已提交
200 201 202 203
  snprintf(pDnode->ep, TSDB_EP_LEN, "%s:%u", pDnode->fqdn, pDnode->port);
  return 0;
}

S
Shengliang Guan 已提交
204
static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
205
  mTrace("dnode:%d, perform delete action, row:%p", pDnode->id, pDnode);
S
Shengliang Guan 已提交
206 207
  return 0;
}
S
Shengliang Guan 已提交
208

209
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew) {
S
Shengliang Guan 已提交
210
  mTrace("dnode:%d, perform update action, old row:%p new row:%p", pOld->id, pOld, pNew);
211
  pOld->updateTime = pNew->updateTime;
S
Shengliang Guan 已提交
212
  return 0;
S
Shengliang Guan 已提交
213 214
}

S
Shengliang Guan 已提交
215
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId) {
S
Shengliang Guan 已提交
216 217 218 219 220 221
  SSdb      *pSdb = pMnode->pSdb;
  SDnodeObj *pDnode = sdbAcquire(pSdb, SDB_DNODE, &dnodeId);
  if (pDnode == NULL) {
    terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
  }
  return pDnode;
S
Shengliang Guan 已提交
222
}
S
Shengliang Guan 已提交
223

S
Shengliang Guan 已提交
224 225 226
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode) {
  SSdb *pSdb = pMnode->pSdb;
  sdbRelease(pSdb, pDnode);
S
Shengliang Guan 已提交
227 228
}

S
Shengliang Guan 已提交
229
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode) {
H
Haojun Liao 已提交
230 231
  SEpSet epSet = {0};
  addEpIntoEpSet(&epSet, pDnode->fqdn, pDnode->port);
S
Shengliang Guan 已提交
232 233 234
  return epSet;
}

S
Shengliang Guan 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247
static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
  SSdb *pSdb = pMnode->pSdb;

  void *pIter = NULL;
  while (1) {
    SDnodeObj *pDnode = NULL;
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
    if (pIter == NULL) break;

    if (strncasecmp(pEpStr, pDnode->ep, TSDB_EP_LEN) == 0) {
      sdbCancelFetch(pSdb, pIter);
      return pDnode;
    }
S
Shengliang Guan 已提交
248 249

    sdbRelease(pSdb, pDnode);
S
Shengliang Guan 已提交
250 251 252 253 254
  }

  return NULL;
}

S
Shengliang Guan 已提交
255
int32_t mndGetDnodeSize(SMnode *pMnode) {
S
Shengliang Guan 已提交
256 257 258 259
  SSdb *pSdb = pMnode->pSdb;
  return sdbGetSize(pSdb, SDB_DNODE);
}

S
Shengliang Guan 已提交
260
bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) {
dengyihao's avatar
dengyihao 已提交
261
  int64_t interval = TABS(pDnode->lastAccessTime - curMs);
262
  if (interval > 30000 * tsStatusInterval) {
S
Shengliang Guan 已提交
263 264 265
    if (pDnode->rebootTime > 0) {
      pDnode->offlineReason = DND_REASON_STATUS_MSG_TIMEOUT;
    }
S
Shengliang Guan 已提交
266 267 268 269 270
    return false;
  }
  return true;
}

S
Shengliang Guan 已提交
271
static void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeEps) {
S
Shengliang Guan 已提交
272 273
  SSdb *pSdb = pMnode->pSdb;

274
  int32_t numOfEps = 0;
S
Shengliang Guan 已提交
275 276 277 278 279 280
  void   *pIter = NULL;
  while (1) {
    SDnodeObj *pDnode = NULL;
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
    if (pIter == NULL) break;

S
Shengliang Guan 已提交
281 282 283 284 285 286
    SDnodeEp dnodeEp = {0};
    dnodeEp.id = pDnode->id;
    dnodeEp.isMnode = 0;
    dnodeEp.ep.port = pDnode->port;
    memcpy(dnodeEp.ep.fqdn, pDnode->fqdn, TSDB_FQDN_LEN);

S
Shengliang Guan 已提交
287
    if (mndIsMnode(pMnode, pDnode->id)) {
S
Shengliang Guan 已提交
288
      dnodeEp.isMnode = 1;
S
Shengliang Guan 已提交
289
    }
S
Shengliang Guan 已提交
290

291
    sdbRelease(pSdb, pDnode);
S
Shengliang Guan 已提交
292
    taosArrayPush(pDnodeEps, &dnodeEp);
S
Shengliang Guan 已提交
293 294 295 296
  }
}

static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
S
Shengliang Guan 已提交
297 298
  if (pCfg->statusInterval != tsStatusInterval) {
    mError("statusInterval [%d - %d] cfg inconsistent", pCfg->statusInterval, tsStatusInterval);
S
Shengliang Guan 已提交
299 300 301
    return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
  }

wafwerar's avatar
wafwerar 已提交
302 303
  if ((0 != strcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) {
    mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezoneStr,
S
Shengliang Guan 已提交
304
           pCfg->checkTime, pMnode->checkTime);
S
Shengliang Guan 已提交
305 306 307
    return DND_REASON_TIME_ZONE_NOT_MATCH;
  }

S
os env  
Shengliang Guan 已提交
308 309
  if (0 != strcasecmp(pCfg->locale, tsLocale)) {
    mError("locale [%s - %s]  cfg inconsistent", pCfg->locale, tsLocale);
S
Shengliang Guan 已提交
310 311 312
    return DND_REASON_LOCALE_NOT_MATCH;
  }

S
os env  
Shengliang Guan 已提交
313 314
  if (0 != strcasecmp(pCfg->charset, tsCharset)) {
    mError("charset [%s - %s] cfg inconsistent.", pCfg->charset, tsCharset);
S
Shengliang Guan 已提交
315 316 317 318 319 320
    return DND_REASON_CHARSET_NOT_MATCH;
  }

  return 0;
}

S
Shengliang Guan 已提交
321 322
static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
  SMnode    *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
323 324 325
  SStatusReq statusReq = {0};
  SDnodeObj *pDnode = NULL;
  int32_t    code = -1;
S
Shengliang Guan 已提交
326

S
Shengliang Guan 已提交
327
  if (tDeserializeSStatusReq(pReq->pCont, pReq->contLen, &statusReq) != 0) {
S
Shengliang Guan 已提交
328 329 330
    terrno = TSDB_CODE_INVALID_MSG;
    goto PROCESS_STATUS_MSG_OVER;
  }
S
Shengliang Guan 已提交
331

S
Shengliang Guan 已提交
332 333
  if (statusReq.dnodeId == 0) {
    pDnode = mndAcquireDnodeByEp(pMnode, statusReq.dnodeEp);
S
Shengliang Guan 已提交
334
    if (pDnode == NULL) {
S
Shengliang Guan 已提交
335
      mDebug("dnode:%s, not created yet", statusReq.dnodeEp);
336
      terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
S
Shengliang Guan 已提交
337
      goto PROCESS_STATUS_MSG_OVER;
S
Shengliang Guan 已提交
338 339
    }
  } else {
S
Shengliang Guan 已提交
340
    pDnode = mndAcquireDnode(pMnode, statusReq.dnodeId);
S
Shengliang Guan 已提交
341
    if (pDnode == NULL) {
S
Shengliang Guan 已提交
342
      pDnode = mndAcquireDnodeByEp(pMnode, statusReq.dnodeEp);
S
Shengliang Guan 已提交
343
      if (pDnode != NULL) {
S
Shengliang Guan 已提交
344 345
        pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH;
      }
S
Shengliang Guan 已提交
346
      mError("dnode:%d, %s not exist", statusReq.dnodeId, statusReq.dnodeEp);
347
      terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
S
Shengliang Guan 已提交
348
      goto PROCESS_STATUS_MSG_OVER;
S
Shengliang Guan 已提交
349 350 351
    }
  }

S
Shengliang Guan 已提交
352 353 354 355 356 357
  int32_t numOfVloads = (int32_t)taosArrayGetSize(statusReq.pVloads);
  for (int32_t v = 0; v < numOfVloads; ++v) {
    SVnodeLoad *pVload = taosArrayGet(statusReq.pVloads, v);

    SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId);
    if (pVgroup != NULL) {
S
Shengliang Guan 已提交
358
      if (pVload->syncState == TAOS_SYNC_STATE_LEADER) {
S
Shengliang Guan 已提交
359 360 361 362 363 364
        pVgroup->numOfTables = pVload->numOfTables;
        pVgroup->numOfTimeSeries = pVload->numOfTimeSeries;
        pVgroup->totalStorage = pVload->totalStorage;
        pVgroup->compStorage = pVload->compStorage;
        pVgroup->pointsWritten = pVload->pointsWritten;
      }
L
Liu Jicong 已提交
365
      bool roleChanged = false;
S
Shengliang Guan 已提交
366
      for (int32_t vg = 0; vg < pVgroup->replica; ++vg) {
M
Minghao Li 已提交
367
        if (pVgroup->vnodeGid[vg].dnodeId == statusReq.dnodeId) {
M
Minghao Li 已提交
368
          if (pVgroup->vnodeGid[vg].role != pVload->syncState) {
M
Minghao Li 已提交
369 370
            roleChanged = true;
          }
M
Minghao Li 已提交
371
          pVgroup->vnodeGid[vg].role = pVload->syncState;
L
Liu Jicong 已提交
372
        }
S
Shengliang Guan 已提交
373
      }
L
Liu Jicong 已提交
374 375 376
      if (roleChanged) {
        // notify scheduler role has changed
      }
S
Shengliang Guan 已提交
377 378 379 380 381
    }

    mndReleaseVgroup(pMnode, pVgroup);
  }

382 383 384 385 386 387 388 389 390
  SMnodeObj *pObj = mndAcquireMnode(pMnode, pDnode->id);
  if (pObj != NULL) {
    if (pObj->state != statusReq.mload.syncState) {
      pObj->state = statusReq.mload.syncState;
      pObj->stateStartTime = taosGetTimestampMs();
    }
    mndReleaseMnode(pMnode, pObj);
  }

S
Shengliang Guan 已提交
391 392
  int64_t curMs = taosGetTimestampMs();
  bool    online = mndIsDnodeOnline(pMnode, pDnode, curMs);
S
Shengliang Guan 已提交
393
  bool    dnodeChanged = (statusReq.dnodeVer != sdbGetTableVer(pMnode->pSdb, SDB_DNODE));
S
Shengliang Guan 已提交
394
  bool    reboot = (pDnode->rebootTime != statusReq.rebootTime);
395
  bool    needCheck = !online || dnodeChanged || reboot;
S
Shengliang Guan 已提交
396

397
  if (needCheck) {
S
Shengliang Guan 已提交
398
    if (statusReq.sver != tsVersion) {
S
Shengliang Guan 已提交
399
      if (pDnode != NULL) {
S
Shengliang Guan 已提交
400
        pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
S
Shengliang Guan 已提交
401
      }
S
Shengliang Guan 已提交
402
      mError("dnode:%d, status msg version:%d not match cluster:%d", statusReq.dnodeId, statusReq.sver, tsVersion);
403
      terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
S
Shengliang Guan 已提交
404
      goto PROCESS_STATUS_MSG_OVER;
S
Shengliang Guan 已提交
405 406
    }

S
Shengliang Guan 已提交
407
    if (statusReq.dnodeId == 0) {
S
Shengliang Guan 已提交
408
      mDebug("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId);
S
Shengliang Guan 已提交
409
    } else {
S
Shengliang Guan 已提交
410
      if (statusReq.clusterId != pMnode->clusterId) {
S
Shengliang Guan 已提交
411 412 413
        if (pDnode != NULL) {
          pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH;
        }
S
Shengliang Guan 已提交
414
        mError("dnode:%d, clusterId %" PRId64 " not match exist %" PRId64, pDnode->id, statusReq.clusterId,
S
Shengliang Guan 已提交
415 416 417 418 419 420 421
               pMnode->clusterId);
        terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID;
        goto PROCESS_STATUS_MSG_OVER;
      } else {
        pDnode->accessTimes++;
        mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes);
      }
S
Shengliang Guan 已提交
422 423 424
    }

    // Verify whether the cluster parameters are consistent when status change from offline to ready
S
Shengliang Guan 已提交
425
    int32_t ret = mndCheckClusterCfgPara(pMnode, &statusReq.clusterCfg);
S
Shengliang Guan 已提交
426 427 428
    if (0 != ret) {
      pDnode->offlineReason = ret;
      mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[ret]);
429
      terrno = TSDB_CODE_MND_INVALID_CLUSTER_CFG;
S
Shengliang Guan 已提交
430
      goto PROCESS_STATUS_MSG_OVER;
S
Shengliang Guan 已提交
431 432
    }

433 434 435 436 437
    if (!online) {
      mInfo("dnode:%d, from offline to online", pDnode->id);
    } else {
      mDebug("dnode:%d, send dnode eps", pDnode->id);
    }
S
Shengliang Guan 已提交
438

S
Shengliang Guan 已提交
439 440 441
    pDnode->rebootTime = statusReq.rebootTime;
    pDnode->numOfCores = statusReq.numOfCores;
    pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes;
S
Shengliang Guan 已提交
442

S
Shengliang Guan 已提交
443
    SStatusRsp statusRsp = {0};
S
Shengliang Guan 已提交
444
    statusRsp.dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE);
S
Shengliang Guan 已提交
445 446 447 448
    statusRsp.dnodeCfg.dnodeId = pDnode->id;
    statusRsp.dnodeCfg.clusterId = pMnode->clusterId;
    statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp));
    if (statusRsp.pDnodeEps == NULL) {
S
Shengliang Guan 已提交
449 450 451 452
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      goto PROCESS_STATUS_MSG_OVER;
    }

S
Shengliang Guan 已提交
453 454
    mndGetDnodeData(pMnode, statusRsp.pDnodeEps);

S
Shengliang Guan 已提交
455
    int32_t contLen = tSerializeSStatusRsp(NULL, 0, &statusRsp);
S
Shengliang Guan 已提交
456
    void   *pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
457
    tSerializeSStatusRsp(pHead, contLen, &statusRsp);
S
Shengliang Guan 已提交
458
    taosArrayDestroy(statusRsp.pDnodeEps);
S
Shengliang Guan 已提交
459

S
Shengliang Guan 已提交
460 461
    pReq->info.rspLen = contLen;
    pReq->info.rsp = pHead;
S
Shengliang Guan 已提交
462
  }
S
Shengliang Guan 已提交
463

S
Shengliang Guan 已提交
464
  pDnode->lastAccessTime = curMs;
S
Shengliang Guan 已提交
465 466 467 468
  code = 0;

PROCESS_STATUS_MSG_OVER:
  mndReleaseDnode(pMnode, pDnode);
S
Shengliang Guan 已提交
469
  taosArrayDestroy(statusReq.pVloads);
S
Shengliang Guan 已提交
470
  return code;
S
Shengliang Guan 已提交
471 472
}

S
Shengliang Guan 已提交
473
static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pCreate) {
S
Shengliang Guan 已提交
474
  SDnodeObj dnodeObj = {0};
S
Shengliang Guan 已提交
475
  dnodeObj.id = sdbGetMaxId(pMnode->pSdb, SDB_DNODE);
S
Shengliang Guan 已提交
476 477
  dnodeObj.createdTime = taosGetTimestampMs();
  dnodeObj.updateTime = dnodeObj.createdTime;
S
Shengliang Guan 已提交
478 479
  dnodeObj.port = pCreate->port;
  memcpy(dnodeObj.fqdn, pCreate->fqdn, TSDB_FQDN_LEN);
S
Shengliang Guan 已提交
480
  snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port);
S
Shengliang Guan 已提交
481

S
Shengliang Guan 已提交
482
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_DNODE, pReq);
S
Shengliang Guan 已提交
483
  if (pTrans == NULL) {
S
Shengliang Guan 已提交
484
    mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr());
S
Shengliang Guan 已提交
485 486
    return -1;
  }
S
Shengliang Guan 已提交
487
  mDebug("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep);
S
Shengliang Guan 已提交
488

489 490 491
  SSdbRaw *pCommitRaw = mndDnodeActionEncode(&dnodeObj);
  if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
S
Shengliang Guan 已提交
492 493 494
    mndTransDrop(pTrans);
    return -1;
  }
495
  sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
S
Shengliang Guan 已提交
496

S
Shengliang Guan 已提交
497
  if (mndTransPrepare(pMnode, pTrans) != 0) {
S
Shengliang Guan 已提交
498 499 500 501 502 503 504 505 506
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
    mndTransDrop(pTrans);
    return -1;
  }

  mndTransDrop(pTrans);
  return 0;
}

S
Shengliang Guan 已提交
507 508
static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
  SMnode         *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
509 510 511 512 513
  int32_t         code = -1;
  SUserObj       *pUser = NULL;
  SDnodeObj      *pDnode = NULL;
  SCreateDnodeReq createReq = {0};

S
Shengliang Guan 已提交
514
  if (tDeserializeSCreateDnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
S
Shengliang Guan 已提交
515 516 517 518 519
    terrno = TSDB_CODE_INVALID_MSG;
    goto CREATE_DNODE_OVER;
  }

  mDebug("dnode:%s:%d, start to create", createReq.fqdn, createReq.port);
S
Shengliang Guan 已提交
520

S
Shengliang Guan 已提交
521
  if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) {
522
    terrno = TSDB_CODE_MND_INVALID_DNODE_EP;
S
Shengliang Guan 已提交
523
    goto CREATE_DNODE_OVER;
S
Shengliang Guan 已提交
524 525
  }

S
Shengliang Guan 已提交
526
  char ep[TSDB_EP_LEN];
S
Shengliang Guan 已提交
527 528
  snprintf(ep, TSDB_EP_LEN, "%s:%d", createReq.fqdn, createReq.port);
  pDnode = mndAcquireDnodeByEp(pMnode, ep);
S
Shengliang Guan 已提交
529 530
  if (pDnode != NULL) {
    terrno = TSDB_CODE_MND_DNODE_ALREADY_EXIST;
S
Shengliang Guan 已提交
531
    goto CREATE_DNODE_OVER;
S
Shengliang Guan 已提交
532
  }
S
Shengliang Guan 已提交
533

S
Shengliang Guan 已提交
534
  pUser = mndAcquireUser(pMnode, pReq->conn.user);
S
Shengliang Guan 已提交
535 536 537 538
  if (pUser == NULL) {
    terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
    goto CREATE_DNODE_OVER;
  }
S
Shengliang Guan 已提交
539

S
Shengliang Guan 已提交
540
  if (mndCheckNodeAuth(pUser)) {
S
Shengliang Guan 已提交
541 542 543 544
    goto CREATE_DNODE_OVER;
  }

  code = mndCreateDnode(pMnode, pReq, &createReq);
S
Shengliang Guan 已提交
545
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
546 547

CREATE_DNODE_OVER:
S
Shengliang Guan 已提交
548
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
S
Shengliang Guan 已提交
549
    mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, terrstr());
S
Shengliang Guan 已提交
550 551
  }

S
Shengliang Guan 已提交
552 553 554
  mndReleaseDnode(pMnode, pDnode);
  mndReleaseUser(pMnode, pUser);
  return code;
S
Shengliang Guan 已提交
555 556
}

S
Shengliang Guan 已提交
557 558
static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode) {
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_DNODE, pReq);
S
Shengliang Guan 已提交
559 560 561 562
  if (pTrans == NULL) {
    mError("dnode:%d, failed to drop since %s", pDnode->id, terrstr());
    return -1;
  }
563
  mDebug("trans:%d, used to drop dnode:%d", pTrans->id, pDnode->id);
S
Shengliang Guan 已提交
564

565 566 567
  SSdbRaw *pCommitRaw = mndDnodeActionEncode(pDnode);
  if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
S
Shengliang Guan 已提交
568 569 570
    mndTransDrop(pTrans);
    return -1;
  }
571
  sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
S
Shengliang Guan 已提交
572

S
Shengliang Guan 已提交
573
  if (mndTransPrepare(pMnode, pTrans) != 0) {
S
Shengliang Guan 已提交
574 575 576 577 578 579 580 581 582
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
    mndTransDrop(pTrans);
    return -1;
  }

  mndTransDrop(pTrans);
  return 0;
}

S
Shengliang Guan 已提交
583 584
static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
  SMnode        *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
585 586 587
  int32_t        code = -1;
  SUserObj      *pUser = NULL;
  SDnodeObj     *pDnode = NULL;
588
  SMnodeObj     *pMObj = NULL;
S
Shengliang Guan 已提交
589
  SMDropMnodeReq dropReq = {0};
S
Shengliang Guan 已提交
590

S
Shengliang Guan 已提交
591
  if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
S
Shengliang Guan 已提交
592 593 594
    terrno = TSDB_CODE_INVALID_MSG;
    goto DROP_DNODE_OVER;
  }
S
Shengliang Guan 已提交
595

S
Shengliang Guan 已提交
596
  mDebug("dnode:%d, start to drop", dropReq.dnodeId);
S
Shengliang Guan 已提交
597

S
Shengliang Guan 已提交
598
  if (dropReq.dnodeId <= 0) {
599
    terrno = TSDB_CODE_MND_INVALID_DNODE_ID;
S
Shengliang Guan 已提交
600
    goto DROP_DNODE_OVER;
S
Shengliang Guan 已提交
601 602
  }

S
Shengliang Guan 已提交
603
  pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId);
S
Shengliang Guan 已提交
604 605
  if (pDnode == NULL) {
    terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
S
Shengliang Guan 已提交
606 607 608
    goto DROP_DNODE_OVER;
  }

609 610 611 612 613 614
  pMObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
  if (pMObj != NULL) {
    terrno = TSDB_CODE_MND_MNODE_DEPLOYED;
    goto DROP_DNODE_OVER;
  }

S
Shengliang Guan 已提交
615
  pUser = mndAcquireUser(pMnode, pReq->conn.user);
S
Shengliang Guan 已提交
616 617 618
  if (pUser == NULL) {
    terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
    goto DROP_DNODE_OVER;
S
Shengliang Guan 已提交
619 620
  }

S
Shengliang Guan 已提交
621
  if (mndCheckNodeAuth(pUser)) {
S
Shengliang Guan 已提交
622 623 624 625
    goto DROP_DNODE_OVER;
  }

  code = mndDropDnode(pMnode, pReq, pDnode);
S
Shengliang Guan 已提交
626
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
627 628

DROP_DNODE_OVER:
S
Shengliang Guan 已提交
629
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
S
Shengliang Guan 已提交
630
    mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
S
Shengliang Guan 已提交
631 632
  }

633
  mndReleaseDnode(pMnode, pDnode);
S
Shengliang Guan 已提交
634
  mndReleaseUser(pMnode, pUser);
635
  mndReleaseMnode(pMnode, pMObj);
S
Shengliang Guan 已提交
636 637

  return code;
S
Shengliang Guan 已提交
638 639
}

S
Shengliang Guan 已提交
640 641
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
  SMnode *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
642 643

  SMCfgDnodeReq cfgReq = {0};
S
Shengliang Guan 已提交
644
  if (tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
S
Shengliang Guan 已提交
645 646 647
    terrno = TSDB_CODE_INVALID_MSG;
    return -1;
  }
S
Shengliang Guan 已提交
648

S
Shengliang Guan 已提交
649
  SDnodeObj *pDnode = mndAcquireDnode(pMnode, cfgReq.dnodeId);
S
Shengliang Guan 已提交
650 651
  if (pDnode == NULL) {
    terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
S
Shengliang Guan 已提交
652
    mError("dnode:%d, failed to config since %s ", cfgReq.dnodeId, terrstr());
S
Shengliang Guan 已提交
653 654 655 656 657 658
    return -1;
  }

  SEpSet epSet = mndGetDnodeEpset(pDnode);
  mndReleaseDnode(pMnode, pDnode);

S
Shengliang Guan 已提交
659 660 661 662
  int32_t bufLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq);
  void   *pBuf = rpcMallocCont(bufLen);
  tSerializeSMCfgDnodeReq(pBuf, bufLen, &cfgReq);

S
Shengliang Guan 已提交
663
  SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen, .info = pReq->info};
S
Shengliang Guan 已提交
664

S
Shengliang Guan 已提交
665 666
  mDebug("dnode:%d, send config req to dnode, app:%p", cfgReq.dnodeId, rpcMsg.info.ahandle);
  return tmsgSendReq(&epSet, &rpcMsg);
S
Shengliang Guan 已提交
667 668
}

S
Shengliang Guan 已提交
669
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
670
  mDebug("config rsp from dnode, app:%p", pRsp->info.ahandle);
671
  return TSDB_CODE_SUCCESS;
672
}
S
Shengliang Guan 已提交
673

S
Shengliang Guan 已提交
674 675
static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
  SMnode *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
676
  int32_t totalRows = 0;
S
Shengliang Guan 已提交
677 678 679 680 681 682
  int32_t numOfRows = 0;
  char   *cfgOpts[TSDB_CONFIG_NUMBER] = {0};
  char    cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONIIG_VALUE_LEN + 1] = {0};
  char   *pWrite;
  int32_t cols = 0;

S
Shengliang Guan 已提交
683 684 685
  cfgOpts[totalRows] = "statusInterval";
  snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%d", tsStatusInterval);
  totalRows++;
S
Shengliang Guan 已提交
686

S
Shengliang Guan 已提交
687
  cfgOpts[totalRows] = "timezone";
wafwerar's avatar
wafwerar 已提交
688
  snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr);
S
Shengliang Guan 已提交
689
  totalRows++;
S
Shengliang Guan 已提交
690

S
Shengliang Guan 已提交
691 692 693
  cfgOpts[totalRows] = "locale";
  snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsLocale);
  totalRows++;
S
Shengliang Guan 已提交
694

S
Shengliang Guan 已提交
695 696 697
  cfgOpts[totalRows] = "charset";
  snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsCharset);
  totalRows++;
S
Shengliang Guan 已提交
698

699 700 701
  char buf[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
  char bufVal[TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};

S
Shengliang Guan 已提交
702
  for (int32_t i = 0; i < totalRows; i++) {
S
Shengliang Guan 已提交
703 704
    cols = 0;

705 706
    STR_WITH_MAXSIZE_TO_VARSTR(buf, cfgOpts[i], TSDB_CONFIG_OPTION_LEN);

M
Minghao Li 已提交
707 708
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, (const char *)buf, false);
S
Shengliang Guan 已提交
709

710 711
    STR_WITH_MAXSIZE_TO_VARSTR(bufVal, cfgVals[i], TSDB_CONIIG_VALUE_LEN);
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
M
Minghao Li 已提交
712
    colDataAppend(pColInfo, numOfRows, (const char *)bufVal, false);
S
Shengliang Guan 已提交
713 714

    numOfRows++;
S
Shengliang Guan 已提交
715 716
  }

717
  pShow->numOfRows += numOfRows;
S
Shengliang Guan 已提交
718 719 720 721 722
  return numOfRows;
}

static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter) {}

S
Shengliang Guan 已提交
723 724
static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
  SMnode    *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
725 726 727 728
  SSdb      *pSdb = pMnode->pSdb;
  int32_t    numOfRows = 0;
  int32_t    cols = 0;
  SDnodeObj *pDnode = NULL;
S
Shengliang Guan 已提交
729
  int64_t    curMs = taosGetTimestampMs();
S
Shengliang Guan 已提交
730 731 732 733

  while (numOfRows < rows) {
    pShow->pIter = sdbFetch(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode);
    if (pShow->pIter == NULL) break;
S
Shengliang Guan 已提交
734
    bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
S
Shengliang Guan 已提交
735 736 737

    cols = 0;

M
Minghao Li 已提交
738 739
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, (const char *)&pDnode->id, false);
740 741

    char buf[tListLen(pDnode->ep) + VARSTR_HEADER_SIZE] = {0};
742
    STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
743 744 745 746 747 748

    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, buf, false);

    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    int16_t id = mndGetVnodesNum(pMnode, pDnode->id);
M
Minghao Li 已提交
749
    colDataAppend(pColInfo, numOfRows, (const char *)&id, false);
S
Shengliang Guan 已提交
750

751 752
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, (const char *)&pDnode->numOfSupportVnodes, false);
S
Shengliang Guan 已提交
753

754
    char b1[9] = {0};
M
Minghao Li 已提交
755
    STR_TO_VARSTR(b1, online ? "ready" : "offline");
S
Shengliang Guan 已提交
756

757 758
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, b1, false);
S
Shengliang Guan 已提交
759

760
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
M
Minghao Li 已提交
761
    colDataAppend(pColInfo, numOfRows, (const char *)&pDnode->createdTime, false);
S
Shengliang Guan 已提交
762

763 764
    char b[tListLen(offlineReason) + VARSTR_HEADER_SIZE] = {0};
    STR_TO_VARSTR(b, online ? "" : offlineReason[pDnode->offlineReason]);
S
Shengliang Guan 已提交
765

766 767
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, b, false);
S
Shengliang Guan 已提交
768 769 770 771 772

    numOfRows++;
    sdbRelease(pSdb, pDnode);
  }

773
  pShow->numOfRows += numOfRows;
S
Shengliang Guan 已提交
774

S
Shengliang Guan 已提交
775 776 777 778 779 780
  return numOfRows;
}

static void mndCancelGetNextDnode(SMnode *pMnode, void *pIter) {
  SSdb *pSdb = pMnode->pSdb;
  sdbCancelFetch(pSdb, pIter);
L
Liu Jicong 已提交
781
}