mndBnode.c 14.7 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * 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"
#include "mndShow.h"
#include "mndTrans.h"

#define TSDB_BNODE_VER_NUMBER 1
#define TSDB_BNODE_RESERVE_SIZE 64

static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj);
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw);
static int32_t  mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj);
static int32_t  mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj);
S
Shengliang Guan 已提交
29
static int32_t  mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew);
S
Shengliang Guan 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
static int32_t  mndProcessCreateBnodeReq(SMnodeMsg *pMsg);
static int32_t  mndProcessDropBnodeReq(SMnodeMsg *pMsg);
static int32_t  mndProcessCreateBnodeRsp(SMnodeMsg *pMsg);
static int32_t  mndProcessDropBnodeRsp(SMnodeMsg *pMsg);
static int32_t  mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
static int32_t  mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
static void     mndCancelGetNextBnode(SMnode *pMnode, void *pIter);

int32_t mndInitBnode(SMnode *pMnode) {
  SSdbTable table = {.sdbType = SDB_BNODE,
                     .keyType = SDB_KEY_INT32,
                     .encodeFp = (SdbEncodeFp)mndBnodeActionEncode,
                     .decodeFp = (SdbDecodeFp)mndBnodeActionDecode,
                     .insertFp = (SdbInsertFp)mndBnodeActionInsert,
                     .updateFp = (SdbUpdateFp)mndBnodeActionUpdate,
                     .deleteFp = (SdbDeleteFp)mndBnodeActionDelete};

  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_BNODE, mndProcessCreateBnodeReq);
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_BNODE, mndProcessDropBnodeReq);
  mndSetMsgHandle(pMnode, TDMT_DND_CREATE_BNODE_RSP, mndProcessCreateBnodeRsp);
  mndSetMsgHandle(pMnode, TDMT_DND_DROP_BNODE_RSP, mndProcessDropBnodeRsp);

  mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndGetBnodeMeta);
  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) {
S
Shengliang Guan 已提交
62
  SSdb      *pSdb = pMnode->pSdb;
63
  SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &bnodeId);
S
Shengliang Guan 已提交
64 65 66 67 68 69 70 71 72 73 74 75
  if (pObj == NULL) {
    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) {
76 77
  terrno = TSDB_CODE_OUT_OF_MEMORY;

S
Shengliang Guan 已提交
78
  SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, TSDB_BNODE_VER_NUMBER, sizeof(SBnodeObj) + TSDB_BNODE_RESERVE_SIZE);
79
  if (pRaw == NULL) goto BNODE_ENCODE_OVER;
S
Shengliang Guan 已提交
80 81

  int32_t dataPos = 0;
82 83 84 85 86 87
  SDB_SET_INT32(pRaw, dataPos, pObj->id, BNODE_ENCODE_OVER)
  SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, BNODE_ENCODE_OVER)
  SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, BNODE_ENCODE_OVER)
  SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE, BNODE_ENCODE_OVER)

  terrno = 0;
S
Shengliang Guan 已提交
88

89 90 91 92 93 94 95 96
BNODE_ENCODE_OVER:
  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 已提交
97 98 99 100
  return pRaw;
}

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

S
Shengliang Guan 已提交
103
  int8_t sver = 0;
104
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto BNODE_DECODE_OVER;
S
Shengliang Guan 已提交
105 106 107

  if (sver != TSDB_BNODE_VER_NUMBER) {
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
108
    goto BNODE_DECODE_OVER;
S
Shengliang Guan 已提交
109 110
  }

111 112 113
  SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj));
  if (pRow == NULL) goto BNODE_DECODE_OVER;

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

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

  terrno = 0;
S
Shengliang Guan 已提交
124

125 126 127 128 129 130 131 132
BNODE_DECODE_OVER:
  if (terrno != 0) {
    mError("bnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
    tfree(pRow);
    return NULL;
  }

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

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

  return 0;
}

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

  return 0;
}

