catalogTests.cpp 66.8 KB
Newer Older
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/>.
 */

D
dapan1121 已提交
16
#include <gtest/gtest.h>
17 18
#include <iostream>

S
Shengliang Guan 已提交
19 20
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
21 22 23
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
S
Shengliang Guan 已提交
24
#pragma GCC diagnostic ignored "-Wformat"
25
#include <addr_any.h>
26

wafwerar's avatar
wafwerar 已提交
27 28 29
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
S
Shengliang Guan 已提交
30
#include "catalog.h"
H
Haojun Liao 已提交
31
#include "catalogInt.h"
H
Hongze Cheng 已提交
32
#include "os.h"
S
Shengliang Guan 已提交
33
#include "stub.h"
D
dapan1121 已提交
34
#include "taos.h"
H
Haojun Liao 已提交
35
#include "tdatablock.h"
36
#include "tdef.h"
H
Hongze Cheng 已提交
37
#include "tglobal.h"
D
ut test  
dapan1121 已提交
38
#include "trpc.h"
S
Shengliang Guan 已提交
39
#include "tvariant.h"
40

D
dapan1121 已提交
41
namespace {
42

H
Hongze Cheng 已提交
43
extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog *pCatalog, int32_t type);
D
dapan1121 已提交
44 45
extern "C" int32_t ctgdEnableDebug(char *option);
extern "C" int32_t ctgdGetStatNum(char *option, void *res);
D
dapan1121 已提交
46

D
dapan 已提交
47 48 49 50 51
void ctgTestSetRspTableMeta();
void ctgTestSetRspCTableMeta();
void ctgTestSetRspSTableMeta();
void ctgTestSetRspMultiSTableMeta();

H
Hongze Cheng 已提交
52
// extern "C" SCatalogMgmt gCtgMgmt;
D
dapan 已提交
53 54 55 56 57 58 59

enum {
  CTGT_RSP_VGINFO = 1,
  CTGT_RSP_TBMETA,
  CTGT_RSP_CTBMETA,
  CTGT_RSP_STBMETA,
  CTGT_RSP_MSTBMETA,
D
dapan1121 已提交
60
  CTGT_RSP_INDEXINFO_E,
D
dapan1121 已提交
61
  CTGT_RSP_TBMETA_NOT_EXIST,
D
dapan 已提交
62
};
D
dapan1121 已提交
63

S
Shengliang Guan 已提交
64 65
bool    ctgTestStop = false;
bool    ctgTestEnableSleep = false;
D
dapan1121 已提交
66
bool    ctgTestEnableLog = true;
S
Shengliang Guan 已提交
67
bool    ctgTestDeadLoop = false;
D
dapan1121 已提交
68
int32_t ctgTestPrintNum = 10000;
D
dapan1121 已提交
69
int32_t ctgTestMTRunSec = 5;
D
dapan1121 已提交
70

S
Shengliang Guan 已提交
71 72 73 74 75 76 77 78
int32_t  ctgTestCurrentVgVersion = 0;
int32_t  ctgTestVgVersion = 1;
int32_t  ctgTestVgNum = 10;
int32_t  ctgTestColNum = 2;
int32_t  ctgTestTagNum = 1;
int32_t  ctgTestSVersion = 1;
int32_t  ctgTestTVersion = 1;
int32_t  ctgTestSuid = 2;
D
dapan1121 已提交
79
uint64_t ctgTestDbId = 33;
D
dapan1121 已提交
80
uint64_t ctgTestNormalTblUid = 1;
D
dapan1121 已提交
81

82
uint64_t ctgTestClusterId = 0x1;
S
Shengliang Guan 已提交
83 84 85 86
char    *ctgTestDbname = "1.db1";
char    *ctgTestTablename = "table1";
char    *ctgTestCTablename = "ctable1";
char    *ctgTestSTablename = "stable1";
D
dapan1121 已提交
87 88 89
char    *ctgTestCurrentCTableName = NULL;
char    *ctgTestCurrentTableName = NULL;
char    *ctgTestCurrentSTableName = NULL;
D
dapan1121 已提交
90

D
dapan1121 已提交
91
int32_t ctgTestRspFunc[100] = {0};
D
dapan 已提交
92 93
int32_t ctgTestRspIdx = 0;

D
ut test  
dapan1121 已提交
94
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
S
Shengliang Guan 已提交
95 96 97
  SCreateDbReq createReq = {0};
  strcpy(createReq.db, "1.db1");
  createReq.numOfVgroups = 2;
S
Shengliang Guan 已提交
98 99 100
  createReq.buffer = -1;
  createReq.pageSize = -1;
  createReq.pages = -1;
S
Shengliang Guan 已提交
101 102 103 104
  createReq.daysPerFile = 10;
  createReq.daysToKeep0 = 3650;
  createReq.daysToKeep1 = 3650;
  createReq.daysToKeep2 = 3650;
S
Shengliang Guan 已提交
105 106
  createReq.minRows = 100;
  createReq.maxRows = 4096;
107
  createReq.walFsyncPeriod = 3000;
S
Shengliang Guan 已提交
108 109 110 111
  createReq.walLevel = 1;
  createReq.precision = 0;
  createReq.compression = 2;
  createReq.replications = 1;
S
Shengliang Guan 已提交
112
  createReq.strict = 1;
113
  createReq.cacheLast = 0;
S
Shengliang Guan 已提交
114 115 116 117 118
  createReq.ignoreExist = 1;

  int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSCreateDbReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
119

D
ut test  
dapan1121 已提交
120 121
  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
S
Shengliang Guan 已提交
122
  rpcMsg.contLen = contLen;
H
Hongze Cheng 已提交
123
  rpcMsg.msgType = TDMT_MND_CREATE_DB;
D
ut test  
dapan1121 已提交
124 125 126 127 128 129 130

  SRpcMsg rpcRsp = {0};
  rpcSendRecv(shandle, pEpSet, &rpcMsg, &rpcRsp);

  ASSERT_EQ(rpcRsp.code, 0);
}

D
dapan1121 已提交
131
void ctgTestInitLogFile() {
D
dapan1121 已提交
132 133 134
  if (!ctgTestEnableLog) {
    return;
  }
H
Hongze Cheng 已提交
135

S
Shengliang Guan 已提交
136 137
  const char   *defaultLogFileNamePrefix = "taoslog";
  const int32_t maxLogFileNum = 10;
D
dapan1121 已提交
138 139

  tsAsyncLog = 0;
D
dapan1121 已提交
140
  qDebugFlag = 159;
wafwerar's avatar
wafwerar 已提交
141
  strcpy(tsLogDir, TD_LOG_DIR_PATH);
D
dapan1121 已提交
142

D
dapan1121 已提交
143 144 145
  ctgdEnableDebug("api");
  ctgdEnableDebug("meta");
  ctgdEnableDebug("cache");
D
dapan1121 已提交
146
  ctgdEnableDebug("lock");
H
Hongze Cheng 已提交
147

S
Shengliang Guan 已提交
148
  if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
D
dapan1121 已提交
149 150 151 152 153 154 155 156 157
    printf("failed to open log file in directory:%s\n", tsLogDir);
  }
}

int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) {
  return ((vgVersion % 2) == 0) ? ctgTestVgNum - 2 : ctgTestVgNum;
}

void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) {
H
Hongze Cheng 已提交
158
  SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
159 160 161
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);

H
Hongze Cheng 已提交
162
  SName sn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
163 164 165
  strcpy(sn.dbname, "db1");
  strcpy(sn.tname, ctgTestSTablename);

D
dapan 已提交
166 167 168 169
  char db[TSDB_DB_FNAME_LEN] = {0};
  tNameGetFullDbName(&cn, db);

  strcpy(output->dbFName, db);
D
dapan1121 已提交
170
  SET_META_TYPE_BOTH_TABLE(output->metaType);
D
dapan1121 已提交
171

D
dapan1121 已提交
172 173
  strcpy(output->ctbName, cn.tname);
  strcpy(output->tbName, sn.tname);
D
dapan1121 已提交
174 175 176 177 178 179

  output->ctbMeta.vgId = 9;
  output->ctbMeta.tableType = TSDB_CHILD_TABLE;
  output->ctbMeta.uid = 3;
  output->ctbMeta.suid = 2;

H
Hongze Cheng 已提交
180 181
  output->tbMeta =
      (STableMeta *)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum));
D
dapan1121 已提交
182 183 184 185 186 187 188
  output->tbMeta->vgId = 9;
  output->tbMeta->tableType = TSDB_SUPER_TABLE;
  output->tbMeta->uid = 2;
  output->tbMeta->suid = 2;

  output->tbMeta->tableInfo.numOfColumns = ctgTestColNum;
  output->tbMeta->tableInfo.numOfTags = ctgTestTagNum;
S
Shengliang Guan 已提交
189

D
dapan1121 已提交
190 191
  output->tbMeta->sversion = ctgTestSVersion;
  output->tbMeta->tversion = ctgTestTVersion;
S
Shengliang Guan 已提交
192

