mndDnode.c 25.5 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"
D
dapan1121 已提交
20
#include "mndQnode.h"
S
Shengliang Guan 已提交
21
#include "mndShow.h"
S
Shengliang Guan 已提交
22
#include "mndTrans.h"
S
Shengliang Guan 已提交
23
#include "mndUser.h"
S
Shengliang Guan 已提交
24
#include "mndVgroup.h"
S
Shengliang Guan 已提交
25

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

S
Shengliang Guan 已提交
29
static const char *offlineReason[] = {
S
Shengliang Guan 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42
    "",
    "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 已提交
43 44 45 46 47
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);
48
static int32_t  mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew);
S
Shengliang Guan 已提交
49

S
Shengliang Guan 已提交
50 51 52 53 54
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 已提交
55

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

int32_t mndInitDnode(SMnode *pMnode) {
62 63 64 65 66 67 68 69 70 71
  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 已提交
72

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

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

S
Shengliang Guan 已提交
84 85 86 87 88 89 90 91 92 93 94 95
  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);
96
  snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port);
S
Shengliang Guan 已提交
97 98 99

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

102
  mDebug("dnode:%d, will be created when deploying, raw:%p", dnodeObj.id, pRaw);
103

104
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, NULL);
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
  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;
S
Shengliang Guan 已提交
126 127
}

S
Shengliang Guan 已提交
128
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
129 130
  terrno = TSDB_CODE_OUT_OF_MEMORY;

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

  int32_t dataPos = 0;
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
  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 已提交
151

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

static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
157 158
  terrno = TSDB_CODE_OUT_OF_MEMORY;

S
Shengliang Guan 已提交
159
  int8_t sver = 0;
160
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DNODE_DECODE_OVER;
S
Shengliang Guan 已提交
161

S
Shengliang Guan 已提交
162
  if (sver != TSDB_DNODE_VER_NUMBER) {
S
Shengliang Guan 已提交
163
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
164
    goto DNODE_DECODE_OVER;
S
Shengliang Guan 已提交
165 166
  }

167 168 169
  SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj));
  if (pRow == NULL) goto DNODE_DECODE_OVER;

S
Shengliang Guan 已提交
170
  SDnodeObj *pDnode = sdbGetRowObj(pRow);
171
  if (pDnode == NULL) goto DNODE_DECODE_OVER;
S
Shengliang Guan 已提交
172 173

  int32_t dataPos = 0;
174 175 176 177 178 179 180 181 182 183 184 185
  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 已提交
186
    taosMemoryFreeClear(pRow);
187 188
    return NULL;
  }
S
Shengliang Guan 已提交
189

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

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

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

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

S
Shengliang Guan 已提交
212
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId) {
S
Shengliang Guan 已提交
213 214 215 216 217 218
  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 已提交
219
}
S
Shengliang Guan 已提交
220

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

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

S
Shengliang Guan 已提交
232 233 234 235 236 237 238 239 240 241 242 243 244
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 已提交
245 246

    sdbRelease(pSdb, pDnode);
S
Shengliang Guan 已提交
247 248 249 250 251
  }

  return NULL;
}

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

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

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

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

S
Shengliang Guan 已提交
278 279 280 281 282 283
    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 已提交
284
    if (mndIsMnode(pMnode, pDnode->id)) {
S
Shengliang Guan 已提交
285
      dnodeEp.isMnode = 1;
S
Shengliang Guan 已提交
286
    }
S
Shengliang Guan 已提交
287

288
    sdbRelease(pSdb, pDnode);
S
Shengliang Guan 已提交
289
    taosArrayPush(pDnodeEps, &dnodeEp);
S
Shengliang Guan 已提交
290 291 292 293
  }
}

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

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

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

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

  return 0;
}

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

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

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

S
Shengliang Guan 已提交
349 350 351 352 353 354
  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 已提交
355
      if (pVload->syncState == TAOS_SYNC_STATE_LEADER) {
S
Shengliang Guan 已提交
356 357 358 359 360 361
        pVgroup->numOfTables = pVload->numOfTables;
        pVgroup->numOfTimeSeries = pVload->numOfTimeSeries;
        pVgroup->totalStorage = pVload->totalStorage;
        pVgroup->compStorage = pVload->compStorage;
        pVgroup->pointsWritten = pVload->pointsWritten;
      }