S
Shengliang Guan 已提交
158 159 160
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew) {
  mTrace("bnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
  pOld->updateTime = pNew->updateTime;
S
Shengliang Guan 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
  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;
}

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 已提交
181
  SDCreateBnodeReq *pMsg = malloc(sizeof(SDCreateBnodeReq));
S
Shengliang Guan 已提交
182 183 184 185
  if (pMsg == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }
S
Shengliang Guan 已提交
186
  pMsg->dnodeId = htonl(pDnode->id);
S
Shengliang Guan 已提交
187 188 189 190

  STransAction action = {0};
  action.epSet = mndGetDnodeEpset(pDnode);
  action.pCont = pMsg;
S
Shengliang Guan 已提交
191
  action.contLen = sizeof(SDCreateBnodeReq);
S
Shengliang Guan 已提交
192 193 194 195 196 197 198 199 200 201
  action.msgType = TDMT_DND_CREATE_BNODE;

  if (mndTransAppendRedoAction(pTrans, &action) != 0) {
    free(pMsg);
    return -1;
  }

  return 0;
}

S
Shengliang Guan 已提交
202
static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) {
203 204 205 206
  SBnodeObj bnodeObj = {0};
  bnodeObj.id = pDnode->id;
  bnodeObj.createdTime = taosGetTimestampMs();
  bnodeObj.updateTime = bnodeObj.createdTime;
S
Shengliang Guan 已提交
207 208 209 210

  int32_t code = -1;
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
  if (pTrans == NULL) {
211
    mError("bnode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
S
Shengliang Guan 已提交
212 213
    goto CREATE_BNODE_OVER;
  }
214
  mDebug("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId);
S
Shengliang Guan 已提交
215

216
  if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) {
S
Shengliang Guan 已提交
217 218 219 220
    mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
    goto CREATE_BNODE_OVER;
  }

221
  if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) {
S
Shengliang Guan 已提交
222 223 224 225
    mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
    goto CREATE_BNODE_OVER;
  }

226
  if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) {
S
Shengliang Guan 已提交
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
    mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
    goto CREATE_BNODE_OVER;
  }

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

  code = 0;

CREATE_BNODE_OVER:
  mndTransDrop(pTrans);
  return code;
}

static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) {
  SMnode           *pMnode = pMsg->pMnode;
S
Shengliang Guan 已提交
245
  SMCreateBnodeReq *pCreate = pMsg->rpcMsg.pCont;
S
Shengliang Guan 已提交
246 247 248

  pCreate->dnodeId = htonl(pCreate->dnodeId);

249
  mDebug("bnode:%d, start to create", pCreate->dnodeId);
S
Shengliang Guan 已提交
250 251 252

  SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId);
  if (pObj != NULL) {
253
    mError("bnode:%d, bnode already exist", pObj->id);
S
Shengliang Guan 已提交
254
    terrno = TSDB_CODE_MND_BNODE_ALREADY_EXIST;
S
Shengliang Guan 已提交
255 256 257 258 259 260
    mndReleaseBnode(pMnode, pObj);
    return -1;
  }

  SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
  if (pDnode == NULL) {
261
    mError("bnode:%d, dnode not exist", pCreate->dnodeId);
S
Shengliang Guan 已提交
262 263 264 265 266 267 268 269
    terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
    return -1;
  }

  int32_t code = mndCreateBnode(pMnode, pMsg, pDnode, pCreate);
  mndReleaseDnode(pMnode, pDnode);

  if (code != 0) {
270
    mError("bnode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
S
Shengliang Guan 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
    return -1;
  }

  return TSDB_CODE_MND_ACTION_IN_PROGRESS;
}

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 已提交
294
  SDDropBnodeReq *pMsg = malloc(sizeof(SDDropBnodeReq));
S
Shengliang Guan 已提交
295 296 297 298
  if (pMsg == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }
S
Shengliang Guan 已提交
299
  pMsg->dnodeId = htonl(pDnode->id);
S
Shengliang Guan 已提交
300 301 302 303

  STransAction action = {0};
  action.epSet = mndGetDnodeEpset(pDnode);
  action.pCont = pMsg;