D
dapan1121 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
  SSchema *s = NULL;
  s = &output->tbMeta->schema[0];
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
  s->colId = 1;
  s->bytes = 8;
  strcpy(s->name, "ts");

  s = &output->tbMeta->schema[1];
  s->type = TSDB_DATA_TYPE_INT;
  s->colId = 2;
  s->bytes = 4;
  strcpy(s->name, "col1s");

  s = &output->tbMeta->schema[2];
  s->type = TSDB_DATA_TYPE_BINARY;
  s->colId = 3;
  s->bytes = 12;
  strcpy(s->name, "tag1s");
}

D
dapan1121 已提交
213
void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) {
D
dapan1121 已提交
214
  static int32_t vgVersion = ctgTestVgVersion + 1;
S
Shengliang Guan 已提交
215 216
  int32_t        vgNum = 0;
  SVgroupInfo    vgInfo = {0};
H
Hongze Cheng 已提交
217
  SDBVgInfo     *dbVgroup = (SDBVgInfo *)taosMemoryCalloc(1, sizeof(SDBVgInfo));
S
Shengliang Guan 已提交
218

D
dapan1121 已提交
219
  dbVgroup->vgVersion = vgVersion++;
S
Shengliang Guan 已提交
220

D
dapan1121 已提交
221
  ctgTestCurrentVgVersion = dbVgroup->vgVersion;
S
Shengliang Guan 已提交
222

D
dapan1121 已提交
223
  dbVgroup->hashMethod = 0;
224 225
  dbVgroup->hashPrefix = 0;
  dbVgroup->hashSuffix = 0;
D
dapan1121 已提交
226
  dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
D
dapan1121 已提交
227 228 229 230 231 232 233 234

  vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion);
  uint32_t hashUnit = UINT32_MAX / vgNum;

  for (int32_t i = 0; i < vgNum; ++i) {
    vgInfo.vgId = i + 1;
    vgInfo.hashBegin = i * hashUnit;
    vgInfo.hashEnd = hashUnit * (i + 1) - 1;
L
Liu Jicong 已提交
235 236 237 238
    vgInfo.epSet.numOfEps = i % TSDB_MAX_REPLICA + 1;
    vgInfo.epSet.inUse = i % vgInfo.epSet.numOfEps;
    for (int32_t n = 0; n < vgInfo.epSet.numOfEps; ++n) {
      SEp *addr = &vgInfo.epSet.eps[n];
D
dapan1121 已提交
239
      strcpy(addr->fqdn, "a0");
S
Shengliang Guan 已提交
240
      addr->port = n + 22;
D
dapan1121 已提交
241 242
    }

D
dapan1121 已提交
243
    taosHashPut(dbVgroup->vgHash, &vgInfo.vgId, sizeof(vgInfo.vgId), &vgInfo, sizeof(vgInfo));
D
dapan1121 已提交
244
  }
D
dapan 已提交
245 246

  *pdbVgroup = dbVgroup;
D
dapan1121 已提交
247 248
}

D
dapan1121 已提交
249 250 251 252 253 254 255 256 257 258
void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
  strcpy(rspMsg->dbFName, ctgTestDbname);
  sprintf(rspMsg->tbName, "%s", ctgTestSTablename);
  sprintf(rspMsg->stbName, "%s", ctgTestSTablename);
  rspMsg->numOfTags = ctgTestTagNum;
  rspMsg->numOfColumns = ctgTestColNum;
  rspMsg->precision = 1 + 1;
  rspMsg->tableType = TSDB_SUPER_TABLE;
  rspMsg->sversion = ctgTestSVersion + 1;
  rspMsg->tversion = ctgTestTVersion + 1;
D
dapan1121 已提交
259 260
  rspMsg->suid = ctgTestSuid;
  rspMsg->tuid = ctgTestSuid;
D
dapan1121 已提交
261
  rspMsg->vgId = 1;
H
Hongze Cheng 已提交
262

wafwerar's avatar
wafwerar 已提交
263
  rspMsg->pSchemas = (SSchema *)taosMemoryCalloc(rspMsg->numOfTags + rspMsg->numOfColumns, sizeof(SSchema));
D
dapan1121 已提交
264 265

  SSchema *s = NULL;
S
Shengliang Guan 已提交
266
  s = &rspMsg->pSchemas[0];
D
dapan1121 已提交
267 268 269 270 271
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
  s->colId = 1;
  s->bytes = 8;
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
272
  s = &rspMsg->pSchemas[1];
D
dapan1121 已提交
273 274 275 276 277
  s->type = TSDB_DATA_TYPE_INT;
  s->colId = 2;
  s->bytes = 4;
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
278
  s = &rspMsg->pSchemas[2];
D
dapan1121 已提交
279 280 281 282 283 284 285 286
  s->type = TSDB_DATA_TYPE_BINARY;
  s->colId = 3;
  s->bytes = 12 + 1;
  strcpy(s->name, "tag1s");

  return;
}

D
dapan 已提交
287
void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
288 289 290
  SUseDbRsp usedbRsp = {0};
  strcpy(usedbRsp.db, ctgTestDbname);
  usedbRsp.vgVersion = ctgTestVgVersion;
D
dapan1121 已提交
291
  ctgTestCurrentVgVersion = ctgTestVgVersion;
S
Shengliang Guan 已提交
292 293 294 295
  usedbRsp.vgNum = ctgTestVgNum;
  usedbRsp.hashMethod = 0;
  usedbRsp.uid = ctgTestDbId;
  usedbRsp.pVgroupInfos = taosArrayInit(usedbRsp.vgNum, sizeof(SVgroupInfo));
D
dapan1121 已提交
296

S
Shengliang Guan 已提交
297
  uint32_t hashUnit = UINT32_MAX / ctgTestVgNum;
D
dapan1121 已提交
298
  for (int32_t i = 0; i < ctgTestVgNum; ++i) {
S
Shengliang Guan 已提交
299 300 301 302 303 304 305 306
    SVgroupInfo vg = {0};
    vg.vgId = i + 1;
    vg.hashBegin = i * hashUnit;
    vg.hashEnd = hashUnit * (i + 1) - 1;
    if (i == ctgTestVgNum - 1) {
      vg.hashEnd = htonl(UINT32_MAX);
    }

L
Liu Jicong 已提交
307 308 309 310
    vg.epSet.numOfEps = i % TSDB_MAX_REPLICA + 1;
    vg.epSet.inUse = i % vg.epSet.numOfEps;
    for (int32_t n = 0; n < vg.epSet.numOfEps; ++n) {
      SEp *addr = &vg.epSet.eps[n];
D
dapan1121 已提交
311
      strcpy(addr->fqdn, "a0");
S
Shengliang Guan 已提交
312
      addr->port = n + 22;
D
dapan1121 已提交
313
    }
S
Shengliang Guan 已提交
314 315

    taosArrayPush(usedbRsp.pVgroupInfos, &vg);
D
dapan1121 已提交
316 317
  }

S
Shengliang Guan 已提交
318 319 320
  int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSUseDbRsp(pReq, contLen, &usedbRsp);
D
dapan1121 已提交
321

S
Shengliang Guan 已提交
322 323 324
  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;
D
dapan1121 已提交
325 326
}

D
dapan 已提交
327
void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
328 329 330 331 332 333 334 335 336 337
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
  strcpy(metaRsp.tbName, ctgTestTablename);
  metaRsp.numOfTags = 0;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_NORMAL_TABLE;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = 0;
D
dapan1121 已提交
338
  metaRsp.tuid = ctgTestNormalTblUid++;
S
Shengliang Guan 已提交
339
  metaRsp.vgId = 8;
wafwerar's avatar
wafwerar 已提交
340
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
341 342

  SSchema *s = NULL;
S
Shengliang Guan 已提交
343
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
344
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
345 346
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
347 348
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
349
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
350
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
351 352
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
353
  strcpy(s->name, "col1");
S
Shengliang Guan 已提交
354

S
Shengliang Guan 已提交
355 356 357 358 359 360 361 362 363
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;

  tFreeSTableMetaRsp(&metaRsp);
D
dapan1121 已提交
364 365
}

D
dapan1121 已提交
366 367 368 369
void ctgTestRspTableMetaNotExist(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  pRsp->code = CTG_ERR_CODE_TABLE_NOT_EXIST;
}

D
dapan 已提交
370
void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
371 372
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
D
dapan1121 已提交
373
  strcpy(metaRsp.tbName, ctgTestCurrentCTableName ? ctgTestCurrentCTableName : ctgTestCTablename);
S
Shengliang Guan 已提交
374 375 376 377 378 379 380 381 382 383
  strcpy(metaRsp.stbName, ctgTestSTablename);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_CHILD_TABLE;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = 0x0000000000000002;
  metaRsp.tuid = 0x0000000000000003;
  metaRsp.vgId = 9;
wafwerar's avatar
wafwerar 已提交
384
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
385 386

  SSchema *s = NULL;
S
Shengliang Guan 已提交
387
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
388
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
389 390
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
391 392
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
393
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
394
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
395 396
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
397 398
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
399
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
400
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
401 402
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
403 404
  strcpy(s->name, "tag1s");

S
Shengliang Guan 已提交
405 406 407 408 409 410 411 412 413
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;

  tFreeSTableMetaRsp(&metaRsp);
