MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
latch_memo.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 2023/03/08.
13//
14
15#pragma once
16
17#include <deque>
18#include <vector>
19
20#include "common/rc.h"
21#include "storage/buffer/page.h"
22
23class Frame;
24class DiskBufferPool;
25
26namespace common {
27class SharedMutex;
28}
29
30enum class LatchMemoType
31{
32 NONE,
33 SHARED,
34 EXCLUSIVE,
35 PIN,
36};
37
39{
40 LatchMemoItem() = default;
41 LatchMemoItem(LatchMemoType type, Frame *frame);
42 LatchMemoItem(LatchMemoType type, common::SharedMutex *lock);
43
44 LatchMemoType type = LatchMemoType::NONE;
45 Frame *frame = nullptr;
46 common::SharedMutex *lock = nullptr;
47};
48
49class LatchMemo final
50{
51public:
55 LatchMemo(DiskBufferPool *buffer_pool);
56 ~LatchMemo();
57
58 RC get_page(PageNum page_num, Frame *&frame);
59 RC allocate_page(Frame *&frame);
60 void dispose_page(PageNum page_num);
61 void latch(Frame *frame, LatchMemoType type);
62 void xlatch(Frame *frame);
63 void slatch(Frame *frame);
64 bool try_slatch(Frame *frame);
65
66 void xlatch(common::SharedMutex *lock);
67 void slatch(common::SharedMutex *lock);
68
69 void release();
70
71 void release_to(int point);
72
73 int memo_point() const { return static_cast<int>(items_.size()); }
74
75private:
76 void release_item(LatchMemoItem &item);
77
78private:
79 DiskBufferPool * buffer_pool_ = nullptr;
80 std::deque<LatchMemoItem> items_;
81 std::vector<PageNum> disposed_pages_;
82};
BufferPool的实现
Definition: disk_buffer_pool.h:193
页帧
Definition: frame.h:62
Definition: latch_memo.h:50
Definition: latch_memo.h:39