Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8050546d
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8050546d
编写于
2月 15, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
698377b8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
85 addition
and
28 deletion
+85
-28
source/libs/tdb/inc/tdb.h
source/libs/tdb/inc/tdb.h
+10
-7
source/libs/tdb/src/db/tdb.c
source/libs/tdb/src/db/tdb.c
+58
-14
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+1
-1
source/libs/tdb/test/tdbTest.cpp
source/libs/tdb/test/tdbTest.cpp
+16
-6
未找到文件。
source/libs/tdb/inc/tdb.h
浏览文件 @
8050546d
...
...
@@ -29,29 +29,32 @@ typedef struct STDbCurosr TDBC;
typedef
int32_t
pgsz_t
;
typedef
int32_t
cachesz_t
;
typedef
int
(
*
TdbKeyCmprFn
)(
int
keyLen1
,
const
void
*
pKey1
,
int
keyLen2
,
const
void
*
pKey2
);
// TEVN
int
tdbEnvCreate
(
TENV
**
ppEnv
,
const
char
*
rootDir
);
int
tdbEnvOpen
(
TENV
*
ppEnv
);
int
tdbEnvClose
(
TENV
*
pEnv
);
int
tdbEnvBeginTxn
(
TENV
*
pEnv
);
int
tdbEnvCommit
(
TENV
*
pEnv
);
int
tdbEnvSetCache
(
TENV
*
pEnv
,
pgsz_t
pgSize
,
cachesz_t
cacheSize
);
pgsz_t
tdbEnvGetPageSize
(
TENV
*
pEnv
);
cachesz_t
tdbEnvGetCacheSize
(
TENV
*
pEnv
);
int
tdbEnvBeginTxn
(
TENV
*
pEnv
);
int
tdbEnvCommit
(
TENV
*
pEnv
);
// TDB
int
tdbCreate
(
TDB
**
ppDb
);
int
tdbOpen
(
TDB
*
*
p
pDb
,
const
char
*
fname
,
const
char
*
dbname
,
TENV
*
pEnv
);
int
tdbOpen
(
TDB
*
pDb
,
const
char
*
fname
,
const
char
*
dbname
,
TENV
*
pEnv
);
int
tdbClose
(
TDB
*
pDb
);
int
tdbSetKeyLen
(
TDB
*
pDb
,
int
klen
);
int
tdbSetValLen
(
TDB
*
pDb
,
int
vlen
);
int
tdbSetDup
(
TDB
*
pDb
,
int
dup
);
int
tdbGetKeyLen
(
TDB
*
pDb
,
int
*
pklen
);
int
tdbGetValLen
(
TDB
*
pDb
,
int
*
pvlen
);
int
tdbGetDup
(
TDB
*
pDb
,
int
*
pdup
);
int
tdbSetCmprFunc
(
TDB
*
pDb
,
TdbKeyCmprFn
fn
);
int
tdbGetKeyLen
(
TDB
*
pDb
);
int
tdbGetValLen
(
TDB
*
pDb
);
int
tdbGetDup
(
TDB
*
pDb
);
int
tdbInsert
(
TDB
*
pDb
,
const
void
*
pKey
,
int
nKey
,
const
void
*
pData
,
int
nData
);
...
...
source/libs/tdb/src/db/tdb.c
浏览文件 @
8050546d
...
...
@@ -16,9 +16,14 @@
#include "tdbInt.h"
struct
STDb
{
SBTree
*
pBt
;
// current access method
SPgFile
*
pPgFile
;
// backend page file this DB is using
TENV
*
pEnv
;
// TENV containing the DB
char
*
dbname
;
// dbname;
SBTree
*
pBt
;
// current access method (may extend)
SPgFile
*
pPgFile
;
// backend page file this DB is using
TENV
*
pEnv
;
// TENV containing the DB
int
klen
;
// key length if know
int
vlen
;
// value length if know
bool
dup
;
// dup mode
TdbKeyCmprFn
cFn
;
// compare function
};
struct
STDbCurosr
{
...
...
@@ -28,13 +33,18 @@ struct STDbCurosr {
int
tdbCreate
(
TDB
**
ppDb
)
{
TDB
*
pDb
;
// create the handle
pDb
=
(
TDB
*
)
calloc
(
1
,
sizeof
(
*
pDb
));
if
(
pDb
==
NULL
)
{
return
-
1
;
}
/* TODO */
pDb
->
klen
=
TDB_VARIANT_LEN
;
pDb
->
vlen
=
TDB_VARIANT_LEN
;
pDb
->
dup
=
false
;
pDb
->
cFn
=
NULL
/*TODO*/
;
*
ppDb
=
pDb
;
return
0
;
}
...
...
@@ -45,22 +55,14 @@ static int tdbDestroy(TDB *pDb) {
return
0
;
}
int
tdbOpen
(
TDB
**
ppDb
,
const
char
*
fname
,
const
char
*
dbname
,
TENV
*
pEnv
)
{
TDB
*
pDb
;
int
tdbOpen
(
TDB
*
pDb
,
const
char
*
fname
,
const
char
*
dbname
,
TENV
*
pEnv
)
{
int
ret
;
uint8_t
fileid
[
TDB_FILE_ID_LEN
];
SPgFile
*
pPgFile
;
SPgCache
*
pPgCache
;
SBTree
*
pBt
;
// Create DB if DB handle is not created yet
if
(
ppDb
==
NULL
)
{
if
((
ret
=
tdbCreate
(
ppDb
))
!=
0
)
{
return
-
1
;
}
}
pDb
=
*
ppDb
;
ASSERT
(
pDb
!=
NULL
);
// Create a default ENV if pEnv is not set
if
(
pEnv
==
NULL
)
{
...
...
@@ -107,4 +109,46 @@ int tdbOpen(TDB **ppDb, const char *fname, const char *dbname, TENV *pEnv) {
int
tdbClose
(
TDB
*
pDb
)
{
if
(
pDb
==
NULL
)
return
0
;
return
tdbDestroy
(
pDb
);
}
int
tdbSetKeyLen
(
TDB
*
pDb
,
int
klen
)
{
// TODO: check `klen`
pDb
->
klen
=
klen
;
return
0
;
}
int
tdbSetValLen
(
TDB
*
pDb
,
int
vlen
)
{
// TODO: check `vlen`
pDb
->
vlen
=
vlen
;
return
0
;
}
int
tdbSetDup
(
TDB
*
pDb
,
int
dup
)
{
if
(
dup
)
{
pDb
->
dup
=
true
;
}
else
{
pDb
->
dup
=
false
;
}
return
0
;
}
int
tdbSetCmprFunc
(
TDB
*
pDb
,
TdbKeyCmprFn
fn
)
{
if
(
fn
==
NULL
)
{
return
-
1
;
}
else
{
pDb
->
cFn
=
fn
;
}
return
0
;
}
int
tdbGetKeyLen
(
TDB
*
pDb
)
{
return
pDb
->
klen
;
}
int
tdbGetValLen
(
TDB
*
pDb
)
{
return
pDb
->
vlen
;
}
int
tdbGetDup
(
TDB
*
pDb
)
{
if
(
pDb
->
dup
)
{
return
1
;
}
else
{
return
0
;
}
}
\ No newline at end of file
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
8050546d
...
...
@@ -96,7 +96,7 @@ typedef TD_DLIST(SPgFile) SPgFileList;
} \
} while (0)
#define TDB_VARIANT_LEN (int
32_t) -
1
#define TDB_VARIANT_LEN (int
)-
1
// page payload format
// <keyLen> + <valLen> + [key] + [value]
...
...
source/libs/tdb/test/tdbTest.cpp
浏览文件 @
8050546d
...
...
@@ -19,12 +19,19 @@ TEST(tdb_test, simple_test) {
GTEST_ASSERT_EQ
(
tdbEnvOpen
(
pEnv
),
0
);
#if
0
#if
1
// DB
tdbOpen(&pDb1, "db.db", "db1", pEnv);
tdbOpen(&pDb2, "db.db", "db2", pEnv);
tdbOpen(&pDb3, "index.db", NULL, pEnv);
GTEST_ASSERT_EQ
(
tdbCreate
(
&
pDb1
),
0
);
GTEST_ASSERT_EQ
(
tdbSetKeyLen
(
pDb1
,
8
),
0
);
// GTEST_ASSERT_EQ(tdbSetValLen(pDb1, 3), 0);
// GTEST_ASSERT_EQ(tdbSetDup(pDb1, 3), 0);
GTEST_ASSERT_EQ
(
tdbOpen
(
pDb1
,
"db.db"
,
"db1"
,
pEnv
),
0
);
#if 0
// Insert
// Query
...
...
@@ -32,10 +39,13 @@ TEST(tdb_test, simple_test) {
// Delete
// Query
#endif
// Close
// GTEST_ASSERT_EQ(tdbOpen(&pDb2, "db.db", "db2", pEnv), 0);
// GTEST_ASSERT_EQ(tdbOpen(&pDb3, "index.db", NULL, pEnv), 0);
// tdbClose(pDb3);
// tdbClose(pDb2);
tdbClose
(
pDb1
);
tdbClose(pDb2);
#endif
tdbEnvClose
(
pEnv
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录