提交 d1b6f2b2 编写于 作者: H Hongze Cheng

more

上级 7d7c380c
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册