L
Liu Jicong 已提交
362
      bool roleChanged = false;
S
Shengliang Guan 已提交
363
      for (int32_t vg = 0; vg < pVgroup->replica; ++vg) {
M
Minghao Li 已提交
364
        if (pVgroup->vnodeGid[vg].dnodeId == statusReq.dnodeId) {
M
Minghao Li 已提交
365
          if (pVgroup->vnodeGid[vg].role != pVload->syncState) {
M
Minghao Li 已提交
366 367
            roleChanged = true;
          }
M
Minghao Li 已提交
368
          pVgroup->vnodeGid[vg].role = pVload->syncState;
L
Liu Jicong 已提交
369
        }
S
Shengliang Guan 已提交
370
      }
L
Liu Jicong 已提交
371 372 373
      if (roleChanged) {
        // notify scheduler role has changed
      }
S
Shengliang Guan 已提交
374 375 376 377 378
    }

    mndReleaseVgroup(pMnode, pVgroup);
  }

379 380 381 382 383 384 385 386 387
  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);
  }

D
dapan1121 已提交
388 389 390 391 392 393
  SQnodeObj *pQnode = mndAcquireQnode(pMnode, statusReq.qload.dnodeId);
  if (pQnode != NULL) {
    pQnode->load = statusReq.qload;
    mndReleaseQnode(pMnode, pQnode);
  }

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

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

S
Shengliang Guan 已提交
411
    if (statusReq.dnodeId == 0) {
S
Shengliang Guan 已提交
412
      mDebug("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId);
S
Shengliang Guan 已提交
413
    } else {
S
Shengliang Guan 已提交
414
      if (statusReq.clusterId != pMnode->clusterId) {
S
Shengliang Guan 已提交
415 416 417
        if (pDnode != NULL) {
          pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH;
        }
S
Shengliang Guan 已提交
418
        mError("dnode:%d, clusterId %" PRId64 " not match exist %" PRId64, pDnode->id, statusReq.clusterId,
S
Shengliang Guan 已提交
419 420 421 422 423 424 425
               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 已提交
426 427 428
    }

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

437 438 439
    if (!online) {
      mInfo("dnode:%d, from offline to online", pDnode->id);
    } else {
440 441
      mDebug("dnode:%d, send dnode epset, online:%d ver:% " PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online,
             statusReq.dnodeVer, dnodeVer, reboot);
442
    }
S
Shengliang Guan 已提交
443

S
Shengliang Guan 已提交
444 445 446
    pDnode->rebootTime = statusReq.rebootTime;
    pDnode->numOfCores = statusReq.numOfCores;
    pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes;
S
Shengliang Guan 已提交
447

S
Shengliang Guan 已提交
448
    SStatusRsp statusRsp = {0};
449
    statusRsp.dnodeVer = dnodeVer;
S
Shengliang Guan 已提交
450 451 452 453
    statusRsp.dnodeCfg.dnodeId = pDnode->id;
    statusRsp.dnodeCfg.clusterId = pMnode->clusterId;
    statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp));
    if (statusRsp.pDnodeEps == NULL) {
S
Shengliang Guan 已提交
454 455 456 457
      terrno = TSDB_CODE_OUT_OF_MEMORY;
      goto PROCESS_STATUS_MSG_OVER;
    }

S
Shengliang Guan 已提交
458 459
    mndGetDnodeData(pMnode, statusRsp.pDnodeEps);

S
Shengliang Guan 已提交
460
    int32_t contLen = tSerializeSStatusRsp(NULL, 0, &statusRsp);
S
Shengliang Guan 已提交
461
    void   *pHead = rpcMallocCont(contLen);
S
Shengliang Guan 已提交
462
    tSerializeSStatusRsp(pHead, contLen, &statusRsp);
S
Shengliang Guan 已提交
463
    taosArrayDestroy(statusRsp.pDnodeEps);
S
Shengliang Guan 已提交
464

S
Shengliang Guan 已提交
465 466
    pReq->info.rspLen = contLen;
    pReq->info.rsp = pHead;
S
Shengliang Guan 已提交
467
  }
S
Shengliang Guan 已提交
468

