catalogTests.cpp 37.1 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 <tglobal.h>
#include <iostream>
S
Shengliang Guan 已提交
19
#include "os.h"
20

S
Shengliang Guan 已提交
21 22
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
23 24 25
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
S
Shengliang Guan 已提交
26
#pragma GCC diagnostic ignored "-Wformat"
27

S
Shengliang Guan 已提交
28 29 30
#include "addr_any.h"
#include "catalog.h"
#include "stub.h"
D
dapan1121 已提交
31
#include "taos.h"
32
#include "tdef.h"
D
dapan1121 已提交
33
#include "tep.h"
D
ut test  
dapan1121 已提交
34
#include "trpc.h"
S
Shengliang Guan 已提交
35
#include "tvariant.h"
36

D
dapan1121 已提交
37
namespace {
38

S
Shengliang Guan 已提交
39 40
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
                                            int32_t *exist);
D
dapan1121 已提交
41 42
extern "C" int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output);

D
dapan 已提交
43
void ctgTestSetPrepareTableMeta();
D
dapan1121 已提交
44 45
void ctgTestSetPrepareCTableMeta();
void ctgTestSetPrepareSTableMeta();
D
dapan1121 已提交
46
void ctgTestSetPrepareMultiSTableMeta();
D
dapan1121 已提交
47

S
Shengliang Guan 已提交
48 49 50
bool    ctgTestStop = false;
bool    ctgTestEnableSleep = false;
bool    ctgTestDeadLoop = false;
D
dapan1121 已提交
51
int32_t ctgTestPrintNum = 200000;
D
dapan1121 已提交
52
int32_t ctgTestMTRunSec = 30;
D
dapan1121 已提交
53

D
dapan1121 已提交
54 55
int32_t ctgTestCurrentVgVersion = 0;
int32_t ctgTestVgVersion = 1;
D
dapan1121 已提交
56
int32_t ctgTestVgNum = 10;
D
dapan1121 已提交
57 58 59 60
int32_t ctgTestColNum = 2;
int32_t ctgTestTagNum = 1;
int32_t ctgTestSVersion = 1;
int32_t ctgTestTVersion = 1;
D
dapan1121 已提交
61
int32_t ctgTestSuid = 2;
D
dapan1121 已提交
62
uint64_t ctgTestDbId = 33;
D
dapan1121 已提交
63

64
uint64_t ctgTestClusterId = 0x1;
S
Shengliang Guan 已提交
65 66 67 68
char    *ctgTestDbname = "1.db1";
char    *ctgTestTablename = "table1";
char    *ctgTestCTablename = "ctable1";
char    *ctgTestSTablename = "stable1";
D
dapan1121 已提交
69

D
ut test  
dapan1121 已提交
70
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
S
Shengliang Guan 已提交
71
  SCreateDbReq *pReq = (SCreateDbReq *)rpcMallocCont(sizeof(SCreateDbReq));
D
ut test  
dapan1121 已提交
72 73 74 75 76 77 78 79
  strcpy(pReq->db, "1.db1");
  pReq->numOfVgroups = htonl(2);
  pReq->cacheBlockSize = htonl(16);
  pReq->totalBlocks = htonl(10);
  pReq->daysPerFile = htonl(10);
  pReq->daysToKeep0 = htonl(3650);
  pReq->daysToKeep1 = htonl(3650);
  pReq->daysToKeep2 = htonl(3650);
S
Shengliang Guan 已提交
80 81
  pReq->minRows = htonl(100);
  pReq->maxRows = htonl(4096);
D
ut test  
dapan1121 已提交
82 83 84 85 86 87 88 89 90 91
  pReq->commitTime = htonl(3600);
  pReq->fsyncPeriod = htonl(3000);
  pReq->walLevel = 1;
  pReq->precision = 0;
  pReq->compression = 2;
  pReq->replications = 1;
  pReq->quorum = 1;
  pReq->update = 0;
  pReq->cacheLastRow = 0;
  pReq->ignoreExist = 1;
S
Shengliang Guan 已提交
92

D
ut test  
dapan1121 已提交
93 94
  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
S
Shengliang Guan 已提交
95
  rpcMsg.contLen = sizeof(SCreateDbReq);
H
Hongze Cheng 已提交
96
  rpcMsg.msgType = TDMT_MND_CREATE_DB;
D
ut test  
dapan1121 已提交
97 98 99 100 101 102 103 104

  SRpcMsg rpcRsp = {0};

  rpcSendRecv(shandle, pEpSet, &rpcMsg, &rpcRsp);

  ASSERT_EQ(rpcRsp.code, 0);
}

D
dapan1121 已提交
105
void ctgTestInitLogFile() {
S
Shengliang Guan 已提交
106 107
  const char   *defaultLogFileNamePrefix = "taoslog";
  const int32_t maxLogFileNum = 10;
D
dapan1121 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

  tsAsyncLog = 0;

  char temp[128] = {0};
  sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
  if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
    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) {
  SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);

  SName sn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(sn.dbname, "db1");
  strcpy(sn.tname, ctgTestSTablename);

D
dapan 已提交
131 132 133 134
  char db[TSDB_DB_FNAME_LEN] = {0};
  tNameGetFullDbName(&cn, db);

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

D
dapan1121 已提交
137 138
  strcpy(output->ctbName, cn.tname);
  strcpy(output->tbName, sn.tname);
D
dapan1121 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152

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

  output->tbMeta = (STableMeta *)calloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum));
  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 已提交
153

D
dapan1121 已提交
154 155
  output->tbMeta->sversion = ctgTestSVersion;
  output->tbMeta->tversion = ctgTestTVersion;
S
Shengliang Guan 已提交
156

