Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
miniob
提交
e0d2919b
M
miniob
项目概览
oceanbase
/
miniob
1 年多 前同步成功
通知
74
Star
1521
Fork
537
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
M
miniob
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
提交
e0d2919b
编写于
4月 30, 2022
作者:
羽飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implenment record iterator
上级
8d904d04
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
95 addition
and
10 deletion
+95
-10
src/observer/storage/common/record_manager.cpp
src/observer/storage/common/record_manager.cpp
+9
-2
src/observer/storage/common/record_manager.h
src/observer/storage/common/record_manager.h
+9
-6
src/observer/storage/default/disk_buffer_pool.cpp
src/observer/storage/default/disk_buffer_pool.cpp
+2
-2
unitest/record_manager_test.cpp
unitest/record_manager_test.cpp
+75
-0
未找到文件。
src/observer/storage/common/record_manager.cpp
浏览文件 @
e0d2919b
...
@@ -390,6 +390,13 @@ RC RecordFileScanner::open_scan(DiskBufferPool &buffer_pool, ConditionFilter *co
...
@@ -390,6 +390,13 @@ RC RecordFileScanner::open_scan(DiskBufferPool &buffer_pool, ConditionFilter *co
RC
RecordFileScanner
::
fetch_next_record
()
RC
RecordFileScanner
::
fetch_next_record
()
{
{
RC
rc
=
RC
::
SUCCESS
;
RC
rc
=
RC
::
SUCCESS
;
if
(
record_page_iterator_
.
is_valid
())
{
rc
=
fetch_next_record_in_page
();
if
(
rc
==
RC
::
SUCCESS
||
rc
!=
RC
::
RECORD_EOF
)
{
return
rc
;
}
}
while
(
bp_iterator_
.
has_next
())
{
while
(
bp_iterator_
.
has_next
())
{
PageNum
page_num
=
bp_iterator_
.
next
();
PageNum
page_num
=
bp_iterator_
.
next
();
record_page_handler_
.
cleanup
();
record_page_handler_
.
cleanup
();
...
@@ -400,7 +407,7 @@ RC RecordFileScanner::fetch_next_record()
...
@@ -400,7 +407,7 @@ RC RecordFileScanner::fetch_next_record()
}
}
record_page_iterator_
.
init
(
record_page_handler_
);
record_page_iterator_
.
init
(
record_page_handler_
);
rc
=
fetch_record_in_page
();
rc
=
fetch_
next_
record_in_page
();
if
(
rc
==
RC
::
SUCCESS
||
rc
!=
RC
::
RECORD_EOF
)
{
if
(
rc
==
RC
::
SUCCESS
||
rc
!=
RC
::
RECORD_EOF
)
{
return
rc
;
return
rc
;
}
}
...
@@ -409,7 +416,7 @@ RC RecordFileScanner::fetch_next_record()
...
@@ -409,7 +416,7 @@ RC RecordFileScanner::fetch_next_record()
return
RC
::
RECORD_EOF
;
return
RC
::
RECORD_EOF
;
}
}
RC
RecordFileScanner
::
fetch_record_in_page
()
RC
RecordFileScanner
::
fetch_
next_
record_in_page
()
{
{
RC
rc
=
RC
::
SUCCESS
;
RC
rc
=
RC
::
SUCCESS
;
while
(
record_page_iterator_
.
has_next
())
{
while
(
record_page_iterator_
.
has_next
())
{
...
...
src/observer/storage/common/record_manager.h
浏览文件 @
e0d2919b
...
@@ -24,11 +24,11 @@ typedef int32_t SlotNum;
...
@@ -24,11 +24,11 @@ typedef int32_t SlotNum;
class
ConditionFilter
;
class
ConditionFilter
;
struct
PageHeader
{
struct
PageHeader
{
int
record_num
;
// 当前页面记录的个数
int
32_t
record_num
;
// 当前页面记录的个数
int
record_capacity
;
// 最大记录个数
int
32_t
record_capacity
;
// 最大记录个数
int
record_real_size
;
// 每条记录的实际大小
int
32_t
record_real_size
;
// 每条记录的实际大小
int
record_size
;
// 每条记录占用实际空间大小(可能对齐)
int
32_t
record_size
;
// 每条记录占用实际空间大小(可能对齐)
int
first_record_offset
;
// 第一条记录的偏移量
int
32_t
first_record_offset
;
// 第一条记录的偏移量
};
};
struct
RID
{
struct
RID
{
...
@@ -108,6 +108,9 @@ public:
...
@@ -108,6 +108,9 @@ public:
bool
has_next
();
bool
has_next
();
RC
next
(
Record
&
record
);
RC
next
(
Record
&
record
);
bool
is_valid
()
const
{
return
record_page_handler_
!=
nullptr
;
}
private:
private:
RecordPageHandler
*
record_page_handler_
=
nullptr
;
RecordPageHandler
*
record_page_handler_
=
nullptr
;
PageNum
page_num_
=
BP_INVALID_PAGE_NUM
;
PageNum
page_num_
=
BP_INVALID_PAGE_NUM
;
...
@@ -227,7 +230,7 @@ public:
...
@@ -227,7 +230,7 @@ public:
private:
private:
RC
fetch_next_record
();
RC
fetch_next_record
();
RC
fetch_record_in_page
();
RC
fetch_
next_
record_in_page
();
private:
private:
DiskBufferPool
*
disk_buffer_pool_
=
nullptr
;
DiskBufferPool
*
disk_buffer_pool_
=
nullptr
;
...
...
src/observer/storage/default/disk_buffer_pool.cpp
浏览文件 @
e0d2919b
...
@@ -106,12 +106,12 @@ RC BufferPoolIterator::init(DiskBufferPool &bp, PageNum start_page /* = 0 */)
...
@@ -106,12 +106,12 @@ RC BufferPoolIterator::init(DiskBufferPool &bp, PageNum start_page /* = 0 */)
bool
BufferPoolIterator
::
has_next
()
bool
BufferPoolIterator
::
has_next
()
{
{
return
bitmap_
.
next_setted_bit
(
current_page_num_
)
!=
-
1
;
return
bitmap_
.
next_setted_bit
(
current_page_num_
+
1
)
!=
-
1
;
}
}
PageNum
BufferPoolIterator
::
next
()
PageNum
BufferPoolIterator
::
next
()
{
{
PageNum
next_page
=
bitmap_
.
next_setted_bit
(
current_page_num_
);
PageNum
next_page
=
bitmap_
.
next_setted_bit
(
current_page_num_
+
1
);
if
(
next_page
!=
-
1
)
{
if
(
next_page
!=
-
1
)
{
current_page_num_
=
next_page
;
current_page_num_
=
next_page
;
}
}
...
...
unitest/record_manager_test.cpp
浏览文件 @
e0d2919b
...
@@ -102,6 +102,81 @@ TEST(test_record_page_handler, test_record_page_handler)
...
@@ -102,6 +102,81 @@ TEST(test_record_page_handler, test_record_page_handler)
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
}
}
ASSERT_EQ
(
count
,
6
);
ASSERT_EQ
(
count
,
6
);
bpm
->
close_file
(
record_manager_file
);
}
TEST
(
test_record_page_handler
,
test_record_file_iterator
)
{
const
char
*
record_manager_file
=
"record_manager.bp"
;
::
remove
(
record_manager_file
);
BufferPoolManager
*
bpm
=
new
BufferPoolManager
();
DiskBufferPool
*
bp
=
nullptr
;
RC
rc
=
bpm
->
create_file
(
record_manager_file
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
rc
=
bpm
->
open_file
(
record_manager_file
,
bp
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
RecordFileHandler
file_handler
;
rc
=
file_handler
.
init
(
bp
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
RecordFileScanner
file_scanner
;
rc
=
file_scanner
.
open_scan
(
*
bp
,
nullptr
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
int
count
=
0
;
Record
record
;
while
(
file_scanner
.
has_next
())
{
rc
=
file_scanner
.
next
(
record
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
count
++
;
}
file_scanner
.
close_scan
();
ASSERT_EQ
(
count
,
0
);
const
int
record_insert_num
=
1000
;
char
record_data
[
20
];
std
::
vector
<
RID
>
rids
;
for
(
int
i
=
0
;
i
<
record_insert_num
;
i
++
)
{
RID
rid
;
rc
=
file_handler
.
insert_record
(
record_data
,
sizeof
(
record_data
),
&
rid
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
rids
.
push_back
(
rid
);
}
rc
=
file_scanner
.
open_scan
(
*
bp
,
nullptr
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
count
=
0
;
while
(
file_scanner
.
has_next
())
{
rc
=
file_scanner
.
next
(
record
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
count
++
;
}
file_scanner
.
close_scan
();
ASSERT_EQ
(
count
,
rids
.
size
());
for
(
int
i
=
0
;
i
<
record_insert_num
;
i
+=
2
)
{
rc
=
file_handler
.
delete_record
(
&
rids
[
i
]);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
}
rc
=
file_scanner
.
open_scan
(
*
bp
,
nullptr
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
count
=
0
;
while
(
file_scanner
.
has_next
())
{
rc
=
file_scanner
.
next
(
record
);
ASSERT_EQ
(
rc
,
RC
::
SUCCESS
);
count
++
;
}
file_scanner
.
close_scan
();
ASSERT_EQ
(
count
,
rids
.
size
()
/
2
);
bpm
->
close_file
(
record_manager_file
);
}
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录