S
Shengliang Guan 已提交
469
  pDnode->lastAccessTime = curMs;
S
Shengliang Guan 已提交
470 471 472 473
  code = 0;

PROCESS_STATUS_MSG_OVER:
  mndReleaseDnode(pMnode, pDnode);
S
Shengliang Guan 已提交
474
  taosArrayDestroy(statusReq.pVloads);
S
Shengliang Guan 已提交
475
  return code;
S
Shengliang Guan 已提交
476 477
}

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

487
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq);
S
Shengliang Guan 已提交
488
  if (pTrans == NULL) {
S
Shengliang Guan 已提交
489
    mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr());
S
Shengliang Guan 已提交
490 491
    return -1;
  }
S
Shengliang Guan 已提交
492
  mDebug("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep);
S
Shengliang Guan 已提交
493

494 495 496
  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 已提交
497 498 499
    mndTransDrop(pTrans);
    return -1;
  }
500
  sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
S
Shengliang Guan 已提交
501

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

  mndTransDrop(pTrans);
  return 0;
}

S
Shengliang Guan 已提交
512 513
static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
  SMnode         *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
514 515 516 517 518
  int32_t         code = -1;
  SUserObj       *pUser = NULL;
  SDnodeObj      *pDnode = NULL;
  SCreateDnodeReq createReq = {0};

S
Shengliang Guan 已提交
519
  if (tDeserializeSCreateDnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
S
Shengliang Guan 已提交
520 521 522 523 524
    terrno = TSDB_CODE_INVALID_MSG;
    goto CREATE_DNODE_OVER;
  }

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

S
Shengliang Guan 已提交
526
  if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) {
527
    terrno = TSDB_CODE_MND_INVALID_DNODE_EP;
S
Shengliang Guan 已提交
528
    goto CREATE_DNODE_OVER;
S
Shengliang Guan 已提交
529 530
  }

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

S
Shengliang Guan 已提交
539
  pUser = mndAcquireUser(pMnode, pReq->conn.user);
S
Shengliang Guan 已提交
540 541 542 543
  if (pUser == NULL) {
    terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
    goto CREATE_DNODE_OVER;
  }
S
Shengliang Guan 已提交
544

S
Shengliang Guan 已提交
545
  if (mndCheckNodeAuth(pUser)) {
S
Shengliang Guan 已提交
546 547 548 549
    goto CREATE_DNODE_OVER;
  }

  code = mndCreateDnode(pMnode, pReq, &createReq);
S
Shengliang Guan 已提交
550
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
551 552

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

S
Shengliang Guan 已提交
557 558 559
  mndReleaseDnode(pMnode, pDnode);
  mndReleaseUser(pMnode, pUser);
  return code;
S
Shengliang Guan 已提交
560 561
}

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

570 571 572
  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 已提交
573 574 575
    mndTransDrop(pTrans);
    return -1;
  }
576
  sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
S
Shengliang Guan 已提交
577

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

  mndTransDrop(pTrans);
  return 0;
}

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

S
Shengliang Guan 已提交
596
  if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
S
Shengliang Guan 已提交
597 598 599
    terrno = TSDB_CODE_INVALID_MSG;
    goto DROP_DNODE_OVER;
  }
S
Shengliang Guan 已提交
600

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

S
Shengliang Guan 已提交
603
  if (dropReq.dnodeId <= 0) {
604
    terrno = TSDB_CODE_MND_INVALID_DNODE_ID;
S
Shengliang Guan 已提交
605
    goto DROP_DNODE_OVER;
S
Shengliang Guan 已提交
606 607
  }

S
Shengliang Guan 已提交
608
  pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId);
S
Shengliang Guan 已提交
609 610
  if (pDnode == NULL) {
    terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
S
Shengliang Guan 已提交
611 612 613
    goto DROP_DNODE_OVER;
  }

614 615
  pMObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
  if (pMObj != NULL) {
S
Shengliang Guan 已提交
616
    terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
617 618 619
    goto DROP_DNODE_OVER;
  }

S
Shengliang Guan 已提交
620
  pUser = mndAcquireUser(pMnode, pReq->conn.user);
S
Shengliang Guan 已提交
621 622 623
  if (pUser == NULL) {
    terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
    goto DROP_DNODE_OVER;
S
Shengliang Guan 已提交
624 625
  }