D
dapan1121 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  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
dapan 已提交
177
void ctgTestBuildDBVgroup(SDBVgroupInfo **pdbVgroup) {
D
dapan1121 已提交
178
  static int32_t vgVersion = ctgTestVgVersion + 1;
S
Shengliang Guan 已提交
179 180
  int32_t        vgNum = 0;
  SVgroupInfo    vgInfo = {0};
D
dapan 已提交
181
  SDBVgroupInfo *dbVgroup = (SDBVgroupInfo *)calloc(1, sizeof(SDBVgroupInfo));
S
Shengliang Guan 已提交
182

D
dapan1121 已提交
183
  dbVgroup->vgVersion = vgVersion++;
S
Shengliang Guan 已提交
184

D
dapan1121 已提交
185
  ctgTestCurrentVgVersion = dbVgroup->vgVersion;
S
Shengliang Guan 已提交
186

D
dapan1121 已提交
187
  dbVgroup->hashMethod = 0;
D
dapan1121 已提交
188
  dbVgroup->dbId = ctgTestDbId;
D
dapan1121 已提交
189
  dbVgroup->vgHash = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
D
dapan1121 已提交
190 191 192 193 194 195 196 197

  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;
H
Haojun Liao 已提交
198 199 200 201
    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 已提交
202 203 204 205
      strcpy(addr->fqdn, "a0");
      addr->port = htons(n + 22);
    }

D
dapan1121 已提交
206
    taosHashPut(dbVgroup->vgHash, &vgInfo.vgId, sizeof(vgInfo.vgId), &vgInfo, sizeof(vgInfo));
D
dapan1121 已提交
207
  }
D
dapan 已提交
208 209

  *pdbVgroup = dbVgroup;
D
dapan1121 已提交
210 211
}

D
dapan1121 已提交
212
void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
213
  SUseDbRsp *rspMsg = NULL;  // todo
D
dapan1121 已提交
214

S
Shengliang Guan 已提交
215
  pRsp->code = 0;
D
dapan1121 已提交
216 217 218 219
  pRsp->contLen = sizeof(SUseDbRsp) + ctgTestVgNum * sizeof(SVgroupInfo);
  pRsp->pCont = calloc(1, pRsp->contLen);
  rspMsg = (SUseDbRsp *)pRsp->pCont;
  strcpy(rspMsg->db, ctgTestDbname);
D
dapan1121 已提交
220 221
  rspMsg->vgVersion = htonl(ctgTestVgVersion);
  ctgTestCurrentVgVersion = ctgTestVgVersion;
D
dapan1121 已提交
222
  rspMsg->vgNum = htonl(ctgTestVgNum);
D
dapan1121 已提交
223
  rspMsg->hashMethod = 0;
D
dapan1121 已提交
224
  rspMsg->uid = htobe64(ctgTestDbId);
D
dapan1121 已提交
225 226

  SVgroupInfo *vg = NULL;
S
Shengliang Guan 已提交
227
  uint32_t     hashUnit = UINT32_MAX / ctgTestVgNum;
D
dapan1121 已提交
228 229 230
  for (int32_t i = 0; i < ctgTestVgNum; ++i) {
    vg = &rspMsg->vgroupInfo[i];

D
dapan1121 已提交
231 232 233
    vg->vgId = htonl(i + 1);
    vg->hashBegin = htonl(i * hashUnit);
    vg->hashEnd = htonl(hashUnit * (i + 1) - 1);
H
Haojun Liao 已提交
234 235 236 237
    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 已提交
238
      strcpy(addr->fqdn, "a0");
D
dapan1121 已提交
239
      addr->port = htons(n + 22);
D
dapan1121 已提交
240 241 242
    }
  }

D
dapan1121 已提交
243 244 245 246 247 248
  vg->hashEnd = htonl(UINT32_MAX);

  return;
}

void ctgTestPrepareTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
249
  STableMetaRsp *rspMsg = NULL;  // todo
D
dapan1121 已提交
250

S
Shengliang Guan 已提交
251
  pRsp->code = 0;
S
Shengliang Guan 已提交
252
  pRsp->contLen = sizeof(STableMetaRsp) + (ctgTestColNum + ctgTestTagNum) * sizeof(SSchema);
D
dapan1121 已提交
253
  pRsp->pCont = calloc(1, pRsp->contLen);
S
Shengliang Guan 已提交
254
  rspMsg = (STableMetaRsp *)pRsp->pCont;
D
dapan1121 已提交
255 256
  strcpy(rspMsg->dbFName, ctgTestDbname);
  strcpy(rspMsg->tbName, ctgTestTablename);
D
dapan1121 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270
  rspMsg->numOfTags = 0;
  rspMsg->numOfColumns = htonl(ctgTestColNum);
  rspMsg->precision = 1;
  rspMsg->tableType = TSDB_NORMAL_TABLE;
  rspMsg->update = 1;
  rspMsg->sversion = htonl(ctgTestSVersion);
  rspMsg->tversion = htonl(ctgTestTVersion);
  rspMsg->suid = 0;
  rspMsg->tuid = htobe64(0x0000000000000001);
  rspMsg->vgId = htonl(8);

  SSchema *s = NULL;
  s = &rspMsg->pSchema[0];
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
D
dapan1121 已提交
271
  s->colId = htonl(1);
D
dapan1121 已提交
272 273 274 275 276
  s->bytes = htonl(8);
  strcpy(s->name, "ts");

  s = &rspMsg->pSchema[1];
  s->type = TSDB_DATA_TYPE_INT;
D
dapan1121 已提交
277
  s->colId = htonl(2);
D
dapan1121 已提交
278 279
  s->bytes = htonl(4);
  strcpy(s->name, "col1");
S
Shengliang Guan 已提交
280

