ctgDbg.c 16.4 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 "catalogInt.h"
D
dapan1121 已提交
17 18
#include "query.h"
#include "tname.h"
H
Hongze Cheng 已提交
19
#include "trpc.h"
D
dapan1121 已提交
20 21

extern SCatalogMgmt gCtgMgmt;
H
Hongze Cheng 已提交
22
SCtgDebug           gCTGDebug = {0};
D
dapan1121 已提交
23

D
dapan1121 已提交
24 25
#if 0

H
Hongze Cheng 已提交
26
void ctgdUserCallback(SMetaData *pResult, void *param, int32_t code) {
D
dapan1121 已提交
27 28
  taosMemoryFree(param);

D
dapan1121 已提交
29
  qDebug("async call result: %s", tstrerror(code));
D
dapan1121 已提交
30
  if (NULL == pResult) {
D
dapan1121 已提交
31
    qDebug("empty meta result");
D
dapan1121 已提交
32 33 34 35 36 37 38 39
    return;
  }

  int32_t num = 0;

  if (pResult->pTableMeta && taosArrayGetSize(pResult->pTableMeta) > 0) {
    num = taosArrayGetSize(pResult->pTableMeta);
    for (int32_t i = 0; i < num; ++i) {
H
Hongze Cheng 已提交
40
      STableMeta    *p = *(STableMeta **)taosArrayGet(pResult->pTableMeta, i);
D
dapan1121 已提交
41
      STableComInfo *c = &p->tableInfo;
H
Hongze Cheng 已提交
42

D
dapan1121 已提交
43
      if (TSDB_CHILD_TABLE == p->tableType) {
H
Hongze Cheng 已提交
44 45
        qDebug("table meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64, p->tableType, p->vgId, p->uid,
               p->suid);
D
dapan1121 已提交
46
      } else {
H
Hongze Cheng 已提交
47 48 49 50
        qDebug("table meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64
               ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d",
               p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision,
               c->numOfColumns, c->rowSize);
D
dapan1121 已提交
51
      }
H
Hongze Cheng 已提交
52

D
dapan1121 已提交
53 54 55
      int32_t colNum = c->numOfColumns + c->numOfTags;
      for (int32_t j = 0; j < colNum; ++j) {
        SSchema *s = &p->schema[j];
D
dapan1121 已提交
56
        qDebug("[%d] name:%s, type:%d, colId:%d, bytes:%d", j, s->name, s->type, s->colId, s->bytes);
D
dapan1121 已提交
57 58 59
      }
    }
  } else {
D
dapan1121 已提交
60
    qDebug("empty table meta");
D
dapan1121 已提交
61 62 63 64 65
  }

  if (pResult->pDbVgroup && taosArrayGetSize(pResult->pDbVgroup) > 0) {
    num = taosArrayGetSize(pResult->pDbVgroup);
    for (int32_t i = 0; i < num; ++i) {
H
Hongze Cheng 已提交
66
      SArray *pDb = *(SArray **)taosArrayGet(pResult->pDbVgroup, i);
D
dapan1121 已提交
67
      int32_t vgNum = taosArrayGetSize(pDb);
D
dapan1121 已提交
68
      qDebug("db %d vgInfo:", i);
D
dapan1121 已提交
69
      for (int32_t j = 0; j < vgNum; ++j) {
H
Hongze Cheng 已提交
70
        SVgroupInfo *pInfo = taosArrayGet(pDb, j);
S
Shengliang Guan 已提交
71
        qDebug("vg :%d info: vgId:%d", j, pInfo->vgId);
D
dapan1121 已提交
72 73 74
      }
    }
  } else {
D
dapan1121 已提交
75
    qDebug("empty db vgroup");
D
dapan1121 已提交
76
  }
D
dapan1121 已提交
77

D
dapan1121 已提交
78 79 80 81
  if (pResult->pDbInfo && taosArrayGetSize(pResult->pDbInfo) > 0) {
    num = taosArrayGetSize(pResult->pDbInfo);
    for (int32_t i = 0; i < num; ++i) {
      SDbInfo *pDb = taosArrayGet(pResult->pDbInfo, i);
D
dapan1121 已提交
82
      qDebug("db %d dbInfo: vgVer:%d, tbNum:%d, stateTs:%" PRId64 " dbId:0x%" PRIx64, i, pDb->vgVer, pDb->tbNum, pDb->stateTs, pDb->dbId);
D
dapan1121 已提交
83 84 85 86 87
    }
  } else {
    qDebug("empty db info");
  }

D
dapan1121 已提交
88 89 90
  if (pResult->pTableHash && taosArrayGetSize(pResult->pTableHash) > 0) {
    num = taosArrayGetSize(pResult->pTableHash);
    for (int32_t i = 0; i < num; ++i) {
H
Hongze Cheng 已提交
91
      SVgroupInfo *pInfo = taosArrayGet(pResult->pTableHash, i);
D
dapan1121 已提交
92 93 94 95 96 97 98 99 100
      qDebug("table %d vg info: vgId:%d", i, pInfo->vgId);
    }
  } else {
    qDebug("empty table hash vgroup");
  }

  if (pResult->pUdfList && taosArrayGetSize(pResult->pUdfList) > 0) {
    num = taosArrayGetSize(pResult->pUdfList);
    for (int32_t i = 0; i < num; ++i) {
H
Hongze Cheng 已提交
101
      SFuncInfo *pInfo = taosArrayGet(pResult->pUdfList, i);
D
dapan1121 已提交
102 103 104 105 106 107 108 109 110
      qDebug("udf %d info: name:%s, funcType:%d", i, pInfo->name, pInfo->funcType);
    }
  } else {
    qDebug("empty udf info");
  }

  if (pResult->pDbCfg && taosArrayGetSize(pResult->pDbCfg) > 0) {
    num = taosArrayGetSize(pResult->pDbCfg);
    for (int32_t i = 0; i < num; ++i) {
H
Hongze Cheng 已提交
111
      SDbCfgInfo *pInfo = taosArrayGet(pResult->pDbCfg, i);
D
dapan1121 已提交
112 113 114 115
      qDebug("db %d info: numOFVgroups:%d, numOfStables:%d", i, pInfo->numOfVgroups, pInfo->numOfStables);
    }
  } else {
    qDebug("empty db cfg info");
H
Hongze Cheng 已提交
116
  }
D
dapan1121 已提交
117 118 119 120

  if (pResult->pUser && taosArrayGetSize(pResult->pUser) > 0) {
    num = taosArrayGetSize(pResult->pUser);
    for (int32_t i = 0; i < num; ++i) {
H
Hongze Cheng 已提交
121
      bool *auth = taosArrayGet(pResult->pUser, i);
D
dapan1121 已提交
122 123 124 125
      qDebug("user auth %d info: %d", i, *auth);
    }
  } else {
    qDebug("empty user auth info");
H
Hongze Cheng 已提交
126
  }
D
dapan1121 已提交
127 128 129 130

  if (pResult->pQnodeList && taosArrayGetSize(pResult->pQnodeList) > 0) {
    num = taosArrayGetSize(pResult->pQnodeList);
    for (int32_t i = 0; i < num; ++i) {
H
Hongze Cheng 已提交
131
      SQueryNodeAddr *qaddr = taosArrayGet(pResult->pQnodeList, i);
D
dapan1121 已提交
132 133 134 135
      qDebug("qnode %d info: id:%d", i, qaddr->nodeId);
    }
  } else {
    qDebug("empty qnode info");
H
Hongze Cheng 已提交
136
  }
D
dapan1121 已提交
137 138
}