S
Shengliang Guan 已提交
626
  if (mndCheckNodeAuth(pUser)) {
S
Shengliang Guan 已提交
627 628 629 630
    goto DROP_DNODE_OVER;
  }

  code = mndDropDnode(pMnode, pReq, pDnode);
S
Shengliang Guan 已提交
631
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
632 633

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

638
  mndReleaseDnode(pMnode, pDnode);
S
Shengliang Guan 已提交
639
  mndReleaseUser(pMnode, pUser);
640
  mndReleaseMnode(pMnode, pMObj);
S
Shengliang Guan 已提交
641 642

  return code;
S
Shengliang Guan 已提交
643 644
}

S
Shengliang Guan 已提交
645 646
static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
  SMnode *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
647 648

  SMCfgDnodeReq cfgReq = {0};
S
Shengliang Guan 已提交
649
  if (tDeserializeSMCfgDnodeReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
S
Shengliang Guan 已提交
650 651 652
    terrno = TSDB_CODE_INVALID_MSG;
    return -1;
  }
S
Shengliang Guan 已提交
653

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

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

S
Shengliang Guan 已提交
664 665 666 667
  int32_t bufLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq);
  void   *pBuf = rpcMallocCont(bufLen);
  tSerializeSMCfgDnodeReq(pBuf, bufLen, &cfgReq);

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

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

S
Shengliang Guan 已提交
674
static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
675
  mDebug("config rsp from dnode, app:%p", pRsp->info.ahandle);
676
  return TSDB_CODE_SUCCESS;
677
}
S
Shengliang Guan 已提交
678

S
Shengliang Guan 已提交
679 680
static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
  SMnode *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
681
  int32_t totalRows = 0;
S
Shengliang Guan 已提交
682 683 684 685 686 687
  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 已提交
688 689 690
  cfgOpts[totalRows] = "statusInterval";
  snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%d", tsStatusInterval);
  totalRows++;
S
Shengliang Guan 已提交
691

S
Shengliang Guan 已提交
692
  cfgOpts[totalRows] = "timezone";
wafwerar's avatar
wafwerar 已提交
693
  snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr);
S
Shengliang Guan 已提交
694
  totalRows++;
S
Shengliang Guan 已提交
695

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

S
Shengliang Guan 已提交
700 701 702
  cfgOpts[totalRows] = "charset";
  snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsCharset);
  totalRows++;
S
Shengliang Guan 已提交
703

704 705 706
  char buf[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
  char bufVal[TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0};

S
Shengliang Guan 已提交
707
  for (int32_t i = 0; i < totalRows; i++) {
S
Shengliang Guan 已提交
708 709
    cols = 0;

710 711
    STR_WITH_MAXSIZE_TO_VARSTR(buf, cfgOpts[i], TSDB_CONFIG_OPTION_LEN);

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

715 716
    STR_WITH_MAXSIZE_TO_VARSTR(bufVal, cfgVals[i], TSDB_CONIIG_VALUE_LEN);
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
M
Minghao Li 已提交
717
    colDataAppend(pColInfo, numOfRows, (const char *)bufVal, false);
S
Shengliang Guan 已提交
718 719

    numOfRows++;
S
Shengliang Guan 已提交
720 721
  }

722
  pShow->numOfRows += numOfRows;
S
Shengliang Guan 已提交
723 724 725 726 727
  return numOfRows;
}

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

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

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

    cols = 0;

M
Minghao Li 已提交
743 744
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, (const char *)&pDnode->id, false);
745 746

    char buf[tListLen(pDnode->ep) + VARSTR_HEADER_SIZE] = {0};
747
    STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
748 749 750 751 752 753

    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 已提交
754
    colDataAppend(pColInfo, numOfRows, (const char *)&id, false);
S
Shengliang Guan 已提交
755

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

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

762 763
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, b1, false);
S
Shengliang Guan 已提交
764

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

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

771 772
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, b, false);
S
Shengliang Guan 已提交
773 774 775 776 777

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

778
  pShow->numOfRows += numOfRows;
S
Shengliang Guan 已提交
779

S
Shengliang Guan 已提交
780 781 782 783 784 785
  return numOfRows;
}

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