sdbHash.c 11.3 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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/>.
 */

#define _DEFAULT_SOURCE
#include "sdbInt.h"

S
Shengliang Guan 已提交
19
const char *sdbTableName(ESdbType type) {
S
Shengliang Guan 已提交
20 21 22 23 24 25 26
  switch (type) {
    case SDB_TRANS:
      return "trans";
    case SDB_CLUSTER:
      return "cluster";
    case SDB_MNODE:
      return "mnode";
S
Shengliang Guan 已提交
27 28 29 30 31 32
    case SDB_QNODE:
      return "qnode";
    case SDB_SNODE:
      return "snode";
    case SDB_BNODE:
      return "bnode";
S
Shengliang Guan 已提交
33 34 35 36 37 38 39 40
    case SDB_DNODE:
      return "dnode";
    case SDB_USER:
      return "user";
    case SDB_AUTH:
      return "auth";
    case SDB_ACCT:
      return "acct";
L
Liu Jicong 已提交
41 42
    case SDB_SUBSCRIBE:
      return "subscribe";
S
Shengliang Guan 已提交
43 44
    case SDB_CONSUMER:
      return "consumer";
S
Shengliang Guan 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    case SDB_TOPIC:
      return "topic";
    case SDB_VGROUP:
      return "vgId";
    case SDB_STB:
      return "stb";
    case SDB_DB:
      return "db";
    case SDB_FUNC:
      return "func";
    default:
      return "undefine";
  }
}

S
Shengliang Guan 已提交
60 61 62 63 64 65 66 67 68 69 70 71
static const char *sdbStatusStr(ESdbStatus status) {
  switch (status) {
    case SDB_STATUS_CREATING:
      return "creating";
    case SDB_STATUS_UPDATING:
      return "updating";
    case SDB_STATUS_DROPPING:
      return "dropping";
    case SDB_STATUS_READY:
      return "ready";
    case SDB_STATUS_DROPPED:
      return "dropped";
72 73
    case SDB_STATUS_INIT:
      return "init";
S
Shengliang Guan 已提交
74 75 76 77 78
    default:
      return "undefine";
  }
}

S
Shengliang Guan 已提交
79 80 81 82
void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
  EKeyType keyType = pSdb->keyTypes[pRow->type];

  if (keyType == SDB_KEY_BINARY) {
S
Shengliang Guan 已提交
83 84
    mTrace("%s:%s, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount,
           oper, pRow->pObj, sdbStatusStr(pRow->status));
S
Shengliang Guan 已提交
85
  } else if (keyType == SDB_KEY_INT32) {
S
Shengliang Guan 已提交
86 87
    mTrace("%s:%d, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj,
           pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status));
S
Shengliang Guan 已提交
88
  } else if (keyType == SDB_KEY_INT64) {
S
Shengliang Guan 已提交
89 90
    mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj,
           pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status));
S
Shengliang Guan 已提交
91 92 93 94
  } else {
  }
}

S
Shengliang Guan 已提交
95
static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) {
S
Shengliang Guan 已提交
96
  if (type >= SDB_MAX || type < 0) {
S
Shengliang Guan 已提交
97 98 99 100
    terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
    return NULL;
  }

S
Shengliang Guan 已提交
101
  SHashObj *hash = pSdb->hashObjs[type];
S
Shengliang Guan 已提交
102 103 104 105 106 107 108 109
  if (hash == NULL) {
    terrno = TSDB_CODE_SDB_APP_ERROR;
    return NULL;
  }

  return hash;
}

S
Shengliang Guan 已提交
110
static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) {
S
Shengliang Guan 已提交
111
  int32_t  keySize;
S
Shengliang Guan 已提交
112
  EKeyType keyType = pSdb->keyTypes[type];
S
Shengliang Guan 已提交
113 114 115 116 117 118 119 120 121 122 123 124

  if (keyType == SDB_KEY_INT32) {
    keySize = sizeof(int32_t);
  } else if (keyType == SDB_KEY_BINARY) {
    keySize = strlen(pKey) + 1;
  } else {
    keySize = sizeof(int64_t);
  }

  return keySize;
}

S
Shengliang Guan 已提交
125
static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
S
Shengliang Guan 已提交
126
  SRWLatch *pLock = &pSdb->locks[pRow->type];
S
Shengliang Guan 已提交
127 128
  taosWLockLatch(pLock);

