vnodeQuery.c 13.7 KB
Newer Older
D
dapan1121 已提交
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/>.
 */

H
Hongze Cheng 已提交
16
#include "vnd.h"
D
dapan1121 已提交
17

S
Shengliang Guan 已提交
18
int vnodeQueryOpen(SVnode *pVnode) {
H
refact  
Hongze Cheng 已提交
19
  return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), NULL, (void **)&pVnode->pQuery, &pVnode->msgCb);
S
Shengliang Guan 已提交
20
}
D
dapan1121 已提交
21

L
Liu Jicong 已提交
22
void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); }
D
dapan1121 已提交
23

D
dapan1121 已提交
24
int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
H
Hongze Cheng 已提交
25 26 27 28 29
  STableInfoReq  infoReq = {0};
  STableMetaRsp  metaRsp = {0};
  SMetaReader    mer1 = {0};
  SMetaReader    mer2 = {0};
  char           tableFName[TSDB_TABLE_FNAME_LEN];
dengyihao's avatar
dengyihao 已提交
30
  SRpcMsg        rpcMsg = {0};
H
Hongze Cheng 已提交
31 32
  int32_t        code = 0;
  int32_t        rspLen = 0;
33
  void          *pRsp = NULL;
H
Hongze Cheng 已提交
34 35
  SSchemaWrapper schema = {0};
  SSchemaWrapper schemaTag = {0};
H
Hongze Cheng 已提交
36 37 38 39 40 41 42

  // decode req
  if (tDeserializeSTableInfoReq(pMsg->pCont, pMsg->contLen, &infoReq) != 0) {
    code = TSDB_CODE_INVALID_MSG;
    goto _exit;
  }

H
Hongze Cheng 已提交
43
  metaRsp.dbId = pVnode->config.dbId;
D
dapan1121 已提交
44
  strcpy(metaRsp.tbName, infoReq.tbName);
H
Hongze Cheng 已提交
45
  memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
H
Hongze Cheng 已提交
46

D
dapan1121 已提交
47
  sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName);
H
Hongze Cheng 已提交
48
  code = vnodeValidateTableHash(pVnode, tableFName);
D
dapan1121 已提交
49 50 51 52
  if (code) {
    goto _exit;
  }

H
Hongze Cheng 已提交
53
  // query meta
H
Hongze Cheng 已提交
54
  metaReaderInit(&mer1, pVnode->pMeta, 0);
H
more  
Hongze Cheng 已提交
55

H
Hongze Cheng 已提交
56
  if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
H
Hongze Cheng 已提交
57
    code = terrno;
H
more  
Hongze Cheng 已提交
58
    goto _exit;
H
more  
Hongze Cheng 已提交
59 60
  }

H
Hongze Cheng 已提交
61
  metaRsp.tableType = mer1.me.type;
H
Hongze Cheng 已提交
62
  metaRsp.vgId = TD_VID(pVnode);