D
dapan1121 已提交
281 282 283 284
  return;
}

void ctgTestPrepareCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
285
  STableMetaRsp *rspMsg = NULL;  // todo
D
dapan1121 已提交
286

S
Shengliang Guan 已提交
287
  pRsp->code = 0;
S
Shengliang Guan 已提交
288
  pRsp->contLen = sizeof(STableMetaRsp) + (ctgTestColNum + ctgTestTagNum) * sizeof(SSchema);
D
dapan1121 已提交
289
  pRsp->pCont = calloc(1, pRsp->contLen);
S
Shengliang Guan 已提交
290
  rspMsg = (STableMetaRsp *)pRsp->pCont;
D
dapan1121 已提交
291 292 293
  strcpy(rspMsg->dbFName, ctgTestDbname);
  strcpy(rspMsg->tbName, ctgTestCTablename);
  strcpy(rspMsg->stbName, ctgTestSTablename);
D
dapan1121 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307
  rspMsg->numOfTags = htonl(ctgTestTagNum);
  rspMsg->numOfColumns = htonl(ctgTestColNum);
  rspMsg->precision = 1;
  rspMsg->tableType = TSDB_CHILD_TABLE;
  rspMsg->update = 1;
  rspMsg->sversion = htonl(ctgTestSVersion);
  rspMsg->tversion = htonl(ctgTestTVersion);
  rspMsg->suid = htobe64(0x0000000000000002);
  rspMsg->tuid = htobe64(0x0000000000000003);
  rspMsg->vgId = htonl(9);

  SSchema *s = NULL;
  s = &rspMsg->pSchema[0];
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
D
dapan1121 已提交
308
  s->colId = htonl(1);
D
dapan1121 已提交
309 310 311 312 313
  s->bytes = htonl(8);
  strcpy(s->name, "ts");

  s = &rspMsg->pSchema[1];
  s->type = TSDB_DATA_TYPE_INT;
D
dapan1121 已提交
314
  s->colId = htonl(2);
D
dapan1121 已提交
315 316 317 318 319
  s->bytes = htonl(4);
  strcpy(s->name, "col1s");

  s = &rspMsg->pSchema[2];
  s->type = TSDB_DATA_TYPE_BINARY;
D
dapan1121 已提交
320
  s->colId = htonl(3);
D
dapan1121 已提交
321 322 323 324 325 326 327
  s->bytes = htonl(12);
  strcpy(s->name, "tag1s");

  return;
}

void ctgTestPrepareSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
328
  STableMetaRsp *rspMsg = NULL;  // todo
D
dapan1121 已提交
329

S
Shengliang Guan 已提交
330
  pRsp->code = 0;
S
Shengliang Guan 已提交
331
  pRsp->contLen = sizeof(STableMetaRsp) + (ctgTestColNum + ctgTestTagNum) * sizeof(SSchema);
D
dapan1121 已提交
332
  pRsp->pCont = calloc(1, pRsp->contLen);
S
Shengliang Guan 已提交
333
  rspMsg = (STableMetaRsp *)pRsp->pCont;
D
dapan1121 已提交
334 335 336
  strcpy(rspMsg->dbFName, ctgTestDbname);
  strcpy(rspMsg->tbName, ctgTestSTablename);  
  strcpy(rspMsg->stbName, ctgTestSTablename);  
D
dapan1121 已提交
337 338 339 340 341 342 343
  rspMsg->numOfTags = htonl(ctgTestTagNum);
  rspMsg->numOfColumns = htonl(ctgTestColNum);
  rspMsg->precision = 1;
  rspMsg->tableType = TSDB_SUPER_TABLE;
  rspMsg->update = 1;
  rspMsg->sversion = htonl(ctgTestSVersion);
  rspMsg->tversion = htonl(ctgTestTVersion);
D
dapan1121 已提交
344 345
  rspMsg->suid = htobe64(ctgTestSuid);
  rspMsg->tuid = htobe64(ctgTestSuid);
D
dapan1121 已提交
346 347 348 349 350
  rspMsg->vgId = 0;

  SSchema *s = NULL;
  s = &rspMsg->pSchema[0];
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
D
dapan1121 已提交
351
  s->colId = htonl(1);
D
dapan1121 已提交
352 353 354 355 356
  s->bytes = htonl(8);
  strcpy(s->name, "ts");

  s = &rspMsg->pSchema[1];
  s->type = TSDB_DATA_TYPE_INT;
D
dapan1121 已提交
357
  s->colId = htonl(2);
D
dapan1121 已提交
358 359 360 361 362
  s->bytes = htonl(4);
  strcpy(s->name, "col1s");

  s = &rspMsg->pSchema[2];
  s->type = TSDB_DATA_TYPE_BINARY;
D
dapan1121 已提交
363
  s->colId = htonl(3);
D
dapan1121 已提交
364 365 366 367 368 369
  s->bytes = htonl(12);
  strcpy(s->name, "tag1s");

  return;
}

D
dapan1121 已提交
370
void ctgTestPrepareMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
S
Shengliang Guan 已提交
371
  STableMetaRsp *rspMsg = NULL;  // todo
D
dapan1121 已提交
372 373
  static int32_t idx = 1;

S
Shengliang Guan 已提交
374
  pRsp->code = 0;
S
Shengliang Guan 已提交
375
  pRsp->contLen = sizeof(STableMetaRsp) + (ctgTestColNum + ctgTestTagNum) * sizeof(SSchema);
D
dapan1121 已提交
376
  pRsp->pCont = calloc(1, pRsp->contLen);
S
Shengliang Guan 已提交
377
  rspMsg = (STableMetaRsp *)pRsp->pCont;
D
dapan1121 已提交
378
  strcpy(rspMsg->dbFName, ctgTestDbname);