S
Shengliang Guan 已提交
129 130
  SSdbRow *pOldRow = taosHashGet(hash, pRow->pObj, keySize);
  if (pOldRow != NULL) {
S
Shengliang Guan 已提交
131
    taosWUnLockLatch(pLock);
S
Shengliang Guan 已提交
132
    sdbFreeRow(pSdb, pRow);
S
Shengliang Guan 已提交
133 134
    terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
    return terrno;
S
Shengliang Guan 已提交
135 136
  }

S
Shengliang Guan 已提交
137
  pRow->refCount = 0;
S
Shengliang Guan 已提交
138
  pRow->status = pRaw->status;
S
Shengliang Guan 已提交
139
  sdbPrintOper(pSdb, pRow, "insertRow");
S
Shengliang Guan 已提交
140 141

  if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
S
Shengliang Guan 已提交
142
    taosWUnLockLatch(pLock);
S
Shengliang Guan 已提交
143
    sdbFreeRow(pSdb, pRow);
S
Shengliang Guan 已提交
144 145
    terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
    return terrno;
S
Shengliang Guan 已提交
146 147
  }

S
Shengliang Guan 已提交
148 149
  taosWUnLockLatch(pLock);

S
Shengliang Guan 已提交
150
  int32_t     code = 0;
S
Shengliang Guan 已提交
151
  SdbInsertFp insertFp = pSdb->insertFps[pRow->type];
S
Shengliang Guan 已提交
152
  if (insertFp != NULL) {
S
Shengliang Guan 已提交
153 154
    code = (*insertFp)(pSdb, pRow->pObj);
    if (code != 0) {
S
Shengliang Guan 已提交
155
      code = terrno;
S
Shengliang Guan 已提交
156
      taosWLockLatch(pLock);
S
Shengliang Guan 已提交
157
      taosHashRemove(hash, pRow->pObj, keySize);
S
Shengliang Guan 已提交
158
      taosWUnLockLatch(pLock);
S
Shengliang Guan 已提交
159
      sdbFreeRow(pSdb, pRow);
S
Shengliang Guan 已提交
160 161
      terrno = code;
      return terrno;
S
Shengliang Guan 已提交
162 163 164
    }
  }

S
Shengliang Guan 已提交
165
  if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) {
dengyihao's avatar
dengyihao 已提交
166
    pSdb->maxId[pRow->type] = TMAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj));
S
Shengliang Guan 已提交
167 168
  }
  if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT64) {
dengyihao's avatar
dengyihao 已提交
169
    pSdb->maxId[pRow->type] = TMAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj));
S
Shengliang Guan 已提交
170 171 172
  }
  pSdb->tableVer[pRow->type]++;

S
Shengliang Guan 已提交
173 174 175
  return 0;
}

S
Shengliang Guan 已提交
176 177
static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pNewRow, int32_t keySize) {
  SRWLatch *pLock = &pSdb->locks[pNewRow->type];
S
Shengliang Guan 已提交
178 179
  taosRLockLatch(pLock);

S
Shengliang Guan 已提交
180 181
  SSdbRow **ppOldRow = taosHashGet(hash, pNewRow->pObj, keySize);
  if (ppOldRow == NULL || *ppOldRow == NULL) {
S
Shengliang Guan 已提交
182
    taosRUnLockLatch(pLock);
S
Shengliang Guan 已提交
183
    return sdbInsertRow(pSdb, hash, pRaw, pNewRow, keySize);
S
Shengliang Guan 已提交
184 185
  }

S
Shengliang Guan 已提交
186
  SSdbRow *pOldRow = *ppOldRow;
S
Shengliang Guan 已提交
187
  pOldRow->status = pRaw->status;
S
Shengliang Guan 已提交
188
  sdbPrintOper(pSdb, pOldRow, "updateRow");
S
Shengliang Guan 已提交
189 190
  taosRUnLockLatch(pLock);

S
Shengliang Guan 已提交
191
  int32_t     code = 0;
S
Shengliang Guan 已提交
192
  SdbUpdateFp updateFp = pSdb->updateFps[pNewRow->type];
S
Shengliang Guan 已提交
193
  if (updateFp != NULL) {
S
Shengliang Guan 已提交
194
    code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj);
S
Shengliang Guan 已提交
195 196
  }

S
Shengliang Guan 已提交
197
  sdbFreeRow(pSdb, pNewRow);
S
Shengliang Guan 已提交
198 199

  pSdb->tableVer[pOldRow->type]++;