D
dapan1121 已提交
414 415
}

D
dapan 已提交
416
void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
417 418
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
D
dapan1121 已提交
419
  strcpy(metaRsp.tbName, ctgTestCurrentSTableName ? ctgTestCurrentSTableName : ctgTestSTablename);
S
Shengliang Guan 已提交
420 421 422 423 424 425 426 427
  strcpy(metaRsp.stbName, ctgTestSTablename);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_SUPER_TABLE;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = ctgTestSuid;
D
dapan1121 已提交
428
  metaRsp.tuid = ctgTestSuid+1;
S
Shengliang Guan 已提交
429
  metaRsp.vgId = 0;
wafwerar's avatar
wafwerar 已提交
430
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
431 432

  SSchema *s = NULL;
S
Shengliang Guan 已提交
433
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
434
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
435 436
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
437 438
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
439
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
440
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
441 442
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
443 444
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
445
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
446
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
447 448
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
449 450
  strcpy(s->name, "tag1s");

S
Shengliang Guan 已提交
451 452 453 454 455 456 457 458 459
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;

  tFreeSTableMetaRsp(&metaRsp);
D
dapan1121 已提交
460 461
}

D
dapan 已提交
462
void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
D
dapan1121 已提交
463 464
  static int32_t idx = 1;

S
Shengliang Guan 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477
  STableMetaRsp metaRsp = {0};
  strcpy(metaRsp.dbFName, ctgTestDbname);
  sprintf(metaRsp.tbName, "%s_%d", ctgTestSTablename, idx);
  sprintf(metaRsp.stbName, "%s_%d", ctgTestSTablename, idx);
  metaRsp.numOfTags = ctgTestTagNum;
  metaRsp.numOfColumns = ctgTestColNum;
  metaRsp.precision = 1;
  metaRsp.tableType = TSDB_SUPER_TABLE;
  metaRsp.sversion = ctgTestSVersion;
  metaRsp.tversion = ctgTestTVersion;
  metaRsp.suid = ctgTestSuid + idx;
  metaRsp.tuid = ctgTestSuid + idx;
  metaRsp.vgId = 0;
wafwerar's avatar
wafwerar 已提交
478
  metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
D
dapan1121 已提交
479 480

  SSchema *s = NULL;
S
Shengliang Guan 已提交
481
  s = &metaRsp.pSchemas[0];
D
dapan1121 已提交
482
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
S
Shengliang Guan 已提交
483 484
  s->colId = 1;
  s->bytes = 8;
D
dapan1121 已提交
485 486
  strcpy(s->name, "ts");

S
Shengliang Guan 已提交
487
  s = &metaRsp.pSchemas[1];
D
dapan1121 已提交
488
  s->type = TSDB_DATA_TYPE_INT;
S
Shengliang Guan 已提交
489 490
  s->colId = 2;
  s->bytes = 4;
D
dapan1121 已提交
491 492
  strcpy(s->name, "col1s");

S
Shengliang Guan 已提交
493
  s = &metaRsp.pSchemas[2];
D
dapan1121 已提交
494
  s->type = TSDB_DATA_TYPE_BINARY;
S
Shengliang Guan 已提交
495 496
  s->colId = 3;
  s->bytes = 12;
D
dapan1121 已提交
497 498 499
  strcpy(s->name, "tag1s");

  ++idx;
S
Shengliang Guan 已提交
500

S
Shengliang Guan 已提交
501 502 503 504 505 506 507
  int32_t contLen = tSerializeSTableMetaRsp(NULL, 0, &metaRsp);
  void   *pReq = rpcMallocCont(contLen);
  tSerializeSTableMetaRsp(pReq, contLen, &metaRsp);

  pRsp->code = 0;
  pRsp->contLen = contLen;
  pRsp->pCont = pReq;
D
dapan1121 已提交
508

S
Shengliang Guan 已提交
509 510
  tFreeSTableMetaRsp(&metaRsp);
}
S
Shengliang Guan 已提交
511

D
dapan1121 已提交
512 513 514 515 516 517 518 519

void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  pRsp->code = TSDB_CODE_MND_DB_INDEX_NOT_EXIST;
  pRsp->contLen = 0;
  pRsp->pCont = NULL;
}


D
dapan 已提交
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  switch (ctgTestRspFunc[ctgTestRspIdx]) {
    case CTGT_RSP_VGINFO:
      ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_TBMETA:
      ctgTestRspTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_CTBMETA:
      ctgTestRspCTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_STBMETA:
      ctgTestRspSTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
    case CTGT_RSP_MSTBMETA:
      ctgTestRspMultiSTableMeta(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
537 538 539
    case CTGT_RSP_INDEXINFO_E:
      ctgTestRspErrIndexInfo(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan1121 已提交
540 541 542
    case CTGT_RSP_TBMETA_NOT_EXIST:
      ctgTestRspTableMetaNotExist(shandle, pEpSet, pMsg, pRsp);
      break;
D
dapan 已提交
543 544 545 546 547
    default:
      break;
  }

  ctgTestRspIdx++;
S
Shengliang Guan 已提交
548

D
dapan 已提交
549 550 551
  return;
}

D
dapan 已提交
552 553 554 555
void ctgTestRspDbVgroupsAndNormalMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);

  ctgTestSetRspTableMeta();
S
Shengliang Guan 已提交
556

D
dapan 已提交
557 558 559
  return;
}

D
dapan 已提交
560 561
void ctgTestRspDbVgroupsAndChildMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
562

D
dapan 已提交
563
  ctgTestSetRspCTableMeta();
S
Shengliang Guan 已提交
564

D
dapan 已提交
565 566 567
  return;
}

D
dapan 已提交
568 569
void ctgTestRspDbVgroupsAndSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
570

D
dapan 已提交
571
  ctgTestSetRspSTableMeta();
S
Shengliang Guan 已提交
572

D
dapan1121 已提交
573 574 575
  return;
}

D
dapan 已提交
576 577
void ctgTestRspDbVgroupsAndMultiSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
578

D
dapan 已提交
579
  ctgTestSetRspMultiSTableMeta();
S
Shengliang Guan 已提交
580

D
dapan1121 已提交
581 582 583
  return;
}

D
dapan 已提交
584
void ctgTestSetRspDbVgroups() {
D
dapan1121 已提交
585
  static Stub stub;
D
dapan 已提交
586
  stub.set(rpcSendRecv, ctgTestRspDbVgroups);
D
dapan1121 已提交
587
  {
wafwerar's avatar
wafwerar 已提交
588
#ifdef WINDOWS
H
Hongze Cheng 已提交
589 590
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
591 592 593
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
594 595
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
596
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
597
#endif
S
Shengliang Guan 已提交
598
    for (const auto &f : result) {
D
dapan 已提交
599
      stub.set(f.second, ctgTestRspDbVgroups);
D
dapan1121 已提交
600 601 602 603
    }
  }
}

D
dapan 已提交
604
void ctgTestSetRspTableMeta() {
D
dapan1121 已提交
605
  static Stub stub;
D
dapan 已提交
606
  stub.set(rpcSendRecv, ctgTestRspTableMeta);
D
dapan1121 已提交
607
  {
wafwerar's avatar
wafwerar 已提交
608
#ifdef WINDOWS
H
Hongze Cheng 已提交
609 610
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
611 612 613
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
614 615
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
616
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
617
#endif
S
Shengliang Guan 已提交
618
    for (const auto &f : result) {
D
dapan 已提交
619
      stub.set(f.second, ctgTestRspTableMeta);
D
dapan1121 已提交
620 621 622 623
    }
  }
}

D
dapan 已提交
624
void ctgTestSetRspCTableMeta() {
D
dapan1121 已提交
625
  static Stub stub;
D
dapan 已提交
626
  stub.set(rpcSendRecv, ctgTestRspCTableMeta);
D
dapan1121 已提交
627
  {
wafwerar's avatar
wafwerar 已提交
628
#ifdef WINDOWS
H
Hongze Cheng 已提交
629 630
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
631 632 633
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
634 635
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
636
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
637
#endif
S
Shengliang Guan 已提交
638
    for (const auto &f : result) {
D
dapan 已提交
639
      stub.set(f.second, ctgTestRspCTableMeta);
D
dapan1121 已提交
640 641 642 643
    }
  }
}

D
dapan 已提交
644
void ctgTestSetRspSTableMeta() {
D
dapan1121 已提交
645
  static Stub stub;
D
dapan 已提交
646
  stub.set(rpcSendRecv, ctgTestRspSTableMeta);
D
dapan1121 已提交
647
  {
wafwerar's avatar
wafwerar 已提交
648
#ifdef WINDOWS
H
Hongze Cheng 已提交
649 650
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
651 652 653
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
654 655
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
656
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
657
#endif
S
Shengliang Guan 已提交
658
    for (const auto &f : result) {
D
dapan 已提交
659
      stub.set(f.second, ctgTestRspSTableMeta);
D
dapan1121 已提交
660 661 662 663
    }
  }
}

