MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
|
B+树日志处理辅助类 更多...
#include <bplus_tree_log_entry.h>
Public 成员函数 | |
LogEntryHandler (LogOperation operation, Frame *frame=nullptr) | |
Frame * | frame () |
返回日志对应的frame 更多... | |
const Frame * | frame () const |
PageNum | page_num () const |
void | set_page_num (PageNum page_num) |
LogOperation | operation_type () const |
日志操作类型 | |
RC | serialize (common::Serializer &buffer) const |
序列化日志 | |
RC | serialize_header (common::Serializer &buffer) const |
序列化日志头 | |
virtual RC | serialize_body (common::Serializer &buffer) const =0 |
序列化日志内容。所有子类应该实现这个函数 更多... | |
virtual RC | rollback (BplusTreeMiniTransaction &mtr, BplusTreeHandler &tree_handler)=0 |
回滚 更多... | |
virtual RC | redo (BplusTreeMiniTransaction &mtr, BplusTreeHandler &tree_handler)=0 |
重做 更多... | |
virtual string | to_string () const |
静态 Public 成员函数 | |
static RC | from_buffer (function< RC(PageNum, Frame *&)> frame_getter, common::Deserializer &buffer, unique_ptr< LogEntryHandler > &handler) |
从buffer中反序列化出一个LogEntryHandler 更多... | |
static RC | from_buffer (DiskBufferPool &buffer_pool, common::Deserializer &buffer, unique_ptr< LogEntryHandler > &handler) |
static RC | from_buffer (common::Deserializer &deserializer, unique_ptr< LogEntryHandler > &handler) |
Protected 属性 | |
LogOperation | operation_type_ |
Frame * | frame_ = nullptr |
PageNum | page_num_ = BP_INVALID_PAGE_NUM |
page num本来存放在frame中。但是只有在运行时才能拿到frame,为了强制适配 解析文件buffer时不存在运行时的情况,直接记录page num | |
B+树日志处理辅助类
每种操作类型的日志,都有一个具体的实现类。
|
inline |
返回日志对应的frame
每条日志都对应着操作关联的页面。但是在日志重放时,或者只是想将日志内容格式化时,是没有对应的页面的。
|
static |
从buffer中反序列化出一个LogEntryHandler
frame_getter | 为了方便测试增加的一个接口。如果把BufferPool抽象的更好,或者把BplusTree日志的二进制数据与Handler解耦,也不需要这样的接口 | |
buffer | 二进制Buffer | |
[out] | handler | 返回结果 |
这里有个比较别扭的地方。一个日志应该有两种表现形式,一个是内存或磁盘中的二进制数据,另一个是可以进行操作的Handler。 但是这里实现的时候,只使用了handler,所以在反序列化时,有些场景下根本不需要Frame,但是为了适配,允许传入一个null frame。 在LogEntryHandler类中也做了特殊处理。就是虽然有frame指针对象,但是也另外单独记录了page_num。
|
pure virtual |
重做
在系统重启时,需要根据日志内容进行重做
在 bplus_tree::InitHeaderPageLogEntryHandler, bplus_tree::UpdateRootPageLogEntryHandler, bplus_tree::SetParentPageLogEntryHandler, bplus_tree::NormalOperationLogEntryHandler, bplus_tree::LeafInitEmptyLogEntryHandler, bplus_tree::LeafSetNextPageLogEntryHandler, bplus_tree::InternalInitEmptyLogEntryHandler, bplus_tree::InternalCreateNewRootLogEntryHandler , 以及 bplus_tree::InternalUpdateKeyLogEntryHandler 内被实现.
|
pure virtual |
回滚
在事务回滚时,需要根据日志内容进行回滚
在 bplus_tree::InitHeaderPageLogEntryHandler, bplus_tree::UpdateRootPageLogEntryHandler, bplus_tree::SetParentPageLogEntryHandler, bplus_tree::NormalOperationLogEntryHandler, bplus_tree::LeafInitEmptyLogEntryHandler, bplus_tree::LeafSetNextPageLogEntryHandler, bplus_tree::InternalInitEmptyLogEntryHandler, bplus_tree::InternalCreateNewRootLogEntryHandler , 以及 bplus_tree::InternalUpdateKeyLogEntryHandler 内被实现.
|
pure virtual |
序列化日志内容。所有子类应该实现这个函数
在 bplus_tree::InitHeaderPageLogEntryHandler, bplus_tree::UpdateRootPageLogEntryHandler, bplus_tree::SetParentPageLogEntryHandler, bplus_tree::NormalOperationLogEntryHandler, bplus_tree::LeafInitEmptyLogEntryHandler, bplus_tree::LeafSetNextPageLogEntryHandler, bplus_tree::InternalInitEmptyLogEntryHandler, bplus_tree::InternalCreateNewRootLogEntryHandler , 以及 bplus_tree::InternalUpdateKeyLogEntryHandler 内被实现.