S
Shengliang Guan 已提交
200
  return code;
S
Shengliang Guan 已提交
201 202
}

S
Shengliang Guan 已提交
203
static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
S
Shengliang Guan 已提交
204
  SRWLatch *pLock = &pSdb->locks[pRow->type];
S
Shengliang Guan 已提交
205 206
  taosWLockLatch(pLock);

S
Shengliang Guan 已提交
207 208
  SSdbRow **ppOldRow = taosHashGet(hash, pRow->pObj, keySize);
  if (ppOldRow == NULL || *ppOldRow == NULL) {
S
Shengliang Guan 已提交
209
    taosWUnLockLatch(pLock);
S
Shengliang Guan 已提交
210
    sdbFreeRow(pSdb, pRow);
S
Shengliang Guan 已提交
211 212
    terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
    return terrno;
S
Shengliang Guan 已提交
213
  }
S
Shengliang Guan 已提交
214
  SSdbRow *pOldRow = *ppOldRow;
S
Shengliang Guan 已提交
215

S
Shengliang Guan 已提交
216
  pOldRow->status = pRaw->status;
S
Shengliang Guan 已提交
217 218
  sdbPrintOper(pSdb, pOldRow, "deleteRow");

S
Shengliang Guan 已提交
219
  taosHashRemove(hash, pOldRow->pObj, keySize);
S
Shengliang Guan 已提交
220 221
  taosWUnLockLatch(pLock);

S
Shengliang Guan 已提交
222
  pSdb->tableVer[pOldRow->type]++;
S
Shengliang Guan 已提交
223
  sdbFreeRow(pSdb, pRow);
S
Shengliang Guan 已提交
224 225
  // sdbRelease(pSdb, pOldRow->pObj);
  return 0;
S
Shengliang Guan 已提交
226 227
}

S
Shengliang Guan 已提交
228
int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) {
S
Shengliang Guan 已提交
229
  SHashObj *hash = sdbGetHash(pSdb, pRaw->type);
S
Shengliang Guan 已提交
230
  if (hash == NULL) return terrno;
S
Shengliang Guan 已提交
231

S
Shengliang Guan 已提交
232
  SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->type];
S
Shengliang Guan 已提交
233 234
  SSdbRow    *pRow = (*decodeFp)(pRaw);
  if (pRow == NULL) {
S
Shengliang Guan 已提交
235
    return terrno;
S
Shengliang Guan 已提交
236 237
  }

S
Shengliang Guan 已提交
238
  pRow->type = pRaw->type;
S
Shengliang Guan 已提交
239

S
Shengliang Guan 已提交
240
  int32_t keySize = sdbGetkeySize(pSdb, pRow->type, pRow->pObj);
S
Shengliang Guan 已提交
241
  int32_t code = TSDB_CODE_SDB_INVALID_ACTION_TYPE;
S
Shengliang Guan 已提交
242 243 244

  switch (pRaw->status) {
    case SDB_STATUS_CREATING:
S
Shengliang Guan 已提交
245
      code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
S
Shengliang Guan 已提交
246
      break;
S
Shengliang Guan 已提交
247
    case SDB_STATUS_UPDATING:
S
Shengliang Guan 已提交
248
    case SDB_STATUS_READY:
S
Shengliang Guan 已提交
249
    case SDB_STATUS_DROPPING:
S
Shengliang Guan 已提交
250
      code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize);
S
Shengliang Guan 已提交
251 252
      break;
    case SDB_STATUS_DROPPED:
S
Shengliang Guan 已提交
253
      code = sdbDeleteRow(pSdb, hash, pRaw, pRow, keySize);
S
Shengliang Guan 已提交
254
      break;
S
Shengliang Guan 已提交
255 256
  }

257
  return code;
S
Shengliang Guan 已提交
258 259
}

S
Shengliang Guan 已提交
260
int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
S
Shengliang Guan 已提交
261
  int32_t code = sdbWriteNotFree(pSdb, pRaw);
S
Shengliang Guan 已提交
262 263 264 265
  sdbFreeRaw(pRaw);
  return code;
}

