metaOpen.c 14.0 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

H
Hongze Cheng 已提交
16
#include "meta.h"
17
#include "vnd.h"
H
Hongze Cheng 已提交
18

H
Hongze Cheng 已提交
19 20 21 22
static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
H
Hongze Cheng 已提交
23
static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
24
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
L
Liu Jicong 已提交
25
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
H
Hongze Cheng 已提交
26

27
static int btimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
dengyihao's avatar
dengyihao 已提交
28 29
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);

H
Hongze Cheng 已提交
30 31 32
static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); }
static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); }

33 34
static void metaCleanup(SMeta **ppMeta);

H
Hongze Cheng 已提交
35
int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
H
Hongze Cheng 已提交
36
  SMeta *pMeta = NULL;
H
Hongze Cheng 已提交
37
  int    ret;
38 39
  int    offset;
  char   path[TSDB_FILENAME_LEN] = {0};
H
Hongze Cheng 已提交
40 41 42 43

  *ppMeta = NULL;

  // create handle
44
  vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, path, TSDB_FILENAME_LEN);
45 46 47 48
  offset = strlen(path);
  snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VNODE_META_DIR);

  if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + strlen(path) + 1)) == NULL) {
H
Hongze Cheng 已提交
49 50 51 52
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

H
Hongze Cheng 已提交
53
  metaInitLock(pMeta);
54

H
Hongze Cheng 已提交
55
  pMeta->path = (char *)&pMeta[1];
56 57 58
  strcpy(pMeta->path, path);
  taosRealPath(pMeta->path, NULL, strlen(path) + 1);

H
Hongze Cheng 已提交
59 60 61 62 63
  pMeta->pVnode = pVnode;

  // create path if not created yet
  taosMkDir(pMeta->path);

H
Hongze Cheng 已提交
64
  // open env
65
  ret = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv, rollback);
H
Hongze Cheng 已提交
66
  if (ret < 0) {
S
Shengliang Guan 已提交
67
    metaError("vgId:%d, failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
68 69 70 71
    goto _err;
  }

  // open pTbDb
72
  ret = tdbTbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb, 0);
H
Hongze Cheng 已提交
73
  if (ret < 0) {
S
Shengliang Guan 已提交
74
    metaError("vgId:%d, failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
75 76 77 78
    goto _err;
  }

  // open pSkmDb
79
  ret = tdbTbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb, 0);