D
dapan1121 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152
/*
prepare SQL:
create database db1;
use db1;
create stable st1 (ts timestamp, f1 int) tags(t1 int);
create table tb1 using st1 tags(1);
insert into tb1 values (now, 1);
create qnode on dnode 1;
create user user1 pass "abc";
create database db2;
grant write on db2.* to user1;
create function udf1 as '/tmp/libudf1.so' outputtype int;
create aggregate function udf2 as '/tmp/libudf2.so' outputtype int;
*/
H
Hongze Cheng 已提交
153 154
int32_t ctgdLaunchAsyncCall(SCatalog *pCtg, SRequestConnInfo *pConn, uint64_t reqId, bool forceUpdate) {
  int32_t     code = 0;
D
dapan1121 已提交
155 156 157
  SCatalogReq req = {0};
  req.pTableMeta = taosArrayInit(2, sizeof(SName));
  req.pDbVgroup = taosArrayInit(2, TSDB_DB_FNAME_LEN);
D
dapan1121 已提交
158
  req.pDbInfo = taosArrayInit(2, TSDB_DB_FNAME_LEN);
D
dapan1121 已提交
159 160 161
  req.pTableHash = taosArrayInit(2, sizeof(SName));
  req.pUdf = taosArrayInit(2, TSDB_FUNC_NAME_LEN);
  req.pDbCfg = taosArrayInit(2, TSDB_DB_FNAME_LEN);
H
Hongze Cheng 已提交
162
  req.pIndex = NULL;  // taosArrayInit(2, TSDB_INDEX_FNAME_LEN);
D
dapan1121 已提交
163 164
  req.pUser = taosArrayInit(2, sizeof(SUserAuthInfo));
  req.qNodeRequired = true;
D
dapan1121 已提交
165
  req.forceUpdate = forceUpdate;
D
dapan1121 已提交
166

H
Hongze Cheng 已提交
167 168 169
  SName         name = {0};
  char          dbFName[TSDB_DB_FNAME_LEN] = {0};
  char          funcName[TSDB_FUNC_NAME_LEN] = {0};
D
dapan1121 已提交
170
  SUserAuthInfo user = {0};
H
Hongze Cheng 已提交
171

D
dapan1121 已提交
172 173 174 175 176 177 178 179 180 181
  tNameFromString(&name, "1.db1.tb1", T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
  taosArrayPush(req.pTableMeta, &name);
  taosArrayPush(req.pTableHash, &name);
  tNameFromString(&name, "1.db1.st1", T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
  taosArrayPush(req.pTableMeta, &name);
  taosArrayPush(req.pTableHash, &name);

  strcpy(dbFName, "1.db1");
  taosArrayPush(req.pDbVgroup, dbFName);
  taosArrayPush(req.pDbCfg, dbFName);
D
dapan1121 已提交
182
  taosArrayPush(req.pDbInfo, dbFName);
D
dapan1121 已提交
183 184 185
  strcpy(dbFName, "1.db2");
  taosArrayPush(req.pDbVgroup, dbFName);
  taosArrayPush(req.pDbCfg, dbFName);
D
dapan1121 已提交
186
  taosArrayPush(req.pDbInfo, dbFName);
D
dapan1121 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

  strcpy(funcName, "udf1");
  taosArrayPush(req.pUdf, funcName);
  strcpy(funcName, "udf2");
  taosArrayPush(req.pUdf, funcName);

  strcpy(user.user, "root");
  strcpy(user.dbFName, "1.db1");
  user.type = AUTH_TYPE_READ;
  taosArrayPush(req.pUser, &user);
  user.type = AUTH_TYPE_WRITE;
  taosArrayPush(req.pUser, &user);
  user.type = AUTH_TYPE_OTHER;
  taosArrayPush(req.pUser, &user);

  strcpy(user.user, "user1");
  strcpy(user.dbFName, "1.db2");
  user.type = AUTH_TYPE_READ;
  taosArrayPush(req.pUser, &user);
  user.type = AUTH_TYPE_WRITE;
  taosArrayPush(req.pUser, &user);
  user.type = AUTH_TYPE_OTHER;
  taosArrayPush(req.pUser, &user);

  int32_t *param = taosMemoryCalloc(1, sizeof(int32_t));
  *param = 1;
H
Hongze Cheng 已提交
213

D
dapan1121 已提交
214
  int64_t jobId = 0;
D
dapan1121 已提交
215

D
dapan1121 已提交
216
  CTG_ERR_JRET(catalogAsyncGetAllMeta(pCtg, pConn, &req, ctgdUserCallback, param, &jobId));
D
dapan1121 已提交
217 218 219 220 221 222 223 224 225 226

_return:

  taosArrayDestroy(req.pTableMeta);
  taosArrayDestroy(req.pDbVgroup);
  taosArrayDestroy(req.pTableHash);
  taosArrayDestroy(req.pUdf);
  taosArrayDestroy(req.pDbCfg);
  taosArrayDestroy(req.pUser);

H
Hongze Cheng 已提交
227
  CTG_RET(code);
D
dapan1121 已提交
228
}
D
dapan1121 已提交
229
#endif
D
dapan1121 已提交
230

D
dapan1121 已提交
231
int32_t ctgdEnableDebug(char *option, bool enable) {
D
dapan1121 已提交
232
  if (0 == strcasecmp(option, "lock")) {
D
dapan1121 已提交
233 234
    gCTGDebug.lockEnable = enable;
    qDebug("catalog lock debug set to %d", enable);
D
dapan1121 已提交
235 236 237 238
    return TSDB_CODE_SUCCESS;
  }

  if (0 == strcasecmp(option, "cache")) {
D
dapan1121 已提交
239 240
    gCTGDebug.cacheEnable = enable;
    qDebug("catalog cache debug set to %d", enable);
D
dapan1121 已提交
241 242 243 244
    return TSDB_CODE_SUCCESS;
  }

  if (0 == strcasecmp(option, "api")) {
D
dapan1121 已提交
245 246
    gCTGDebug.apiEnable = enable;
    qDebug("catalog api debug set to %d", enable);
D
dapan1121 已提交
247 248 249 250
    return TSDB_CODE_SUCCESS;
  }

  if (0 == strcasecmp(option, "meta")) {
D
dapan1121 已提交
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
    gCTGDebug.metaEnable = enable;
    qDebug("catalog meta debug set to %d", enable);
    return TSDB_CODE_SUCCESS;
  }

  if (0 == strcasecmp(option, "stopUpdate")) {
    SCatalog *pCtg = NULL;
    
    void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
    while (pIter) {
      pCtg = *(SCatalog **)pIter;

      pCtg->stopUpdate = enable;
      
      pIter = taosHashIterate(gCtgMgmt.pCluster, pIter);
    }
    
    qDebug("catalog stopUpdate set to %d", enable);
    
D
dapan1121 已提交
270 271 272 273
    return TSDB_CODE_SUCCESS;
  }

  qError("invalid debug option:%s", option);
H
Hongze Cheng 已提交
274

D
dapan1121 已提交
275 276 277
  return TSDB_CODE_CTG_INTERNAL_ERROR;
}

D
dapan1121 已提交
278 279 280 281 282 283 284 285 286
int32_t ctgdHandleDbgCommand(char *command) {
  if (NULL == command) {
    CTG_RET(TSDB_CODE_INVALID_PARA);
  }

  if (strlen(command) > CTG_MAX_COMMAND_LEN) {
    CTG_RET(TSDB_CODE_INVALID_PARA);
  }

287
  char *dup = taosStrdup(command);
D
dapan1121 已提交
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 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
  char *option = NULL;
  char *param = NULL;
  
  int32_t i = 0;
  bool newItem = true;
  while (*(dup + i)) {
    if (isspace(*(dup + i))) {
      *(dup + i) = 0;
      ++i;
      newItem = true;
      continue;
    }

    if (!newItem) {
      ++i;
      continue;
    }
    
    newItem = false;
    if (NULL == option) {
      option = dup + i;
      ++i;
      continue;
    }

    if (NULL == param) {
      param = dup + i;
      ++i;
      continue;
    }

    taosMemoryFree(dup);
    CTG_RET(TSDB_CODE_INVALID_PARA);
  }

  bool enable = atoi(param);

  int32_t code = ctgdEnableDebug(option, enable);

  taosMemoryFree(dup);

  CTG_RET(code);
}

int32_t ctgdGetOneHandle(SCatalog **pHandle) {
  SCatalog *pCtg = NULL;

  void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
  while (pIter) {
    pCtg = *(SCatalog **)pIter;

    taosHashCancelIterate(gCtgMgmt.pCluster, pIter);
    break;
  }

  *pHandle = pCtg;

  return TSDB_CODE_SUCCESS;
}


D
dapan1121 已提交
349
int32_t ctgdGetStatNum(char *option, void *res) {
D
dapan1121 已提交
350
  if (0 == strcasecmp(option, "runtime.numOfOpDequeue")) {
D
dapan1121 已提交
351
    *(uint64_t *)res = atomic_load_64(&gCtgMgmt.statInfo.runtime.numOfOpDequeue);
D
dapan1121 已提交
352 353 354 355
    return TSDB_CODE_SUCCESS;
  }

  qError("invalid stat option:%s", option);
H
Hongze Cheng 已提交
356

D
dapan1121 已提交
357 358 359 360
  return TSDB_CODE_CTG_INTERNAL_ERROR;
}

int32_t ctgdGetTbMetaNum(SCtgDBCache *dbCache) {
D
dapan1121 已提交
361
  return dbCache->tbCache ? (int32_t)taosHashGetSize(dbCache->tbCache) : 0;
D
dapan1121 已提交
362 363 364
}

int32_t ctgdGetStbNum(SCtgDBCache *dbCache) {
D
dapan1121 已提交
365
  return dbCache->stbCache ? (int32_t)taosHashGetSize(dbCache->stbCache) : 0;
D
dapan1121 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
}

int32_t ctgdGetRentNum(SCtgRentMgmt *rent) {
  int32_t num = 0;
  for (uint16_t i = 0; i < rent->slotNum; ++i) {
    SCtgRentSlot *slot = &rent->slots[i];
    if (NULL == slot->meta) {
      continue;
    }

    num += taosArrayGetSize(slot->meta);
  }

  return num;
}

H
Hongze Cheng 已提交
382
int32_t ctgdGetClusterCacheNum(SCatalog *pCtg, int32_t type) {
D
dapan1121 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
  if (NULL == pCtg || NULL == pCtg->dbCache) {
    return 0;
  }

  switch (type) {
    case CTG_DBG_DB_NUM:
      return (int32_t)taosHashGetSize(pCtg->dbCache);
    case CTG_DBG_DB_RENT_NUM:
      return ctgdGetRentNum(&pCtg->dbRent);
    case CTG_DBG_STB_RENT_NUM:
      return ctgdGetRentNum(&pCtg->stbRent);
    default:
      break;
  }

  SCtgDBCache *dbCache = NULL;
H
Hongze Cheng 已提交
399 400
  int32_t      num = 0;
  void        *pIter = taosHashIterate(pCtg->dbCache, NULL);
D
dapan1121 已提交
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
  while (pIter) {
    dbCache = (SCtgDBCache *)pIter;
    switch (type) {
      case CTG_DBG_META_NUM:
        num += ctgdGetTbMetaNum(dbCache);
        break;
      case CTG_DBG_STB_NUM:
        num += ctgdGetStbNum(dbCache);
        break;
      default:
        ctgError("invalid type:%d", type);
        break;
    }
    pIter = taosHashIterate(pCtg->dbCache, pIter);
  }

  return num;
}

H
Hongze Cheng 已提交
420
void ctgdShowTableMeta(SCatalog *pCtg, const char *tbName, STableMeta *p) {
D
dapan1121 已提交
421 422 423 424 425 426 427
  if (!gCTGDebug.metaEnable) {
    return;
  }

  STableComInfo *c = &p->tableInfo;

  if (TSDB_CHILD_TABLE == p->tableType) {
H
Hongze Cheng 已提交
428 429
    ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64, tbName, p->tableType, p->vgId,
             p->uid, p->suid);
D
dapan1121 已提交
430 431
    return;
  } else {
H
Hongze Cheng 已提交
432 433 434 435
    ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64
             ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d",
             tbName, p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision,
             c->numOfColumns, c->rowSize);
D
dapan1121 已提交
436 437 438 439 440 441 442 443 444
  }

  int32_t colNum = c->numOfColumns + c->numOfTags;
  for (int32_t i = 0; i < colNum; ++i) {
    SSchema *s = &p->schema[i];
    ctgDebug("[%d] name:%s, type:%d, colId:%d, bytes:%d", i, s->name, s->type, s->colId, s->bytes);
  }
}