S
Shengliang Guan 已提交
266
void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) {
267 268
  terrno = 0;

S
Shengliang Guan 已提交
269
  SHashObj *hash = sdbGetHash(pSdb, type);
S
Shengliang Guan 已提交
270 271 272
  if (hash == NULL) return NULL;

  void   *pRet = NULL;
S
Shengliang Guan 已提交
273
  int32_t keySize = sdbGetkeySize(pSdb, type, pKey);
S
Shengliang Guan 已提交
274

S
Shengliang Guan 已提交
275
  SRWLatch *pLock = &pSdb->locks[type];
S
Shengliang Guan 已提交
276 277 278
  taosRLockLatch(pLock);

  SSdbRow **ppRow = taosHashGet(hash, pKey, keySize);
S
Shengliang Guan 已提交
279
  if (ppRow == NULL || *ppRow == NULL) {
S
Shengliang Guan 已提交
280
    taosRUnLockLatch(pLock);
S
Shengliang Guan 已提交
281
    terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
S
Shengliang Guan 已提交
282 283 284
    return NULL;
  }

S
Shengliang Guan 已提交
285 286 287
  SSdbRow *pRow = *ppRow;
  switch (pRow->status) {
    case SDB_STATUS_READY:
S
Shengliang Guan 已提交
288
    case SDB_STATUS_UPDATING:
S
Shengliang Guan 已提交
289 290
      atomic_add_fetch_32(&pRow->refCount, 1);
      pRet = pRow->pObj;
S
Shengliang Guan 已提交
291
      sdbPrintOper(pSdb, pRow, "acquireRow");
S
Shengliang Guan 已提交
292
      break;
S
Shengliang Guan 已提交
293 294
    case SDB_STATUS_CREATING:
      terrno = TSDB_CODE_SDB_OBJ_CREATING;
S
Shengliang Guan 已提交
295
      break;
S
Shengliang Guan 已提交
296
    case SDB_STATUS_DROPPING:
S
Shengliang Guan 已提交
297
      terrno = TSDB_CODE_SDB_OBJ_DROPPING;
S
Shengliang Guan 已提交
298 299
      break;
    default:
S
Shengliang Guan 已提交
300 301
      terrno = TSDB_CODE_SDB_APP_ERROR;
      break;
S
Shengliang Guan 已提交
302 303
  }

S
Shengliang Guan 已提交
304 305
  taosRUnLockLatch(pLock);
  return pRet;
S
Shengliang Guan 已提交
306 307
}

S
Shengliang Guan 已提交
308
void sdbRelease(SSdb *pSdb, void *pObj) {
S
Shengliang Guan 已提交
309 310
  if (pObj == NULL) return;

S
Shengliang Guan 已提交
311
  SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
S
Shengliang Guan 已提交
312
  if (pRow->type >= SDB_MAX ) return;
S
Shengliang Guan 已提交
313

S
Shengliang Guan 已提交
314
  SRWLatch *pLock = &pSdb->locks[pRow->type];
S
Shengliang Guan 已提交
315 316 317
  taosRLockLatch(pLock);

  int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
S
Shengliang Guan 已提交
318
  sdbPrintOper(pSdb, pRow, "releaseRow");
S
Shengliang Guan 已提交
319
  if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
S
Shengliang Guan 已提交
320
    sdbFreeRow(pSdb, pRow);
S
Shengliang Guan 已提交
321 322 323
  }

  taosRUnLockLatch(pLock);
S
Shengliang Guan 已提交
324 325
}

S
Shengliang Guan 已提交
326
void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
327 328
  *ppObj = NULL;

S
Shengliang Guan 已提交
329
  SHashObj *hash = sdbGetHash(pSdb, type);
S
Shengliang Guan 已提交
330
  if (hash == NULL) return NULL;
S
Shengliang Guan 已提交
331

S
Shengliang Guan 已提交
332
  SRWLatch *pLock = &pSdb->locks[type];
S
Shengliang Guan 已提交
333
  taosRLockLatch(pLock);
S
Shengliang Guan 已提交
334

S
Shengliang Guan 已提交
335 336
  if (pIter != NULL) {
    SSdbRow *pLastRow = *(SSdbRow **)pIter;
S
Shengliang Guan 已提交
337
    int32_t  ref = atomic_load_32(&pLastRow->refCount);
S
Shengliang Guan 已提交
338
    if (ref <= 0 && pLastRow->status == SDB_STATUS_DROPPED) {
S
Shengliang Guan 已提交
339
      sdbFreeRow(pSdb, pLastRow);
S
Shengliang Guan 已提交
340 341 342 343
    }
  }

  SSdbRow **ppRow = taosHashIterate(hash, pIter);