D
dapan 已提交
379
  sprintf(rspMsg->tbName, "%s_%d", ctgTestSTablename, idx);
D
dapan1121 已提交
380
  sprintf(rspMsg->stbName, "%s_%d", ctgTestSTablename, idx);
D
dapan1121 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
  rspMsg->numOfTags = htonl(ctgTestTagNum);
  rspMsg->numOfColumns = htonl(ctgTestColNum);
  rspMsg->precision = 1;
  rspMsg->tableType = TSDB_SUPER_TABLE;
  rspMsg->update = 1;
  rspMsg->sversion = htonl(ctgTestSVersion);
  rspMsg->tversion = htonl(ctgTestTVersion);
  rspMsg->suid = htobe64(ctgTestSuid + idx);
  rspMsg->tuid = htobe64(ctgTestSuid + idx);
  rspMsg->vgId = 0;

  SSchema *s = NULL;
  s = &rspMsg->pSchema[0];
  s->type = TSDB_DATA_TYPE_TIMESTAMP;
  s->colId = htonl(1);
  s->bytes = htonl(8);
  strcpy(s->name, "ts");

  s = &rspMsg->pSchema[1];
  s->type = TSDB_DATA_TYPE_INT;
  s->colId = htonl(2);
  s->bytes = htonl(4);
  strcpy(s->name, "col1s");

  s = &rspMsg->pSchema[2];
  s->type = TSDB_DATA_TYPE_BINARY;
  s->colId = htonl(3);
  s->bytes = htonl(12);
  strcpy(s->name, "tag1s");

  ++idx;
S
Shengliang Guan 已提交
412

D
dapan1121 已提交
413 414 415
  return;
}

D
dapan 已提交
416 417
void ctgTestPrepareDbVgroupsAndNormalMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestPrepareDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
418

D
dapan 已提交
419
  ctgTestSetPrepareTableMeta();
S
Shengliang Guan 已提交
420

D
dapan 已提交
421 422 423 424 425
  return;
}

void ctgTestPrepareDbVgroupsAndChildMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestPrepareDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
426

D
dapan 已提交
427
  ctgTestSetPrepareCTableMeta();
S
Shengliang Guan 已提交
428

D
dapan 已提交
429 430 431 432 433
  return;
}

void ctgTestPrepareDbVgroupsAndSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestPrepareDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
434

D
dapan 已提交
435
  ctgTestSetPrepareSTableMeta();
S
Shengliang Guan 已提交
436

D
dapan 已提交
437 438 439
  return;
}

D
dapan1121 已提交
440 441
void ctgTestPrepareDbVgroupsAndMultiSuperMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  ctgTestPrepareDbVgroups(shandle, pEpSet, pMsg, pRsp);
S
Shengliang Guan 已提交
442

D
dapan1121 已提交
443
  ctgTestSetPrepareMultiSTableMeta();
S
Shengliang Guan 已提交
444

D
dapan1121 已提交
445 446 447
  return;
}

D
dapan1121 已提交
448 449 450 451
void ctgTestSetPrepareDbVgroups() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareDbVgroups);
  {
S
Shengliang Guan 已提交
452 453
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
454
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
455
    for (const auto &f : result) {
D
dapan1121 已提交
456 457 458 459 460 461 462 463 464
      stub.set(f.second, ctgTestPrepareDbVgroups);
    }
  }
}

void ctgTestSetPrepareTableMeta() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareTableMeta);
  {
S
Shengliang Guan 已提交
465 466
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
467
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
468
    for (const auto &f : result) {
D
dapan1121 已提交
469 470 471 472 473 474 475 476 477
      stub.set(f.second, ctgTestPrepareTableMeta);
    }
  }
}

void ctgTestSetPrepareCTableMeta() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareCTableMeta);
  {
S
Shengliang Guan 已提交
478 479
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
480
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
481
    for (const auto &f : result) {
D
dapan1121 已提交
482 483 484 485 486 487 488 489 490
      stub.set(f.second, ctgTestPrepareCTableMeta);
    }
  }
}

void ctgTestSetPrepareSTableMeta() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareSTableMeta);
  {
S
Shengliang Guan 已提交
491 492
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
493
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
494
    for (const auto &f : result) {
D
dapan1121 已提交
495 496 497 498 499
      stub.set(f.second, ctgTestPrepareSTableMeta);
    }
  }
}

D
dapan1121 已提交
500 501 502 503
void ctgTestSetPrepareMultiSTableMeta() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareMultiSTableMeta);
  {
S
Shengliang Guan 已提交
504 505
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
506
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
507
    for (const auto &f : result) {
D
dapan1121 已提交
508 509 510 511 512
      stub.set(f.second, ctgTestPrepareMultiSTableMeta);
    }
  }
}

D
dapan 已提交
513 514 515 516
void ctgTestSetPrepareDbVgroupsAndNormalMeta() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareDbVgroupsAndNormalMeta);
  {
S
Shengliang Guan 已提交
517 518
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan 已提交
519
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
520
    for (const auto &f : result) {
D
dapan 已提交
521 522 523 524 525
      stub.set(f.second, ctgTestPrepareDbVgroupsAndNormalMeta);
    }
  }
}

D
dapan1121 已提交
526
void ctgTestSetPrepareDbVgroupsAndChildMeta() {
D
dapan1121 已提交
527
  static Stub stub;
D
dapan1121 已提交
528
  stub.set(rpcSendRecv, ctgTestPrepareDbVgroupsAndChildMeta);
D
dapan1121 已提交
529
  {
S
Shengliang Guan 已提交
530 531
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
532
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
533
    for (const auto &f : result) {
D
dapan 已提交
534
      stub.set(f.second, ctgTestPrepareDbVgroupsAndChildMeta);
D
dapan1121 已提交
535 536 537 538 539 540 541 542
    }
  }
}

