MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
bplus_tree_log.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by wangyunlai.wyl on 2024/02/05.
13//
14
15#pragma once
16
17#include <stddef.h>
18
19#include "common/types.h"
20#include "common/sys/rc.h"
21#include "common/lang/span.h"
22#include "common/lang/memory.h"
23#include "common/lang/vector.h"
24#include "common/lang/string.h"
25#include "storage/index/latch_memo.h"
26#include "storage/clog/log_replayer.h"
27// #include "storage/index/bplus_tree_log_entry.h"
28
29struct IndexFileHeader;
30class LogEntry;
31class LogHandler;
33class Frame;
37
38namespace bplus_tree {
39class LogEntryHandler;
40}
41
42namespace common {
43class Deserializer;
44}
45
61class BplusTreeLogger final
62{
63public:
69 BplusTreeLogger(LogHandler &log_handler, int32_t buffer_pool_id);
71
76 RC init_header_page(Frame *frame, const IndexFileHeader &header);
82 RC update_root_page(Frame *frame, PageNum root_page_num, PageNum old_page_num);
83
91 RC node_insert_items(IndexNodeHandler &node_handler, int index, span<const char> items, int item_num);
100 RC node_remove_items(IndexNodeHandler &node_handler, int index, span<const char> items, int item_num);
101
105 RC leaf_init_empty(IndexNodeHandler &node_handler);
109 RC leaf_set_next_page(IndexNodeHandler &node_handler, PageNum page_num, PageNum old_page_num);
110
114 RC internal_init_empty(IndexNodeHandler &node_handler);
119 IndexNodeHandler &node_handler, PageNum first_page_num, span<const char> key, PageNum page_num);
123 RC internal_update_key(IndexNodeHandler &node_handler, int index, span<const char> key, span<const char> old_key);
124
128 RC set_parent_page(IndexNodeHandler &node_handler, PageNum page_num, PageNum old_page_num);
129
133 RC commit();
137 RC rollback(BplusTreeMiniTransaction &mtr, BplusTreeHandler &tree_handler);
138
142 static RC redo(BufferPoolManager &bpm, const LogEntry &entry);
146 static string log_entry_to_string(const LogEntry &entry);
147
148private:
149 RC __redo(LSN lsn, BplusTreeMiniTransaction &mtr, BplusTreeHandler &tree_handler, common::Deserializer &redo_buffer);
150
151protected:
152 RC append_log_entry(unique_ptr<bplus_tree::LogEntryHandler> entry);
153
154private:
155 LogHandler &log_handler_;
156 int32_t buffer_pool_id_ = -1;
157
158 vector<unique_ptr<bplus_tree::LogEntryHandler>> entries_;
159
160 bool need_log_ = true;
161};
162
170{
171public:
177 BplusTreeMiniTransaction(BplusTreeHandler &tree_handler, RC *operation_result = nullptr);
179
180 LatchMemo &latch_memo() { return latch_memo_; }
181 BplusTreeLogger &logger() { return logger_; }
182
183 RC commit();
184 RC rollback();
185
186private:
187 BplusTreeHandler &tree_handler_;
188 RC *operation_result_ = nullptr;
189 LatchMemo latch_memo_;
190 BplusTreeLogger logger_;
191};
192
198{
199public:
201 virtual ~BplusTreeLogReplayer() = default;
202
204 virtual RC replay(const LogEntry &entry) override;
205
206private:
207 BufferPoolManager &buffer_pool_manager_;
208};
B+树的实现
Definition: bplus_tree.h:450
B+树日志重做器
Definition: bplus_tree_log.h:198
virtual RC replay(const LogEntry &entry) override
回放一条日志
Definition: bplus_tree_log.cpp:292
B+树日志记录辅助类,同时可以利用此类做回滚操作
Definition: bplus_tree_log.h:62
RC set_parent_page(IndexNodeHandler &node_handler, PageNum page_num, PageNum old_page_num)
修改某个页面的父节点编号
Definition: bplus_tree_log.cpp:88
RC node_remove_items(IndexNodeHandler &node_handler, int index, span< const char > items, int item_num)
在某个页面中删除一些元素
Definition: bplus_tree_log.cpp:59
RC commit()
提交。表示整个操作成功
Definition: bplus_tree_log.cpp:103
RC update_root_page(Frame *frame, PageNum root_page_num, PageNum old_page_num)
更新B+树文件头页,也就是指向根页的页面编号
Definition: bplus_tree_log.cpp:43
RC internal_init_empty(IndexNodeHandler &node_handler)
初始化一个空的内部节点
Definition: bplus_tree_log.cpp:70
RC leaf_init_empty(IndexNodeHandler &node_handler)
初始化一个空的叶子节点
Definition: bplus_tree_log.cpp:48
RC rollback(BplusTreeMiniTransaction &mtr, BplusTreeHandler &tree_handler)
回滚。操作执行一半失败了,把所有操作都回滚回来
Definition: bplus_tree_log.cpp:133
RC init_header_page(Frame *frame, const IndexFileHeader &header)
初始化B+树文件头页
Definition: bplus_tree_log.cpp:38
bool need_log_
当前记录了的日志
Definition: bplus_tree_log.h:160
RC leaf_set_next_page(IndexNodeHandler &node_handler, PageNum page_num, PageNum old_page_num)
修改叶子节点的下一个兄弟节点编号
Definition: bplus_tree_log.cpp:65
static string log_entry_to_string(const LogEntry &entry)
日志记录转字符串
Definition: bplus_tree_log.cpp:235
RC internal_update_key(IndexNodeHandler &node_handler, int index, span< const char > key, span< const char > old_key)
更新某个内部页面上,更新指定位置的键值
Definition: bplus_tree_log.cpp:82
vector< unique_ptr< bplus_tree::LogEntryHandler > > entries_
关联的缓冲池ID
Definition: bplus_tree_log.h:158
RC internal_create_new_root(IndexNodeHandler &node_handler, PageNum first_page_num, span< const char > key, PageNum page_num)
创建一个新的根节点
Definition: bplus_tree_log.cpp:75
RC node_insert_items(IndexNodeHandler &node_handler, int index, span< const char > items, int item_num)
在某个页面中插入一些元素
Definition: bplus_tree_log.cpp:53
static RC redo(BufferPoolManager &bpm, const LogEntry &entry)
重做日志。通常在系统启动时,会把所有日志重做一遍
Definition: bplus_tree_log.cpp:147
B+树使用的事务辅助类
Definition: bplus_tree_log.h:170
BufferPool的管理类
Definition: disk_buffer_pool.h:322
页帧
Definition: frame.h:66
IndexNode 仅作为数据在内存或磁盘中的表示IndexNodeHandler 负责对IndexNode做各种操作。 作为一个类来说,虚函数会影响“结构体”真实的内存布局,所以将数据存储与操作分开
Definition: bplus_tree.h:267
Definition: latch_memo.h:52
描述一条日志
Definition: log_entry.h:44
对外提供服务的CLog模块
Definition: log_handler.h:40
日志回放接口类
Definition: log_replayer.h:26
反序列化工具
Definition: serializer.h:63
the meta information of bplus tree
Definition: bplus_tree.h:170