MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
record_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 on 2024/02/02.
13//
14
15#pragma once
16
17#include <stdint.h>
18
19#include "common/types.h"
20#include "common/sys/rc.h"
21#include "common/lang/span.h"
22#include "common/lang/string.h"
23#include "storage/clog/log_replayer.h"
24#include "sql/parser/parse_defs.h"
25
26struct RID;
27class LogHandler;
28class Frame;
30class DiskBufferPool;
31
37{
38public:
39 enum class Type : int32_t
40 {
41 INIT_PAGE,
42 INSERT,
43 DELETE,
44 UPDATE
45 };
46
47public:
48 explicit RecordOperation(Type type) : type_(type) {}
49 explicit RecordOperation(int32_t type) : type_(static_cast<Type>(type)) {}
50 ~RecordOperation() = default;
51
52 Type type() const { return type_; }
53 int32_t type_id() const { return static_cast<int32_t>(type_); }
54
55 string to_string() const;
56
57private:
58 Type type_;
59};
60
62{
63 int32_t buffer_pool_id;
64 int32_t operation_type;
65 PageNum page_num;
66 int32_t storage_format;
67 int32_t column_num;
68 union
69 {
70 SlotNum slot_num;
71 int32_t record_size;
72 };
73
74 char data[0];
75
76 string to_string() const;
77
78 static const int32_t SIZE;
79};
80
82{
83public:
84 RecordLogHandler() = default;
85 ~RecordLogHandler() = default;
86
87 RC init(LogHandler &log_handler, int32_t buffer_pool_id, int32_t record_size, StorageFormat storage_format);
88
102 RC init_new_page(Frame *frame, PageNum page_num, span<const char> data);
103
110 RC insert_record(Frame *frame, const RID &rid, const char *record);
111
117 RC delete_record(Frame *frame, const RID &rid);
118
126 RC update_record(Frame *frame, const RID &rid, const char *record);
127
128private:
129 LogHandler *log_handler_ = nullptr;
130 int32_t buffer_pool_id_ = -1;
131 int32_t record_size_ = -1;
132 StorageFormat storage_format_ = StorageFormat::ROW_FORMAT;
133};
134
139class RecordLogReplayer final : public LogReplayer
140{
141public:
143 virtual ~RecordLogReplayer() = default;
144
145 virtual RC replay(const LogEntry &entry) override;
146
147private:
148 RC replay_init_page(DiskBufferPool &buffer_pool, const RecordLogHeader &log_header);
149 RC replay_insert(DiskBufferPool &buffer_pool, const RecordLogHeader &log_header);
150 RC replay_delete(DiskBufferPool &buffer_pool, const RecordLogHeader &log_header);
151 RC replay_update(DiskBufferPool &buffer_pool, const RecordLogHeader &log_header);
152
153private:
154 BufferPoolManager &bpm_;
155};
BufferPool的管理类
Definition: disk_buffer_pool.h:322
BufferPool的实现
Definition: disk_buffer_pool.h:189
页帧
Definition: frame.h:66
描述一条日志
Definition: log_entry.h:44
对外提供服务的CLog模块
Definition: log_handler.h:40
日志回放接口类
Definition: log_replayer.h:26
Definition: record_log.h:82
RC insert_record(Frame *frame, const RID &rid, const char *record)
插入一条记录
Definition: record_log.cpp:112
RC update_record(Frame *frame, const RID &rid, const char *record)
更新一条记录
Definition: record_log.cpp:132
RC delete_record(Frame *frame, const RID &rid)
删除一条记录
Definition: record_log.cpp:152
RC init_new_page(Frame *frame, PageNum page_num, span< const char > data)
初始化一个新的页面
Definition: record_log.cpp:89
记录相关的日志重放器
Definition: record_log.h:140
virtual RC replay(const LogEntry &entry) override
回放一条日志
Definition: record_log.cpp:176
记录管理器操作相关的日志类型
Definition: record_log.h:37
Type
Definition: record_log.h:40
@ UPDATE
删除一条记录
@ DELETE
插入一条记录
@ INSERT
初始化空页面
标识一个记录的位置 一个记录是放在某个文件的某个页面的某个槽位。这里不记录文件信息,记录页面和槽位信息
Definition: record.h:35
Definition: record_log.h:62