void ctgTestSetPrepareDbVgroupsAndSuperMeta() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareDbVgroupsAndSuperMeta);
  {
S
Shengliang Guan 已提交
543 544
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
545
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
546
    for (const auto &f : result) {
D
dapan 已提交
547
      stub.set(f.second, ctgTestPrepareDbVgroupsAndSuperMeta);
D
dapan1121 已提交
548 549 550 551
    }
  }
}

D
dapan1121 已提交
552 553 554 555
void ctgTestSetPrepareDbVgroupsAndMultiSuperMeta() {
  static Stub stub;
  stub.set(rpcSendRecv, ctgTestPrepareDbVgroupsAndMultiSuperMeta);
  {
S
Shengliang Guan 已提交
556 557
    AddrAny                       any("libtransport.so");
    std::map<std::string, void *> result;
D
dapan1121 已提交
558
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
S
Shengliang Guan 已提交
559
    for (const auto &f : result) {
D
dapan1121 已提交
560 561 562 563 564
      stub.set(f.second, ctgTestPrepareDbVgroupsAndMultiSuperMeta);
    }
  }
}

S
Shengliang Guan 已提交
565
}  // namespace
566

D
dapan1121 已提交
567
void *ctgTestGetDbVgroupThread(void *param) {
S
Shengliang Guan 已提交
568 569 570 571 572 573
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
  void            *mockPointer = (void *)0x1;
  SArray          *vgList = NULL;
  int32_t          n = 0;

D
dapan1121 已提交
574 575 576 577 578 579 580 581 582 583 584
  while (!ctgTestStop) {
    code = catalogGetDBVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList);
    if (code) {
      assert(0);
    }

    if (vgList) {
      taosArrayDestroy(vgList);
    }

    if (ctgTestEnableSleep) {
S
Shengliang Guan 已提交
585
      usleep(rand() % 5);
D
dapan1121 已提交
586
    }
D
dapan1121 已提交
587
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
588 589 590 591 592 593 594 595
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

void *ctgTestSetDbVgroupThread(void *param) {
S
Shengliang Guan 已提交
596 597
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
D
dapan 已提交
598
  SDBVgroupInfo    *dbVgroup = NULL;
S
Shengliang Guan 已提交
599 600
  int32_t          n = 0;

D
dapan1121 已提交
601 602
  while (!ctgTestStop) {
    ctgTestBuildDBVgroup(&dbVgroup);
D
dapan 已提交
603
    code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, dbVgroup);
D
dapan1121 已提交
604 605 606 607
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
608 609
    if (ctgTestEnableSleep) {
      usleep(rand() % 5);
D
dapan1121 已提交
610
    }
D
dapan1121 已提交
611
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
612 613 614 615 616 617 618 619
      printf("Set:%d\n", n);
    }
  }

  return NULL;
}

void *ctgTestGetCtableMetaThread(void *param) {
S
Shengliang Guan 已提交
620 621 622 623 624
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
  int32_t          n = 0;
  STableMeta      *tbMeta = NULL;
  int32_t          exist = 0;
D
dapan1121 已提交
625 626 627 628

  SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(cn.dbname, "db1");
  strcpy(cn.tname, ctgTestCTablename);
S
Shengliang Guan 已提交
629

D
dapan1121 已提交
630 631 632 633 634 635
  while (!ctgTestStop) {
    code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &exist);
    if (code || 0 == exist) {
      assert(0);
    }

D
dapan1121 已提交
636 637
    tfree(tbMeta);

D
dapan1121 已提交
638
    if (ctgTestEnableSleep) {
S
Shengliang Guan 已提交
639
      usleep(rand() % 5);
D
dapan1121 已提交
640
    }
S
Shengliang Guan 已提交
641

D
dapan1121 已提交
642
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
643 644 645 646 647 648 649 650
      printf("Get:%d\n", n);
    }
  }

  return NULL;
}

void *ctgTestSetCtableMetaThread(void *param) {
S
Shengliang Guan 已提交
651 652 653 654
  struct SCatalog *pCtg = (struct SCatalog *)param;
  int32_t          code = 0;
  SDBVgroupInfo    dbVgroup = {0};
  int32_t          n = 0;
D
dapan1121 已提交
655 656 657
  STableMetaOutput output = {0};

  ctgTestBuildCTableMetaOutput(&output);
S
Shengliang Guan 已提交
658

D
dapan1121 已提交
659 660 661 662 663 664
  while (!ctgTestStop) {
    code = ctgUpdateTableMetaCache(pCtg, &output);
    if (code) {
      assert(0);
    }

S
Shengliang Guan 已提交
665 666
    if (ctgTestEnableSleep) {
      usleep(rand() % 5);
D
dapan1121 已提交
667
    }
D
dapan1121 已提交
668
    if (++n % ctgTestPrintNum == 0) {
D
dapan1121 已提交
669 670 671 672
      printf("Set:%d\n", n);
    }
  }

D
dapan1121 已提交
673 674
  tfree(output.tbMeta);

D
dapan1121 已提交
675 676 677
  return NULL;
}

D
dapan 已提交
678