H
Hongze Cheng 已提交
80
  if (ret < 0) {
S
Shengliang Guan 已提交
81
    metaError("vgId:%d, failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
82 83 84
    goto _err;
  }

H
Hongze Cheng 已提交
85
  // open pUidIdx
86
  ret = tdbTbOpen("uid.idx", sizeof(tb_uid_t), sizeof(SUidIdxVal), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx, 0);
H
Hongze Cheng 已提交
87
  if (ret < 0) {
S
Shengliang Guan 已提交
88
    metaError("vgId:%d, failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
89 90 91
    goto _err;
  }

H
Hongze Cheng 已提交
92
  // open pNameIdx
93
  ret = tdbTbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx, 0);
H
Hongze Cheng 已提交
94
  if (ret < 0) {
S
Shengliang Guan 已提交
95
    metaError("vgId:%d, failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
96 97 98
    goto _err;
  }

H
Hongze Cheng 已提交
99
  // open pCtbIdx
100
  ret = tdbTbOpen("ctb.idx", sizeof(SCtbIdxKey), -1, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx, 0);
H
Hongze Cheng 已提交
101
  if (ret < 0) {
S
Shengliang Guan 已提交
102
    metaError("vgId:%d, failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
103 104 105
    goto _err;
  }

C
Cary Xu 已提交
106
  // open pSuidIdx
107
  ret = tdbTbOpen("suid.idx", sizeof(tb_uid_t), 0, uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pSuidIdx, 0);
C
Cary Xu 已提交
108 109 110 111 112
  if (ret < 0) {
    metaError("vgId:%d, failed to open meta super table index since %s", TD_VID(pVnode), tstrerror(terrno));
    goto _err;
  }

dengyihao's avatar
dengyihao 已提交
113 114 115
  char indexFullPath[128] = {0};
  sprintf(indexFullPath, "%s/%s", pMeta->path, "invert");
  taosMkDir(indexFullPath);
dengyihao's avatar
dengyihao 已提交
116

dengyihao's avatar
dengyihao 已提交
117 118
  SIndexOpts opts = {.cacheSize = 8 * 1024 * 1024};
  ret = indexOpen(&opts, indexFullPath, (SIndex **)&pMeta->pTagIvtIdx);
dengyihao's avatar
dengyihao 已提交
119
  if (ret < 0) {
S
Shengliang Guan 已提交
120
    metaError("vgId:%d, failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
dengyihao's avatar
dengyihao 已提交
121 122 123
    goto _err;
  }

124
  ret = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx, 0);
H
Hongze Cheng 已提交
125
  if (ret < 0) {
S
Shengliang Guan 已提交
126
    metaError("vgId:%d, failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
127 128 129
    goto _err;
  }

130
  // open pTtlMgr ("ttlv1.idx")
131 132 133
  char logPrefix[128] = {0};
  sprintf(logPrefix, "vgId:%d", TD_VID(pVnode));
  ret = ttlMgrOpen(&pMeta->pTtlMgr, pMeta->pEnv, 0, logPrefix);
H
Hongze Cheng 已提交
134
  if (ret < 0) {
S
Shengliang Guan 已提交
135
    metaError("vgId:%d, failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
136 137 138
    goto _err;
  }

C
Cary Xu 已提交
139
  // open pSmaIdx
140
  ret = tdbTbOpen("sma.idx", sizeof(SSmaIdxKey), 0, smaIdxKeyCmpr, pMeta->pEnv, &pMeta->pSmaIdx, 0);
C
Cary Xu 已提交
141
  if (ret < 0) {
S
Shengliang Guan 已提交
142
    metaError("vgId:%d, failed to open meta sma index since %s", TD_VID(pVnode), tstrerror(terrno));
C
Cary Xu 已提交
143 144 145
    goto _err;
  }

dengyihao's avatar
dengyihao 已提交
146
  // idx table create time
147
  ret = tdbTbOpen("ctime.idx", sizeof(SBtimeIdxKey), 0, btimeIdxCmpr, pMeta->pEnv, &pMeta->pBtimeIdx, 0);
dengyihao's avatar
dengyihao 已提交
148 149 150 151 152 153
  if (ret < 0) {
    metaError("vgId:%d, failed to open meta ctime index since %s", TD_VID(pVnode), tstrerror(terrno));
    goto _err;
  }

  // idx num of col, normal table only
dengyihao's avatar
dengyihao 已提交
154
  ret = tdbTbOpen("ncol.idx", sizeof(SNcolIdxKey), 0, ncolIdxCmpr, pMeta->pEnv, &pMeta->pNcolIdx, 0);
dengyihao's avatar
dengyihao 已提交
155 156 157 158 159
  if (ret < 0) {
    metaError("vgId:%d, failed to open meta ncol index since %s", TD_VID(pVnode), tstrerror(terrno));
    goto _err;
  }

160
  ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb, 0);
L
Liu Jicong 已提交
161
  if (ret < 0) {
S
Shengliang Guan 已提交
162
    metaError("vgId:%d, failed to open meta stream task index since %s", TD_VID(pVnode), tstrerror(terrno));
L
Liu Jicong 已提交
163 164 165
    goto _err;
  }

H
Hongze Cheng 已提交
166
  // open index
H
Hongze Cheng 已提交
167
  if (metaOpenIdx(pMeta) < 0) {
S
Shengliang Guan 已提交
168
    metaError("vgId:%d, failed to open meta index since %s", TD_VID(pVnode), tstrerror(terrno));
H
Hongze Cheng 已提交
169 170
    goto _err;
  }
H
Hongze Cheng 已提交
171

H
Hongze Cheng 已提交
172 173 174 175 176 177 178
  int32_t code = metaCacheOpen(pMeta);
  if (code) {
    terrno = code;
    metaError("vgId:%d, failed to open meta cache since %s", TD_VID(pVnode), tstrerror(terrno));
    goto _err;
  }

S
Shengliang Guan 已提交
179
  metaDebug("vgId:%d, meta is opened", TD_VID(pVnode));
H
Hongze Cheng 已提交
180 181 182 183 184

  *ppMeta = pMeta;
  return 0;

_err:
185
  metaCleanup(&pMeta);
H
Hongze Cheng 已提交
186 187 188
  return -1;
}

S
Shungang Li 已提交
189 190
int metaUpgrade(SVnode *pVnode, SMeta **ppMeta) {
  int    code = TSDB_CODE_SUCCESS;
191
  SMeta *pMeta = *ppMeta;
S
Shungang Li 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

  if (ttlMgrNeedUpgrade(pMeta->pEnv)) {
    code = metaBegin(pMeta, META_BEGIN_HEAP_OS);
    if (code < 0) {
      metaError("vgId:%d, failed to upgrade meta, meta begin failed since %s", TD_VID(pVnode), tstrerror(terrno));
      goto _err;
    }

    code = ttlMgrUpgrade(pMeta->pTtlMgr, pMeta);
    if (code < 0) {
      metaError("vgId:%d, failed to upgrade meta ttl since %s", TD_VID(pVnode), tstrerror(terrno));
      goto _err;
    }

    code = metaCommit(pMeta, pMeta->txn);
    if (code < 0) {
      metaError("vgId:%d, failed to upgrade meta ttl, meta commit failed since %s", TD_VID(pVnode), tstrerror(terrno));
      goto _err;
    }
H
Hongze Cheng 已提交
211 212
  }

S
Shungang Li 已提交
213
  return TSDB_CODE_SUCCESS;
214 215 216

_err:
  metaCleanup(ppMeta);
S
Shungang Li 已提交
217
  return code;
218 219 220 221 222
}

int metaClose(SMeta **ppMeta) {
  metaCleanup(ppMeta);
  return 0;
H
Hongze Cheng 已提交
223 224
}

H
Hongze Cheng 已提交
225 226 227 228 229 230 231 232 233 234 235 236
int metaAlterCache(SMeta *pMeta, int32_t nPage) {
  metaWLock(pMeta);

  if (tdbAlter(pMeta->pEnv, nPage) < 0) {
    metaULock(pMeta);
    return -1;
  }

  metaULock(pMeta);
  return 0;
}

M
Minglei Jin 已提交
237 238
int32_t metaRLock(SMeta *pMeta) {
  int32_t ret = 0;
H
Hongze Cheng 已提交
239

dengyihao's avatar
dengyihao 已提交
240
  metaTrace("meta rlock %p", &pMeta->lock);
H
Hongze Cheng 已提交
241

M
Minglei Jin 已提交
242 243 244 245 246 247 248 249
  ret = taosThreadRwlockRdlock(&pMeta->lock);

  return ret;
}

int32_t metaWLock(SMeta *pMeta) {
  int32_t ret = 0;

dengyihao's avatar
dengyihao 已提交
250
  metaTrace("meta wlock %p", &pMeta->lock);
M
Minglei Jin 已提交
251 252 253 254 255 256 257 258 259

  ret = taosThreadRwlockWrlock(&pMeta->lock);

  return ret;
}

int32_t metaULock(SMeta *pMeta) {
  int32_t ret = 0;

dengyihao's avatar
dengyihao 已提交
260
  metaTrace("meta ulock %p", &pMeta->lock);
M
Minglei Jin 已提交
261 262 263 264 265

  ret = taosThreadRwlockUnlock(&pMeta->lock);

  return ret;
}
H
Hongze Cheng 已提交
266

267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
static void metaCleanup(SMeta **ppMeta) {
  SMeta *pMeta = *ppMeta;
  if (pMeta) {
    if (pMeta->pEnv) metaAbort(pMeta);
    if (pMeta->pCache) metaCacheClose(pMeta);
    if (pMeta->pIdx) metaCloseIdx(pMeta);
    if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
    if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx);
    if (pMeta->pBtimeIdx) tdbTbClose(pMeta->pBtimeIdx);
    if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
    if (pMeta->pTtlMgr) ttlMgrClose(pMeta->pTtlMgr);
    if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
    if (pMeta->pTagIdx) tdbTbClose(pMeta->pTagIdx);
    if (pMeta->pCtbIdx) tdbTbClose(pMeta->pCtbIdx);
    if (pMeta->pSuidIdx) tdbTbClose(pMeta->pSuidIdx);
    if (pMeta->pNameIdx) tdbTbClose(pMeta->pNameIdx);
    if (pMeta->pUidIdx) tdbTbClose(pMeta->pUidIdx);
    if (pMeta->pSkmDb) tdbTbClose(pMeta->pSkmDb);
    if (pMeta->pTbDb) tdbTbClose(pMeta->pTbDb);
    if (pMeta->pEnv) tdbClose(pMeta->pEnv);
    metaDestroyLock(pMeta);

    taosMemoryFreeClear(*ppMeta);
  }
}

H
Hongze Cheng 已提交
293
static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
H
Hongze Cheng 已提交
294 295
  STbDbKey *pTbDbKey1 = (STbDbKey *)pKey1;
  STbDbKey *pTbDbKey2 = (STbDbKey *)pKey2;
H
Hongze Cheng 已提交
296

H
Hongze Cheng 已提交
297
  if (pTbDbKey1->version > pTbDbKey2->version) {
H
Hongze Cheng 已提交
298
    return 1;
H
Hongze Cheng 已提交
299 300 301 302 303 304 305
  } else if (pTbDbKey1->version < pTbDbKey2->version) {
    return -1;
  }

  if (pTbDbKey1->uid > pTbDbKey2->uid) {
    return 1;
  } else if (pTbDbKey1->uid < pTbDbKey2->uid) {
H
Hongze Cheng 已提交
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
    return -1;
  }

  return 0;
}

static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  SSkmDbKey *pSkmDbKey1 = (SSkmDbKey *)pKey1;
  SSkmDbKey *pSkmDbKey2 = (SSkmDbKey *)pKey2;

  if (pSkmDbKey1->uid > pSkmDbKey2->uid) {
    return 1;
  } else if (pSkmDbKey1->uid < pSkmDbKey2->uid) {
    return -1;
  }

  if (pSkmDbKey1->sver > pSkmDbKey2->sver) {
    return 1;
  } else if (pSkmDbKey1->sver < pSkmDbKey2->sver) {
    return -1;
H
Hongze Cheng 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338
  }

  return 0;
}

