This commit is contained in:
Hongze Cheng 2021-11-03 10:00:49 +08:00
parent f184d1d3d4
commit 27f465a884
3 changed files with 39 additions and 18 deletions

View File

@ -27,13 +27,13 @@ typedef struct STbUidGenerator {
tb_uid_t nextUid; tb_uid_t nextUid;
} STbUidGenerator; } STbUidGenerator;
// STableUidGenerator
int metaOpenUidGnrt(SMeta *pMeta);
void metaCloseUidGnrt(SMeta *pMeta);
// tb_uid_t // tb_uid_t
#define IVLD_TB_UID 0 #define IVLD_TB_UID 0
tb_uid_t generateUid(STbUidGenerator *); tb_uid_t metaGenerateUid(SMeta *pMeta);
// STableUidGenerator
void tableUidGeneratorInit(STbUidGenerator *, tb_uid_t suid);
#define tableUidGeneratorClear(ug)
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -44,25 +44,41 @@ SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) {
return NULL; return NULL;
} }
// Create META path // Create META path (TODO)
taosMkDir(path); taosMkDir(path);
// Open the DBs needed // Open meta cache
if (metaOpenDB(pMeta) < 0) { if (metaOpenCache(pMeta) < 0) {
// TODO: handle error // TODO: handle error
metaFree(pMeta);
return NULL; return NULL;
} }
tableUidGeneratorInit(&(pMeta->uidGnrt), IVLD_TB_UID); // Open meta db
if (metaOpenDB(pMeta) < 0) {
// TODO: handle error
return NULL;
}
// Open meta index
if (metaOpenIdx(pMeta) < 0) {
// TODO: handle error
return NULL;
}
// Open meta table uid generator
if (metaOpenUidGnrt(pMeta) < 0) {
return NULL;
}
return pMeta; return pMeta;
} }
void metaClose(SMeta *pMeta) { void metaClose(SMeta *pMeta) {
if (pMeta) { if (pMeta) {
tableUidGeneratorClear(&pMeta->uidGnrt); metaCloseUidGnrt(pMeta);
metaCloseIdx(pMeta);
metaCloseDB(pMeta); metaCloseDB(pMeta);
metaCloseCache(pMeta);
metaFree(pMeta); metaFree(pMeta);
} }
} }
@ -81,6 +97,7 @@ static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions) {
pMeta->path = strdup(path); pMeta->path = strdup(path);
if (pMeta->path == NULL) { if (pMeta->path == NULL) {
metaFree(pMeta);
return NULL; return NULL;
} }

View File

@ -13,14 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "metaTbUid.h" #include "meta.h"
#include "metaDef.h"
tb_uid_t generateUid(STbUidGenerator *pGen) { int metaOpenUidGnrt(SMeta *pMeta) {
// Generate a new table UID // Init a generator
return ++(pGen->nextUid); pMeta->uidGnrt.nextUid = IVLD_TB_UID;
return 0;
} }
void tableUidGeneratorInit(STbUidGenerator *pGen, tb_uid_t suid) { void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ }
// Init a generator
pGen->nextUid = suid; tb_uid_t metaGenerateUid(SMeta *pMeta) {
// Generate a new table UID
return ++(pMeta->uidGnrt.nextUid);
} }