mndBnode.c 13.9 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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
#include "mndBnode.h"
#include "mndDnode.h"
H
Hongze Cheng 已提交
19
#include "mndPrivilege.h"
S
Shengliang Guan 已提交
20 21
#include "mndShow.h"
#include "mndTrans.h"
S
Shengliang Guan 已提交
22
#include "mndUser.h"
S
Shengliang Guan 已提交
23

24 25
#define BNODE_VER_NUMBER   1
#define BNODE_RESERVE_SIZE 64
S
Shengliang Guan 已提交
26 27 28 29

static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj);
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw);
static int32_t  mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj);
S
Shengliang Guan 已提交
30
static int32_t  mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew);
31
static int32_t  mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj);
S
Shengliang Guan 已提交
32 33 34
static int32_t  mndProcessCreateBnodeReq(SRpcMsg *pReq);
static int32_t  mndProcessDropBnodeReq(SRpcMsg *pReq);
static int32_t  mndRetrieveBnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
S
Shengliang Guan 已提交
35 36 37
static void     mndCancelGetNextBnode(SMnode *pMnode, void *pIter);

int32_t mndInitBnode(SMnode *pMnode) {
38 39 40 41 42 43 44 45 46
  SSdbTable table = {
      .sdbType = SDB_BNODE,
      .keyType = SDB_KEY_INT32,
      .encodeFp = (SdbEncodeFp)mndBnodeActionEncode,
      .decodeFp = (SdbDecodeFp)mndBnodeActionDecode,
      .insertFp = (SdbInsertFp)mndBnodeActionInsert,
      .updateFp = (SdbUpdateFp)mndBnodeActionUpdate,
      .deleteFp = (SdbDeleteFp)mndBnodeActionDelete,
  };
S
Shengliang Guan 已提交
47 48 49

  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_BNODE, mndProcessCreateBnodeReq);
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_BNODE, mndProcessDropBnodeReq);
50 51
  mndSetMsgHandle(pMnode, TDMT_DND_CREATE_BNODE_RSP, mndTransProcessRsp);
  mndSetMsgHandle(pMnode, TDMT_DND_DROP_BNODE_RSP, mndTransProcessRsp);
S
Shengliang Guan 已提交
52 53 54 55 56 57 58 59 60

  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndRetrieveBnodes);
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndCancelGetNextBnode);

  return sdbSetTable(pMnode->pSdb, table);
}

void mndCleanupBnode(SMnode *pMnode) {}

61
static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t bnodeId) {
62 63
  SBnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_BNODE, &bnodeId);
  if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
S
Shengliang Guan 已提交
64 65 66 67 68 69 70 71 72 73 74
    terrno = TSDB_CODE_MND_BNODE_NOT_EXIST;
  }
  return pObj;
}

static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) {
  SSdb *pSdb = pMnode->pSdb;
  sdbRelease(pSdb, pObj);
}

static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj) {
75 76
  terrno = TSDB_CODE_OUT_OF_MEMORY;

77 78
  SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, BNODE_VER_NUMBER, sizeof(SBnodeObj) + BNODE_RESERVE_SIZE);
  if (pRaw == NULL) goto _OVER;
S
Shengliang Guan 已提交
79 80

  int32_t dataPos = 0;
81 82 83 84
  SDB_SET_INT32(pRaw, dataPos, pObj->id, _OVER)
  SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, _OVER)
  SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, _OVER)
  SDB_SET_RESERVE(pRaw, dataPos, BNODE_RESERVE_SIZE, _OVER)
85 86

  terrno = 0;
S
Shengliang Guan 已提交
87

88
_OVER:
89 90 91 92 93 94 95
  if (terrno != 0) {
    mError("bnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr());
    sdbFreeRaw(pRaw);
    return NULL;
  }

  mTrace("bnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj);
S
Shengliang Guan 已提交
96 97 98 99
  return pRaw;
}

static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) {
100 101
  terrno = TSDB_CODE_OUT_OF_MEMORY;

S
Shengliang Guan 已提交
102
  int8_t sver = 0;
103
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
S
Shengliang Guan 已提交
104

105
  if (sver != BNODE_VER_NUMBER) {
S
Shengliang Guan 已提交
106
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
107
    goto _OVER;
S
Shengliang Guan 已提交
108 109
  }

110
  SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj));
111
  if (pRow == NULL) goto _OVER;
112

S
Shengliang Guan 已提交
113
  SBnodeObj *pObj = sdbGetRowObj(pRow);