static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  tb_uid_t uid1 = *(tb_uid_t *)pKey1;
  tb_uid_t uid2 = *(tb_uid_t *)pKey2;

  if (uid1 > uid2) {
    return 1;
  } else if (uid1 < uid2) {
    return -1;
H
Hongze Cheng 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
  }

  return 0;
}

static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  SCtbIdxKey *pCtbIdxKey1 = (SCtbIdxKey *)pKey1;
  SCtbIdxKey *pCtbIdxKey2 = (SCtbIdxKey *)pKey2;

  if (pCtbIdxKey1->suid > pCtbIdxKey2->suid) {
    return 1;
  } else if (pCtbIdxKey1->suid < pCtbIdxKey2->suid) {
    return -1;
  }

  if (pCtbIdxKey1->uid > pCtbIdxKey2->uid) {
    return 1;
  } else if (pCtbIdxKey1->uid < pCtbIdxKey2->uid) {
    return -1;
  }

  return 0;
}

static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  STagIdxKey *pTagIdxKey1 = (STagIdxKey *)pKey1;
  STagIdxKey *pTagIdxKey2 = (STagIdxKey *)pKey2;
M
Minglei Jin 已提交
366
  tb_uid_t    uid1 = 0, uid2 = 0;
H
Hongze Cheng 已提交
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
  int         c;

  // compare suid
  if (pTagIdxKey1->suid > pTagIdxKey2->suid) {
    return 1;
  } else if (pTagIdxKey1->suid < pTagIdxKey2->suid) {
    return -1;
  }

  // compare column id
  if (pTagIdxKey1->cid > pTagIdxKey2->cid) {
    return 1;
  } else if (pTagIdxKey1->cid < pTagIdxKey2->cid) {
    return -1;
  }