D
dapan 已提交
664
void ctgTestSetRspMultiSTableMeta() {
D
dapan1121 已提交
665
  static Stub stub;
D
dapan 已提交
666
  stub.set(rpcSendRecv, ctgTestRspMultiSTableMeta);
D
dapan1121 已提交
667
  {
wafwerar's avatar
wafwerar 已提交
668
#ifdef WINDOWS
H
Hongze Cheng 已提交
669 670
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
671 672 673
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
674 675
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
676
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
677
#endif
S
Shengliang Guan 已提交
678
    for (const auto &f : result) {
D
dapan 已提交
679
      stub.set(f.second, ctgTestRspMultiSTableMeta);
D
dapan1121 已提交
680 681 682 683
    }
  }
}

D
dapan 已提交
684
void ctgTestSetRspByIdx() {
D
dapan1121 已提交
685
  static Stub stub;
D
dapan 已提交
686
  stub.set(rpcSendRecv, ctgTestRspByIdx);
D
dapan1121 已提交
687
  {
wafwerar's avatar
wafwerar 已提交
688
#ifdef WINDOWS
H
Hongze Cheng 已提交
689 690
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
691 692 693
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
694 695
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
696
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
697
#endif
S
Shengliang Guan 已提交
698
    for (const auto &f : result) {
D
dapan 已提交
699
      stub.set(f.second, ctgTestRspByIdx);
D
dapan1121 已提交
700 701 702 703
    }
  }
}

D
dapan 已提交
704
void ctgTestSetRspDbVgroupsAndNormalMeta() {
D
dapan 已提交
705
  static Stub stub;
D
dapan 已提交
706
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndNormalMeta);
D
dapan 已提交
707
  {
wafwerar's avatar
wafwerar 已提交
708
#ifdef WINDOWS
H
Hongze Cheng 已提交
709 710
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
711 712 713
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
714 715
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan 已提交
716
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
717
#endif
S
Shengliang Guan 已提交
718
    for (const auto &f : result) {
D
dapan 已提交
719
      stub.set(f.second, ctgTestRspDbVgroupsAndNormalMeta);
D
dapan 已提交
720 721 722 723
    }
  }
}

D
dapan 已提交
724
void ctgTestSetRspDbVgroupsAndChildMeta() {
D
dapan1121 已提交
725
  static Stub stub;
D
dapan 已提交
726
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndChildMeta);
D
dapan1121 已提交
727
  {
wafwerar's avatar
wafwerar 已提交
728
#ifdef WINDOWS
H
Hongze Cheng 已提交
729 730
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
731 732 733
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
734 735
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
736
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
737
#endif
S
Shengliang Guan 已提交
738
    for (const auto &f : result) {
D
dapan 已提交
739
      stub.set(f.second, ctgTestRspDbVgroupsAndChildMeta);
D
dapan1121 已提交
740 741 742 743
    }
  }
}

D
dapan 已提交
744
void ctgTestSetRspDbVgroupsAndSuperMeta() {
D
dapan1121 已提交
745
  static Stub stub;
D
dapan 已提交
746
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndSuperMeta);
D
dapan1121 已提交
747
  {
wafwerar's avatar
wafwerar 已提交
748
#ifdef WINDOWS
H
Hongze Cheng 已提交
749 750
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
751 752 753
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
754 755
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
756
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
757
#endif
S
Shengliang Guan 已提交
758
    for (const auto &f : result) {
D
dapan 已提交
759
      stub.set(f.second, ctgTestRspDbVgroupsAndSuperMeta);
D
dapan1121 已提交
760 761 762 763
    }
  }
}

D
dapan 已提交
764
void ctgTestSetRspDbVgroupsAndMultiSuperMeta() {
D
dapan1121 已提交
765
  static Stub stub;
D
dapan 已提交
766
  stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndMultiSuperMeta);
D
dapan1121 已提交
767
  {
wafwerar's avatar
wafwerar 已提交
768
#ifdef WINDOWS
H
Hongze Cheng 已提交
769 770
    AddrAny                       any;
    std::map<std::string, void *> result;
wafwerar's avatar
wafwerar 已提交
771 772 773
    any.get_func_addr("rpcSendRecv", result);
#endif
#ifdef LINUX
S
Shengliang Guan 已提交
774 775
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
776
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
wafwerar's avatar
wafwerar 已提交
777
#endif
S
Shengliang Guan 已提交
778
    for (const auto &f : result) {
D
dapan 已提交
779
      stub.set(f.second, ctgTestRspDbVgroupsAndMultiSuperMeta);
D
dapan1121 已提交
780 781 782 783
    }
  }
}

S
Shengliang Guan 已提交
784
}  // namespace
785

D
dapan1121 已提交
786
void *ctgTestGetDbVgroupThread(void *param) {
H
Hongze Cheng 已提交
787 788
  struct SCatalog  *pCtg = (struct SCatalog *)param;
  int32_t           code = 0;
D
dapan1121 已提交
789 790
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
791 792
  SArray           *vgList = NULL;
  int32_t           n = 0;
S
Shengliang Guan 已提交
793

D
dapan1121 已提交
794
  while (!ctgTestStop) {
795
    code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList);
D
dapan1121 已提交
796
    if (code) {
D
dapan1121 已提交
797
      printf("code:%x\n", code);
D
dapan1121 已提交
798 799 800 801 802 803 804 805
      assert(0);
    }

    if (vgList) {
      taosArrayDestroy(vgList);
    }

    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
806
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
807
    }
