MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
mvcc_trx_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/28.
13//
14
15#pragma once
16
17#include "common/sys/rc.h"
18#include "common/types.h"
19#include "common/lang/string.h"
20#include "common/lang/unordered_map.h"
21#include "storage/record/record.h"
22#include "storage/clog/log_replayer.h"
23
24class LogHandler;
25class Table;
26class Db;
27class MvccTrxKit;
28class MvccTrx;
29class LogEntry;
30
36{
37public:
38 enum class Type : int32_t
39 {
42 COMMIT,
44 };
45
46public:
47 MvccTrxLogOperation(Type type) : type_(type) {}
48 explicit MvccTrxLogOperation(int32_t type) : type_(static_cast<Type>(type)) {}
49 ~MvccTrxLogOperation() = default;
50
51 Type type() const { return type_; }
52 int32_t index() const { return static_cast<int32_t>(type_); }
53
54 string to_string() const;
55
56private:
57 Type type_;
58};
59
65{
67 int32_t trx_id;
68
69 static const int32_t SIZE;
70
71 string to_string() const;
72};
73
80{
82 int32_t table_id;
84
85 static const int32_t SIZE;
86
87 string to_string() const;
88};
89
96{
98 int32_t commit_trx_id;
99
100 static const int32_t SIZE;
101
102 string to_string() const;
103};
104
110{
111public:
112 MvccTrxLogHandler(LogHandler &log_handler);
114
118 RC insert_record(int32_t trx_id, Table *table, const RID &rid);
119
123 RC delete_record(int32_t trx_id, Table *table, const RID &rid);
124
129 RC commit(int32_t trx_id, int32_t commit_trx_id);
130
135 RC rollback(int32_t trx_id);
136
137private:
138 LogHandler &log_handler_;
139};
140
145class MvccTrxLogReplayer final : public LogReplayer
146{
147public:
148 MvccTrxLogReplayer(Db &db, MvccTrxKit &trx_kit, LogHandler &log_handler);
149 virtual ~MvccTrxLogReplayer() = default;
150
152 RC replay(const LogEntry &entry) override;
153
155 RC on_done() override;
156
157private:
161
163 unordered_map<int32_t, MvccTrx *> trx_map_;
164};
一个DB实例负责管理一批表
Definition: db.h:46
描述一条日志
Definition: log_entry.h:44
对外提供服务的CLog模块
Definition: log_handler.h:40
日志回放接口类
Definition: log_replayer.h:26
Definition: mvcc_trx.h:26
处理事务日志的辅助类
Definition: mvcc_trx_log.h:110
RC delete_record(int32_t trx_id, Table *table, const RID &rid)
记录删除一条记录的日志
Definition: mvcc_trx_log.cpp:86
RC rollback(int32_t trx_id)
记录回滚事务的日志
Definition: mvcc_trx_log.cpp:122
RC insert_record(int32_t trx_id, Table *table, const RID &rid)
记录插入一条记录的日志
Definition: mvcc_trx_log.cpp:71
RC commit(int32_t trx_id, int32_t commit_trx_id)
记录提交事务的日志
Definition: mvcc_trx_log.cpp:101
表示各种操作类型
Definition: mvcc_trx_log.h:36
Type
Definition: mvcc_trx_log.h:39
@ INSERT_RECORD
插入一条记录
@ DELETE_RECORD
删除一条记录
事务日志回放器
Definition: mvcc_trx_log.h:146
Db & db_
所属数据库
Definition: mvcc_trx_log.h:158
RC on_done() override
当所有日志回放完成时的回调函数
Definition: mvcc_trx_log.cpp:177
RC replay(const LogEntry &entry) override
回放一条日志
Definition: mvcc_trx_log.cpp:140
MvccTrxKit & trx_kit_
事务管理器
Definition: mvcc_trx_log.h:159
LogHandler & log_handler_
日志处理器
Definition: mvcc_trx_log.h:160
多版本并发事务TODO 没有垃圾回收
Definition: mvcc_trx.h:63
Definition: table.h:42
事务提交的日志
Definition: mvcc_trx_log.h:96
int32_t commit_trx_id
提交的事务ID
Definition: mvcc_trx_log.h:98
MvccTrxLogHeader header
日志头部
Definition: mvcc_trx_log.h:97
表示事务日志的头部
Definition: mvcc_trx_log.h:65
static const int32_t SIZE
头部大小
Definition: mvcc_trx_log.h:69
int32_t operation_type
操作类型
Definition: mvcc_trx_log.h:66
int32_t trx_id
事务ID
Definition: mvcc_trx_log.h:67
表示事务日志中操作行数据的日志,比如插入和删除
Definition: mvcc_trx_log.h:80
int32_t table_id
表ID
Definition: mvcc_trx_log.h:82
MvccTrxLogHeader header
日志头部
Definition: mvcc_trx_log.h:81
RID rid
记录ID
Definition: mvcc_trx_log.h:83
static const int32_t SIZE
日志大小
Definition: mvcc_trx_log.h:85
标识一个记录的位置 一个记录是放在某个文件的某个页面的某个槽位。这里不记录文件信息,记录页面和槽位信息
Definition: record.h:35