diff --git a/include/server/vnode/meta/meta.h b/include/server/vnode/meta/meta.h index 4775b8c2ad9b057648b8335409c72f176a425453..541f1b03163662f3dcbc6ed908a000e198ac5b7b 100644 --- a/include/server/vnode/meta/meta.h +++ b/include/server/vnode/meta/meta.h @@ -58,10 +58,12 @@ SMetaQueryOpts *metaQueryOptionsCreate(); void metaQueryOptionsDestroy(SMetaQueryOpts *); // STableOpts -void metaTableOptsInit(STableOpts *, int8_t type, const char *name, const STSchema *pSchema); +#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}; +void metaNormalTableOptsInit(STableOpts *, const char *name, const STSchema *pSchema); +void metaTableOptsDestroy(STableOpts *); /* ------------------------ Impl should hidden ------------------------ */ -typedef enum { META_SUPER_TABLE = 0, META_CHILD_TABLE = 1, META_NORMAL_TABLE = 2 } EMetaTableT; +typedef enum { META_INIT_TABLE = 0, META_SUPER_TABLE = 1, META_CHILD_TABLE = 2, META_NORMAL_TABLE = 3 } EMetaTableT; typedef struct SSuperTableOpts { tb_uid_t uid; STSchema *pSchema; // (ts timestamp, a int) @@ -78,8 +80,8 @@ typedef struct SNormalTableOpts { } SNormalTableOpts; struct STableOpts { - EMetaTableT type; - char * name; + int8_t type; + char * name; union { SSuperTableOpts superOpts; SChildTableOpts childOpts; diff --git a/source/server/vnode/meta/src/metaMain.c b/source/server/vnode/meta/src/metaMain.c index 6f529f04c866d911b428b85653c65940863fec61..1b12b540046f935fca66074eabfe7dc880bf42ec 100644 --- a/source/server/vnode/meta/src/metaMain.c +++ b/source/server/vnode/meta/src/metaMain.c @@ -212,6 +212,26 @@ static int metaCreateNormalTable(SMeta *pMeta, const char *tbname, const SNormal return 0; } +void metaNormalTableOptsInit(STableOpts *pTableOpts, const char *name, const STSchema *pSchema) { + pTableOpts->type = META_NORMAL_TABLE; + pTableOpts->name = strdup(name); + pTableOpts->normalOpts.pSchema = tdDupSchema(pSchema); +} + +void metaTableOptsDestroy(STableOpts *pTableOpts) { + switch (pTableOpts->type) { + case META_NORMAL_TABLE: + tfree(pTableOpts->name); + tdFreeSchema(pTableOpts->normalOpts.pSchema); + break; + default: + break; + } + + // TODO + pTableOpts->type = META_INIT_TABLE; +} + #if 0 /* -------------------- Structures -------------------- */ static STable * metaTableNew(tb_uid_t uid, const char *name, int32_t sver); diff --git a/source/server/vnode/meta/test/metaTests.cpp b/source/server/vnode/meta/test/metaTests.cpp index c352b496032548d2603930b479e6e67a6735886c..1fa08f746e5a7e387fff83a73feda42b108709cc 100644 --- a/source/server/vnode/meta/test/metaTests.cpp +++ b/source/server/vnode/meta/test/metaTests.cpp @@ -4,30 +4,36 @@ #include "meta.h" +static STSchema *metaGetSimpleSchema() { + STSchema * pSchema = NULL; + STSchemaBuilder sb; + + tdInitTSchemaBuilder(&sb, 0); + tdAddColToSchema(&sb, TSDB_DATA_TYPE_TIMESTAMP, 0, 8); + tdAddColToSchema(&sb, TSDB_DATA_TYPE_INT, 1, 4); + + pSchema = tdGetSchemaFromBuilder(&sb); + tdDestroyTSchemaBuilder(&sb); + + return pSchema; +} + TEST(MetaTest, meta_open_test) { // Open Meta SMeta *meta = metaOpen(NULL); std::cout << "Meta is opened!" << std::endl; -#if 0 - // Create tables - STableOpts tbOpts; - char tbname[128]; - STSchema * pSchema; - STSchemaBuilder sb; - tdInitTSchemaBuilder(&sb, 0); - for (size_t i = 0; i < 10; i++) { - tdAddColToSchema(&sb, TSDB_DATA_TYPE_TIMESTAMP, i, 8); - } - pSchema = tdGetSchemaFromBuilder(&sb); - tdDestroyTSchemaBuilder(&sb); - for (size_t i = 0; i < 1000000; i++) { - sprintf(tbname, "tb%ld", i); - metaTableOptsInit(&tbOpts, 0, tbname, pSchema); + // Create 1000000 normal tables + META_TABLE_OPTS_DECLARE(tbOpts) + STSchema *pSchema = metaGetSimpleSchema(); + char tbname[128]; + for (size_t i = 0; i < 1000000; i++) { + sprintf(tbname, "ntb%ld", i); + metaNormalTableOptsInit(&tbOpts, tbname, pSchema); metaCreateTable(meta, &tbOpts); + metaTableOptsDestroy(&tbOpts); } -#endif // Close Meta metaClose(meta);