H
Hongze Cheng 已提交
63 64 65
  metaRsp.tuid = mer1.me.uid;

  if (mer1.me.type == TSDB_SUPER_TABLE) {
H
Hongze Cheng 已提交
66
    strcpy(metaRsp.stbName, mer1.me.name);
67
    schema = mer1.me.stbEntry.schemaRow;
H
Hongze Cheng 已提交
68 69 70
    schemaTag = mer1.me.stbEntry.schemaTag;
    metaRsp.suid = mer1.me.uid;
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
H
Hongze Cheng 已提交
71
    metaReaderInit(&mer2, pVnode->pMeta, 0);
H
Hongze Cheng 已提交
72
    if (metaGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;
H
Hongze Cheng 已提交
73

H
Hongze Cheng 已提交
74
    strcpy(metaRsp.stbName, mer2.me.name);
H
Hongze Cheng 已提交
75
    metaRsp.suid = mer2.me.uid;
76
    schema = mer2.me.stbEntry.schemaRow;
H
Hongze Cheng 已提交
77 78
    schemaTag = mer2.me.stbEntry.schemaTag;
  } else if (mer1.me.type == TSDB_NORMAL_TABLE) {
79
    schema = mer1.me.ntbEntry.schemaRow;
H
Hongze Cheng 已提交
80 81
  } else {
    ASSERT(0);
H
Hongze Cheng 已提交
82 83
  }

H
Hongze Cheng 已提交
84 85 86
  metaRsp.numOfTags = schemaTag.nCols;
  metaRsp.numOfColumns = schema.nCols;
  metaRsp.precision = pVnode->config.tsdbCfg.precision;
87
  metaRsp.sversion = schema.version;
H
Hongze Cheng 已提交
88 89 90 91 92 93 94
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (metaRsp.numOfColumns + metaRsp.numOfTags));

  memcpy(metaRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
  if (schemaTag.nCols) {
    memcpy(metaRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
  }

H
Hongze Cheng 已提交
95
  // encode and send response
D
dapan1121 已提交
96
  rspLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
S
Shengliang Guan 已提交
97 98 99 100 101
  if (rspLen < 0) {
    code = TSDB_CODE_INVALID_MSG;
    goto _exit;
  }

D
dapan1121 已提交
102 103 104 105 106
  if (direct) {
    pRsp = rpcMallocCont(rspLen);
  } else {
    pRsp = taosMemoryCalloc(1, rspLen);
  }
107

S
Shengliang Guan 已提交
108 109 110
  if (pRsp == NULL) {
    code = TSDB_CODE_OUT_OF_MEMORY;
    goto _exit;
H
Hongze Cheng 已提交
111
  }
S
Shengliang Guan 已提交
112
  tSerializeSTableMetaRsp(pRsp, rspLen, &metaRsp);
H
more  
Hongze Cheng 已提交
113

H
Hongze Cheng 已提交
114
_exit:
S
Shengliang Guan 已提交
115
  rpcMsg.info = pMsg->info;
S
Shengliang Guan 已提交
116 117
  rpcMsg.pCont = pRsp;
  rpcMsg.contLen = rspLen;
D
dapan1121 已提交
118
  rpcMsg.code = code;
dengyihao's avatar
dengyihao 已提交
119
  rpcMsg.msgType = pMsg->msgType;
D
dapan1121 已提交
120

D
dapan1121 已提交
121 122 123 124
  if (code) {
    qError("get table %s meta failed cause of %s", infoReq.tbName, tstrerror(code));
  }

D
dapan1121 已提交
125 126
  if (direct) {
    tmsgSendRsp(&rpcMsg);
127 128
  } else {
    *pMsg = rpcMsg;
D
dapan1121 已提交
129
  }
130

H
Hongze Cheng 已提交
131
  taosMemoryFree(metaRsp.pSchemas);
H
Hongze Cheng 已提交
132 133
  metaReaderClear(&mer2);
  metaReaderClear(&mer1);
D
dapan 已提交
134
  return TSDB_CODE_SUCCESS;
H
Haojun Liao 已提交
135
}
H
Hongze Cheng 已提交
136

D
dapan1121 已提交
137
int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
D
dapan1121 已提交
138 139 140 141 142
  STableCfgReq   cfgReq = {0};
  STableCfgRsp   cfgRsp = {0};
  SMetaReader    mer1 = {0};
  SMetaReader    mer2 = {0};
  char           tableFName[TSDB_TABLE_FNAME_LEN];
dengyihao's avatar
dengyihao 已提交
143
  SRpcMsg        rpcMsg = {0};
D
dapan1121 已提交
144 145
  int32_t        code = 0;
  int32_t        rspLen = 0;
146
  void          *pRsp = NULL;
D
dapan1121 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
  SSchemaWrapper schema = {0};
  SSchemaWrapper schemaTag = {0};

  // decode req
  if (tDeserializeSTableCfgReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
    code = TSDB_CODE_INVALID_MSG;
    goto _exit;
  }

  strcpy(cfgRsp.tbName, cfgReq.tbName);
  memcpy(cfgRsp.dbFName, cfgReq.dbFName, sizeof(cfgRsp.dbFName));

  sprintf(tableFName, "%s.%s", cfgReq.dbFName, cfgReq.tbName);
  code = vnodeValidateTableHash(pVnode, tableFName);
  if (code) {
    goto _exit;
  }

  // query meta
  metaReaderInit(&mer1, pVnode->pMeta, 0);

  if (metaGetTableEntryByName(&mer1, cfgReq.tbName) < 0) {
    code = terrno;
    goto _exit;
  }

  cfgRsp.tableType = mer1.me.type;

  if (mer1.me.type == TSDB_SUPER_TABLE) {
D
dapan1121 已提交
176 177
    code = TSDB_CODE_VND_HASH_MISMATCH;
    goto _exit;
D
dapan1121 已提交
178 179 180 181 182 183 184
  } else if (mer1.me.type == TSDB_CHILD_TABLE) {
    metaReaderInit(&mer2, pVnode->pMeta, 0);
    if (metaGetTableEntryByUid(&mer2, mer1.me.ctbEntry.suid) < 0) goto _exit;

    strcpy(cfgRsp.stbName, mer2.me.name);
    schema = mer2.me.stbEntry.schemaRow;
    schemaTag = mer2.me.stbEntry.schemaTag;
D
dapan1121 已提交
185 186 187 188 189 190 191 192 193
    cfgRsp.ttl = mer1.me.ctbEntry.ttlDays;
    cfgRsp.commentLen = mer1.me.ctbEntry.commentLen;
    if (mer1.me.ctbEntry.commentLen > 0) {
      cfgRsp.pComment = strdup(mer1.me.ctbEntry.comment);
    }
    STag *pTag = (STag *)mer1.me.ctbEntry.pTags;
    cfgRsp.tagsLen = pTag->len;
    cfgRsp.pTags = taosMemoryMalloc(cfgRsp.tagsLen);
    memcpy(cfgRsp.pTags, pTag, cfgRsp.tagsLen);
D
dapan1121 已提交
194 195
  } else if (mer1.me.type == TSDB_NORMAL_TABLE) {
    schema = mer1.me.ntbEntry.schemaRow;
D
dapan1121 已提交
196 197 198 199 200
    cfgRsp.ttl = mer1.me.ntbEntry.ttlDays;
    cfgRsp.commentLen = mer1.me.ntbEntry.commentLen;
    if (mer1.me.ntbEntry.commentLen > 0) {
      cfgRsp.pComment = strdup(mer1.me.ntbEntry.comment);
    }
D
dapan1121 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
  } else {
    ASSERT(0);
  }

  cfgRsp.numOfTags = schemaTag.nCols;
  cfgRsp.numOfColumns = schema.nCols;
  cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));

  memcpy(cfgRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
  if (schemaTag.nCols) {
    memcpy(cfgRsp.pSchemas + schema.nCols, schemaTag.pSchema, sizeof(SSchema) * schemaTag.nCols);
  }

  // encode and send response
  rspLen = tSerializeSTableCfgRsp(NULL, 0, &cfgRsp);
  if (rspLen < 0) {
    code = TSDB_CODE_INVALID_MSG;
    goto _exit;
  }

D
dapan1121 已提交
221 222 223 224 225 226
  if (direct) {
    pRsp = rpcMallocCont(rspLen);
  } else {
    pRsp = taosMemoryCalloc(1, rspLen);
  }

D
dapan1121 已提交
227 228 229 230 231 232 233 234 235 236 237
  if (pRsp == NULL) {
    code = TSDB_CODE_OUT_OF_MEMORY;
    goto _exit;
  }
  tSerializeSTableCfgRsp(pRsp, rspLen, &cfgRsp);

_exit:
  rpcMsg.info = pMsg->info;
  rpcMsg.pCont = pRsp;
  rpcMsg.contLen = rspLen;
  rpcMsg.code = code;
dengyihao's avatar
dengyihao 已提交
238
  rpcMsg.msgType = pMsg->msgType;
D
dapan1121 已提交
239 240 241 242 243

  if (code) {
    qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code));
  }