D
dapan1121 已提交
808
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
809 810 811 812 813 814 815
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
816
void *ctgTestSetSameDbVgroupThread(void *param) {
S
Shengliang Guan 已提交
817 818
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
D
dapan1121 已提交
819
  SDBVgInfo       *dbVgroup = NULL;
S
Shengliang Guan 已提交
820 821
  int32_t          n = 0;

D
dapan1121 已提交
822 823
  while (!ctgTestStop) {
    ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
824
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
D
dapan1121 已提交
825 826 827 828
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
829
    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
830
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
831
    }
D
dapan1121 已提交
832
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
833 834 835 836 837 838 839
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
840 841 842
void *ctgTestSetDiffDbVgroupThread(void *param) {
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
H
Hongze Cheng 已提交
843
  SDBVgInfo       *dbVgroup = NULL;
D
dapan1121 已提交
844 845 846 847
  int32_t          n = 0;

  while (!ctgTestStop) {
    ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
848
    code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId++, dbVgroup);
D
dapan1121 已提交
849 850 851 852 853
    if (code) {
      assert(0);
    }

    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
854
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
855 856 857 858 859 860 861 862 863
    }
    if (++n % ctgTestPrintNum == 0) {
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan1121 已提交
864
void *ctgTestGetCtableMetaThread(void *param) {
S
Shengliang Guan 已提交
865 866 867 868
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
  int32_t          n = 0;
  STableMeta      *tbMeta = NULL;
D
dapan1121 已提交
869
  bool             inCache = false;
D
dapan1121 已提交
870

H
Hongze Cheng 已提交
871
  SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
872 873
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);
S
Shengliang Guan 已提交
874

D
dapan1121 已提交
875 876 877 878
  SCtgTbMetaCtx ctx = {0};
  ctx.pName = &cn;
  ctx.flag = CTG_FLAG_UNKNOWN_STB;

D
dapan1121 已提交
879
  while (!ctgTestStop) {
D
dapan1121 已提交
880
    code = ctgReadTbMetaFromCache(pCtg, &ctx, &tbMeta);
D
dapan1121 已提交
881
    if (code || NULL == tbMeta) {
D
dapan1121 已提交
882 883 884
      assert(0);
    }

wafwerar's avatar
wafwerar 已提交
885
    taosMemoryFreeClear(tbMeta);
D
dapan1121 已提交
886

D
dapan1121 已提交
887
    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
888
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
889
    }
S
Shengliang Guan 已提交
890

D
dapan1121 已提交
891
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
892 893 894 895 896 897 898 899
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

void *ctgTestSetCtableMetaThread(void *param) {
H
Hongze Cheng 已提交
900 901 902 903
  struct SCatalog  *pCtg = (struct SCatalog *)param;
  int32_t           code = 0;
  SDBVgInfo         dbVgroup = {0};
  int32_t           n = 0;
D
dapan 已提交
904
  STableMetaOutput *output = NULL;
D
dapan1121 已提交
905

D
dapan1121 已提交
906
  SCtgCacheOperation operation = {0};
H
Hongze Cheng 已提交
907

D
dapan1121 已提交
908
  operation.opId = CTG_OP_UPDATE_TB_META;
S
Shengliang Guan 已提交
909

D
dapan1121 已提交
910
  while (!ctgTestStop) {
wafwerar's avatar
wafwerar 已提交
911
    output = (STableMetaOutput *)taosMemoryMalloc(sizeof(STableMetaOutput));
D
dapan 已提交
912 913
    ctgTestBuildCTableMetaOutput(output);

D
dapan1121 已提交
914
    SCtgUpdateTbMetaMsg *msg = (SCtgUpdateTbMetaMsg *)taosMemoryMalloc(sizeof(SCtgUpdateTbMetaMsg));
D
dapan1121 已提交
915
    msg->pCtg = pCtg;
D
dapan1121 已提交
916
    msg->pMeta = output;
D
dapan1121 已提交
917
    operation.data = msg;
D
dapan1121 已提交
918

D
dapan1121 已提交
919
    code = ctgOpUpdateTbMeta(&operation);
D
dapan1121 已提交
920 921 922 923
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
924
    if (ctgTestEnableSleep) {
wafwerar's avatar
wafwerar 已提交
925
      taosUsleep(taosRand() % 5);
D
dapan1121 已提交
926
    }
D
dapan1121 已提交
927
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
928 929 930 931 932 933 934
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

D
dapan 已提交
935

D
dapan 已提交
936
TEST(tableMeta, normalTable) {
H
Hongze Cheng 已提交
937 938
  struct SCatalog  *pCtg = NULL;
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
939 940
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
941

D
dapan1121 已提交
942 943
  ctgTestInitLogFile();

D
dapan 已提交
944
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
945

946
  initQueryModuleMsgHandle();
D
ut test  
dapan1121 已提交
947

S
Shengliang Guan 已提交
948 949
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
950 951
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
952

D
dapan1121 已提交
953
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
954
  ASSERT_EQ(code, 0);
955

H
Hongze Cheng 已提交
956
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
957 958 959
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

D
dapan1121 已提交
960
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
961
  ASSERT_EQ(code, 0);
D
dapan1121 已提交
962
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
963
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
964

D
dapan1121 已提交
965
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
wafwerar's avatar
wafwerar 已提交
966
    taosMsleep(50);
D
dapan 已提交
967
  }
H
Hongze Cheng 已提交
968

D
dapan 已提交
969
  ctgTestSetRspTableMeta();
D
dapan1121 已提交
970 971

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
972
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
973 974 975
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
D
dapan1121 已提交
976
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
977 978 979 980 981 982 983
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
984
  while (true) {
D
dapan1121 已提交
985
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
986
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
987
      taosMsleep(50);
D
dapan 已提交
988 989 990
    } else {
      break;
    }
D
dapan 已提交
991 992
  }

D
dapan1121 已提交
993
  tableMeta = NULL;
D
dapan1121 已提交
994
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
995 996 997 998 999 1000 1001 1002 1003 1004
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

H
Hongze Cheng 已提交
1005
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
1006
  SSTableVersion *stb = NULL;
H
Hongze Cheng 已提交
1007 1008
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t         i = 0;
D
dapan1121 已提交
1009 1010 1011 1012 1013 1014
  while (i < 5) {
    ++i;
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
    ASSERT_EQ(code, 0);
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
    ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
1015

D
dapan1121 已提交
1016
    if (dbNum) {
S
Shengliang Guan 已提交
1017
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
wafwerar's avatar
wafwerar 已提交
1018
      taosMemoryFree(dbs);
D
dapan1121 已提交
1019 1020 1021 1022 1023 1024
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
1025
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
wafwerar's avatar
wafwerar 已提交
1026
      taosMemoryFree(stb);
D
dapan1121 已提交
1027 1028 1029 1030 1031 1032 1033
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
wafwerar's avatar
wafwerar 已提交
1034
    taosSsleep(2);
D
dapan1121 已提交
1035
  }
S
Shengliang Guan 已提交
1036

D
dapan1121 已提交
1037 1038 1039
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 0);

D
dapan1121 已提交
1040
  catalogDestroy();
D
dapan 已提交
1041
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1042 1043
}

D
dapan 已提交
1044
TEST(tableMeta, childTableCase) {
H
Hongze Cheng 已提交
1045
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1046 1047
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1048
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1049

D
dapan1121 已提交
1050 1051
  ctgTestInitLogFile();

D
dapan 已提交
1052
  ctgTestSetRspDbVgroupsAndChildMeta();
D
dapan1121 已提交
1053 1054 1055

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
1056
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
1057 1058
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
1059

D
dapan1121 已提交
1060
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
1061 1062
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1063
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
1064 1065
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
D
dapan1121 已提交
1066 1067

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1068
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1079
  while (true) {
D
dapan1121 已提交
1080
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1081
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1082
      taosMsleep(50);
D
dapan 已提交
1083 1084 1085
    } else {
      break;
    }
D
dapan 已提交
1086 1087
  }

D
dapan1121 已提交
1088
  tableMeta = NULL;
D
dapan1121 已提交
1089
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

wafwerar's avatar
wafwerar 已提交
1100
  taosMemoryFreeClear(tableMeta);
H
Haojun Liao 已提交
1101 1102

  strcpy(n.tname, ctgTestSTablename);
D
dapan1121 已提交
1103
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

H
Hongze Cheng 已提交
1114
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
1115
  SSTableVersion *stb = NULL;
H
Hongze Cheng 已提交
1116 1117
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t         i = 0;
D
dapan1121 已提交
1118 1119 1120 1121 1122 1123
  while (i < 5) {
    ++i;
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
    ASSERT_EQ(code, 0);
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
    ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
1124

D
dapan1121 已提交
1125
    if (dbNum) {
S
Shengliang Guan 已提交
1126
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
wafwerar's avatar
wafwerar 已提交
1127
      taosMemoryFree(dbs);
D
dapan1121 已提交
1128 1129 1130 1131 1132 1133
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
S
Shengliang Guan 已提交
1134
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
wafwerar's avatar
wafwerar 已提交
1135
      taosMemoryFree(stb);
D
dapan1121 已提交
1136 1137 1138 1139 1140 1141 1142
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
wafwerar's avatar
wafwerar 已提交
1143
    taosSsleep(2);
D
dapan1121 已提交
1144
  }
S
Shengliang Guan 已提交
1145

D
dapan1121 已提交
1146 1147 1148
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);

D
dapan1121 已提交
1149
  catalogDestroy();
D
dapan 已提交
1150
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1151 1152
}

D
dapan 已提交
1153
TEST(tableMeta, superTableCase) {
H
Hongze Cheng 已提交
1154
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1155 1156
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1157
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1158

D
dapan 已提交
1159
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1160 1161 1162

  initQueryModuleMsgHandle();

D
dapan1121 已提交
1163 1164 1165
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
1166
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
1167
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
1168 1169
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1170
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
1171 1172
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan1121 已提交
1173 1174

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1175
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1176 1177 1178 1179 1180
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1181 1182
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1183 1184 1185 1186 1187
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1188
  while (true) {
D
dapan1121 已提交
1189
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1190
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1191
      taosMsleep(50);
D
dapan 已提交
1192 1193 1194
    } else {
      break;
    }
D
dapan 已提交
1195 1196 1197
  }

  ctgTestSetRspCTableMeta();
D
dapan1121 已提交
1198 1199

  tableMeta = NULL;
H
Haojun Liao 已提交
1200 1201 1202

  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
D
dapan1121 已提交
1203
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1214
  while (true) {
D
dapan1121 已提交
1215
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1216
    if (2 != n) {
wafwerar's avatar
wafwerar 已提交
1217
      taosMsleep(50);
D
dapan 已提交
1218 1219 1220
    } else {
      break;
    }
D
dapan 已提交
1221 1222
  }

D
dapan1121 已提交
1223
  tableMeta = NULL;
D
dapan1121 已提交
1224
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

H
Hongze Cheng 已提交
1235
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
1236
  SSTableVersion *stb = NULL;
H
Hongze Cheng 已提交
1237 1238
  uint32_t        dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t         i = 0;
D
dapan1121 已提交
1239 1240 1241 1242 1243 1244
  while (i < 5) {
    ++i;
    code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum);
    ASSERT_EQ(code, 0);
    code = catalogGetExpiredSTables(pCtg, &stb, &stbNum);
    ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
1245

D
dapan1121 已提交
1246
    if (dbNum) {
S
Shengliang Guan 已提交
1247
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
wafwerar's avatar
wafwerar 已提交
1248
      taosMemoryFree(dbs);
D
dapan1121 已提交
1249 1250 1251 1252 1253 1254
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
1255
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
S
Shengliang Guan 已提交
1256

wafwerar's avatar
wafwerar 已提交
1257
      taosMemoryFree(stb);
D
dapan1121 已提交
1258 1259 1260 1261 1262 1263 1264
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
wafwerar's avatar
wafwerar 已提交
1265
    taosSsleep(2);
D
dapan1121 已提交
1266
  }
S
Shengliang Guan 已提交
1267

D
dapan1121 已提交
1268 1269
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);
D
dapan1121 已提交
1270 1271

  catalogDestroy();
D
dapan 已提交
1272
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1273
}
1274

D
dapan1121 已提交
1275
TEST(tableMeta, rmStbMeta) {
H
Hongze Cheng 已提交
1276
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1277 1278
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1279
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1280 1281 1282

  ctgTestInitLogFile();

D
dapan 已提交
1283
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1294
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1295 1296 1297 1298
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1299
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1300 1301 1302 1303 1304
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1305 1306
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1307 1308 1309 1310 1311
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1312
  while (true) {
D
dapan1121 已提交
1313
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1314
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1315
      taosMsleep(50);
D
dapan 已提交
1316 1317 1318
    } else {
      break;
    }
D
dapan 已提交
1319 1320
  }

D
dapan1121 已提交
1321
  code = catalogRemoveStbMeta(pCtg, "1.db1", ctgTestDbId, ctgTestSTablename, ctgTestSuid);