S
Shengliang Guan 已提交
304
  action.contLen = sizeof(SDDropBnodeReq);
S
Shengliang Guan 已提交
305 306 307 308 309 310 311 312 313 314 315 316 317 318
  action.msgType = TDMT_DND_DROP_BNODE;

  if (mndTransAppendRedoAction(pTrans, &action) != 0) {
    free(pMsg);
    return -1;
  }

  return 0;
}

static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) {
  int32_t code = -1;
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
  if (pTrans == NULL) {
319
    mError("bnode:%d, failed to drop since %s", pObj->id, terrstr());
S
Shengliang Guan 已提交
320 321 322
    goto DROP_BNODE_OVER;
  }

323
  mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id);
S
Shengliang Guan 已提交
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352

  if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) {
    mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
    goto DROP_BNODE_OVER;
  }

  if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) {
    mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
    goto DROP_BNODE_OVER;
  }

  if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) {
    mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
    goto DROP_BNODE_OVER;
  }

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

  code = 0;

DROP_BNODE_OVER:
  mndTransDrop(pTrans);
  return code;
}

static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) {
S
Shengliang Guan 已提交
353
  SMnode         *pMnode = pMsg->pMnode;
S
Shengliang Guan 已提交
354
  SMDropBnodeReq *pDrop = pMsg->rpcMsg.pCont;
S
Shengliang Guan 已提交
355 356
  pDrop->dnodeId = htonl(pDrop->dnodeId);

357
  mDebug("bnode:%d, start to drop", pDrop->dnodeId);
S
Shengliang Guan 已提交
358 359 360

  if (pDrop->dnodeId <= 0) {
    terrno = TSDB_CODE_SDB_APP_ERROR;
361
    mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
S
Shengliang Guan 已提交
362 363 364 365 366
    return -1;
  }

  SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId);
  if (pObj == NULL) {
367 368
    mError("bnode:%d, not exist", pDrop->dnodeId);
    terrno = TSDB_CODE_MND_BNODE_NOT_EXIST;
S
Shengliang Guan 已提交
369 370 371 372 373
    return -1;
  }

  int32_t code = mndDropBnode(pMnode, pMsg, pObj);
  if (code != 0) {
S
Shengliang Guan 已提交
374
    sdbRelease(pMnode->pSdb, pObj);
375
    mError("bnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
S
Shengliang Guan 已提交
376 377 378
    return -1;
  }

S
Shengliang Guan 已提交
379
  sdbRelease(pMnode->pSdb, pObj);
S
Shengliang Guan 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
  return TSDB_CODE_MND_ACTION_IN_PROGRESS;
}

static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg) {
  mndTransProcessRsp(pMsg);
  return 0;
}

static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg) {
  mndTransProcessRsp(pMsg);
  return 0;
}

static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
  SMnode *pMnode = pMsg->pMnode;
  SSdb   *pSdb = pMnode->pSdb;

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

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

  pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
  pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
  strcpy(pSchema[cols].name, "endpoint");
  pSchema[cols].bytes = htonl(pShow->bytes[cols]);
  cols++;

  pShow->bytes[cols] = 8;
  pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
  strcpy(pSchema[cols].name, "create_time");
  pSchema[cols].bytes = htonl(pShow->bytes[cols]);
  cols++;

  pMeta->numOfColumns = htonl(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 = sdbGetSize(pSdb, SDB_BNODE);
  pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
  strcpy(pMeta->tbFname, mndShowStr(pShow->type));

  return 0;
}

static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
  SMnode    *pMnode = pMsg->pMnode;
  SSdb      *pSdb = pMnode->pSdb;
  int32_t    numOfRows = 0;
  int32_t    cols = 0;
  SBnodeObj *pObj = NULL;
  char      *pWrite;

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

    cols = 0;

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

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
    STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]);

    cols++;

    pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
    *(int64_t *)pWrite = pObj->createdTime;
    cols++;

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

  mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
  pShow->numOfReads += numOfRows;

  return numOfRows;
}

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