114
  if (pObj == NULL) goto _OVER;
S
Shengliang Guan 已提交
115 116

  int32_t dataPos = 0;
117 118 119 120
  SDB_GET_INT32(pRaw, dataPos, &pObj->id, _OVER)
  SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, _OVER)
  SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, _OVER)
  SDB_GET_RESERVE(pRaw, dataPos, BNODE_RESERVE_SIZE, _OVER)
121 122

  terrno = 0;
S
Shengliang Guan 已提交
123

124
_OVER:
125 126
  if (terrno != 0) {
    mError("bnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
wafwerar's avatar
wafwerar 已提交
127
    taosMemoryFreeClear(pRow);
128 129 130 131
    return NULL;
  }

  mTrace("bnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj);
S
Shengliang Guan 已提交
132 133 134 135
  return pRow;
}

static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) {
136
  mTrace("bnode:%d, perform insert action, row:%p", pObj->id, pObj);
S
Shengliang Guan 已提交
137 138 139
  pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
  if (pObj->pDnode == NULL) {
    terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
140
    mError("bnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
S
Shengliang Guan 已提交
141 142 143 144 145 146 147
    return -1;
  }

  return 0;
}

static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) {
148
  mTrace("bnode:%d, perform delete action, row:%p", pObj->id, pObj);
S
Shengliang Guan 已提交
149 150 151 152 153 154 155 156
  if (pObj->pDnode != NULL) {
    sdbRelease(pSdb, pObj->pDnode);
    pObj->pDnode = NULL;
  }

  return 0;
}

S
Shengliang Guan 已提交
157
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew) {
S
Shengliang Guan 已提交
158
  mTrace("bnode:%d, perform update action, old row:%p new row:%p", pOld->id, pOld, pNew);
S
Shengliang Guan 已提交
159
  pOld->updateTime = pNew->updateTime;
S
Shengliang Guan 已提交
160 161 162 163 164 165 166 167 168 169 170
  return 0;
}

static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
  SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj);
  if (pRedoRaw == NULL) return -1;
  if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
  if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
  return 0;
}

171 172 173 174 175 176 177 178
static int32_t mndSetCreateBnodeUndoLogs(STrans *pTrans, SBnodeObj *pObj) {
  SSdbRaw *pUndoRaw = mndBnodeActionEncode(pObj);
  if (pUndoRaw == NULL) return -1;
  if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
  if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
  return 0;
}

S
Shengliang Guan 已提交
179 180 181 182 183 184 185 186 187
static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
  SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
  if (pCommitRaw == NULL) return -1;
  if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
  if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
  return 0;
}

static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
S
Shengliang Guan 已提交
188 189 190
  SDCreateBnodeReq createReq = {0};
  createReq.dnodeId = pDnode->id;

191
  int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
wafwerar's avatar
wafwerar 已提交
192
  void   *pReq = taosMemoryMalloc(contLen);
S
Shengliang Guan 已提交
193
  if (pReq == NULL) {
S
Shengliang Guan 已提交
194 195 196
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }
197
  tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
198 199 200

  STransAction action = {0};
  action.epSet = mndGetDnodeEpset(pDnode);
S
Shengliang Guan 已提交
201
  action.pCont = pReq;
S
Shengliang Guan 已提交
202
  action.contLen = contLen;
S
Shengliang Guan 已提交
203
  action.msgType = TDMT_DND_CREATE_BNODE;
S
shm  
Shengliang Guan 已提交
204
  action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
S
Shengliang Guan 已提交
205 206

  if (mndTransAppendRedoAction(pTrans, &action) != 0) {
wafwerar's avatar
wafwerar 已提交
207
    taosMemoryFree(pReq);
S
Shengliang Guan 已提交
208 209 210 211 212 213
    return -1;
  }

  return 0;
}

214
static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
S
Shengliang Guan 已提交
215 216 217
  SDDropBnodeReq dropReq = {0};
  dropReq.dnodeId = pDnode->id;

218
  int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
wafwerar's avatar
wafwerar 已提交
219
  void   *pReq = taosMemoryMalloc(contLen);
S
Shengliang Guan 已提交
220
  if (pReq == NULL) {
221 222 223
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }
224
  tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
225 226 227

  STransAction action = {0};
  action.epSet = mndGetDnodeEpset(pDnode);
S
Shengliang Guan 已提交
228
  action.pCont = pReq;
S
Shengliang Guan 已提交
229
  action.contLen = contLen;