D
dapan1121 已提交
1322 1323
  ASSERT_EQ(code, 0);

D
dapan 已提交
1324
  while (true) {
D
dapan1121 已提交
1325 1326
    int32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
    int32_t m = ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM);
D
dapan 已提交
1327
    if (n || m) {
wafwerar's avatar
wafwerar 已提交
1328
      taosMsleep(50);
D
dapan 已提交
1329 1330 1331
    } else {
      break;
    }
D
dapan 已提交
1332 1333
  }

D
dapan1121 已提交
1334 1335 1336 1337 1338
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 0);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0);
S
Shengliang Guan 已提交
1339

D
dapan1121 已提交
1340
  catalogDestroy();
D
dapan 已提交
1341
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
1342 1343 1344
}

TEST(tableMeta, updateStbMeta) {
H
Hongze Cheng 已提交
1345
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1346 1347
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1348
  SVgroupInfo       vgInfo = {0};
D
dapan1121 已提交
1349 1350 1351

  ctgTestInitLogFile();

D
dapan 已提交
1352
  ctgTestSetRspDbVgroupsAndSuperMeta();
D
dapan1121 已提交
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1363
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1364 1365 1366 1367
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1368
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1369 1370 1371 1372 1373
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1374 1375
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1376 1377 1378 1379 1380
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

D
dapan 已提交
1381
  while (true) {
D
dapan1121 已提交
1382
    uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
D
dapan 已提交
1383
    if (0 == n) {
wafwerar's avatar
wafwerar 已提交
1384
      taosMsleep(50);
D
dapan 已提交
1385 1386 1387
    } else {
      break;
    }
D
dapan 已提交
1388 1389
  }

wafwerar's avatar
wafwerar 已提交
1390
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1391 1392 1393 1394

  STableMetaRsp rsp = {0};
  ctgTestBuildSTableMetaRsp(&rsp);

D
dapan1121 已提交
1395
  code = catalogUpdateTableMeta(pCtg, &rsp);
D
dapan1121 已提交
1396
  ASSERT_EQ(code, 0);
wafwerar's avatar
wafwerar 已提交
1397
  taosMemoryFreeClear(rsp.pSchemas);
D
dapan1121 已提交
1398

D
dapan 已提交
1399 1400
  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1401
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan 已提交
1402
    if (n != 3) {
wafwerar's avatar
wafwerar 已提交
1403
      taosMsleep(50);
D
dapan 已提交
1404 1405 1406 1407 1408
    } else {
      break;
    }
  }

D
dapan1121 已提交
1409 1410 1411 1412 1413
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
  ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 1);
D
dapan1121 已提交
1414

D
dapan1121 已提交
1415
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1416 1417 1418 1419 1420
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion + 1);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion + 1);
D
dapan1121 已提交
1421 1422
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1423 1424 1425 1426 1427
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1 + 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

wafwerar's avatar
wafwerar 已提交
1428
  taosMemoryFreeClear(tableMeta);
S
Shengliang Guan 已提交
1429

D
dapan1121 已提交
1430
  catalogDestroy();
D
dapan 已提交
1431
  memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat));
D
dapan1121 已提交
1432 1433
}

D
dapan1121 已提交
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
TEST(getIndexInfo, notExists) {
  struct SCatalog  *pCtg = NULL;
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1;
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_INDEXINFO_E;

  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

  SIndexInfo info;
  code = catalogGetIndexMeta(pCtg, mockPointer, "index1", &info);
  ASSERT_TRUE(code != 0);
}

D
dapan1121 已提交
1461
TEST(refreshGetMeta, normal2normal) {
H
Hongze Cheng 已提交
1462
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1463 1464
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1465 1466
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1467 1468 1469 1470 1471 1472 1473 1474

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_TBMETA;
H
Hongze Cheng 已提交
1475

D
dapan1121 已提交
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1488
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1489 1490 1491
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

D
dapan1121 已提交
1492
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1493 1494
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1495
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1496 1497 1498

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1499
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1500 1501 1502
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1503
    taosMsleep(50);
D
dapan1121 已提交
1504 1505 1506
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1507
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1508 1509 1510
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1511
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1512 1513 1514 1515 1516 1517
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1518
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1519

D
dapan1121 已提交
1520
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1521
    taosMsleep(50);
D
dapan1121 已提交
1522 1523
  }

D
dapan1121 已提交
1524
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1525 1526 1527
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1528
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1529 1530 1531 1532 1533 1534
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1535
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1536 1537 1538 1539 1540 1541

  catalogDestroy();
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
}

TEST(refreshGetMeta, normal2notexist) {
H
Hongze Cheng 已提交
1542
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1543 1544
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1545 1546
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1547 1548 1549 1550 1551 1552 1553 1554

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_TBMETA_NOT_EXIST;
H
Hongze Cheng 已提交
1555

D
dapan1121 已提交
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1568
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1569 1570 1571
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

D
dapan1121 已提交
1572
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1573 1574
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1575
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1576 1577 1578

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1579
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1580 1581 1582
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1583
    taosMsleep(50);
D
dapan1121 已提交
1584 1585 1586
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1587
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1588 1589 1590
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1591
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1592 1593 1594 1595 1596 1597
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1598
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1599

D
dapan1121 已提交
1600
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1601
    taosMsleep(50);
D
dapan1121 已提交
1602 1603
  }

D
dapan1121 已提交
1604
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1605 1606 1607 1608 1609 1610 1611 1612
  ASSERT_EQ(code, CTG_ERR_CODE_TABLE_NOT_EXIST);
  ASSERT_TRUE(tableMeta == NULL);

  catalogDestroy();
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
}

TEST(refreshGetMeta, normal2child) {
H
Hongze Cheng 已提交
1613
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1614 1615
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1616 1617
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1618 1619 1620 1621 1622 1623 1624 1625 1626

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_CTBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
1627

D
dapan1121 已提交
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1640
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1641 1642 1643 1644 1645
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentCTableName = ctgTestTablename;
  ctgTestCurrentSTableName = ctgTestSTablename;

D
dapan1121 已提交
1646
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1647 1648
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1649
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1650 1651 1652

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1653
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1654 1655 1656
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1657
    taosMsleep(50);
D
dapan1121 已提交
1658 1659 1660
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1661
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1662 1663 1664
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 8);
  ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE);
H
Hongze Cheng 已提交
1665
  ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1);
D
dapan1121 已提交
1666 1667 1668 1669 1670 1671
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1672
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1673

D
dapan1121 已提交
1674
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1675
    taosMsleep(50);
D
dapan1121 已提交
1676 1677
  }

D
dapan1121 已提交
1678
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1679 1680 1681 1682 1683 1684 1685 1686 1687
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1688
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1689 1690 1691 1692 1693 1694 1695

  catalogDestroy();
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

D
dapan1121 已提交
1696

D
dapan1121 已提交
1697
TEST(refreshGetMeta, stable2child) {
H
Hongze Cheng 已提交
1698
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1699 1700
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1701 1702
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1703 1704 1705 1706 1707 1708 1709 1710 1711 1712

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_CTBMETA;
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
1713

D
dapan1121 已提交
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1726
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1727 1728 1729 1730 1731
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentSTableName = ctgTestTablename;
  ctgTestCurrentCTableName = ctgTestTablename;

D
dapan1121 已提交
1732
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1733 1734
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1735
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1736 1737 1738

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1739
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1740 1741 1742
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1743
    taosMsleep(50);
D
dapan1121 已提交
1744 1745 1746
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1747
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1748 1749 1750 1751 1752
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1753 1754
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1755 1756 1757 1758
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1759
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1760

D
dapan1121 已提交
1761
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1762
    taosMsleep(50);
D
dapan1121 已提交
1763 1764 1765
  }

  ctgTestCurrentSTableName = ctgTestSTablename;
D
dapan1121 已提交
1766
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1767 1768 1769 1770 1771 1772 1773 1774 1775
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1776
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1777 1778 1779 1780 1781 1782 1783 1784

  catalogDestroy();
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

TEST(refreshGetMeta, stable2stable) {
H
Hongze Cheng 已提交
1785
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1786 1787
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1788 1789
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
1800

D
dapan1121 已提交
1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812
  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1813
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1814 1815 1816 1817
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentSTableName = ctgTestTablename;

D
dapan1121 已提交
1818
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1819 1820
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1821
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1822 1823 1824

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1825
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1826 1827 1828
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1829
    taosMsleep(50);
D
dapan1121 已提交
1830 1831 1832
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1833
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1834 1835 1836 1837 1838
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1839 1840
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1841 1842 1843 1844
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1845
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1846

D
dapan1121 已提交
1847
  while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1848
    taosMsleep(50);
D
dapan1121 已提交
1849 1850
  }

D
dapan1121 已提交
1851
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1852 1853 1854 1855 1856
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1857 1858
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1859 1860 1861 1862
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1863
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1864 1865 1866 1867 1868 1869 1870 1871

  catalogDestroy();
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