D
dapan 已提交
679
TEST(tableMeta, normalTable) {
S
Shengliang Guan 已提交
680 681 682
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
683

D
dapan1121 已提交
684
  ctgTestSetPrepareDbVgroups();
D
dapan1121 已提交
685

686
  initQueryModuleMsgHandle();
D
ut test  
dapan1121 已提交
687

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

D
dapan1121 已提交
690 691
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
692

D
dapan1121 已提交
693
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
694
  ASSERT_EQ(code, 0);
695

D
dapan1121 已提交
696
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
697 698 699 700
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
D
dapan1121 已提交
701
  ASSERT_EQ(code, 0);
D
dapan1121 已提交
702
  ASSERT_EQ(vgInfo.vgId, 8);
H
Haojun Liao 已提交
703
  ASSERT_EQ(vgInfo.epset.numOfEps, 3);
D
dapan1121 已提交
704 705 706 707

  ctgTestSetPrepareTableMeta();

  STableMeta *tableMeta = NULL;
H
Haojun Liao 已提交
708
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
709 710 711 712 713 714 715 716 717 718 719
  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);

  tableMeta = NULL;
H
Haojun Liao 已提交
720
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
721 722 723 724 725 726 727 728 729 730
  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);

S
Shengliang Guan 已提交
731
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
732
  SSTableMetaVersion *stb = NULL;
S
Shengliang Guan 已提交
733 734
  uint32_t            dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t             i = 0;
D
dapan1121 已提交
735 736 737 738 739 740
  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 已提交
741

D
dapan1121 已提交
742
    if (dbNum) {
S
Shengliang Guan 已提交
743
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
D
dapan1121 已提交
744 745 746 747 748 749 750
      free(dbs);
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
751
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
D
dapan1121 已提交
752 753 754 755 756 757 758 759 760 761
      free(stb);
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
    sleep(2);
  }
S
Shengliang Guan 已提交
762

D
dapan1121 已提交
763 764 765
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 0);

D
dapan1121 已提交
766 767 768
  catalogDestroy();
}

D
dapan 已提交
769
TEST(tableMeta, childTableCase) {
S
Shengliang Guan 已提交
770 771 772
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
D
dapan1121 已提交
773 774 775 776 777

  ctgTestSetPrepareDbVgroupsAndChildMeta();

  initQueryModuleMsgHandle();

S
Shengliang Guan 已提交
778
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
779 780
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
S
Shengliang Guan 已提交
781

D
dapan1121 已提交
782
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
783 784
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
785
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
786 787
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
D
dapan1121 已提交
788 789

  STableMeta *tableMeta = NULL;
H
Haojun Liao 已提交
790
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
791 792 793 794 795 796 797 798 799 800 801
  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);

  tableMeta = NULL;
H
Haojun Liao 已提交
802
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
803 804 805 806 807 808 809 810 811 812 813
  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);

  tableMeta = NULL;
H
Haojun Liao 已提交
814 815 816

  strcpy(n.tname, ctgTestSTablename);
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
817 818 819 820 821 822 823 824 825 826
  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);

S
Shengliang Guan 已提交
827
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
828
  SSTableMetaVersion *stb = NULL;
S
Shengliang Guan 已提交
829 830
  uint32_t            dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t             i = 0;
D
dapan1121 已提交
831 832 833 834 835 836
  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 已提交
837

D
dapan1121 已提交
838
    if (dbNum) {
S
Shengliang Guan 已提交
839
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
D
dapan1121 已提交
840 841 842 843 844 845 846
      free(dbs);
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
847
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);      
D
dapan1121 已提交
848 849 850 851 852 853 854 855 856 857
      free(stb);
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
    sleep(2);
  }
S
Shengliang Guan 已提交
858

D
dapan1121 已提交
859 860 861
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);

D
dapan1121 已提交
862 863 864
  catalogDestroy();
}

D
dapan 已提交
865
TEST(tableMeta, superTableCase) {
S
Shengliang Guan 已提交
866 867 868
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
D
dapan1121 已提交
869 870 871 872 873

  ctgTestSetPrepareDbVgroupsAndSuperMeta();

  initQueryModuleMsgHandle();

D
dapan1121 已提交
874 875 876
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
877
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
878
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan1121 已提交
879 880
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
881
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
882 883
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan1121 已提交
884 885

  STableMeta *tableMeta = NULL;
H
Haojun Liao 已提交
886
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
887 888 889 890 891
  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 已提交
892 893
  ASSERT_EQ(tableMeta->uid, ctgTestSuid);
  ASSERT_EQ(tableMeta->suid, ctgTestSuid);
D
dapan1121 已提交
894 895 896 897 898 899 900 901
  ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum);
  ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum);
  ASSERT_EQ(tableMeta->tableInfo.precision, 1);
  ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);

  ctgTestSetPrepareCTableMeta();

  tableMeta = NULL;
H
Haojun Liao 已提交
902 903 904 905

  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);
  code = catalogGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
D
dapan1121 已提交
906 907 908 909 910 911 912 913 914 915 916
  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);

  tableMeta = NULL;
D
dapan1121 已提交
917
  code = catalogRenewAndGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0);
D
dapan1121 已提交
918 919 920 921 922 923 924 925 926 927
  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);

S
Shengliang Guan 已提交
928
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
929
  SSTableMetaVersion *stb = NULL;
S
Shengliang Guan 已提交
930 931
  uint32_t            dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0;
  int32_t             i = 0;
D
dapan1121 已提交
932 933 934 935 936 937
  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 已提交
938

D
dapan1121 已提交
939
    if (dbNum) {
S
Shengliang Guan 已提交
940
      printf("got expired db,dbId:%" PRId64 "\n", dbs->dbId);
D
dapan1121 已提交
941 942 943 944 945 946 947
      free(dbs);
      dbs = NULL;
    } else {
      printf("no expired db\n");
    }

    if (stbNum) {
D
dapan 已提交
948 949
      printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
      
D
dapan1121 已提交
950 951 952 953 954 955 956 957 958 959
      free(stb);
      stb = NULL;
    } else {
      printf("no expired stb\n");
    }

    allDbNum += dbNum;
    allStbNum += stbNum;
    sleep(2);
  }
