-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
390 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[submodule "deps/googletest"] | ||
path = deps/googletest | ||
url = https://github.com/google/googletest | ||
[submodule "deps/jsoncpp"] | ||
path = deps/jsoncpp | ||
url = https://github.com/open-source-parsers/jsoncpp.git | ||
[submodule "deps/libevent"] | ||
path = deps/libevent | ||
url = https://github.com/libevent/libevent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule googletest
added at
16f637
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
|
||
|
||
2. build libevent | ||
2. build cd libevent | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Created by windwheel on 2021/10/24. | ||
// | ||
|
||
//这里因为参考了cmu的讲义 所以实现的不是传统的lru,而是nru | ||
//根据时钟进行淘汰的算法 | ||
#include <cstdlib> | ||
#include "clock_replacer.h" | ||
|
||
bool ClockReplacer::Victim(Frame *frame) { | ||
latch_.lock(); | ||
if (size<=0){ | ||
latch_.unlock(); | ||
return false; | ||
} | ||
|
||
while (true){ | ||
if (!in_replacer[clockhand]){ | ||
clockhand = (clockhand+1) % buffer_pool_size; | ||
continue; | ||
} | ||
|
||
if (!ref_bits_[clockhand]){ | ||
clockhand = (clockhand+1) % buffer_pool_size; | ||
continue; | ||
} | ||
|
||
frame->file_desc = clockhand; | ||
in_replacer[clockhand] = false; | ||
ref_bits_[clockhand] = false; | ||
size-=1; | ||
break; | ||
} | ||
latch_.unlock(); | ||
return true; | ||
} | ||
//对空闲列表中 正在准备替换的page进行状态标记 | ||
void ClockReplacer::Pin(Frame *frame) { | ||
latch_.lock(); | ||
if (in_replacer[frame->file_desc]){ | ||
in_replacer[frame->file_desc] = false; | ||
ref_bits_[frame->file_desc] = false; | ||
size -=1; | ||
} | ||
latch_.unlock(); | ||
} | ||
|
||
void ClockReplacer::Unpin(Frame *frame) { | ||
latch_.lock(); | ||
if (!in_replacer[frame->file_desc]){ | ||
in_replacer[frame->file_desc] = true; | ||
ref_bits_[frame->file_desc] = true; | ||
} | ||
} | ||
|
||
ClockReplacer::ClockReplacer(ClockReplacer *pReplacer) { | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Created by windwheel on 2021/10/24. | ||
// | ||
|
||
#ifndef MINIDB_CLOCK_REPLACER_H | ||
#define MINIDB_CLOCK_REPLACER_H | ||
|
||
|
||
#include <vector> | ||
#include <mutex> | ||
#include "common.h" | ||
|
||
class ClockReplacer { | ||
|
||
public: | ||
ClockReplacer(PageNum page_nums){ | ||
using std::vector; | ||
ref_bits_ = vector<bool>(page_nums, false); | ||
in_replacer = vector<bool>(page_nums, false); | ||
buffer_pool_size = page_nums; | ||
size = 0; | ||
clockhand = 0; | ||
|
||
} | ||
|
||
ClockReplacer(ClockReplacer *pReplacer); | ||
|
||
~ClockReplacer() = default; | ||
|
||
public: | ||
std::vector<bool > ref_bits_; //待被替换的page进行标记状态 | ||
std::vector<bool> in_replacer;//正在被替换的page | ||
size_t buffer_pool_size; //缓冲池管理器的大小 | ||
std::mutex latch_;//维持操作系统空闲列表换页的互斥锁 | ||
int size; //维护当前动态遍历的空闲列表大小 | ||
int clockhand; //记录当前遍历到的Page 利用同余摸循环遍历空闲列表 | ||
Frame *frame;//待分配的新页 | ||
|
||
|
||
public: | ||
bool Victim(Frame *frame); //双指针遍历待替换的freelist列表 | ||
void Pin(Frame *frame); //Pin住的页 正在准备被替换 | ||
void Unpin(Frame *frame); //已经被淘汰掉的Page | ||
}; | ||
|
||
|
||
|
||
|
||
#endif //MINIDB_CLOCK_REPLACER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Created by windwheel on 2021/10/24. | ||
// | ||
|
||
#ifndef MINIDB_COMMON_H | ||
#define MINIDB_COMMON_H | ||
#define BP_INVALID_PAGE_NUM (-1) | ||
#define BP_PAGE_SIZE (1 << 12) | ||
#define BP_FILE_SUB_HDR_SIZE (sizeof(BPFileSubHeader)) | ||
#define BP_BUFFER_SIZE 50 | ||
#define MAX_OPEN_FILE 1024 | ||
#define BP_PAGE_DATA_SIZE (BP_PAGE_SIZE - sizeof(PageNum)) | ||
|
||
|
||
#endif //MINIDB_COMMON_H | ||
|
||
typedef int PageNum; | ||
|
||
|
||
|
||
typedef struct{ | ||
PageNum page_num; | ||
char data[BP_PAGE_DATA_SIZE]; | ||
} Page; | ||
|
||
typedef struct{ | ||
bool dirty; | ||
unsigned int pin_count; | ||
unsigned long acc_time; | ||
int file_desc; | ||
Page page; | ||
} Frame; | ||
|
||
|
||
typedef struct { | ||
PageNum page_count; | ||
int allocated_pages; | ||
} BPFileSubHeader; | ||
|
||
class BPFileHandle{ | ||
public: | ||
BPFileHandle() { | ||
memset(this, 0, sizeof(*this)); | ||
} | ||
|
||
public: | ||
bool bopen; | ||
const char *file_name; | ||
int file_desc; | ||
Frame *hdr_frame; | ||
Page *hdr_page; | ||
char *bitmap; | ||
BPFileSubHeader *file_sub_header; | ||
} ; | ||
|
||
//因为在操作系统中页和页表项都会有落盘的页表ID长度,所以需要做数据类型的适配 | ||
|
||
using frame_id_t = int32_t; | ||
using page_id = int32_t; | ||
using old_t = uint16_t; | ||
|
||
|
||
|
Oops, something went wrong.