Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4bf754b1
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4bf754b1
编写于
12月 03, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
try to use SQLite
上级
92ec8790
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
138 addition
and
43 deletion
+138
-43
source/dnode/vnode/impl/CMakeLists.txt
source/dnode/vnode/impl/CMakeLists.txt
+1
-1
source/dnode/vnode/meta/inc/metaDB.h
source/dnode/vnode/meta/inc/metaDB.h
+6
-0
source/dnode/vnode/meta/src/metaDB.c
source/dnode/vnode/meta/src/metaDB.c
+127
-42
source/dnode/vnode/meta/src/metaIdx.c
source/dnode/vnode/meta/src/metaIdx.c
+4
-0
未找到文件。
source/dnode/vnode/impl/CMakeLists.txt
浏览文件 @
4bf754b1
...
...
@@ -19,5 +19,5 @@ target_link_libraries(
# test
if
(
${
BUILD_TEST
}
)
#
add_subdirectory(test)
add_subdirectory
(
test
)
endif
(
${
BUILD_TEST
}
)
\ No newline at end of file
source/dnode/vnode/meta/inc/metaDB.h
浏览文件 @
4bf754b1
...
...
@@ -16,6 +16,8 @@
#ifndef _TD_META_DB_H_
#define _TD_META_DB_H_
#define USE_SQLITE_IMPL 1
#include "rocksdb/c.h"
#include "sqlite3.h"
...
...
@@ -25,6 +27,7 @@
extern
"C"
{
#endif
#if !USE_SQLITE_IMPL
typedef
struct
{
rocksdb_t
*
tbDb
;
// uid -> tb obj
rocksdb_t
*
nameDb
;
// name -> uid
...
...
@@ -32,6 +35,9 @@ typedef struct {
rocksdb_t
*
schemaDb
;
// uid+version -> schema
sqlite3
*
mapDb
;
// suid -> uid_list
}
meta_db_t
;
#else
typedef
sqlite3
meta_db_t
;
#endif
int
metaOpenDB
(
SMeta
*
pMeta
);
void
metaCloseDB
(
SMeta
*
pMeta
);
...
...
source/dnode/vnode/meta/src/metaDB.c
浏览文件 @
4bf754b1
...
...
@@ -15,9 +15,9 @@
#include "metaDef.h"
#if !USE_SQLITE_IMPL
static
void
metaSaveSchemaDB
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
STSchema
*
pSchema
);
static
void
metaGetSchemaDBKey
(
char
key
[],
tb_uid_t
uid
,
int
sversion
);
// static int metaSaveMapDB(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid);
#define SCHEMA_KEY_LEN (sizeof(tb_uid_t) + sizeof(int))
...
...
@@ -31,9 +31,20 @@ static void metaGetSchemaDBKey(char key[], tb_uid_t uid, int sversion);
} \
} while (0)
#define META_CLOSE_DB_IMPL(pDB) \
do { \
if (pDB) { \
rocksdb_close(pDB); \
pDB = NULL; \
} \
} while (0)
#endif
int
metaOpenDB
(
SMeta
*
pMeta
)
{
char
dir
[
128
];
char
*
err
=
NULL
;
int
rc
;
char
*
err
=
NULL
;
#if !USE_SQLITE_IMPL
rocksdb_options_t
*
options
=
rocksdb_options_create
();
if
(
pMeta
->
pCache
)
{
...
...
@@ -75,18 +86,63 @@ int metaOpenDB(SMeta *pMeta) {
sqlite3_exec
(
pMeta
->
pDB
->
mapDb
,
"BEGIN;"
,
0
,
0
,
0
);
rocksdb_options_destroy
(
options
);
#else
sprintf
(
dir
,
"%s/meta.db"
,
pMeta
->
path
);
rc
=
sqlite3_open
(
dir
,
&
(
pMeta
->
pDB
));
if
(
rc
!=
SQLITE_OK
)
{
// TODO: handle error
printf
(
"failed to open meta.db
\n
"
);
}
// For all tables
rc
=
sqlite3_exec
(
pMeta
->
pDB
,
"CREATE TABLE IF NOT EXISTS tb ("
" tbname VARCHAR(256) NOT NULL UNIQUE,"
" tb_uid INTEGER NOT NULL UNIQUE "
");"
,
NULL
,
NULL
,
&
err
);
if
(
rc
!=
SQLITE_OK
)
{
// TODO: handle error
printf
(
"failed to create meta table tb since %s
\n
"
,
err
);
}
// For super tables
rc
=
sqlite3_exec
(
pMeta
->
pDB
,
"CREATE TABLE IF NOT EXISTS stb ("
" tb_uid INTEGER NOT NULL UNIQUE,"
" tbname VARCHAR(256) NOT NULL UNIQUE,"
" tb_schema BLOB NOT NULL,"
" tag_schema BLOB NOT NULL"
");"
,
NULL
,
NULL
,
&
err
);
if
(
rc
!=
SQLITE_OK
)
{
// TODO: handle error
printf
(
"failed to create meta table stb since %s
\n
"
,
err
);
}
// For normal tables
rc
=
sqlite3_exec
(
pMeta
->
pDB
,
"CREATE TABLE IF NOT EXISTS ntb ("
" tb_uid INTEGER NOT NULL UNIQUE,"
" tbname VARCHAR(256) NOT NULL,"
" tb_schema BLOB NOT NULL"
");"
,
NULL
,
NULL
,
&
err
);
if
(
rc
!=
SQLITE_OK
)
{
// TODO: handle error
printf
(
"failed to create meta table ntb since %s
\n
"
,
err
);
}
sqlite3_exec
(
pMeta
->
pDB
,
"BEGIN;"
,
NULL
,
NULL
,
&
err
);
tfree
(
err
);
#endif
return
0
;
}
#define META_CLOSE_DB_IMPL(pDB) \
do { \
if (pDB) { \
rocksdb_close(pDB); \
pDB = NULL; \
} \
} while (0)
void
metaCloseDB
(
SMeta
*
pMeta
)
{
#if !USE_SQLITE_IMPL
if
(
pMeta
->
pDB
)
{
if
(
pMeta
->
pDB
->
mapDb
)
{
sqlite3_exec
(
pMeta
->
pDB
->
mapDb
,
"COMMIT;"
,
0
,
0
,
0
);
...
...
@@ -101,9 +157,19 @@ void metaCloseDB(SMeta *pMeta) {
free
(
pMeta
->
pDB
);
pMeta
->
pDB
=
NULL
;
}
#else
if
(
pMeta
->
pDB
)
{
sqlite3_exec
(
pMeta
->
pDB
,
"BEGIN;"
,
NULL
,
NULL
,
NULL
);
sqlite3_close
(
pMeta
->
pDB
);
pMeta
->
pDB
=
NULL
;
}
// TODO
#endif
}
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
const
STbCfg
*
pTbOptions
)
{
#if !USE_SQLITE_IMPL
tb_uid_t
uid
;
char
*
err
=
NULL
;
size_t
size
;
...
...
@@ -140,7 +206,7 @@ int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions) {
// rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&uid), sizeof(uid), "", 0, &err);
sprintf
(
sql
,
"create table st_%"
PRIu64
" (uid BIGINT);"
,
uid
);
if
(
sqlite3_exec
(
pMeta
->
pDB
->
mapDb
,
sql
,
NULL
,
NULL
,
&
err
)
!=
SQLITE_OK
)
{
// fprintf(stderr,
"Failed to create table, since %s\n", err);
// fprintf(stderr,"Failed to create table, since %s\n", err);
}
break
;
case
META_CHILD_TABLE
:
...
...
@@ -159,6 +225,53 @@ int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions) {
}
rocksdb_writeoptions_destroy
(
wopt
);
#else
char
sql
[
256
];
char
*
err
=
NULL
;
int
rc
;
switch
(
pTbOptions
->
type
)
{
case
META_SUPER_TABLE
:
// sprintf(sql, "INSERT INTO tb VALUES (\'%s\', %" PRIu64
// ");"
// "INSERT INTO stb VALUES (%" PRIu64
// ", \'%s\', );"
// "CREATE TABLE IF NOT EXISTS stb_%" PRIu64
// " ("
// " tb_uid INTEGER NOT NULL UNIQUE,"
// " tbname VARCHAR(256),"
// " tag1 INTEGER"
// ");"
// "CREATE INDEX IF NOT EXISTS stb_%" PRIu64 "_tag1_idx ON stb_1638517480 (tag1);");
rc
=
sqlite3_exec
(
pMeta
->
pDB
,
sql
,
NULL
,
NULL
,
&
err
);
if
(
rc
!=
SQLITE_OK
)
{
printf
(
"failed to create normal table since %s
\n
"
,
err
);
}
break
;
case
META_NORMAL_TABLE
:
// sprintf(sql, "INSERT INTO tb VALUES (\'%s\', %" PRIu64
// ");"
// "INSERT INTO ntb VALUES (%" PRIu64 ", \'%s\', );");
rc
=
sqlite3_exec
(
pMeta
->
pDB
,
sql
,
NULL
,
NULL
,
&
err
);
if
(
rc
!=
SQLITE_OK
)
{
printf
(
"failed to create normal table since %s
\n
"
,
err
);
}
break
;
case
META_CHILD_TABLE
:
// sprintf(sql, "INSERT INTO tb VALUES (\'%s\', %" PRIu64
// ");"
// "INSERT INTO stb_%" PRIu64 " VALUES (%" PRIu64 ", \'%s\', );");
rc
=
sqlite3_exec
(
pMeta
->
pDB
,
sql
,
NULL
,
NULL
,
&
err
);
if
(
rc
!=
SQLITE_OK
)
{
printf
(
"failed to create normal table since %s
\n
"
,
err
);
}
break
;
default:
break
;
}
tfree
(
err
);
#endif
return
0
;
}
...
...
@@ -169,6 +282,7 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
}
/* ------------------------ STATIC METHODS ------------------------ */
#if !USE_SQLITE_IMPL
static
void
metaSaveSchemaDB
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
STSchema
*
pSchema
)
{
char
key
[
64
];
char
pBuf
[
1024
];
...
...
@@ -190,33 +304,4 @@ static void metaGetSchemaDBKey(char *key, tb_uid_t uid, int sversion) {
*
(
tb_uid_t
*
)
key
=
uid
;
*
(
int
*
)
POINTER_SHIFT
(
key
,
sizeof
(
tb_uid_t
))
=
sversion
;
}
// static int metaSaveMapDB(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid) {
// size_t vlen;
// char * val;
// char * err = NULL;
// rocksdb_readoptions_t *ropt = rocksdb_readoptions_create();
// val = rocksdb_get(pMeta->pDB->mapDb, ropt, (char *)(&suid), sizeof(suid), &vlen, &err);
// rocksdb_readoptions_destroy(ropt);
// void *nval = malloc(vlen + sizeof(uid));
// if (nval == NULL) {
// return -1;
// }
// if (vlen) {
// memcpy(nval, val, vlen);
// }
// memcpy(POINTER_SHIFT(nval, vlen), (void *)(&uid), sizeof(uid));
// rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create();
// rocksdb_writeoptions_disable_WAL(wopt, 1);
// rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&suid), sizeof(suid), nval, vlen + sizeof(uid), &err);
// rocksdb_writeoptions_destroy(wopt);
// free(nval);
// return 0;
// }
\ No newline at end of file
#endif
\ No newline at end of file
source/dnode/vnode/meta/src/metaIdx.c
浏览文件 @
4bf754b1
...
...
@@ -16,6 +16,7 @@
#include "metaDef.h"
int
metaOpenIdx
(
SMeta
*
pMeta
)
{
#if 0
char idxDir[128]; // TODO
char * err = NULL;
rocksdb_options_t *options = rocksdb_options_create();
...
...
@@ -36,15 +37,18 @@ int metaOpenIdx(SMeta *pMeta) {
}
rocksdb_options_destroy(options);
#endif
return
0
;
}
void
metaCloseIdx
(
SMeta
*
pMeta
)
{
/* TODO */
#if 0
if (pMeta->pIdx) {
rocksdb_close(pMeta->pIdx);
pMeta->pIdx = NULL;
}
#endif
}
int
metaSaveTableToIdx
(
SMeta
*
pMeta
,
const
STbCfg
*
pTbOptions
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录