D
dapan1121 已提交
244 245
  if (direct) {
    tmsgSendRsp(&rpcMsg);
246 247
  } else {
    *pMsg = rpcMsg;
D
dapan1121 已提交
248
  }
249

D
dapan1121 已提交
250
  tFreeSTableCfgRsp(&cfgRsp);
D
dapan1121 已提交
251 252
  metaReaderClear(&mer2);
  metaReaderClear(&mer1);
D
dapan 已提交
253
  return TSDB_CODE_SUCCESS;
H
Haojun Liao 已提交
254
}
H
Hongze Cheng 已提交
255

D
dapan1121 已提交
256
int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
257 258 259 260 261
  int32_t    code = 0;
  int32_t    offset = 0;
  int32_t    rspSize = 0;
  SBatchReq *batchReq = (SBatchReq *)pMsg->pCont;
  int32_t    msgNum = ntohl(batchReq->msgNum);
262
  offset += sizeof(SBatchReq);
D
dapan1121 已提交
263 264
  SBatchMsg req = {0};
  SBatchRsp rsp = {0};
265 266 267
  SRpcMsg   reqMsg = *pMsg;
  SRpcMsg   rspMsg = {0};
  void     *pRsp = NULL;
D
dapan1121 已提交
268

269
  SArray *batchRsp = taosArrayInit(msgNum, sizeof(SBatchRsp));
D
dapan1121 已提交
270 271 272 273
  if (NULL == batchRsp) {
    code = TSDB_CODE_OUT_OF_MEMORY;
    goto _exit;
  }
274

