Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c4193ff0
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
c4193ff0
编写于
3月 01, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact
上级
8bd4beec
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
52 deletion
+52
-52
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+52
-52
未找到文件。
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
c4193ff0
...
@@ -41,19 +41,19 @@ typedef struct __attribute__((__packed__)) {
...
@@ -41,19 +41,19 @@ typedef struct __attribute__((__packed__)) {
TDB_STATIC_ASSERT
(
sizeof
(
SFileHdr
)
==
128
,
"Size of file header is not correct"
);
TDB_STATIC_ASSERT
(
sizeof
(
SFileHdr
)
==
128
,
"Size of file header is not correct"
);
static
int
tdbPagerReadPage
(
SPager
*
p
File
,
SPage
*
pPage
);
static
int
tdbPagerReadPage
(
SPager
*
p
Pager
,
SPage
*
pPage
);
int
tdbPagerOpen
(
SPCache
*
pCache
,
const
char
*
fileName
,
SPager
**
pp
File
)
{
int
tdbPagerOpen
(
SPCache
*
pCache
,
const
char
*
fileName
,
SPager
**
pp
Pager
)
{
uint8_t
*
pPtr
;
uint8_t
*
pPtr
;
SPager
*
p
File
;
SPager
*
p
Pager
;
int
fsize
;
int
fsize
;
int
zsize
;
int
zsize
;
int
ret
;
int
ret
;
*
pp
File
=
NULL
;
*
pp
Pager
=
NULL
;
fsize
=
strlen
(
fileName
);
fsize
=
strlen
(
fileName
);
zsize
=
sizeof
(
*
p
File
)
/* SPager */
zsize
=
sizeof
(
*
p
Pager
)
/* SPager */
+
fsize
+
1
/* dbFileName */
+
fsize
+
1
/* dbFileName */
+
fsize
+
8
+
1
;
/* jFileName */
+
fsize
+
8
+
1
;
/* jFileName */
pPtr
=
(
uint8_t
*
)
calloc
(
1
,
zsize
);
pPtr
=
(
uint8_t
*
)
calloc
(
1
,
zsize
);
...
@@ -61,43 +61,43 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppFile) {
...
@@ -61,43 +61,43 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppFile) {
return
-
1
;
return
-
1
;
}
}
p
File
=
(
SPager
*
)
pPtr
;
p
Pager
=
(
SPager
*
)
pPtr
;
pPtr
+=
sizeof
(
*
p
File
);
pPtr
+=
sizeof
(
*
p
Pager
);
// p
File
->dbFileName
// p
Pager
->dbFileName
p
File
->
dbFileName
=
(
char
*
)
pPtr
;
p
Pager
->
dbFileName
=
(
char
*
)
pPtr
;
memcpy
(
p
File
->
dbFileName
,
fileName
,
fsize
);
memcpy
(
p
Pager
->
dbFileName
,
fileName
,
fsize
);
p
File
->
dbFileName
[
fsize
]
=
'\0'
;
p
Pager
->
dbFileName
[
fsize
]
=
'\0'
;
pPtr
+=
fsize
+
1
;
pPtr
+=
fsize
+
1
;
// p
File
->jFileName
// p
Pager
->jFileName
p
File
->
jFileName
=
(
char
*
)
pPtr
;
p
Pager
->
jFileName
=
(
char
*
)
pPtr
;
memcpy
(
p
File
->
jFileName
,
fileName
,
fsize
);
memcpy
(
p
Pager
->
jFileName
,
fileName
,
fsize
);
memcpy
(
p
File
->
jFileName
+
fsize
,
"-journal"
,
8
);
memcpy
(
p
Pager
->
jFileName
+
fsize
,
"-journal"
,
8
);
p
File
->
jFileName
[
fsize
+
8
]
=
'\0'
;
p
Pager
->
jFileName
[
fsize
+
8
]
=
'\0'
;
// p
File
->pCache
// p
Pager
->pCache
p
File
->
pCache
=
pCache
;
p
Pager
->
pCache
=
pCache
;
p
File
->
fd
=
open
(
pFile
->
dbFileName
,
O_RDWR
|
O_CREAT
,
0755
);
p
Pager
->
fd
=
open
(
pPager
->
dbFileName
,
O_RDWR
|
O_CREAT
,
0755
);
if
(
p
File
->
fd
<
0
)
{
if
(
p
Pager
->
fd
<
0
)
{
return
-
1
;
return
-
1
;
}
}
ret
=
tdbGnrtFileID
(
p
File
->
dbFileName
,
pFile
->
fid
,
false
);
ret
=
tdbGnrtFileID
(
p
Pager
->
dbFileName
,
pPager
->
fid
,
false
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
return
-
1
;
return
-
1
;
}
}
p
File
->
jfd
=
-
1
;
p
Pager
->
jfd
=
-
1
;
*
pp
File
=
pFile
;
*
pp
Pager
=
pPager
;
return
0
;
return
0
;
}
}
int
tdbPagerClose
(
SPager
*
p
File
)
{
int
tdbPagerClose
(
SPager
*
p
Pager
)
{
// TODO
// TODO
return
0
;
return
0
;
}
}
int
tdbPagerOpenDB
(
SPager
*
p
File
,
SPgno
*
ppgno
,
bool
toCreate
)
{
int
tdbPagerOpenDB
(
SPager
*
p
Pager
,
SPgno
*
ppgno
,
bool
toCreate
)
{
SPgno
pgno
;
SPgno
pgno
;
SPage
*
pPage
;
SPage
*
pPage
;
int
ret
;
int
ret
;
...
@@ -108,13 +108,13 @@ int tdbPagerOpenDB(SPager *pFile, SPgno *ppgno, bool toCreate) {
...
@@ -108,13 +108,13 @@ int tdbPagerOpenDB(SPager *pFile, SPgno *ppgno, bool toCreate) {
}
}
if
(
pgno
==
0
&&
toCreate
)
{
if
(
pgno
==
0
&&
toCreate
)
{
ret
=
tdbPagerAllocPage
(
p
File
,
&
pPage
,
&
pgno
);
ret
=
tdbPagerAllocPage
(
p
Pager
,
&
pPage
,
&
pgno
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// tdb
PFile
ZeroPage(pPage);
// tdb
pPager
ZeroPage(pPage);
ret
=
tdbPagerWrite
(
p
File
,
pPage
);
ret
=
tdbPagerWrite
(
p
Pager
,
pPage
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -124,25 +124,25 @@ int tdbPagerOpenDB(SPager *pFile, SPgno *ppgno, bool toCreate) {
...
@@ -124,25 +124,25 @@ int tdbPagerOpenDB(SPager *pFile, SPgno *ppgno, bool toCreate) {
return
0
;
return
0
;
}
}
SPage
*
tdbPagerGet
(
SPager
*
p
File
,
SPgno
pgno
)
{
SPage
*
tdbPagerGet
(
SPager
*
p
Pager
,
SPgno
pgno
)
{
SPgid
pgid
;
SPgid
pgid
;
SPage
*
pPage
;
SPage
*
pPage
;
memcpy
(
pgid
.
fileid
,
p
File
->
fid
,
TDB_FILE_ID_LEN
);
memcpy
(
pgid
.
fileid
,
p
Pager
->
fid
,
TDB_FILE_ID_LEN
);
pgid
.
pgno
=
pgno
;
pgid
.
pgno
=
pgno
;
pPage
=
tdbPCacheFetch
(
p
File
->
pCache
,
&
pgid
,
1
);
pPage
=
tdbPCacheFetch
(
p
Pager
->
pCache
,
&
pgid
,
1
);
if
(
pPage
==
NULL
)
{
if
(
pPage
==
NULL
)
{
// TODO
// TODO
ASSERT
(
0
);
ASSERT
(
0
);
}
}
tdbPCacheFetchFinish
(
p
File
->
pCache
,
pPage
);
tdbPCacheFetchFinish
(
p
Pager
->
pCache
,
pPage
);
if
(
!
(
pPage
->
isLoad
))
{
if
(
!
(
pPage
->
isLoad
))
{
if
(
pgno
>
p
File
->
dbFileSize
/*TODO*/
)
{
if
(
pgno
>
p
Pager
->
dbFileSize
/*TODO*/
)
{
memset
(
pPage
->
pData
,
0
,
p
File
->
pageSize
);
memset
(
pPage
->
pData
,
0
,
p
Pager
->
pageSize
);
}
else
{
}
else
{
if
(
tdbPagerReadPage
(
p
File
,
pPage
)
<
0
)
{
if
(
tdbPagerReadPage
(
p
Pager
,
pPage
)
<
0
)
{
// TODO: handle error
// TODO: handle error
return
NULL
;
return
NULL
;
}
}
...
@@ -156,11 +156,11 @@ SPage *tdbPagerGet(SPager *pFile, SPgno pgno) {
...
@@ -156,11 +156,11 @@ SPage *tdbPagerGet(SPager *pFile, SPgno pgno) {
return
pPage
;
return
pPage
;
}
}
int
tdbPagerWrite
(
SPager
*
p
File
,
SPage
*
pPage
)
{
int
tdbPagerWrite
(
SPager
*
p
Pager
,
SPage
*
pPage
)
{
int
ret
;
int
ret
;
if
(
p
File
->
inTran
==
0
)
{
if
(
p
Pager
->
inTran
==
0
)
{
ret
=
tdbPagerBegin
(
p
File
);
ret
=
tdbPagerBegin
(
p
Pager
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -177,13 +177,13 @@ int tdbPagerWrite(SPager *pFile, SPage *pPage) {
...
@@ -177,13 +177,13 @@ int tdbPagerWrite(SPager *pFile, SPage *pPage) {
return
0
;
return
0
;
}
}
int
tdbPagerAllocPage
(
SPager
*
p
File
,
SPage
**
ppPage
,
SPgno
*
ppgno
)
{
int
tdbPagerAllocPage
(
SPager
*
p
Pager
,
SPage
**
ppPage
,
SPgno
*
ppgno
)
{
SPage
*
pPage
;
SPage
*
pPage
;
SPgno
pgno
;
SPgno
pgno
;
if
(
1
/*TODO: no free page*/
)
{
if
(
1
/*TODO: no free page*/
)
{
pgno
=
++
p
File
->
dbFileSize
;
pgno
=
++
p
Pager
->
dbFileSize
;
pPage
=
tdbPagerGet
(
p
File
,
pgno
);
pPage
=
tdbPagerGet
(
p
Pager
,
pgno
);
ASSERT
(
pPage
!=
NULL
);
ASSERT
(
pPage
!=
NULL
);
}
else
{
}
else
{
/* TODO: allocate from the free list */
/* TODO: allocate from the free list */
...
@@ -195,37 +195,37 @@ int tdbPagerAllocPage(SPager *pFile, SPage **ppPage, SPgno *ppgno) {
...
@@ -195,37 +195,37 @@ int tdbPagerAllocPage(SPager *pFile, SPage **ppPage, SPgno *ppgno) {
return
0
;
return
0
;
}
}
int
tdbPagerBegin
(
SPager
*
p
File
)
{
int
tdbPagerBegin
(
SPager
*
p
Pager
)
{
if
(
p
File
->
inTran
)
{
if
(
p
Pager
->
inTran
)
{
return
0
;
return
0
;
}
}
// Open the journal
// Open the journal
p
File
->
jfd
=
open
(
pFile
->
jFileName
,
O_RDWR
|
O_CREAT
,
0755
);
p
Pager
->
jfd
=
open
(
pPager
->
jFileName
,
O_RDWR
|
O_CREAT
,
0755
);
if
(
p
File
->
jfd
<
0
)
{
if
(
p
Pager
->
jfd
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// TODO: write the size of the file
// TODO: write the size of the file
p
File
->
inTran
=
1
;
p
Pager
->
inTran
=
1
;
return
0
;
return
0
;
}
}
int
tdbPagerCommit
(
SPager
*
p
File
)
{
int
tdbPagerCommit
(
SPager
*
p
Pager
)
{
// TODO
// TODO
return
0
;
return
0
;
}
}
static
int
tdbPagerReadPage
(
SPager
*
p
File
,
SPage
*
pPage
)
{
static
int
tdbPagerReadPage
(
SPager
*
p
Pager
,
SPage
*
pPage
)
{
i64
offset
;
i64
offset
;
int
ret
;
int
ret
;
ASSERT
(
memcmp
(
p
File
->
fid
,
pPage
->
pgid
.
fileid
,
TDB_FILE_ID_LEN
)
==
0
);
ASSERT
(
memcmp
(
p
Pager
->
fid
,
pPage
->
pgid
.
fileid
,
TDB_FILE_ID_LEN
)
==
0
);
offset
=
(
pPage
->
pgid
.
pgno
-
1
)
*
(
i64
)(
p
File
->
pageSize
);
offset
=
(
pPage
->
pgid
.
pgno
-
1
)
*
(
i64
)(
p
Pager
->
pageSize
);
ret
=
tdbPRead
(
p
File
->
fd
,
pPage
->
pData
,
pFile
->
pageSize
,
offset
);
ret
=
tdbPRead
(
p
Pager
->
fd
,
pPage
->
pData
,
pPager
->
pageSize
,
offset
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
// TODO: handle error
// TODO: handle error
return
-
1
;
return
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录