S
Shengliang Guan 已提交
960

D
dapan1121 已提交
961 962
  ASSERT_EQ(allDbNum, 1);
  ASSERT_EQ(allStbNum, 1);
D
dapan1121 已提交
963 964

  catalogDestroy();
D
dapan1121 已提交
965
}
966

D
dapan 已提交
967
TEST(tableDistVgroup, normalTable) {
S
Shengliang Guan 已提交
968 969 970 971
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo     *vgInfo = NULL;
  SArray          *vgList = NULL;
D
dapan 已提交
972 973 974 975 976

  ctgTestSetPrepareDbVgroupsAndNormalMeta();

  initQueryModuleMsgHandle();

D
dapan1121 已提交
977 978 979
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

D
dapan1121 已提交
982
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
983 984
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
985
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
986 987
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);
D
dapan 已提交
988

H
Haojun Liao 已提交
989
  code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan 已提交
990 991 992 993
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 8);
H
Haojun Liao 已提交
994
  ASSERT_EQ(vgInfo->epset.numOfEps, 3);
D
dapan 已提交
995 996 997 998 999

  catalogDestroy();
}

TEST(tableDistVgroup, childTableCase) {
S
Shengliang Guan 已提交
1000 1001 1002 1003
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo     *vgInfo = NULL;
  SArray          *vgList = NULL;
D
dapan 已提交
1004 1005 1006 1007 1008

  ctgTestSetPrepareDbVgroupsAndChildMeta();

  initQueryModuleMsgHandle();

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

D
dapan 已提交
1011 1012 1013 1014 1015 1016
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

D
dapan1121 已提交
1017
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
1018 1019 1020 1021
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestCTablename);

  code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan 已提交
1022 1023 1024 1025
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 9);
H
Haojun Liao 已提交
1026
  ASSERT_EQ(vgInfo->epset.numOfEps, 4);
D
dapan 已提交
1027 1028 1029 1030 1031

  catalogDestroy();
}

TEST(tableDistVgroup, superTableCase) {
S
Shengliang Guan 已提交
1032 1033 1034 1035
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo     *vgInfo = NULL;
  SArray          *vgList = NULL;
D
dapan 已提交
1036 1037 1038 1039 1040

  ctgTestSetPrepareDbVgroupsAndSuperMeta();

  initQueryModuleMsgHandle();

D
dapan1121 已提交
1041 1042 1043
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

S
Shengliang Guan 已提交
1044
  // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
1045
  code = catalogGetHandle(ctgTestClusterId, &pCtg);
D
dapan 已提交
1046 1047
  ASSERT_EQ(code, 0);

D
dapan1121 已提交
1048
  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
H
Haojun Liao 已提交
1049 1050
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestSTablename);
D
dapan 已提交
1051

H
Haojun Liao 已提交
1052
  code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
D
dapan 已提交
1053 1054 1055 1056
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10);
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(vgInfo->vgId, 1);
H
Haojun Liao 已提交
1057
  ASSERT_EQ(vgInfo->epset.numOfEps, 1);
D
dapan 已提交
1058 1059
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1);
  ASSERT_EQ(vgInfo->vgId, 2);
H
Haojun Liao 已提交
1060
  ASSERT_EQ(vgInfo->epset.numOfEps, 2);
D
dapan 已提交
1061 1062
  vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2);
  ASSERT_EQ(vgInfo->vgId, 3);
H
Haojun Liao 已提交
1063
  ASSERT_EQ(vgInfo->epset.numOfEps, 3);
D
dapan 已提交
1064 1065 1066 1067

  catalogDestroy();
}

D
dapan1121 已提交
1068
TEST(dbVgroup, getSetDbVgroupCase) {
S
Shengliang Guan 已提交
1069 1070 1071 1072
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
D
dapan 已提交
1073
  SDBVgroupInfo    *dbVgroup = NULL;
S
Shengliang Guan 已提交
1074
  SArray          *vgList = NULL;
D
dapan1121 已提交
1075

D
dapan 已提交
1076 1077
  ctgTestInitLogFile();

D
dapan1121 已提交
1078 1079 1080 1081
  ctgTestSetPrepareDbVgroupsAndNormalMeta();

  initQueryModuleMsgHandle();

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

D
dapan1121 已提交
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  code = catalogGetDBVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
S
Shengliang Guan 已提交
1097

D
dapan1121 已提交
1098 1099 1100
  code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 8);
H
Haojun Liao 已提交
1101
  ASSERT_EQ(vgInfo.epset.numOfEps, 3);
D
dapan1121 已提交
1102 1103 1104 1105 1106 1107

  code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(pvgInfo->vgId, 8);
H
Haojun Liao 已提交
1108
  ASSERT_EQ(pvgInfo->epset.numOfEps, 3);
D
dapan1121 已提交
1109 1110 1111
  taosArrayDestroy(vgList);

  ctgTestBuildDBVgroup(&dbVgroup);
D
dapan 已提交
1112
  code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, dbVgroup);
D
dapan1121 已提交
1113 1114 1115 1116 1117
  ASSERT_EQ(code, 0);

  code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(vgInfo.vgId, 7);
H
Haojun Liao 已提交
1118
  ASSERT_EQ(vgInfo.epset.numOfEps, 2);
D
dapan1121 已提交
1119 1120 1121 1122 1123 1124

  code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
  ASSERT_EQ(code, 0);
  ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
  pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
  ASSERT_EQ(pvgInfo->vgId, 8);
H
Haojun Liao 已提交
1125
  ASSERT_EQ(pvgInfo->epset.numOfEps, 3);
D
dapan1121 已提交
1126
  taosArrayDestroy(vgList);
S
Shengliang Guan 已提交
1127