383 384 385 386
  if (pTagIdxKey1->type != pTagIdxKey2->type) {
    metaError("meta/open: incorrect tag idx type.");
    return TSDB_CODE_FAILED;
  }
H
Hongze Cheng 已提交
387

H
Hongze Cheng 已提交
388 389 390 391 392 393 394
  // check NULL, NULL is always the smallest
  if (pTagIdxKey1->isNull && !pTagIdxKey2->isNull) {
    return -1;
  } else if (!pTagIdxKey1->isNull && pTagIdxKey2->isNull) {
    return 1;
  } else if (!pTagIdxKey1->isNull && !pTagIdxKey2->isNull) {
    // all not NULL, compr tag vals
dengyihao's avatar
dengyihao 已提交
395 396
    __compar_fn_t func = getComparFunc(pTagIdxKey1->type, 0);
    c = func(pTagIdxKey1->data, pTagIdxKey2->data);
H
Hongze Cheng 已提交
397
    if (c) return c;
M
Minglei Jin 已提交
398
  }
H
Hongze Cheng 已提交
399

M
Minglei Jin 已提交
400 401 402 403 404 405 406
  // both null or tag values are equal, then continue to compare uids
  if (IS_VAR_DATA_TYPE(pTagIdxKey1->type)) {
    uid1 = *(tb_uid_t *)(pTagIdxKey1->data + varDataTLen(pTagIdxKey1->data));
    uid2 = *(tb_uid_t *)(pTagIdxKey2->data + varDataTLen(pTagIdxKey2->data));
  } else {
    uid1 = *(tb_uid_t *)(pTagIdxKey1->data + tDataTypes[pTagIdxKey1->type].bytes);
    uid2 = *(tb_uid_t *)(pTagIdxKey2->data + tDataTypes[pTagIdxKey2->type].bytes);
H
Hongze Cheng 已提交
407 408
  }