TEST(refreshGetMeta, child2stable) {
H
Hongze Cheng 已提交
1872
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1873 1874
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1875 1876
  SVgroupInfo       vgInfo = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
1877 1878 1879 1880 1881 1882 1883 1884 1885 1886

  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_CTBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[4] = CTGT_RSP_STBMETA;
H
Hongze Cheng 已提交
1887

D
dapan1121 已提交
1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899
  ctgTestSetRspByIdx();

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1900
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
1901 1902 1903 1904 1905
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
  ctgTestCurrentCTableName = ctgTestTablename;
  ctgTestCurrentSTableName = ctgTestSTablename;

D
dapan1121 已提交
1906
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
1907 1908
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
1909
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
1910 1911 1912

  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
1913
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
1914 1915 1916
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
1917
    taosMsleep(50);
D
dapan1121 已提交
1918 1919 1920
  }

  STableMeta *tableMeta = NULL;
D
dapan1121 已提交
1921
  code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
1922 1923 1924 1925 1926 1927 1928 1929 1930
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 9);
  ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1931
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1932

D
dapan1121 已提交
1933
  while (2 != ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM)) {
wafwerar's avatar
wafwerar 已提交
1934
    taosMsleep(50);
D
dapan1121 已提交
1935 1936 1937
  }

  ctgTestCurrentSTableName = ctgTestTablename;
D
dapan1121 已提交
1938
  code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
1939 1940 1941 1942 1943
  ASSERT_EQ(code, 0);
  ASSERT_EQ(tableMeta->vgId, 0);
  ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
  ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
  ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
D
dapan1121 已提交
1944 1945
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
1946 1947 1948 1949
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
wafwerar's avatar
wafwerar 已提交
1950
  taosMemoryFreeClear(tableMeta);
D
dapan1121 已提交
1951 1952 1953 1954 1955 1956 1957

  catalogDestroy();
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
  ctgTestCurrentCTableName = NULL;
  ctgTestCurrentSTableName = NULL;
}

D
dapan 已提交
1958
TEST(tableDistVgroup, normalTable) {
H
Hongze Cheng 已提交
1959
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1960 1961
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
1962 1963
  SVgroupInfo      *vgInfo = NULL;
  SArray           *vgList = NULL;
D
dapan 已提交
1964

D
dapan 已提交
1965 1966 1967 1968 1969 1970 1971
  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_VGINFO;
H
Hongze Cheng 已提交
1972

D
dapan 已提交
1973
  ctgTestSetRspByIdx();
D
dapan 已提交
1974 1975 1976

  initQueryModuleMsgHandle();

D
dapan1121 已提交
1977 1978 1979
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
1980 1981
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
1982
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
1983 1984
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
1985
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
1986 1987
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
D
dapan 已提交
1988

D
dapan1121 已提交
1989
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
1990
  ASSERT_TRUE(code != 0);
D
dapan 已提交
1991 1992

  catalogDestroy();
D
dapan 已提交
1993
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan 已提交
1994 1995 1996
}

TEST(tableDistVgroup, childTableCase) {
H
Hongze Cheng 已提交
1997
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
1998 1999
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2000 2001
  SVgroupInfo      *vgInfo = NULL;
  SArray           *vgList = NULL;
D
dapan 已提交
2002

D
dapan 已提交
2003 2004 2005 2006 2007 2008 2009 2010
  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_CTBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_VGINFO;
H
Hongze Cheng 已提交
2011

D
dapan 已提交
2012
  ctgTestSetRspByIdx();
D
dapan 已提交
2013 2014 2015

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
2016 2017
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan 已提交
2018 2019 2020 2021 2022 2023
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2024
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
2025 2026 2027
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);

D
dapan1121 已提交
2028
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
2029
  ASSERT_TRUE(code != 0);
D
dapan 已提交
2030 2031

  catalogDestroy();
D
dapan 已提交
2032
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan 已提交
2033 2034 2035
}

TEST(tableDistVgroup, superTableCase) {
H
Hongze Cheng 已提交
2036
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2037 2038
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2039 2040
  SVgroupInfo      *vgInfo = NULL;
  SArray           *vgList = NULL;
D
dapan 已提交
2041

D
dapan 已提交
2042 2043 2044 2045 2046 2047 2048 2049 2050
  ctgTestInitLogFile();

  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[2] = CTGT_RSP_STBMETA;
  ctgTestRspFunc[3] = CTGT_RSP_VGINFO;

H
Hongze Cheng 已提交
2051
  ctgTestSetRspByIdx();
D
dapan 已提交
2052 2053 2054

  initQueryModuleMsgHandle();

D
dapan1121 已提交
2055 2056 2057
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
2058
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
2059
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
2060 2061
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2062
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
H
Haojun Liao 已提交
2063 2064
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan 已提交
2065

D
dapan1121 已提交
2066
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan 已提交
2067 2068 2069 2070
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 1);
L
Liu Jicong 已提交
2071
  ASSERT_EQ(vgInfo->epSet.numOfEps, 1);
D
dapan 已提交
2072 2073
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1);
  ASSERT_EQ(vgInfo->vgId, 2);
L
Liu Jicong 已提交
2074
  ASSERT_EQ(vgInfo->epSet.numOfEps, 2);
D
dapan 已提交
2075 2076
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2);
  ASSERT_EQ(vgInfo->vgId, 3);
L
Liu Jicong 已提交
2077
  ASSERT_EQ(vgInfo->epSet.numOfEps, 3);
D
dapan 已提交
2078 2079

  catalogDestroy();
D
dapan 已提交
2080
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan 已提交
2081 2082
}

D
dapan1121 已提交
2083
TEST(dbVgroup, getSetDbVgroupCase) {
H
Hongze Cheng 已提交
2084
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2085 2086
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2087 2088 2089 2090
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo        *dbVgroup = NULL;
  SArray           *vgList = NULL;
D
dapan1121 已提交
2091

D
dapan 已提交
2092 2093
  ctgTestInitLogFile();

D
dapan 已提交
2094 2095 2096 2097 2098 2099 2100
  memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc));
  ctgTestRspIdx = 0;
  ctgTestRspFunc[0] = CTGT_RSP_VGINFO;
  ctgTestRspFunc[1] = CTGT_RSP_TBMETA;

  ctgTestSetRspByIdx();

D
dapan1121 已提交
2101 2102
  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
2103 2104
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
2105 2106 2107 2108 2109 2110
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2111
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2112 2113 2114
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

2115
  code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList);
D
dapan1121 已提交
2116 2117
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
S
Shengliang Guan 已提交
2118

D
dapan1121 已提交
2119 2120
  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
2121
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan1121 已提交
2122 2123 2124
    if (n > 0) {
      break;
    }
wafwerar's avatar
wafwerar 已提交
2125
    taosMsleep(50);
D
dapan 已提交
2126 2127
  }

D
dapan1121 已提交
2128
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
2129 2130
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
L
Liu Jicong 已提交
2131
  ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
D
dapan1121 已提交
2132

D
dapan1121 已提交
2133
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
2134
  ASSERT_TRUE(code != 0);
D
dapan1121 已提交
2135 2136

  ctgTestBuildDBVgroup(&dbVgroup);
D
dapan1121 已提交
2137
  code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup);
D
dapan1121 已提交
2138 2139
  ASSERT_EQ(code, 0);

D
dapan 已提交
2140 2141
  while (true) {
    uint64_t n = 0;
D
dapan1121 已提交
2142
    ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n);
D
dapan 已提交
2143
    if (n != 3) {
wafwerar's avatar
wafwerar 已提交
2144
      taosMsleep(50);
D
dapan 已提交
2145 2146 2147 2148 2149
    } else {
      break;
    }
  }

D
dapan1121 已提交
2150
  code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo);
D
dapan1121 已提交
2151 2152
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 7);
L
Liu Jicong 已提交
2153
  ASSERT_EQ(vgInfo.epSet.numOfEps, 2);
D
dapan1121 已提交
2154

D
dapan1121 已提交
2155
  code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList);
D
dapan1121 已提交
2156
  ASSERT_TRUE(code != 0);
S
Shengliang Guan 已提交
2157

D
dapan1121 已提交
2158
  catalogDestroy();
D
dapan 已提交
2159
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
2160 2161
}

D
dapan1121 已提交
2162
TEST(multiThread, getSetRmSameDbVgroup) {
H
Hongze Cheng 已提交
2163
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2164 2165
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2166 2167 2168 2169
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2170
  ctgTestStop = false;
D
dapan1121 已提交
2171 2172

  ctgTestInitLogFile();
S
Shengliang Guan 已提交
2173

D
dapan 已提交
2174
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
2175 2176 2177

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
2178 2179
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
2180 2181 2182 2183 2184 2185
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2186
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2187 2188 2189
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

wafwerar's avatar
wafwerar 已提交
2190 2191
  TdThreadAttr thattr;
  taosThreadAttrInit(&thattr);
D
dapan1121 已提交
2192

wafwerar's avatar
wafwerar 已提交
2193 2194
  TdThread thread1, thread2;
  taosThreadCreate(&(thread1), &thattr, ctgTestSetSameDbVgroupThread, pCtg);
D
dapan1121 已提交
2195

wafwerar's avatar
wafwerar 已提交
2196
  taosSsleep(1);
wafwerar's avatar
wafwerar 已提交
2197
  taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
D
dapan1121 已提交
2198 2199 2200

  while (true) {
    if (ctgTestDeadLoop) {
wafwerar's avatar
wafwerar 已提交
2201
      taosSsleep(1);
D
dapan1121 已提交
2202
    } else {
wafwerar's avatar
wafwerar 已提交
2203
      taosSsleep(ctgTestMTRunSec);
D
dapan1121 已提交
2204 2205 2206
      break;
    }
  }
S
Shengliang Guan 已提交
2207

D
dapan1121 已提交
2208
  ctgTestStop = true;
wafwerar's avatar
wafwerar 已提交
2209
  taosSsleep(1);
S
Shengliang Guan 已提交
2210

D
dapan1121 已提交
2211
  catalogDestroy();
D
dapan 已提交
2212
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
2213 2214
}