230
  action.msgType = TDMT_DND_DROP_BNODE;
S
shm  
Shengliang Guan 已提交
231
  action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
232 233

  if (mndTransAppendUndoAction(pTrans, &action) != 0) {
wafwerar's avatar
wafwerar 已提交
234
    taosMemoryFree(pReq);
235 236 237 238 239 240
    return -1;
  }

  return 0;
}

S
Shengliang Guan 已提交
241
static int32_t mndCreateBnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) {
242 243
  int32_t code = -1;

244 245 246 247
  SBnodeObj bnodeObj = {0};
  bnodeObj.id = pDnode->id;
  bnodeObj.createdTime = taosGetTimestampMs();
  bnodeObj.updateTime = bnodeObj.createdTime;
S
Shengliang Guan 已提交
248

249
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-bnode");
250
  if (pTrans == NULL) goto _OVER;
S
Shengliang Guan 已提交
251

252
  mInfo("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId);
253 254 255 256 257 258
  if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) goto _OVER;
  if (mndSetCreateBnodeUndoLogs(pTrans, &bnodeObj) != 0) goto _OVER;
  if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) goto _OVER;
  if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) goto _OVER;
  if (mndSetCreateBnodeUndoActions(pTrans, pDnode, &bnodeObj) != 0) goto _OVER;
  if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
S
Shengliang Guan 已提交
259 260 261

  code = 0;

262
_OVER:
S
Shengliang Guan 已提交
263 264 265 266
  mndTransDrop(pTrans);
  return code;
}

S
Shengliang Guan 已提交
267 268
static int32_t mndProcessCreateBnodeReq(SRpcMsg *pReq) {
  SMnode          *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
269 270 271 272 273
  int32_t          code = -1;
  SBnodeObj       *pObj = NULL;
  SDnodeObj       *pDnode = NULL;
  SMCreateBnodeReq createReq = {0};

S
Shengliang Guan 已提交
274
  if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
S
Shengliang Guan 已提交
275
    terrno = TSDB_CODE_INVALID_MSG;
276
    goto _OVER;
S
Shengliang Guan 已提交
277
  }
S
Shengliang Guan 已提交
278

279
  mInfo("bnode:%d, start to create", createReq.dnodeId);
280
  if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_BNODE) != 0) {
S
Shengliang Guan 已提交
281 282
    goto _OVER;
  }
S
Shengliang Guan 已提交
283

S
Shengliang Guan 已提交
284
  pObj = mndAcquireBnode(pMnode, createReq.dnodeId);
S
Shengliang Guan 已提交
285
  if (pObj != NULL) {
S
Shengliang Guan 已提交
286
    terrno = TSDB_CODE_MND_BNODE_ALREADY_EXIST;
287
    goto _OVER;
288
  } else if (terrno != TSDB_CODE_MND_BNODE_NOT_EXIST) {
289
    goto _OVER;
S
Shengliang Guan 已提交
290 291
  }

S
Shengliang Guan 已提交
292
  pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
S
Shengliang Guan 已提交
293 294
  if (pDnode == NULL) {
    terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
295
    goto _OVER;
S
Shengliang Guan 已提交
296 297
  }

S
Shengliang Guan 已提交
298
  code = mndCreateBnode(pMnode, pReq, pDnode, &createReq);
S
Shengliang Guan 已提交
299
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
300

301
_OVER:
S
Shengliang Guan 已提交
302
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
S
Shengliang Guan 已提交
303 304 305 306 307 308
    mError("bnode:%d, failed to create since %s", createReq.dnodeId, terrstr());
  }

  mndReleaseBnode(pMnode, pObj);
  mndReleaseDnode(pMnode, pDnode);
  return code;
S
Shengliang Guan 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
}

static int32_t mndSetDropBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
  SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj);
  if (pRedoRaw == NULL) return -1;
  if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
  if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
  return 0;
}

static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
  SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
  if (pCommitRaw == NULL) return -1;
  if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
  if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
  return 0;
}

static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
S
Shengliang Guan 已提交
328 329 330
  SDDropBnodeReq dropReq = {0};
  dropReq.dnodeId = pDnode->id;

331
  int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
wafwerar's avatar
wafwerar 已提交
332
  void   *pReq = taosMemoryMalloc(contLen);
S
Shengliang Guan 已提交
333
  if (pReq == NULL) {
S
Shengliang Guan 已提交
334 335 336
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }
337
  tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
