tinySQL
0.1
A self-contained database management system
|
Buffer manager is an abstraction of memory on computer for modules at higher level. More...
#include <buffer_manager.h>
Public Member Functions | |
BufferManager () | |
Construct a new Buffer Manager:: Buffer Manager object. More... | |
BufferManager (int frame_size) | |
~BufferManager () | |
Destroy the Buffer Manager:: Buffer Manager object. More... | |
char * | getPage (const std::string &file_name, int block_id) |
获取一页 More... | |
char * | getPage (const std::string &file_name, int block_id, pageId_t &pageId) |
void | modifyPage (int page_id) |
标记页是否被修改 More... | |
void | pinPage (int page_id) |
钉住一页 More... | |
int | unpinPage (int page_id) |
解钉一次 More... | |
int | flushPage (pageId_t page_id) |
核心函数之一。内存和磁盘交互的接口。 More... | |
int | getPageId (const std::string &file_name, int block_id) |
简单遍历获取页号 More... | |
void | removeFile (const std::string &path) |
int | getBlockNum (const std::string &fileName) |
获取文件块数 More... | |
Static Public Member Functions | |
static size_t | getFileSize (std::string file_name) |
static bool | FileExists (const std::string &path) |
static void | createEmptyFile (const std::string &path) |
Buffer manager is an abstraction of memory on computer for modules at higher level.
Definition at line 69 of file buffer_manager.h.
BufferManager::BufferManager | ( | ) |
Construct a new Buffer Manager:: Buffer Manager object.
Definition at line 96 of file buffer_manager.cpp.
BufferManager::~BufferManager | ( | ) |
Destroy the Buffer Manager:: Buffer Manager object.
Definition at line 108 of file buffer_manager.cpp.
int BufferManager::flushPage | ( | pageId_t | page_id | ) |
核心函数之一。内存和磁盘交互的接口。
将对应内存页写入对应文件的对应块。
page_id | 块ID |
file_name | 文件名 |
block_id | 页ID |
Definition at line 227 of file buffer_manager.cpp.
int BufferManager::getBlockNum | ( | const std::string & | file_name | ) |
获取文件块数
file_name | 文件名 |
Definition at line 270 of file buffer_manager.cpp.
char * BufferManager::getPage | ( | const std::string & | file_name, |
int | block_id | ||
) |
获取一页
通过页号得到页的句柄(一个页的头地址)
file_name | 文件名 |
block_id | 块ID |
Definition at line 130 of file buffer_manager.cpp.
pageId_t BufferManager::getPageId | ( | const std::string & | file_name, |
int | block_id | ||
) |
简单遍历获取页号
获取对应文件的对应块在内存中的页号,没有找到返回-1
file_name | 文件名 |
block_id | 块ID |
Definition at line 258 of file buffer_manager.cpp.
void BufferManager::modifyPage | ( | int | page_id | ) |
标记页是否被修改
标记page_id所对应的页已经被修改
page_id | 页ID |
Definition at line 155 of file buffer_manager.cpp.
void BufferManager::pinPage | ( | int | page_id | ) |
钉住一页
钉住一个页
page_id | 页ID |
Definition at line 163 of file buffer_manager.cpp.
int BufferManager::unpinPage | ( | int | page_id | ) |
解钉一次
解除一个页的钉住状态(需要注意的是一个页可能被多次钉住,该函数只能解除一次),如果对应页的pin_count_为0,则返回-1
page_id | 页ID |
Definition at line 173 of file buffer_manager.cpp.