H
Hongze Cheng 已提交
445
void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) {
D
dapan1121 已提交
446 447 448 449
  if (NULL == dbHash || !gCTGDebug.cacheEnable) {
    return;
  }

H
Hongze Cheng 已提交
450
  int32_t      i = 0;
D
dapan1121 已提交
451
  SCtgDBCache *dbCache = NULL;
H
Hongze Cheng 已提交
452
  void        *pIter = taosHashIterate(dbHash, NULL);
D
dapan1121 已提交
453
  while (pIter) {
H
Hongze Cheng 已提交
454
    char  *dbFName = NULL;
D
dapan1121 已提交
455
    size_t len = 0;
H
Hongze Cheng 已提交
456

D
dapan1121 已提交
457 458 459 460
    dbCache = (SCtgDBCache *)pIter;

    dbFName = taosHashGetKey(pIter, &len);

D
dapan1121 已提交
461 462
    int32_t metaNum = dbCache->tbCache ? taosHashGetSize(dbCache->tbCache) : 0;
    int32_t stbNum = dbCache->stbCache ? taosHashGetSize(dbCache->stbCache) : 0;
D
dapan1121 已提交
463 464
    int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION;
    int32_t hashMethod = -1;
465 466
    int16_t hashPrefix = 0;
    int16_t hashSuffix = 0;
D
dapan1121 已提交
467
    int64_t stateTs = 0;
D
dapan1121 已提交
468 469
    int32_t vgNum = 0;

D
dapan1121 已提交
470 471 472
    if (dbCache->vgCache.vgInfo) {
      vgVersion = dbCache->vgCache.vgInfo->vgVersion;
      hashMethod = dbCache->vgCache.vgInfo->hashMethod;
473 474
      hashPrefix = dbCache->vgCache.vgInfo->hashPrefix;
      hashSuffix = dbCache->vgCache.vgInfo->hashSuffix;
D
dapan1121 已提交
475
      stateTs = dbCache->vgCache.vgInfo->stateTs;
D
dapan1121 已提交
476 477
      if (dbCache->vgCache.vgInfo->vgHash) {
        vgNum = taosHashGetSize(dbCache->vgCache.vgInfo->vgHash);
D
dapan1121 已提交
478 479
      }
    }
H
Hongze Cheng 已提交
480 481

    ctgDebug("[%d] db [%.*s][0x%" PRIx64
D
dapan1121 已提交
482 483
             "] %s: metaNum:%d, stbNum:%d, vgVersion:%d, stateTs:%" PRId64 ", hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d",
             i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted ? "deleted" : "", metaNum, stbNum, vgVersion, stateTs, 
H
Hongze Cheng 已提交
484
             hashMethod, hashPrefix, hashSuffix, vgNum);
D
dapan1121 已提交
485

D
dapan1121 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    if (dbCache->vgCache.vgInfo) {
      int32_t i = 0;
      void *pVgIter = taosHashIterate(dbCache->vgCache.vgInfo->vgHash, NULL);
      while (pVgIter) {
        SVgroupInfo * pVg = (SVgroupInfo *)pVgIter;

        ctgDebug("The %04dth VG [id:%d, hashBegin:%u, hashEnd:%u, numOfTable:%d, epNum:%d, inUse:%d]",
                 i++, pVg->vgId, pVg->hashBegin, pVg->hashEnd, pVg->numOfTable, pVg->epSet.numOfEps, pVg->epSet.inUse);

        for (int32_t n = 0; n < pVg->epSet.numOfEps; ++n) {
          SEp *pEp = &pVg->epSet.eps[n];
          ctgDebug("\tEp %d [fqdn:%s, port:%d]", n, pEp->fqdn, pEp->port);
        }
        
        pVgIter = taosHashIterate(dbCache->vgCache.vgInfo->vgHash, pVgIter);      
      }
    }

D
dapan1121 已提交
504 505 506 507
    pIter = taosHashIterate(dbHash, pIter);
  }
}

