Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1792e49d
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,发现更多精彩内容 >>
提交
1792e49d
编写于
7月 17, 2022
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of github.com:taosdata/TDengine into szhou/feature/user-tags
上级
af1350a6
a579331c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
145 addition
and
11 deletion
+145
-11
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+44
-3
source/libs/tdb/src/db/tdbDb.c
source/libs/tdb/src/db/tdbDb.c
+13
-1
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+21
-1
source/libs/tdb/src/db/tdbTable.c
source/libs/tdb/src/db/tdbTable.c
+52
-4
source/libs/tdb/src/inc/tdbInt.h
source/libs/tdb/src/inc/tdbInt.h
+14
-1
tools/taosws-rs
tools/taosws-rs
+1
-1
未找到文件。
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
1792e49d
...
...
@@ -67,7 +67,8 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
static
int
tdbBtcMoveDownward
(
SBTC
*
pBtc
);
static
int
tdbBtcMoveUpward
(
SBTC
*
pBtc
);
int
tdbBtreeOpen
(
int
keyLen
,
int
valLen
,
SPager
*
pPager
,
tdb_cmpr_fn_t
kcmpr
,
SBTree
**
ppBt
)
{
int
tdbBtreeOpen
(
int
keyLen
,
int
valLen
,
SPager
*
pPager
,
char
const
*
tbname
,
SPgno
pgno
,
tdb_cmpr_fn_t
kcmpr
,
SBTree
**
ppBt
)
{
SBTree
*
pBt
;
int
ret
;
...
...
@@ -99,13 +100,54 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, tdb_cmpr_fn_t kcmpr, SB
// pBt->minLeaf
pBt
->
minLeaf
=
pBt
->
minLocal
;
// if pgno == 0 fetch new btree root leaf page
if
(
pgno
==
0
)
{
// fetch page & insert into main db
// allocate a new child page
SPage
*
pPage
;
TXN
txn
;
tdbTxnOpen
(
&
txn
,
0
,
tdbDefaultMalloc
,
tdbDefaultFree
,
NULL
,
0
);
pPager
->
inTran
=
1
;
SBtreeInitPageArg
zArg
;
zArg
.
flags
=
0x1
|
0x2
;
// root leaf node;
zArg
.
pBt
=
pBt
;
ret
=
tdbPagerFetchPage
(
pPager
,
&
pgno
,
&
pPage
,
tdbBtreeInitPage
,
&
zArg
,
&
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
// TODO: Need to zero the page
ret
=
tdbPagerWrite
(
pPager
,
pPage
);
if
(
ret
<
0
)
{
return
-
1
;
}
if
(
strcmp
(
TDB_MAINDB_NAME
,
tbname
))
{
ret
=
tdbTbInsert
(
pPager
->
pEnv
->
pMainDb
,
tbname
,
strlen
(
tbname
)
+
1
,
&
pgno
,
sizeof
(
SPgno
),
&
txn
);
if
(
ret
<
0
)
{
return
-
1
;
}
}
// tdbUnrefPage(pPage);
tdbPCacheRelease
(
pPager
->
pCache
,
pPage
,
&
txn
);
tdbCommit
(
pPager
->
pEnv
,
&
txn
);
tdbTxnClose
(
&
txn
);
}
ASSERT
(
pgno
!=
0
);
pBt
->
root
=
pgno
;
/*
// TODO: pBt->root
ret = tdbBtreeOpenImpl(pBt);
if (ret < 0) {
tdbOsFree(pBt);
return -1;
}
*/
*
ppBt
=
pBt
;
return
0
;
}
...
...
@@ -338,7 +380,6 @@ static int tdbBtreeOpenImpl(SBTree *pBt) {
ASSERT
(
pgno
!=
0
);
pBt
->
root
=
pgno
;
return
0
;
}
...
...
source/libs/tdb/src/db/tdbDb.c
浏览文件 @
1792e49d
...
...
@@ -64,6 +64,14 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb) {
mkdir
(
dbname
,
0755
);
#ifdef USE_MAINDB
// open main db
ret
=
tdbTbOpen
(
TDB_MAINDB_NAME
,
-
1
,
sizeof
(
SPgno
),
NULL
,
pDb
,
&
pDb
->
pMainDb
);
if
(
ret
<
0
)
{
return
-
1
;
}
#endif
*
ppDb
=
pDb
;
return
0
;
}
...
...
@@ -72,6 +80,10 @@ int tdbClose(TDB *pDb) {
SPager
*
pPager
;
if
(
pDb
)
{
#ifdef USE_MAINDB
if
(
pDb
->
pMainDb
)
tdbTbClose
(
pDb
->
pMainDb
);
#endif
for
(
pPager
=
pDb
->
pgrList
;
pPager
;
pPager
=
pDb
->
pgrList
)
{
pDb
->
pgrList
=
pPager
->
pNext
;
tdbPagerClose
(
pPager
);
...
...
@@ -179,4 +191,4 @@ void tdbEnvRemovePager(TDB *pDb, SPager *pPager) {
if
(
pDb
->
nPgrHash
>
8
&&
pDb
->
nPager
<
pDb
->
nPgrHash
/
2
)
{
// TODO
}
}
\ No newline at end of file
}
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
1792e49d
...
...
@@ -174,6 +174,13 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
for
(
ppPage
=
&
pPager
->
pDirty
;
(
*
ppPage
)
&&
TDB_PAGE_PGNO
(
*
ppPage
)
<
TDB_PAGE_PGNO
(
pPage
);
ppPage
=
&
((
*
ppPage
)
->
pDirtyNext
))
{
}
if
(
*
ppPage
&&
TDB_PAGE_PGNO
(
*
ppPage
)
==
TDB_PAGE_PGNO
(
pPage
))
{
tdbUnrefPage
(
pPage
);
return
0
;
}
ASSERT
(
*
ppPage
==
NULL
||
TDB_PAGE_PGNO
(
*
ppPage
)
>
TDB_PAGE_PGNO
(
pPage
));
pPage
->
pDirtyNext
=
*
ppPage
;
*
ppPage
=
pPage
;
...
...
@@ -467,7 +474,7 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
}
TXN
txn
;
tdbTxnOpen
(
&
txn
,
0
,
tdbDefaultMalloc
,
tdbDefaultFree
,
NULL
,
0
);
tdbTxnOpen
(
&
txn
,
0
,
tdbDefaultMalloc
,
tdbDefaultFree
,
NULL
,
TDB_TXN_WRITE
|
TDB_TXN_READ_UNCOMMITTED
);
SBtreeInitPageArg
iArg
;
iArg
.
pBt
=
pBt
;
iArg
.
flags
=
0
;
...
...
@@ -487,6 +494,7 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
return
-
1
;
}
/*
ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &iArg, &txn);
if (ret < 0) {
return -1;
...
...
@@ -499,6 +507,18 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) {
}
tdbPCacheRelease(pPager->pCache, pPage, &txn);
*/
i64
offset
=
pPager
->
pageSize
*
(
pgno
-
1
);
if
(
tdbOsLSeek
(
pPager
->
fd
,
offset
,
SEEK_SET
)
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
ret
=
tdbOsWrite
(
pPager
->
fd
,
pageBuf
,
pPager
->
pageSize
);
if
(
ret
<
0
)
{
ASSERT
(
0
);
return
-
1
;
}
}
tdbOsFSync
(
pPager
->
fd
);
...
...
source/libs/tdb/src/db/tdbTable.c
浏览文件 @
1792e49d
...
...
@@ -16,7 +16,7 @@
#include "tdbInt.h"
struct
STTB
{
TDB
*
pEnv
;
TDB
*
pEnv
;
SBTree
*
pBt
;
};
...
...
@@ -25,12 +25,16 @@ struct STBC {
};
int
tdbTbOpen
(
const
char
*
tbname
,
int
keyLen
,
int
valLen
,
tdb_cmpr_fn_t
keyCmprFn
,
TDB
*
pEnv
,
TTB
**
ppTb
)
{
TTB
*
pTb
;
TTB
*
pTb
;
SPager
*
pPager
;
int
ret
;
char
fFullName
[
TDB_FILENAME_LEN
];
SPage
*
pPage
;
SPage
*
pPage
;
SPgno
pgno
;
void
*
pKey
=
NULL
;
int
nKey
=
0
;
void
*
pData
=
NULL
;
int
nData
=
0
;
*
ppTb
=
NULL
;
...
...
@@ -42,6 +46,48 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
// pTb->pEnv
pTb
->
pEnv
=
pEnv
;
#ifdef USE_MAINDB
snprintf
(
fFullName
,
TDB_FILENAME_LEN
,
"%s/%s"
,
pEnv
->
dbName
,
TDB_MAINDB_NAME
);
if
(
strcmp
(
TDB_MAINDB_NAME
,
tbname
))
{
pPager
=
tdbEnvGetPager
(
pEnv
,
fFullName
);
if
(
!
pPager
)
{
return
-
1
;
}
ret
=
tdbTbGet
(
pPager
->
pEnv
->
pMainDb
,
tbname
,
strlen
(
tbname
)
+
1
,
&
pData
,
&
nData
);
if
(
ret
<
0
)
{
// new pgno & insert into main db
pgno
=
0
;
}
else
{
pgno
=
*
(
SPgno
*
)
pData
;
tdbFree
(
pKey
);
tdbFree
(
pData
);
}
}
else
{
pPager
=
tdbEnvGetPager
(
pEnv
,
fFullName
);
if
(
pPager
==
NULL
)
{
ret
=
tdbPagerOpen
(
pEnv
->
pCache
,
fFullName
,
&
pPager
);
if
(
ret
<
0
)
{
return
-
1
;
}
tdbEnvAddPager
(
pEnv
,
pPager
);
pPager
->
pEnv
=
pEnv
;
}
if
(
pPager
->
dbOrigSize
>
0
)
{
pgno
=
1
;
}
else
{
pgno
=
0
;
}
}
#else
pPager
=
tdbEnvGetPager
(
pEnv
,
tbname
);
if
(
pPager
==
NULL
)
{
snprintf
(
fFullName
,
TDB_FILENAME_LEN
,
"%s/%s"
,
pEnv
->
dbName
,
tbname
);
...
...
@@ -53,10 +99,12 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
tdbEnvAddPager
(
pEnv
,
pPager
);
}
#endif
ASSERT
(
pPager
!=
NULL
);
// pTb->pBt
ret
=
tdbBtreeOpen
(
keyLen
,
valLen
,
pPager
,
keyCmprFn
,
&
(
pTb
->
pBt
));
ret
=
tdbBtreeOpen
(
keyLen
,
valLen
,
pPager
,
tbname
,
pgno
,
keyCmprFn
,
&
(
pTb
->
pBt
));
if
(
ret
<
0
)
{
return
-
1
;
}
...
...
source/libs/tdb/src/inc/tdbInt.h
浏览文件 @
1792e49d
...
...
@@ -150,7 +150,8 @@ struct SBTC {
};
// SBTree
int
tdbBtreeOpen
(
int
keyLen
,
int
valLen
,
SPager
*
pFile
,
tdb_cmpr_fn_t
kcmpr
,
SBTree
**
ppBt
);
int
tdbBtreeOpen
(
int
keyLen
,
int
valLen
,
SPager
*
pFile
,
char
const
*
tbname
,
SPgno
pgno
,
tdb_cmpr_fn_t
kcmpr
,
SBTree
**
ppBt
);
int
tdbBtreeClose
(
SBTree
*
pBt
);
int
tdbBtreeInsert
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
const
void
*
pVal
,
int
vLen
,
TXN
*
pTxn
);
int
tdbBtreeDelete
(
SBTree
*
pBt
,
const
void
*
pKey
,
int
kLen
,
TXN
*
pTxn
);
...
...
@@ -356,6 +357,12 @@ static inline SCell *tdbPageGetCell(SPage *pPage, int idx) {
return
pCell
;
}
#define USE_MAINDB
#ifdef USE_MAINDB
#define TDB_MAINDB_NAME "main.tdb"
#endif
struct
STDB
{
char
*
dbName
;
char
*
jnName
;
...
...
@@ -365,6 +372,9 @@ struct STDB {
int
nPager
;
int
nPgrHash
;
SPager
**
pgrHash
;
#ifdef USE_MAINDB
TTB
*
pMainDb
;
#endif
};
struct
SPager
{
...
...
@@ -381,6 +391,9 @@ struct SPager {
u8
inTran
;
SPager
*
pNext
;
// used by TDB
SPager
*
pHashNext
;
// used by TDB
#ifdef USE_MAINDB
TDB
*
pEnv
;
#endif
};
#ifdef __cplusplus
...
...
taosws-rs
@
c5fded26
比较
7a94ffab
...
c5fded26
Subproject commit
7a94ffab45f08e16f09b3f430fe75d717054adb6
Subproject commit
c5fded266d3b10508e38bf3285bb7ecf798bc343
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录