From 36c20ec6176dcb2e99e62f633925a8310caeaef8 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 15 Oct 2021 09:55:43 +0800 Subject: [PATCH] more progress --- source/server/vnode/meta/inc/metaInt.h | 31 -------------------------- source/server/vnode/meta/inc/metaUid.h | 16 +++++++++++-- source/server/vnode/meta/src/meta.c | 29 +++++++++++++----------- source/server/vnode/meta/src/metaUid.c | 11 +++++---- 4 files changed, 37 insertions(+), 50 deletions(-) delete mode 100644 source/server/vnode/meta/inc/metaInt.h diff --git a/source/server/vnode/meta/inc/metaInt.h b/source/server/vnode/meta/inc/metaInt.h deleted file mode 100644 index 549ac829ab..0000000000 --- a/source/server/vnode/meta/inc/metaInt.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * 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 . - */ - -#ifndef _TD_META_INT_H_ -#define _TD_META_INT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -struct { - tkv_db_t db; -} SMeta; - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_META_INT_H_*/ \ No newline at end of file diff --git a/source/server/vnode/meta/inc/metaUid.h b/source/server/vnode/meta/inc/metaUid.h index b01492cbf7..f0a747bc74 100644 --- a/source/server/vnode/meta/inc/metaUid.h +++ b/source/server/vnode/meta/inc/metaUid.h @@ -22,10 +22,22 @@ extern "C" { #endif -typedef uint64_t tb_uid_t; -tb_uid_t metaGenerateUid(); +/* ------------------------ APIS EXPOSED ------------------------ */ +typedef uint64_t tb_uid_t; +typedef struct STableUidGenerator STableUidGenerator; +// tb_uid_t #define IVLD_TB_UID 0 +tb_uid_t generateUid(STableUidGenerator *); + +// STableUidGenerator +void tableUidGeneratorInit(STableUidGenerator *, tb_uid_t suid); +#define tableUidGeneratorClear(ug) + +/* ------------------------ FOR TEST AND COMPILE ONLY ------------------------ */ +struct STableUidGenerator { + tb_uid_t nextUid; +}; #ifdef __cplusplus } diff --git a/source/server/vnode/meta/src/meta.c b/source/server/vnode/meta/src/meta.c index 88d0ff2f16..57824e9fe6 100644 --- a/source/server/vnode/meta/src/meta.c +++ b/source/server/vnode/meta/src/meta.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include "tkv.h" #include "thash.h" +#include "tkv.h" #include "tlist.h" #include "tlockfree.h" #include "ttypes.h" @@ -43,13 +43,14 @@ typedef struct STableObj { struct SMeta { pthread_rwlock_t rwLock; - SHashObj *pTableObjHash; // uid --> STableObj - SList * stbList; // super table list - STkvDb * tbnameDb; // tbname --> uid - STkvDb * tagDb; // uid --> tag - STkvDb * schemaDb; - STkvDb * tagIdx; - size_t totalUsed; + STableUidGenerator uidGenerator; + SHashObj * pTableObjHash; // uid --> STableObj + SList * stbList; // super table list + STkvDb * tbnameDb; // tbname --> uid + STkvDb * tagDb; // uid --> tag + STkvDb * schemaDb; + STkvDb * tagIdx; + size_t totalUsed; }; static STable * metaTableNew(tb_uid_t uid, const char *name, int32_t sver); @@ -68,6 +69,7 @@ SMeta *metaOpen(SMetaOpts *options) { pthread_rwlock_init(&(pMeta->rwLock), NULL); + tableUidGeneratorInit(&(pMeta->uidGenerator), IVLD_TB_UID); pMeta->pTableObjHash = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); pMeta->stbList = tdListNew(sizeof(STableObj *)); @@ -109,9 +111,9 @@ void metaClose(SMeta *pMeta) { } int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) { - size_t vallen; - STkvReadOpts *ropt; - STableObj * pTableObj = NULL; + size_t vallen; + STkvReadOpts * ropt; + STableObj * pTableObj = NULL; STkvWriteOpts *wopt; // Check if table already exists @@ -133,7 +135,8 @@ int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) { } // Create table object - pTableObj->pTable = metaTableNew(metaGenerateUid(), pTableOpts->name, schemaVersion(pTableOpts->pSchema)); + pTableObj->pTable = + metaTableNew(generateUid(&(pMeta->uidGenerator)), pTableOpts->name, schemaVersion(pTableOpts->pSchema)); if (pTableObj->pTable == NULL) { // TODO } @@ -147,7 +150,7 @@ int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) { // Add to tbname db tkvPut(pMeta->tbnameDb, wopt, pTableOpts->name, strlen(pTableOpts->name), (char *)&pTableObj->pTable->uid, - sizeof(tb_uid_t)); + sizeof(tb_uid_t)); // Add to schema db char id[12]; diff --git a/source/server/vnode/meta/src/metaUid.c b/source/server/vnode/meta/src/metaUid.c index 4662969a2e..80afa490f3 100644 --- a/source/server/vnode/meta/src/metaUid.c +++ b/source/server/vnode/meta/src/metaUid.c @@ -15,9 +15,12 @@ #include "metaUid.h" -static tb_uid_t nuid = IVLD_TB_UID; +tb_uid_t generateUid(STableUidGenerator *pGen) { + // Generate a new table UID + return ++(pGen->nextUid); +} -tb_uid_t metaGenerateUid() { - // TODO: need a more complex UID generator - return ++nuid; +void tableUidGeneratorInit(STableUidGenerator *pGen, tb_uid_t suid) { + // Init a generator + pGen->nextUid = suid; } \ No newline at end of file