S
Shengliang Guan 已提交
344 345 346 347 348 349 350 351
  while (ppRow != NULL) {
    SSdbRow *pRow = *ppRow;
    if (pRow == NULL || pRow->status != SDB_STATUS_READY) {
      ppRow = taosHashIterate(hash, ppRow);
      continue;
    }

    atomic_add_fetch_32(&pRow->refCount, 1);
S
Shengliang Guan 已提交
352
    sdbPrintOper(pSdb, pRow, "fetchRow");
S
Shengliang Guan 已提交
353 354 355
    *ppObj = pRow->pObj;
    break;
  }
S
Shengliang Guan 已提交
356 357
  taosRUnLockLatch(pLock);

S
Shengliang Guan 已提交
358
  return ppRow;
S
Shengliang Guan 已提交
359 360
}

S
Shengliang Guan 已提交
361
void sdbCancelFetch(SSdb *pSdb, void *pIter) {
S
Shengliang Guan 已提交
362 363
  if (pIter == NULL) return;
  SSdbRow  *pRow = *(SSdbRow **)pIter;
S
Shengliang Guan 已提交
364
  SHashObj *hash = sdbGetHash(pSdb, pRow->type);
S
Shengliang Guan 已提交
365
  if (hash == NULL) return;
S
Shengliang Guan 已提交
366

S
Shengliang Guan 已提交
367
  SRWLatch *pLock = &pSdb->locks[pRow->type];
S
Shengliang Guan 已提交
368
  taosRLockLatch(pLock);
S
Shengliang Guan 已提交
369
  taosHashCancelIterate(hash, pIter);
S
Shengliang Guan 已提交
370
  taosRUnLockLatch(pLock);
S
Shengliang Guan 已提交
371 372
}

S
Shengliang Guan 已提交
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2, void *p3) {
  SHashObj *hash = sdbGetHash(pSdb, type);
  if (hash == NULL) return;

  SRWLatch *pLock = &pSdb->locks[type];
  taosRLockLatch(pLock);

  SSdbRow **ppRow = taosHashIterate(hash, NULL);
  while (ppRow != NULL) {
    SSdbRow *pRow = *ppRow;
    if (pRow->status == SDB_STATUS_READY) {
      bool isContinue = (*fp)(pSdb->pMnode, pRow->pObj, p1, p2, p3);
      if (!isContinue) {
        taosHashCancelIterate(hash, ppRow);
        break;
      }
    }

    ppRow = taosHashIterate(hash, ppRow);
  }

  taosRUnLockLatch(pLock);
}

S
Shengliang Guan 已提交
397 398
int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
  SHashObj *hash = sdbGetHash(pSdb, type);
S
Shengliang Guan 已提交
399
  if (hash == NULL) return 0;
S
Shengliang Guan 已提交
400

S
Shengliang Guan 已提交
401
  SRWLatch *pLock = &pSdb->locks[type];
S
Shengliang Guan 已提交
402 403 404 405 406
  taosRLockLatch(pLock);
  int32_t size = taosHashGetSize(hash);
  taosRUnLockLatch(pLock);

  return size;
S
Shengliang Guan 已提交
407
}
S
Shengliang Guan 已提交
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423

int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type) {
  SHashObj *hash = sdbGetHash(pSdb, type);
  if (hash == NULL) return -1;

  if (pSdb->keyTypes[type] != SDB_KEY_INT32) return -1;

  int32_t maxId = 0;

  SRWLatch *pLock = &pSdb->locks[type];
  taosRLockLatch(pLock);

  SSdbRow **ppRow = taosHashIterate(hash, NULL);
  while (ppRow != NULL) {
    SSdbRow *pRow = *ppRow;
    int32_t  id = *(int32_t *)pRow->pObj;
dengyihao's avatar
dengyihao 已提交
424
    maxId = TMAX(id, maxId);
S
Shengliang Guan 已提交
425 426 427 428 429
    ppRow = taosHashIterate(hash, ppRow);
  }

  taosRUnLockLatch(pLock);

dengyihao's avatar
dengyihao 已提交
430
  maxId = TMAX(maxId, pSdb->maxId[type]);
S
Shengliang Guan 已提交
431 432
  return maxId + 1;
}
433 434 435 436 437 438 439 440 441

int64_t sdbGetTableVer(SSdb *pSdb, ESdbType type) {
  if (type >= SDB_MAX || type < 0) {
    terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
    return -1;
  }

  return pSdb->tableVer[type];
}