D
dapan1121 已提交
275
  for (int32_t i = 0; i < msgNum; ++i) {
D
dapan1121 已提交
276 277 278
    req.msgIdx = ntohl(*(int32_t *)((char *)pMsg->pCont + offset));
    offset += sizeof(req.msgIdx);

279
    req.msgType = ntohl(*(int32_t *)((char *)pMsg->pCont + offset));
280
    offset += sizeof(req.msgType);
D
dapan1121 已提交
281

282
    req.msgLen = ntohl(*(int32_t *)((char *)pMsg->pCont + offset));
283
    offset += sizeof(req.msgLen);
D
dapan1121 已提交
284

285
    req.msg = (char *)pMsg->pCont + offset;
D
dapan1121 已提交
286 287 288 289 290
    offset += req.msgLen;

    reqMsg.msgType = req.msgType;
    reqMsg.pCont = req.msg;
    reqMsg.contLen = req.msgLen;
291

D
dapan1121 已提交
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
    switch (req.msgType) {
      case TDMT_VND_TABLE_META:
        vnodeGetTableMeta(pVnode, &reqMsg, false);
        break;
      case TDMT_VND_TABLE_CFG:
        vnodeGetTableCfg(pVnode, &reqMsg, false);
        break;
      default:
        qError("invalid req msgType %d", req.msgType);
        reqMsg.code = TSDB_CODE_INVALID_MSG;
        reqMsg.pCont = NULL;
        reqMsg.contLen = 0;
        break;
    }

D
dapan1121 已提交
307
    rsp.msgIdx = req.msgIdx;
D
dapan1121 已提交
308 309 310 311
    rsp.reqType = reqMsg.msgType;
    rsp.msgLen = reqMsg.contLen;
    rsp.rspCode = reqMsg.code;
    rsp.msg = reqMsg.pCont;
312

D
dapan1121 已提交
313 314 315 316 317 318 319
    taosArrayPush(batchRsp, &rsp);

    rspSize += sizeof(rsp) + rsp.msgLen - POINTER_BYTES;
  }

  rspSize += sizeof(int32_t);
  offset = 0;
320

D
dapan1121 已提交
321 322 323 324 325 326
  pRsp = rpcMallocCont(rspSize);
  if (pRsp == NULL) {
    code = TSDB_CODE_OUT_OF_MEMORY;
    goto _exit;
  }

327
  *(int32_t *)((char *)pRsp + offset) = htonl(msgNum);
D
dapan1121 已提交
328 329 330
  offset += sizeof(msgNum);
  for (int32_t i = 0; i < msgNum; ++i) {
    SBatchRsp *p = taosArrayGet(batchRsp, i);
331 332

    *(int32_t *)((char *)pRsp + offset) = htonl(p->reqType);
D
dapan1121 已提交
333
    offset += sizeof(p->reqType);
D
dapan1121 已提交
334 335
    *(int32_t *)((char *)pRsp + offset) = htonl(p->msgIdx);
    offset += sizeof(p->msgIdx);
336
    *(int32_t *)((char *)pRsp + offset) = htonl(p->msgLen);
D
dapan1121 已提交
337
    offset += sizeof(p->msgLen);
338
    *(int32_t *)((char *)pRsp + offset) = htonl(p->rspCode);
D
dapan1121 已提交
339
    offset += sizeof(p->rspCode);
340
    memcpy((char *)pRsp + offset, p->msg, p->msgLen);
D
dapan1121 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    offset += p->msgLen;

    taosMemoryFreeClear(p->msg);
  }

  taosArrayDestroy(batchRsp);
  batchRsp = NULL;

_exit:

  rspMsg.info = pMsg->info;
  rspMsg.pCont = pRsp;
  rspMsg.contLen = rspSize;
  rspMsg.code = code;
  rspMsg.msgType = pMsg->msgType;

  if (code) {
358
    qError("vnd get batch meta failed cause of %s", tstrerror(code));
D
dapan1121 已提交
359 360 361 362 363 364
  }

  taosArrayDestroyEx(batchRsp, tFreeSBatchRsp);

  tmsgSendRsp(&rspMsg);

365
  return code;
D
dapan1121 已提交
366 367
}

H
Hongze Cheng 已提交
368
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
H
refact  
Hongze Cheng 已提交
369
  pLoad->vgId = TD_VID(pVnode);
S
Shengliang Guan 已提交
370
  pLoad->syncState = syncGetMyRole(pVnode->sync);
H
Hongze Cheng 已提交
371
  pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
372
  pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta);
C
Cary Xu 已提交
373 374
  pLoad->totalStorage = (int64_t)3 * 1073741824;
  pLoad->compStorage = (int64_t)2 * 1073741824;