H
Hongze Cheng 已提交
409 410
  // compare uid
  if (uid1 < uid2) {
H
Hongze Cheng 已提交
411
    return -1;
H
Hongze Cheng 已提交
412 413 414 415
  } else if (uid1 > uid2) {
    return 1;
  } else {
    return 0;
H
Hongze Cheng 已提交
416 417 418 419 420
  }

  return 0;
}

421 422 423 424
static int btimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  SBtimeIdxKey *pBtimeIdxKey1 = (SBtimeIdxKey *)pKey1;
  SBtimeIdxKey *pBtimeIdxKey2 = (SBtimeIdxKey *)pKey2;
  if (pBtimeIdxKey1->btime > pBtimeIdxKey2->btime) {
dengyihao's avatar
dengyihao 已提交
425
    return 1;
426
  } else if (pBtimeIdxKey1->btime < pBtimeIdxKey2->btime) {
dengyihao's avatar
dengyihao 已提交
427 428 429
    return -1;
  }

430
  if (pBtimeIdxKey1->uid > pBtimeIdxKey2->uid) {
dengyihao's avatar
dengyihao 已提交
431
    return 1;
432
  } else if (pBtimeIdxKey1->uid < pBtimeIdxKey2->uid) {
dengyihao's avatar
dengyihao 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
    return -1;
  }

  return 0;
}

static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  SNcolIdxKey *pNcolIdxKey1 = (SNcolIdxKey *)pKey1;
  SNcolIdxKey *pNcolIdxKey2 = (SNcolIdxKey *)pKey2;

  if (pNcolIdxKey1->ncol > pNcolIdxKey2->ncol) {
    return 1;
  } else if (pNcolIdxKey1->ncol < pNcolIdxKey2->ncol) {
    return -1;
  }

  if (pNcolIdxKey1->uid > pNcolIdxKey2->uid) {
    return 1;
  } else if (pNcolIdxKey1->uid < pNcolIdxKey2->uid) {
    return -1;
  }

  return 0;
}

458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  SSmaIdxKey *pSmaIdxKey1 = (SSmaIdxKey *)pKey1;
  SSmaIdxKey *pSmaIdxKey2 = (SSmaIdxKey *)pKey2;

  if (pSmaIdxKey1->uid > pSmaIdxKey2->uid) {
    return 1;
  } else if (pSmaIdxKey1->uid < pSmaIdxKey2->uid) {
    return -1;
  }

  if (pSmaIdxKey1->smaUid > pSmaIdxKey2->smaUid) {
    return 1;
  } else if (pSmaIdxKey1->smaUid < pSmaIdxKey2->smaUid) {
    return -1;
  }

  return 0;
}
L
Liu Jicong 已提交
476 477 478 479 480 481 482 483 484 485 486 487 488

static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
  int32_t uid1 = *(int32_t *)pKey1;
  int32_t uid2 = *(int32_t *)pKey2;

  if (uid1 > uid2) {
    return 1;
  } else if (uid1 < uid2) {
    return -1;
  }

  return 0;
}