MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
disk_log_handler.h
1/* Copyright (c) 2021-2022 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/01
13//
14
15#pragma once
16
17#include "common/types.h"
18#include "common/sys/rc.h"
19#include "common/lang/vector.h"
20#include "common/lang/deque.h"
21#include "common/lang/memory.h"
22#include "common/lang/thread.h"
23#include "storage/clog/log_module.h"
24#include "storage/clog/log_file.h"
25#include "storage/clog/log_buffer.h"
26#include "storage/clog/log_handler.h"
27
28class LogReplayer;
29
49{
50public:
51 DiskLogHandler() = default;
52 virtual ~DiskLogHandler() = default;
53
59 RC init(const char *path) override;
60
64 RC start() override;
68 RC stop() override;
69
74 RC await_termination() override;
75
83 RC replay(LogReplayer &replayer, LSN start_lsn) override;
84
91 RC iterate(function<RC(LogEntry &)> consumer, LSN start_lsn) override;
92
98 RC wait_lsn(LSN lsn) override;
99
101 LSN current_lsn() const override { return entry_buffer_.current_lsn(); }
103 LSN current_flushed_lsn() const { return entry_buffer_.flushed_lsn(); }
104
105private:
113 RC _append(LSN &lsn, LogModule module, vector<char> &&data) override;
114
115private:
119 void thread_func();
120
121private:
122 unique_ptr<thread> thread_;
123 atomic_bool running_{false};
124
127
128 string path_;
129};
对外提供服务的CLog模块
Definition: disk_log_handler.h:49
RC _append(LSN &lsn, LogModule module, vector< char > &&data) override
在缓存中增加一条日志
Definition: disk_log_handler.cpp:136
LogEntryBuffer entry_buffer_
管理所有的日志文件
Definition: disk_log_handler.h:126
atomic_bool running_
刷新日志的线程
Definition: disk_log_handler.h:123
RC init(const char *path) override
初始化日志模块
Definition: disk_log_handler.cpp:26
RC iterate(function< RC(LogEntry &)> consumer, LSN start_lsn) override
迭代日志
Definition: disk_log_handler.cpp:102
LSN current_lsn() const override
当前的LSN
Definition: disk_log_handler.h:101
LogFileManager file_manager_
是否还要继续运行
Definition: disk_log_handler.h:125
RC await_termination() override
等待线程结束
Definition: disk_log_handler.cpp:58
void thread_func()
刷新日志的线程函数
Definition: disk_log_handler.cpp:164
RC wait_lsn(LSN lsn) override
等待指定的日志刷盘
Definition: disk_log_handler.cpp:150
string path_
缓存日志
Definition: disk_log_handler.h:128
RC start() override
启动线程刷新日志到磁盘
Definition: disk_log_handler.cpp:32
RC stop() override
设置停止标识,并不会真正的停止
Definition: disk_log_handler.cpp:45
RC replay(LogReplayer &replayer, LSN start_lsn) override
回放日志
Definition: disk_log_handler.cpp:76
LSN current_flushed_lsn() const
当前刷新到哪个日志
Definition: disk_log_handler.h:103
日志数据缓冲区
Definition: log_buffer.h:36
描述一条日志
Definition: log_entry.h:44
管理所有的日志文件
Definition: log_file.h:107
对外提供服务的CLog模块
Definition: log_handler.h:40
日志模块
Definition: log_module.h:24
日志回放接口类
Definition: log_replayer.h:26