Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3c044ef2
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看板
提交
3c044ef2
编写于
3月 14, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more TDB
上级
6fa90a91
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
7 deletion
+58
-7
source/libs/tdb/src/db/tdbPage.c
source/libs/tdb/src/db/tdbPage.c
+54
-3
source/libs/tdb/src/inc/tdbPage.h
source/libs/tdb/src/inc/tdbPage.h
+4
-4
未找到文件。
source/libs/tdb/src/db/tdbPage.c
浏览文件 @
3c044ef2
...
@@ -15,7 +15,13 @@
...
@@ -15,7 +15,13 @@
#include "tdbInt.h"
#include "tdbInt.h"
typedef
struct
__attribute__
((
__packed__
))
{
u16
size
;
u16
nOffset
;
}
SFreeCell
;
static
int
tdbPageAllocate
(
SPage
*
pPage
,
int
size
,
SCell
**
ppCell
);
static
int
tdbPageAllocate
(
SPage
*
pPage
,
int
size
,
SCell
**
ppCell
);
static
int
tdbPageDefragment
(
SPage
*
pPage
);
int
tdbPageCreate
(
int
pageSize
,
SPage
**
ppPage
,
void
*
(
*
xMalloc
)(
void
*
,
size_t
),
void
*
arg
)
{
int
tdbPageCreate
(
int
pageSize
,
SPage
**
ppPage
,
void
*
(
*
xMalloc
)(
void
*
,
size_t
),
void
*
arg
)
{
SPage
*
pPage
;
SPage
*
pPage
;
...
@@ -66,7 +72,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
...
@@ -66,7 +72,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
SCell
*
pTarget
;
SCell
*
pTarget
;
if
(
pPage
->
nOverflow
||
szCell
+
pPage
->
szOffset
>
pPage
->
nFree
)
{
if
(
pPage
->
nOverflow
||
szCell
+
pPage
->
szOffset
>
pPage
->
nFree
)
{
// TODO
// TODO
: Page is full
}
else
{
}
else
{
ret
=
tdbPageAllocate
(
pPage
,
szCell
,
&
pTarget
);
ret
=
tdbPageAllocate
(
pPage
,
szCell
,
&
pTarget
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
...
@@ -87,18 +93,63 @@ int tdbPageDropCell(SPage *pPage, int idx) {
...
@@ -87,18 +93,63 @@ int tdbPageDropCell(SPage *pPage, int idx) {
}
}
static
int
tdbPageAllocate
(
SPage
*
pPage
,
int
size
,
SCell
**
ppCell
)
{
static
int
tdbPageAllocate
(
SPage
*
pPage
,
int
size
,
SCell
**
ppCell
)
{
SCell
*
pCell
;
SCell
*
pCell
;
SFreeCell
*
pFreeCell
;
int
ret
;
ASSERT
(
pPage
->
nFree
>
size
+
pPage
->
szOffset
);
ASSERT
(
pPage
->
nFree
>
size
+
pPage
->
szOffset
);
pCell
=
NULL
;
*
ppCell
=
NULL
;
// 1. Try to allocate from the free space area
if
(
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
>
size
+
pPage
->
szOffset
)
{
if
(
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
>
size
+
pPage
->
szOffset
)
{
pPage
->
pFreeEnd
-=
size
;
pPage
->
pFreeEnd
-=
size
;
pPage
->
pFreeStart
+=
pPage
->
szOffset
;
pPage
->
pFreeStart
+=
pPage
->
szOffset
;
pCell
=
pPage
->
pFreeEnd
;
pCell
=
pPage
->
pFreeEnd
;
}
else
{
}
}
// 2. Try to allocate from the page free list
if
(
pCell
==
NULL
&&
TDB_PAGE_FCELL
(
pPage
))
{
pCell
=
pPage
->
pData
+
TDB_PAGE_FCELL
(
pPage
);
for
(;;)
{
pFreeCell
=
(
SFreeCell
*
)
pCell
;
if
(
pFreeCell
->
size
>=
size
)
{
break
;
}
if
(
pFreeCell
->
nOffset
)
{
pCell
=
pPage
->
pData
+
pFreeCell
->
nOffset
;
}
else
{
pCell
=
NULL
;
break
;
}
continue
;
}
}
// 3. Try to dfragment
if
(
pCell
==
NULL
)
{
ret
=
tdbPageDefragment
(
pPage
);
if
(
ret
<
0
)
{
return
-
1
;
}
ASSERT
(
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
>
size
+
pPage
->
szOffset
);
ASSERT
(
pPage
->
nFree
==
pPage
->
pFreeEnd
-
pPage
->
pFreeStart
);
// Allocate from the free space area again
pPage
->
pFreeEnd
-=
size
;
pPage
->
pFreeStart
+=
pPage
->
szOffset
;
pCell
=
pPage
->
pFreeEnd
;
}
ASSERT
(
pCell
!=
NULL
);
pPage
->
nFree
=
pPage
->
nFree
-
size
-
pPage
->
szOffset
;
*
ppCell
=
pCell
;
*
ppCell
=
pCell
;
return
0
;
return
0
;
}
}
...
...
source/libs/tdb/src/inc/tdbPage.h
浏览文件 @
3c044ef2
...
@@ -25,10 +25,10 @@ typedef u8 SCell;
...
@@ -25,10 +25,10 @@ typedef u8 SCell;
// Page header (pageSize < 65536 (64K))
// Page header (pageSize < 65536 (64K))
typedef
struct
__attribute__
((
__packed__
))
{
typedef
struct
__attribute__
((
__packed__
))
{
u16
flags
;
u16
flags
;
u16
nCells
;
u16
nCells
;
// number of cells
u16
cCells
;
u16
cCells
;
// cell content offset
u16
fCell
;
u16
fCell
;
// first free cell offset
u16
nFree
;
u16
nFree
;
// total fragment bytes in this page
}
SPageHdr
;
}
SPageHdr
;
// Large page header (pageSize >= 65536 (64K))
// Large page header (pageSize >= 65536 (64K))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录