H
Hongze Cheng 已提交
375 376 377 378 379 380 381 382
  pLoad->pointsWritten = 100;
  pLoad->numOfSelectReqs = 1;
  pLoad->numOfInsertReqs = 3;
  pLoad->numOfInsertSuccessReqs = 2;
  pLoad->numOfBatchInsertReqs = 5;
  pLoad->numOfBatchInsertSuccessReqs = 4;
  return 0;
}
383 384 385 386 387 388 389 390 391

void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) {
  if (dbname) {
    *dbname = pVnode->config.dbname;
  }

  if (vgId) {
    *vgId = TD_VID(pVnode);
  }
H
Hongze Cheng 已提交
392 393 394 395 396 397 398 399 400 401 402
}

int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode->pMeta, uid);

  while (1) {
    tb_uid_t id = metaCtbCursorNext(pCur);
    if (id == 0) {
      break;
    }

403
    STableKeyInfo info = {uid = id};
H
Hongze Cheng 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
    taosArrayPush(list, &info);
  }

  metaCloseCtbCursor(pCur);
  return TSDB_CODE_SUCCESS;
}

int32_t vnodeGetCtbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode->pMeta, suid);

  while (1) {
    tb_uid_t id = metaCtbCursorNext(pCur);
    if (id == 0) {
      break;
    }

    taosArrayPush(list, &id);
  }

  metaCloseCtbCursor(pCur);
  return TSDB_CODE_SUCCESS;
}

427 428
int32_t vnodeGetStbIdList(SVnode *pVnode, int64_t suid, SArray *list) {
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, suid);
C
Cary Xu 已提交
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
  if (!pCur) {
    return TSDB_CODE_FAILED;
  }

  while (1) {
    tb_uid_t id = metaStbCursorNext(pCur);
    if (id == 0) {
      break;
    }

    taosArrayPush(list, &id);
  }

  metaCloseStbCursor(pCur);
  return TSDB_CODE_SUCCESS;
}

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
  SMCtbCursor *pCur = metaOpenCtbCursor(pVnode->pMeta, suid);
  if (!pCur) {
    return TSDB_CODE_FAILED;
  }

  *num = 0;
  while (1) {
    tb_uid_t id = metaCtbCursorNext(pCur);
    if (id == 0) {
      break;
    }

    ++(*num);
  }

  metaCloseCtbCursor(pCur);
  return TSDB_CODE_SUCCESS;
}

static int32_t vnodeGetStbColumnNum(SVnode *pVnode, tb_uid_t suid, int *num) {
  STSchema *pTSchema = metaGetTbTSchema(pVnode->pMeta, suid, -1);
  // metaGetTbTSchemaEx(pVnode->pMeta, suid, suid, -1, &pTSchema);

470 471
  if (pTSchema) {
    *num = pTSchema->numOfCols;
472

473 474 475 476
    taosMemoryFree(pTSchema);
  } else {
    *num = 2;
  }
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498

  return TSDB_CODE_SUCCESS;
}

int32_t vnodeGetTimeSeriesNum(SVnode *pVnode, int64_t *num) {
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
  if (!pCur) {
    return TSDB_CODE_FAILED;
  }

  *num = 0;
  while (1) {
    tb_uid_t id = metaStbCursorNext(pCur);
    if (id == 0) {
      break;
    }

    int64_t ctbNum = 0;
    vnodeGetCtbNum(pVnode, id, &ctbNum);
    int numOfCols = 0;
    vnodeGetStbColumnNum(pVnode, id, &numOfCols);

499
    *num += ctbNum * (numOfCols - 1);
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
  }

  metaCloseStbCursor(pCur);
  return TSDB_CODE_SUCCESS;
}

int32_t vnodeGetAllCtbNum(SVnode *pVnode, int64_t *num) {
  SMStbCursor *pCur = metaOpenStbCursor(pVnode->pMeta, 0);
  if (!pCur) {
    return TSDB_CODE_FAILED;
  }

  *num = 0;
  while (1) {
    tb_uid_t id = metaStbCursorNext(pCur);
    if (id == 0) {
      break;
    }

    int64_t ctbNum = 0;
    vnodeGetCtbNum(pVnode, id, &ctbNum);

    *num += ctbNum;
  }

  metaCloseStbCursor(pCur);
  return TSDB_CODE_SUCCESS;
}

H
Hongze Cheng 已提交
529 530 531 532 533 534 535 536 537 538 539 540 541
void *vnodeGetIdx(SVnode *pVnode) {
  if (pVnode == NULL) {
    return NULL;
  }
  return metaGetIdx(pVnode->pMeta);
}

void *vnodeGetIvtIdx(SVnode *pVnode) {
  if (pVnode == NULL) {
    return NULL;
  }
  return metaGetIvtIdx(pVnode->pMeta);
}