D
dapan1121 已提交
1128 1129 1130 1131
  catalogDestroy();
}

TEST(multiThread, getSetDbVgroupCase) {
S
Shengliang Guan 已提交
1132 1133 1134 1135 1136 1137
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
  SDBVgroupInfo    dbVgroup = {0};
  SArray          *vgList = NULL;
D
dapan1121 已提交
1138
  ctgTestStop = false;
D
dapan1121 已提交
1139 1140

  ctgTestInitLogFile();
S
Shengliang Guan 已提交
1141

D
dapan1121 已提交
1142 1143 1144 1145
  ctgTestSetPrepareDbVgroups();

  initQueryModuleMsgHandle();

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

D
dapan1121 已提交
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  pthread_attr_t thattr;
  pthread_attr_init(&thattr);

  pthread_t thread1, thread2;
  pthread_create(&(thread1), &thattr, ctgTestSetDbVgroupThread, pCtg);

  sleep(1);
  pthread_create(&(thread1), &thattr, ctgTestGetDbVgroupThread, pCtg);

  while (true) {
    if (ctgTestDeadLoop) {
      sleep(1);
    } else {
D
dapan1121 已提交
1171
      sleep(ctgTestMTRunSec);
D
dapan1121 已提交
1172 1173 1174
      break;
    }
  }
S
Shengliang Guan 已提交
1175

D
dapan1121 已提交
1176 1177
  ctgTestStop = true;
  sleep(1);
S
Shengliang Guan 已提交
1178

D
dapan1121 已提交
1179 1180 1181
  catalogDestroy();
}

D
dapan 已提交
1182

D
dapan1121 已提交
1183
TEST(multiThread, ctableMeta) {
S
Shengliang Guan 已提交
1184 1185 1186 1187 1188 1189
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
  SDBVgroupInfo    dbVgroup = {0};
  SArray          *vgList = NULL;
D
dapan1121 已提交
1190
  ctgTestStop = false;
D
dapan1121 已提交
1191

D
dapan 已提交
1192 1193
  ctgTestInitLogFile();

D
dapan1121 已提交
1194 1195 1196 1197
  ctgTestSetPrepareDbVgroupsAndChildMeta();

  initQueryModuleMsgHandle();

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

D
dapan1121 已提交
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);

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

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");
  strcpy(n.tname, ctgTestTablename);

  pthread_attr_t thattr;
  pthread_attr_init(&thattr);

  pthread_t thread1, thread2;
  pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
D
dapan1121 已提交
1215 1216
  sleep(1);
  pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
D
dapan1121 已提交
1217 1218 1219 1220 1221

  while (true) {
    if (ctgTestDeadLoop) {
      sleep(1);
    } else {
D
dapan1121 已提交
1222
      sleep(ctgTestMTRunSec);
D
dapan1121 已提交
1223 1224 1225
      break;
    }
  }
S
Shengliang Guan 已提交
1226

D
dapan1121 已提交
1227
  ctgTestStop = true;
D
dapan 已提交
1228
  sleep(2);
S
Shengliang Guan 已提交
1229

D
dapan1121 已提交
1230 1231
  catalogDestroy();
}
D
dapan 已提交
1232

D
dapan 已提交
1233 1234


D
dapan1121 已提交
1235
TEST(rentTest, allRent) {
S
Shengliang Guan 已提交
1236 1237 1238 1239 1240 1241
  struct SCatalog *pCtg = NULL;
  void            *mockPointer = (void *)0x1;
  SVgroupInfo      vgInfo = {0};
  SVgroupInfo     *pvgInfo = NULL;
  SDBVgroupInfo    dbVgroup = {0};
  SArray          *vgList = NULL;
D
dapan1121 已提交
1242
  ctgTestStop = false;
S
Shengliang Guan 已提交
1243
  SDbVgVersion       *dbs = NULL;
D
dapan1121 已提交
1244
  SSTableMetaVersion *stable = NULL;
S
Shengliang Guan 已提交
1245
  uint32_t            num = 0;
D
dapan1121 已提交
1246

D
dapan 已提交
1247 1248
  ctgTestInitLogFile();

D
dapan1121 已提交
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
  ctgTestSetPrepareDbVgroupsAndMultiSuperMeta();

  initQueryModuleMsgHandle();

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

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

  SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
  strcpy(n.dbname, "db1");

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

    STableMeta *tableMeta = NULL;
    code = catalogGetSTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta);
    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 已提交
1278

D
dapan1121 已提交
1279 1280 1281 1282
    code = catalogGetExpiredDBs(pCtg, &dbs, &num);
    ASSERT_EQ(code, 0);
    printf("%d - expired dbNum:%d\n", i, num);
    if (dbs) {
S
Shengliang Guan 已提交
1283
      printf("%d - expired dbId:%" PRId64 ", vgVersion:%d\n", i, dbs->dbId, dbs->vgVersion);
D
dapan1121 已提交
1284 1285 1286
      free(dbs);
      dbs = NULL;
    }
S
Shengliang Guan 已提交
1287

D
dapan1121 已提交
1288 1289 1290 1291 1292
    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) {
D
dapan 已提交
1293
        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 已提交
1294 1295 1296 1297 1298
      }
      free(stable);
      stable = NULL;
    }
    printf("*************************************************\n");
S
Shengliang Guan 已提交
1299

D
dapan1121 已提交
1300 1301
    sleep(2);
  }
S
Shengliang Guan 已提交
1302

D
dapan1121 已提交
1303 1304 1305
  catalogDestroy();
}

S
Shengliang Guan 已提交
1306
int main(int argc, char **argv) {
1307 1308 1309
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
D
dapan1121 已提交
1310

D
dapan1121 已提交
1311
#pragma GCC diagnostic pop