MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
|
页帧 更多...
#include <frame.h>
Public 成员函数 | |
void | reinit () |
reinit 和 reset 在 MemPoolSimple 中使用 更多... | |
void | reset () |
void | clear_page () |
int | file_desc () const |
void | set_file_desc (int fd) |
Page & | page () |
PageNum | page_num () const |
void | set_page_num (PageNum page_num) |
FrameId | frame_id () const |
LSN | lsn () const |
void | set_lsn (LSN lsn) |
void | access () |
刷新访问时间 TODO touch is better? | |
void | mark_dirty () |
标记指定页面为“脏”页。如果修改了页面的内容,则应调用此函数, 以便该页面被淘汰出缓冲区时系统将新的页面数据写入磁盘文件 | |
void | clear_dirty () |
bool | dirty () const |
char * | data () |
bool | can_purge () |
void | pin () |
给当前页帧增加引用计数 pin通常都会加着frame manager锁来访问 | |
int | unpin () |
释放一个当前页帧的引用计数 与pin对应,但是通常不会加着frame manager的锁来访问 | |
int | pin_count () const |
void | write_latch () |
void | write_latch (intptr_t xid) |
void | write_unlatch () |
void | write_unlatch (intptr_t xid) |
void | read_latch () |
void | read_latch (intptr_t xid) |
bool | try_read_latch () |
void | read_unlatch () |
void | read_unlatch (intptr_t xid) |
Private 属性 | |
bool | dirty_ = false |
std::atomic< int > | pin_count_ {0} |
unsigned long | acc_time_ = 0 |
int | file_desc_ = -1 |
Page | page_ |
common::RecursiveSharedMutex | lock_ |
在非并发编译时,加锁解锁动作将什么都不做 | |
common::DebugMutex | debug_lock_ |
使用一些手段来做测试,提前检测出头疼的死锁问题 如果编译时没有增加调试选项,这些代码什么都不做 | |
intptr_t | write_locker_ = 0 |
int | write_recursive_count_ = 0 |
std::unordered_map< intptr_t, int > | read_lockers_ |
友元 | |
class | BufferPool |
std::string | to_string (const Frame &frame) |
页帧
页帧是磁盘文件在内存中的表示。磁盘文件按照页面来操作,操作之前先映射到内存中, 将磁盘数据读取到内存中,也就是页帧。
当某个页面被淘汰时,如果有些内容曾经变更过,那么就需要将这些内容刷新到磁盘上。这里有 一个dirty标识,用来标识页面是否被修改过。
为了防止在使用过程中页面被淘汰,这里使用了pin count,当页面被使用时,pin count会增加, 当页面不再使用时,pin count会减少。当pin count为0时,页面可以被淘汰。
|
inline |
reinit 和 reset 在 MemPoolSimple 中使用
在 MemPoolSimple 分配和释放一个Frame对象时,不会调用构造函数和析构函数, 而是调用reinit和reset。