H
Hongze Cheng 已提交
508
void ctgdShowClusterCache(SCatalog *pCtg) {
D
dapan1121 已提交
509 510 511 512
  if (!gCTGDebug.cacheEnable || NULL == pCtg) {
    return;
  }

H
Hongze Cheng 已提交
513 514 515 516 517
  ctgDebug("## cluster 0x%" PRIx64 " %p cache Info BEGIN ##", pCtg->clusterId, pCtg);
  ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM),
           ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM),
           ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM));

D
dapan1121 已提交
518 519
  ctgdShowDBCache(pCtg, pCtg->dbCache);

H
Hongze Cheng 已提交
520
  ctgDebug("## cluster 0x%" PRIx64 " %p cache Info END ##", pCtg->clusterId, pCtg);
D
dapan1121 已提交
521 522
}

D
dapan1121 已提交
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
int32_t ctgdShowStatInfo(void) {
  if (!gCTGDebug.statEnable) {
    return TSDB_CODE_CTG_OUT_OF_SERVICE;
  }

  CTG_API_ENTER();

  SCtgCacheStat cache;
  ctgGetGlobalCacheStat(&cache);

  qDebug("## Global Stat Info %s ##", "begin");
  qDebug("##            \t%s \t%s \t%s ##", "Num", "Hit", "Nhit");
  for (int32_t i = 0; i < CTG_CI_MAX_VALUE; ++i) {
    qDebug("#  %s \t%" PRIu64 " \t%" PRIu64 " \t%" PRIu64 " #", gCtgStatItem[i].name, cache.cacheNum[i], cache.cacheHit[i], cache.cacheNHit[i]);
  }
  qDebug("## Global Stat Info %s ##", "end");

  CTG_API_LEAVE(TSDB_CODE_SUCCESS);
}


D
dapan1121 已提交
544 545 546 547 548 549
int32_t ctgdShowCacheInfo(void) {
  if (!gCTGDebug.cacheEnable) {
    return TSDB_CODE_CTG_OUT_OF_SERVICE;
  }

  CTG_API_ENTER();
D
dapan1121 已提交
550 551

  qDebug("# total catalog cluster number %d #", taosHashGetSize(gCtgMgmt.pCluster));
H
Hongze Cheng 已提交
552

D
dapan1121 已提交
553
  SCatalog *pCtg = NULL;
H
Hongze Cheng 已提交
554
  void     *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
D
dapan1121 已提交
555 556 557 558 559 560
  while (pIter) {
    pCtg = *(SCatalog **)pIter;

    if (pCtg) {
      ctgdShowClusterCache(pCtg);
    }
H
Hongze Cheng 已提交
561

D
dapan1121 已提交
562 563 564 565 566
    pIter = taosHashIterate(gCtgMgmt.pCluster, pIter);
  }

  CTG_API_LEAVE(TSDB_CODE_SUCCESS);
}