Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
59de14ea
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
59de14ea
编写于
10月 12, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wrap tkv
上级
8287a34c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
127 addition
and
46 deletion
+127
-46
CMakeLists.txt
CMakeLists.txt
+1
-1
include/libs/tkv/tkv.h
include/libs/tkv/tkv.h
+21
-8
source/libs/tkv/CMakeLists.txt
source/libs/tkv/CMakeLists.txt
+4
-0
source/libs/tkv/src/tkv.c
source/libs/tkv/src/tkv.c
+68
-1
source/server/vnode/meta/CMakeLists.txt
source/server/vnode/meta/CMakeLists.txt
+1
-1
source/server/vnode/meta/src/meta.c
source/server/vnode/meta/src/meta.c
+31
-34
source/server/vnode/meta/test/CMakeLists.txt
source/server/vnode/meta/test/CMakeLists.txt
+1
-1
未找到文件。
CMakeLists.txt
浏览文件 @
59de14ea
...
...
@@ -42,7 +42,7 @@ if(${BUILD_WITH_LEVELDB})
endif
(
${
BUILD_WITH_LEVELDB
}
)
## rocksdb
option
(
BUILD_WITH_ROCKSDB
"If build with rocksdb"
O
N
)
option
(
BUILD_WITH_ROCKSDB
"If build with rocksdb"
O
FF
)
if
(
${
BUILD_WITH_ROCKSDB
}
)
cat
(
"
${
CMAKE_SUPPORT_DIR
}
/rocksdb_CMakeLists.txt.in"
${
DEPS_TMP_FILE
}
)
endif
(
${
BUILD_WITH_ROCKSDB
}
)
...
...
include/libs/tkv/tkv.h
浏览文件 @
59de14ea
...
...
@@ -16,30 +16,43 @@
#ifndef _TD_TKV_H_
#define _TD_TKV_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// Types exported
typedef
struct
STkvDb
STkvDb
;
typedef
struct
STkvOptions
STkvOptions
;
typedef
struct
STkvCache
STkvCache
;
typedef
struct
STkvDb
STkvDb
;
typedef
struct
STkvOpts
STkvOpts
;
typedef
struct
STkvCache
STkvCache
;
typedef
struct
STkvReadOpts
STkvReadOpts
;
typedef
struct
STkvWriteOpts
STkvWriteOpts
;
// DB operations
STkvDb
*
tkvOpen
(
const
STkvOpt
ion
s
*
options
,
const
char
*
path
);
STkvDb
*
tkvOpen
(
const
STkvOpts
*
options
,
const
char
*
path
);
void
tkvClose
(
STkvDb
*
db
);
void
tkvPut
(
STkvDb
*
db
,
void
*
/*TODO*/
);
void
tkvPut
(
STkvDb
*
db
,
STkvWriteOpts
*
,
char
*
key
,
size_t
keylen
,
char
*
val
,
size_t
vallen
);
char
*
tkvGet
(
STkvDb
*
db
,
STkvReadOpts
*
,
char
*
key
,
size_t
keylen
,
size_t
*
vallen
);
// DB options
STkvOpt
ion
s
*
tkvOptionsCreate
();
void
tkvOptionsDestroy
(
STkvOption
s
*
);
void
tkvOptionsSetCache
(
STkvOption
s
*
,
STkvCache
*
);
STkvOpts
*
tkvOptionsCreate
();
void
tkvOptionsDestroy
(
STkvOpt
s
*
);
void
tkvOptionsSetCache
(
STkvOpt
s
*
,
STkvCache
*
);
// DB cache
typedef
enum
{
TKV_LRU_CACHE
=
0
,
TKV_LFU_CACHE
=
1
}
ETkvCacheType
;
STkvCache
*
tkvCacheCreate
(
size_t
capacity
,
ETkvCacheType
type
);
void
tkvCacheDestroy
(
STkvCache
*
);
// STkvReadOpts
STkvReadOpts
*
tkvReadOptsCreate
();
void
tkvReadOptsDestroy
(
STkvReadOpts
*
);
// STkvWriteOpts
STkvWriteOpts
*
tkvWriteOptsCreate
();
void
tkvWriteOptsDestroy
(
STkvWriteOpts
*
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/tkv/CMakeLists.txt
浏览文件 @
59de14ea
...
...
@@ -4,4 +4,8 @@ target_include_directories(
tkv
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/tkv"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
target_link_libraries
(
tkv
PUBLIC os
)
\ No newline at end of file
source/libs/tkv/src/tkv.c
浏览文件 @
59de14ea
...
...
@@ -11,4 +11,71 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
\ No newline at end of file
*/
#include "tkv.h"
struct
STkvDb
{
// TODO
};
struct
STkvOpts
{
// TODO
};
struct
STkvCache
{
// TODO
};
struct
STkvReadOpts
{
// TODO
};
struct
STkvWriteOpts
{
// TODO
};
STkvDb
*
tkvOpen
(
const
STkvOpts
*
options
,
const
char
*
path
)
{
// TODO
return
NULL
;
}
void
tkvClose
(
STkvDb
*
db
)
{
// TODO
}
void
tkvPut
(
STkvDb
*
db
,
STkvWriteOpts
*
pwopts
,
char
*
key
,
size_t
keylen
,
char
*
val
,
size_t
vallen
)
{
// TODO
}
char
*
tkvGet
(
STkvDb
*
db
,
STkvReadOpts
*
propts
,
char
*
key
,
size_t
keylen
,
size_t
*
vallen
)
{
// TODO
return
NULL
;
}
STkvOpts
*
tkvOptionsCreate
()
{
// TODO
return
NULL
;
}
void
tkvOptionsDestroy
(
STkvOpts
*
popts
)
{
// TODO
}
void
tkvOptionsSetCache
(
STkvOpts
*
popts
,
STkvCache
*
pCache
)
{
// TODO
}
STkvReadOpts
*
tkvReadOptsCreate
()
{
// TODO
return
NULL
;
}
void
tkvReadOptsDestroy
(
STkvReadOpts
*
propts
)
{
// TODO
}
STkvWriteOpts
*
tkvWriteOptsCreate
()
{
// TODO
return
NULL
;
}
void
tkvWriteOptsDestroy
(
STkvWriteOpts
*
pwopts
)
{
// TODO
}
\ No newline at end of file
source/server/vnode/meta/CMakeLists.txt
浏览文件 @
59de14ea
...
...
@@ -8,8 +8,8 @@ target_include_directories(
target_link_libraries
(
meta
PUBLIC common
PUBLIC tkv
)
target_link_libraries
(
meta PUBLIC rocksdb
)
if
(
${
BUILD_TEST
}
)
add_subdirectory
(
test
)
...
...
source/server/vnode/meta/src/meta.c
浏览文件 @
59de14ea
...
...
@@ -13,8 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rocksdb/c.h>
#include "tkv.h"
#include "thash.h"
#include "tlist.h"
#include "tlockfree.h"
...
...
@@ -44,13 +43,13 @@ typedef struct STableObj {
struct
SMeta
{
pthread_rwlock_t
rwLock
;
SHashObj
*
pTableObjHash
;
// uid --> STableObj
SList
*
stbList
;
// super table list
rocksdb_t
*
tbnameDb
;
// tbname --> uid
rocksdb_t
*
tagDb
;
// uid --> tag
rocksdb_t
*
schemaDb
;
rocksdb_t
*
tagIdx
;
size_t
totalUsed
;
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
);
...
...
@@ -74,34 +73,33 @@ SMeta *metaOpen(SMetaOpts *options) {
pMeta
->
stbList
=
tdListNew
(
sizeof
(
STableObj
*
));
// Options
rocksdb_options_t
*
dbOptions
=
rocksdb_options_create
();
rocksdb_options_set_create_if_missing
(
dbOptions
,
1
);
STkvOpts
*
dbOptions
=
tkvOptionsCreate
();
taosMkDir
(
"meta"
);
// Open tbname DB
pMeta
->
tbnameDb
=
rocksdb_open
(
dbOptions
,
"meta/tbname_uid_db"
,
&
err
);
pMeta
->
tbnameDb
=
tkvOpen
(
dbOptions
,
"meta/tbname_uid_db"
);
// Open tag DB
pMeta
->
tagDb
=
rocksdb_open
(
dbOptions
,
"meta/uid_tag_db"
,
&
err
);
pMeta
->
tagDb
=
tkvOpen
(
dbOptions
,
"meta/uid_tag_db"
);
// Open schema DB
pMeta
->
schemaDb
=
rocksdb_open
(
dbOptions
,
"meta/schema_db"
,
&
err
);
pMeta
->
schemaDb
=
tkvOpen
(
dbOptions
,
"meta/schema_db"
);
// Open tag index
pMeta
->
tagIdx
=
rocksdb_open
(
dbOptions
,
"meta/tag_idx_db"
,
&
err
);
pMeta
->
tagIdx
=
tkvOpen
(
dbOptions
,
"meta/tag_idx_db"
);
rocksdb_options_d
estroy
(
dbOptions
);
tkvOptionsD
estroy
(
dbOptions
);
return
pMeta
;
}
void
metaClose
(
SMeta
*
pMeta
)
{
if
(
pMeta
)
{
rocksdb_c
lose
(
pMeta
->
tagIdx
);
rocksdb_c
lose
(
pMeta
->
schemaDb
);
rocksdb_c
lose
(
pMeta
->
tagDb
);
rocksdb_c
lose
(
pMeta
->
tbnameDb
);
tkvC
lose
(
pMeta
->
tagIdx
);
tkvC
lose
(
pMeta
->
schemaDb
);
tkvC
lose
(
pMeta
->
tagDb
);
tkvC
lose
(
pMeta
->
tbnameDb
);
tdListFree
(
pMeta
->
stbList
);
taosHashCleanup
(
pMeta
->
pTableObjHash
);
...
...
@@ -110,22 +108,21 @@ void metaClose(SMeta *pMeta) {
}
int
metaCreateTable
(
SMeta
*
pMeta
,
STableOpts
*
pTableOpts
)
{
size_t
vallen
;
char
*
err
=
NULL
;
rocksdb_readoptions_t
*
ropt
;
STableObj
*
pTableObj
=
NULL
;
rocksdb_writeoptions_t
*
wopt
;
size_t
vallen
;
STkvReadOpts
*
ropt
;
STableObj
*
pTableObj
=
NULL
;
STkvWriteOpts
*
wopt
;
// Check if table already exists
ropt
=
rocksdb_readoptions_c
reate
();
ropt
=
tkvReadOptsC
reate
();
char
*
uidStr
=
rocksdb_get
(
pMeta
->
tbnameDb
,
ropt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
&
vallen
,
&
err
);
char
*
uidStr
=
tkvGet
(
pMeta
->
tbnameDb
,
ropt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
&
vallen
);
if
(
uidStr
!=
NULL
)
{
// Has duplicate named table
return
-
1
;
}
rocksdb_readoptions_d
estroy
(
ropt
);
tkvReadOptsD
estroy
(
ropt
);
// Create table obj
pTableObj
=
metaTableObjNew
();
...
...
@@ -144,12 +141,12 @@ int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
taosHashPut
(
pMeta
->
pTableObjHash
,
&
(
pTableObj
->
pTable
->
uid
),
sizeof
(
tb_uid_t
),
&
pTableObj
,
sizeof
(
pTableObj
));
wopt
=
rocksdb_writeoptions_c
reate
();
rocksdb_writeoptions_disable_WAL
(
wopt
,
1
);
wopt
=
tkvWriteOptsC
reate
();
//
rocksdb_writeoptions_disable_WAL(wopt, 1);
// Add to tbname db
rocksdb_put
(
pMeta
->
tbnameDb
,
wopt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
&
pTableObj
->
pTable
->
uid
,
sizeof
(
tb_uid_t
)
,
&
err
);
tkvPut
(
pMeta
->
tbnameDb
,
wopt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
(
char
*
)
&
pTableObj
->
pTable
->
uid
,
sizeof
(
tb_uid_t
));
// Add to schema db
char
id
[
12
];
...
...
@@ -159,9 +156,9 @@ int metaCreateTable(SMeta *pMeta, STableOpts *pTableOpts) {
*
(
int32_t
*
)(
id
+
sizeof
(
tb_uid_t
))
=
schemaVersion
(
pTableOpts
->
pSchema
);
int
size
=
tdEncodeSchema
(
&
pBuf
,
pTableOpts
->
pSchema
);
rocksdb_put
(
pMeta
->
schemaDb
,
wopt
,
id
,
12
,
buf
,
size
,
&
err
);
tkvPut
(
pMeta
->
schemaDb
,
wopt
,
id
,
12
,
buf
,
size
);
rocksdb_writeoptions_d
estroy
(
wopt
);
tkvWriteOptsD
estroy
(
wopt
);
pthread_rwlock_unlock
(
&
pMeta
->
rwLock
);
...
...
source/server/vnode/meta/test/CMakeLists.txt
浏览文件 @
59de14ea
...
...
@@ -14,8 +14,8 @@ target_link_libraries(metaTest
os
util
common
rocksdb
gtest_main
tkv
)
enable_testing
()
add_test
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录