mndBnode.c 14.1 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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"
S
Shengliang Guan 已提交
18
#include "mndAuth.h"
S
Shengliang Guan 已提交
19 20 21
#include "mndDnode.h"
#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);
250
  if (pTrans == NULL) goto _OVER;
S
Shengliang Guan 已提交
251

252
  mDebug("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 274
  int32_t          code = -1;
  SBnodeObj       *pObj = NULL;
  SDnodeObj       *pDnode = NULL;
  SUserObj        *pUser = NULL;
  SMCreateBnodeReq createReq = {0};

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

S
Shengliang Guan 已提交
280
  mDebug("bnode:%d, start to create", createReq.dnodeId);
S
Shengliang Guan 已提交
281

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

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

S
Shengliang Guan 已提交
296
  pUser = mndAcquireUser(pMnode, pReq->conn.user);
S
Shengliang Guan 已提交
297 298
  if (pUser == NULL) {
    terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
299
    goto _OVER;
S
Shengliang Guan 已提交
300
  }
S
Shengliang Guan 已提交
301

S
Shengliang Guan 已提交
302
  if (mndCheckNodeAuth(pUser) != 0) {
303
    goto _OVER;
S
Shengliang Guan 已提交
304 305
  }

S
Shengliang Guan 已提交
306
  code = mndCreateBnode(pMnode, pReq, pDnode, &createReq);
S
Shengliang Guan 已提交
307
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
308

309
_OVER:
S
Shengliang Guan 已提交
310
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
S
Shengliang Guan 已提交
311 312 313 314 315 316 317
    mError("bnode:%d, failed to create since %s", createReq.dnodeId, terrstr());
  }

  mndReleaseBnode(pMnode, pObj);
  mndReleaseDnode(pMnode, pDnode);
  mndReleaseUser(pMnode, pUser);
  return code;
S
Shengliang Guan 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
}

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 已提交
337 338 339
  SDDropBnodeReq dropReq = {0};
  dropReq.dnodeId = pDnode->id;

340
  int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
wafwerar's avatar
wafwerar 已提交
341
  void   *pReq = taosMemoryMalloc(contLen);
S
Shengliang Guan 已提交
342
  if (pReq == NULL) {
S
Shengliang Guan 已提交
343 344 345
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }
346
  tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
347 348 349

  STransAction action = {0};
  action.epSet = mndGetDnodeEpset(pDnode);
S
Shengliang Guan 已提交
350
  action.pCont = pReq;
S
Shengliang Guan 已提交
351
  action.contLen = contLen;
S
Shengliang Guan 已提交
352
  action.msgType = TDMT_DND_DROP_BNODE;
S
shm  
Shengliang Guan 已提交
353
  action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
S
Shengliang Guan 已提交
354 355

  if (mndTransAppendRedoAction(pTrans, &action) != 0) {
wafwerar's avatar
wafwerar 已提交
356
    taosMemoryFree(pReq);
S
Shengliang Guan 已提交
357 358 359 360 361 362
    return -1;
  }

  return 0;
}

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

366
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq);
367
  if (pTrans == NULL) goto _OVER;
S
Shengliang Guan 已提交
368

369
  mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id);
370 371 372 373
  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 已提交
374 375 376

  code = 0;

377
_OVER:
S
Shengliang Guan 已提交
378 379 380 381
  mndTransDrop(pTrans);
  return code;
}

S
Shengliang Guan 已提交
382 383
static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq) {
  SMnode        *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
384 385 386 387 388
  int32_t        code = -1;
  SUserObj      *pUser = NULL;
  SBnodeObj     *pObj = NULL;
  SMDropBnodeReq dropReq = {0};

S
Shengliang Guan 已提交
389
  if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
S
Shengliang Guan 已提交
390
    terrno = TSDB_CODE_INVALID_MSG;
391
    goto _OVER;
S
Shengliang Guan 已提交
392
  }
S
Shengliang Guan 已提交
393

S
Shengliang Guan 已提交
394
  mDebug("bnode:%d, start to drop", dropReq.dnodeId);
S
Shengliang Guan 已提交
395

S
Shengliang Guan 已提交
396
  if (dropReq.dnodeId <= 0) {
397
    terrno = TSDB_CODE_INVALID_MSG;
398
    goto _OVER;
S
Shengliang Guan 已提交
399 400
  }

S
Shengliang Guan 已提交
401
  pObj = mndAcquireBnode(pMnode, dropReq.dnodeId);
S
Shengliang Guan 已提交
402
  if (pObj == NULL) {
403
    goto _OVER;
S
Shengliang Guan 已提交
404 405
  }

S
Shengliang Guan 已提交
406
  pUser = mndAcquireUser(pMnode, pReq->conn.user);
S
Shengliang Guan 已提交
407 408
  if (pUser == NULL) {
    terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
409
    goto _OVER;
S
Shengliang Guan 已提交
410 411
  }

S
Shengliang Guan 已提交
412
  if (mndCheckNodeAuth(pUser) != 0) {
413
    goto _OVER;
S
Shengliang Guan 已提交
414 415
  }

S
Shengliang Guan 已提交
416
  code = mndDropBnode(pMnode, pReq, pObj);
S
Shengliang Guan 已提交
417
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
S
Shengliang Guan 已提交
418

419
_OVER:
S
Shengliang Guan 已提交
420
  if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
S
Shengliang Guan 已提交
421 422 423 424 425 426 427
    mError("bnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
  }

  mndReleaseBnode(pMnode, pObj);
  mndReleaseUser(pMnode, pUser);

  return code;
S
Shengliang Guan 已提交
428 429
}

S
Shengliang Guan 已提交
430 431
static int32_t mndRetrieveBnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
  SMnode    *pMnode = pReq->info.node;
S
Shengliang Guan 已提交
432 433 434 435 436 437 438 439 440 441
  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 已提交
442 443
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false);
S
Shengliang Guan 已提交
444

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

448 449
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
    colDataAppend(pColInfo, numOfRows, buf, false);
S
Shengliang Guan 已提交
450

451
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
S
Shengliang Guan 已提交
452
    colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false);
S
Shengliang Guan 已提交
453 454 455 456 457

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

458
  pShow->numOfRows += numOfRows;
S
Shengliang Guan 已提交
459 460 461 462 463 464 465 466

  return numOfRows;
}

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