338 339 340

  STransAction action = {0};
  action.epSet = mndGetDnodeEpset(pDnode);
S
Shengliang Guan 已提交
341
  action.pCont = pReq;
S
Shengliang Guan 已提交
342
  action.contLen = contLen;
S
Shengliang Guan 已提交
343
  action.msgType = TDMT_DND_DROP_BNODE;
S
shm  
Shengliang Guan 已提交
344
  action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
S
Shengliang Guan 已提交
345 346

  if (mndTransAppendRedoAction(pTrans, &action) != 0) {
wafwerar's avatar
wafwerar 已提交
347
    taosMemoryFree(pReq);
S
Shengliang Guan 已提交
348 349 350 351 352 353
    return -1;
  }

  return 0;
}

S
Shengliang Guan 已提交
354
static int32_t mndDropBnode(SMnode *pMnode, SRpcMsg *pReq, SBnodeObj *pObj) {
S
Shengliang Guan 已提交
355
  int32_t code = -1;
356

357
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-bnode");
358
  if (pTrans == NULL) goto _OVER;
S
Shengliang Guan 已提交
359

360
  mInfo("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id);
361 362 363 364
  if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) goto _OVER;
  if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) goto _OVER;
  if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto _OVER;
  if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
S
Shengliang Guan 已提交
365 366 367

  code = 0;

368
_OVER:
S
Shengliang Guan 已提交
369 370 371 372
  mndTransDrop(pTrans);
  return code;
}

S
Shengliang Guan 已提交
373 374
static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq) {
  SMnode        *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
375 376 377 378
  int32_t        code = -1;
  SBnodeObj     *pObj = NULL;
  SMDropBnodeReq dropReq = {0};

S
Shengliang Guan 已提交
379
  if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
S
Shengliang Guan 已提交
380
    terrno = TSDB_CODE_INVALID_MSG;
381
    goto _OVER;
S
Shengliang Guan 已提交
382
  }
S
Shengliang Guan 已提交
383

384
  mInfo("bnode:%d, start to drop", dropReq.dnodeId);
385
  if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_BNODE) != 0) {
S
Shengliang Guan 已提交
386 387
    goto _OVER;
  }
S
Shengliang Guan 已提交
388

S
Shengliang Guan 已提交
389
  if (dropReq.dnodeId <= 0) {
390
    terrno = TSDB_CODE_INVALID_MSG;
391
    goto _OVER;
S
Shengliang Guan 已提交
392 393
  }

S
Shengliang Guan 已提交
394
  pObj = mndAcquireBnode(pMnode, dropReq.dnodeId);
S
Shengliang Guan 已提交
395
  if (pObj == NULL) {
396
    goto _OVER;
S
Shengliang Guan 已提交
397 398
  }

S
Shengliang Guan 已提交
399
  code = mndDropBnode(pMnode, pReq, pObj);
S
Shengliang Guan 已提交
400
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
401

402
_OVER:
S
Shengliang Guan 已提交
403
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
S
Shengliang Guan 已提交
404 405 406 407 408
    mError("bnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
  }

  mndReleaseBnode(pMnode, pObj);
  return code;
S
Shengliang Guan 已提交
409 410
}

S
Shengliang Guan 已提交
411 412
static int32_t mndRetrieveBnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
  SMnode    *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
413 414 415 416 417 418 419 420 421 422
  SSdb      *pSdb = pMnode->pSdb;
  int32_t    numOfRows = 0;
  int32_t    cols = 0;
  SBnodeObj *pObj = NULL;

  while (numOfRows < rows) {
    pShow->pIter = sdbFetch(pSdb, SDB_BNODE, pShow->pIter, (void **)&pObj);
    if (pShow->pIter == NULL) break;

    cols = 0;
S
Shengliang Guan 已提交
423 424
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false);
S
Shengliang Guan 已提交
425

426
    char buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
427
    STR_WITH_MAXSIZE_TO_VARSTR(buf, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
S
Shengliang Guan 已提交
428

429 430
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, buf, false);
S
Shengliang Guan 已提交
431

432
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
S
Shengliang Guan 已提交
433
    colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false);
S
Shengliang Guan 已提交
434 435 436 437 438

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

439
  pShow->numOfRows += numOfRows;
S
Shengliang Guan 已提交
440 441 442 443 444 445 446 447

  return numOfRows;
}

static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter) {
  SSdb *pSdb = pMnode->pSdb;
  sdbCancelFetch(pSdb, pIter);
}