D
dapan1121 已提交
2215
TEST(multiThread, getSetRmDiffDbVgroup) {
H
Hongze Cheng 已提交
2216
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2217 2218
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2219 2220 2221 2222
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2223 2224 2225 2226
  ctgTestStop = false;

  ctgTestInitLogFile();

D
dapan 已提交
2227
  ctgTestSetRspDbVgroups();
D
dapan1121 已提交
2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238

  initQueryModuleMsgHandle();

  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2239
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2240 2241 2242
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

wafwerar's avatar
wafwerar 已提交
2243 2244
  TdThreadAttr thattr;
  taosThreadAttrInit(&thattr);
D
dapan1121 已提交
2245

wafwerar's avatar
wafwerar 已提交
2246 2247
  TdThread thread1, thread2;
  taosThreadCreate(&(thread1), &thattr, ctgTestSetDiffDbVgroupThread, pCtg);
D
dapan1121 已提交
2248

wafwerar's avatar
wafwerar 已提交
2249
  taosSsleep(1);
wafwerar's avatar
wafwerar 已提交
2250
  taosThreadCreate(&(thread2), &thattr, ctgTestGetDbVgroupThread, pCtg);
D
dapan1121 已提交
2251 2252 2253

  while (true) {
    if (ctgTestDeadLoop) {
wafwerar's avatar
wafwerar 已提交
2254
      taosSsleep(1);
D
dapan1121 已提交
2255
    } else {
wafwerar's avatar
wafwerar 已提交
2256
      taosSsleep(ctgTestMTRunSec);
D
dapan1121 已提交
2257 2258 2259 2260 2261
      break;
    }
  }

  ctgTestStop = true;
wafwerar's avatar
wafwerar 已提交
2262
  taosSsleep(1);
D
dapan1121 已提交
2263 2264

  catalogDestroy();
D
dapan 已提交
2265
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
2266 2267
}

D
dapan1121 已提交
2268
TEST(multiThread, ctableMeta) {
H
Hongze Cheng 已提交
2269
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2270 2271
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2272 2273 2274 2275
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2276
  ctgTestStop = false;
D
dapan1121 已提交
2277

D
dapan 已提交
2278 2279
  ctgTestInitLogFile();

D
dapan 已提交
2280
  ctgTestSetRspDbVgroupsAndChildMeta();
D
dapan1121 已提交
2281 2282 2283

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
2284 2285
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);

D
dapan1121 已提交
2286 2287 2288 2289 2290 2291
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2292
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2293 2294 2295
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

wafwerar's avatar
wafwerar 已提交
2296 2297
  TdThreadAttr thattr;
  taosThreadAttrInit(&thattr);
D
dapan1121 已提交
2298

wafwerar's avatar
wafwerar 已提交
2299 2300
  TdThread thread1, thread2;
  taosThreadCreate(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
wafwerar's avatar
wafwerar 已提交
2301
  taosSsleep(1);
wafwerar's avatar
wafwerar 已提交
2302
  taosThreadCreate(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
D
dapan1121 已提交
2303 2304 2305

  while (true) {
    if (ctgTestDeadLoop) {
wafwerar's avatar
wafwerar 已提交
2306
      taosSsleep(1);
D
dapan1121 已提交
2307
    } else {
wafwerar's avatar
wafwerar 已提交
2308
      taosSsleep(ctgTestMTRunSec);
D
dapan1121 已提交
2309 2310 2311
      break;
    }
  }
S
Shengliang Guan 已提交
2312

D
dapan1121 已提交
2313
  ctgTestStop = true;
wafwerar's avatar
wafwerar 已提交
2314
  taosSsleep(2);
S
Shengliang Guan 已提交
2315

D
dapan1121 已提交
2316
  catalogDestroy();
D
dapan 已提交
2317
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
2318
}
D
dapan 已提交
2319

D
dapan1121 已提交
2320
TEST(rentTest, allRent) {
H
Hongze Cheng 已提交
2321
  struct SCatalog  *pCtg = NULL;
D
dapan1121 已提交
2322 2323
  SRequestConnInfo connInfo = {0};  
  SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
H
Hongze Cheng 已提交
2324 2325 2326 2327
  SVgroupInfo       vgInfo = {0};
  SVgroupInfo      *pvgInfo = NULL;
  SDBVgInfo         dbVgroup = {0};
  SArray           *vgList = NULL;
D
dapan1121 已提交
2328
  ctgTestStop = false;
H
Hongze Cheng 已提交
2329
  SDbVgVersion   *dbs = NULL;
D
dapan1121 已提交
2330
  SSTableVersion *stable = NULL;
H
Hongze Cheng 已提交
2331
  uint32_t        num = 0;
D
dapan1121 已提交
2332

D
dapan 已提交
2333 2334
  ctgTestInitLogFile();

D
dapan 已提交
2335
  ctgTestSetRspDbVgroupsAndMultiSuperMeta();
D
dapan1121 已提交
2336 2337 2338 2339 2340 2341 2342 2343 2344

  initQueryModuleMsgHandle();

  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

  code = catalogGetHandle(ctgTestClusterId, &pCtg);
  ASSERT_EQ(code, 0);

H
Hongze Cheng 已提交
2345
  SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}};
D
dapan1121 已提交
2346 2347 2348 2349 2350 2351
  strcpy(n.dbname, "db1");

  for (int32_t i = 1; i <= 10; ++i) {
    sprintf(n.tname, "%s_%d", ctgTestSTablename, i);

    STableMeta *tableMeta = NULL;
D
dapan1121 已提交
2352
    code = catalogGetSTableMeta(pCtg, mockPointer, &n, &tableMeta);
D
dapan1121 已提交
2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363
    ASSERT_EQ(code, 0);
    ASSERT_EQ(tableMeta->vgId, 0);
    ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE);
    ASSERT_EQ(tableMeta->sversion, ctgTestSVersion);
    ASSERT_EQ(tableMeta->tversion, ctgTestTVersion);
    ASSERT_EQ(tableMeta->uid, ctgTestSuid + i);
    ASSERT_EQ(tableMeta->suid, ctgTestSuid + i);
    ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
    ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
    ASSERT_EQ(tableMeta->tableInfo.precision, 1);
    ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
S
Shengliang Guan 已提交
2364

D
dapan1121 已提交
2365
    while (ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) {
wafwerar's avatar
wafwerar 已提交
2366
      taosMsleep(50);
D
dapan 已提交
2367 2368
    }

D
dapan1121 已提交
2369 2370 2371 2372
    code = catalogGetExpiredDBs(pCtg, &dbs, &num);
    ASSERT_EQ(code, 0);
    printf("%d - expired dbNum:%d\n", i, num);
    if (dbs) {
S
Shengliang Guan 已提交
2373
      printf("%d - expired dbId:%" PRId64 ", vgVersion:%d\n", i, dbs->dbId, dbs->vgVersion);
wafwerar's avatar
wafwerar 已提交
2374
      taosMemoryFree(dbs);
D
dapan1121 已提交
2375 2376
      dbs = NULL;
    }
S
Shengliang Guan 已提交
2377

D
dapan1121 已提交
2378 2379 2380 2381 2382
    code = catalogGetExpiredSTables(pCtg, &stable, &num);
    ASSERT_EQ(code, 0);
    printf("%d - expired stableNum:%d\n", i, num);
    if (stable) {
      for (int32_t n = 0; n < num; ++n) {
S
Shengliang Guan 已提交
2383 2384
        printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid,
               stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion);
D
dapan1121 已提交
2385
      }
wafwerar's avatar
wafwerar 已提交
2386
      taosMemoryFree(stable);
D
dapan1121 已提交
2387 2388 2389
      stable = NULL;
    }
    printf("*************************************************\n");
S
Shengliang Guan 已提交
2390

wafwerar's avatar
wafwerar 已提交
2391
    taosSsleep(2);
D
dapan1121 已提交
2392
  }
S
Shengliang Guan 已提交
2393

D
dapan1121 已提交
2394
  catalogDestroy();
D
dapan 已提交
2395
  memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
D
dapan1121 已提交
2396 2397
}

D
dapan1121 已提交
2398

S
Shengliang Guan 已提交
2399
int main(int argc, char **argv) {
2400 2401 2402
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
D
dapan1121 已提交
2403

D
dapan1121 已提交
2404
#pragma GCC diagnostic pop