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 "common/sys/rc.h"
18#include "common/lang/deque.h"
19#include "common/lang/vector.h"
20#include "storage/buffer/page.h"
21
22class Frame;
23class DiskBufferPool;
24
25namespace common {
26class SharedMutex;
27}
28
32enum class LatchMemoType
33{
34 NONE,
35 SHARED,
36 EXCLUSIVE,
37 PIN,
38};
39
41{
42 LatchMemoItem() = default;
43 LatchMemoItem(LatchMemoType type, Frame *frame);
44 LatchMemoItem(LatchMemoType type, common::SharedMutex *lock);
45
46 LatchMemoType type = LatchMemoType::NONE;
47 Frame *frame = nullptr;
48 common::SharedMutex *lock = nullptr;
49};
50
51class LatchMemo final
52{
53public:
57 LatchMemo(DiskBufferPool *buffer_pool);
58 ~LatchMemo();
59
60 RC get_page(PageNum page_num, Frame *&frame);
61
63 RC allocate_page(Frame *&frame);
64
66 void dispose_page(PageNum page_num);
67
69 void latch(Frame *frame, LatchMemoType type);
70 void xlatch(Frame *frame);
71 void slatch(Frame *frame);
72 bool try_slatch(Frame *frame);
73
74 void xlatch(common::SharedMutex *lock);
75 void slatch(common::SharedMutex *lock);
76
77 void release();
78
79 void release_to(int point);
80
81 int memo_point() const { return static_cast<int>(items_.size()); }
82
83private:
84 void release_item(LatchMemoItem &item);
85
86private:
87 DiskBufferPool *buffer_pool_ = nullptr;
88 deque<LatchMemoItem> items_;
89 vector<PageNum> disposed_pages_;
90};
BufferPool的实现
Definition: disk_buffer_pool.h:189
页帧
Definition: frame.h:66
Definition: latch_memo.h:52
RC allocate_page(Frame *&frame)
分配页面
Definition: latch_memo.cpp:51
void dispose_page(PageNum page_num)
标记为即将释放的页面
Definition: latch_memo.cpp:64
void latch(Frame *frame, LatchMemoType type)
对指定页面加锁
Definition: latch_memo.cpp:66
Definition: mutex.h:284
Definition: latch_memo.h:41