CMU15445 LAB1 BUFFER POOL
2020fall lab1
实验说明
- 该lab需要实现一个buffer pool
- lab的实现需要是线程安全的,用latch(在os中被称作lock)来保护内部数据结构的关键部分
- 任务1 LRU替换策略
- 主要是实现
LRUReplacer
这个子类 - LRUReplacer的大小与BufferPool一致,但是只有unpinned的frame才会放到LRUReplacer之中
- 需要实现
Victim(T*)
,Pin(T)
,Unpin(T)
,Size()
这几个方法
- 主要是实现
- 任务2 BUFFER POOL MANAGER
- BufferPoolManager的主要功能是在磁盘与内存读写database的数据 ,DiskManager以及实现了
- BufferPoolManager将会将数据读写在Page对象中
- Page对象会记录dirty flag与pin reference以及它现在存有的物理页的page_id
- 需要实现的函数有
- Buffer Pool是有一个free list的,如果没有空闲的Page了,那就返回NULL
- FlushPageImpl需要直接flush一个Page对象,不论其pin的状态
测试
记得去掉测试中的DISABLED_
$ mkdir build
$ cd build
$ make lru_replacer_test
$ ./test/lru_replacer_test
// 测试全部
make check-tests
gradescope打分
// 每次在bash中输入这打包提交
zip project1.zip src/include/buffer/lru_replacer.h src/buffer/lru_replacer.cpp src/include/buffer/buffer_pool_manager.h src/buffer/buffer_pool_manager.cpp
# 别人写的bash,侵删
#!/usr/bin/env bash
print_help() {
echo -e "Usage:\n"
echo -e " $ archive_submission proj#\n"
echo -e "Example:\n"
echo -e " $ archive_submission 0\n"
echo -e "This will archive project 0. Choices:\n"
echo -e " 0 - C++ Primer"
echo -e " 1 - Buffer Pool Manager"
echo -e " 2 - B+ Tree Index"
echo -e " 3 - Query Execution"
echo -e " 4 - Concurrency Control"
}
out="proj$1-submission"
if [[ -f ./$out.zip ]]; then
rm $out.zip
fi
case $1 in
4)
zip $out -urq \
src/concurrency/lock_manager.cpp \
src/include/concurrency/lock_manager.h
;;
3)
zip $out -urq \
src/include/catalog/catalog.h \
src/include/execution/execution_engine.h \
src/include/execution/executor_factory.h \
src/include/execution/executors/seq_scan_executor.h \
src/include/execution/executors/index_scan_executor.h \
src/include/execution/executors/insert_executor.h \
src/include/execution/executors/update_executor.h \
src/include/execution/executors/delete_executor.h \
src/include/execution/executors/nested_loop_join_executor.h \
src/include/execution/executors/nested_index_join_executor.h \
src/include/execution/executors/limit_executor.h \
src/include/execution/executors/aggregation_executor.h \
src/include/storage/index/b_plus_tree_index.h \
src/include/storage/index/index.h \
src/execution/executor_factory.cpp \
src/execution/seq_scan_executor.cpp \
src/execution/index_scan_executor.cpp \
src/execution/insert_executor.cpp \
src/execution/update_executor.cpp \
src/execution/delete_executor.cpp \
src/execution/nested_loop_join_executor.cpp \
src/execution/nested_index_join_executor.cpp \
src/execution/limit_executor.cpp \
src/execution/aggregation_executor.cpp \
src/storage/index/b_plus_tree_index.cpp
;;
2)
zip $out -urq \
src/include/storage/page/b_plus_tree_page.h \
src/storage/page/b_plus_tree_page.cpp \
src/include/storage/page/b_plus_tree_internal_page.h \
src/storage/page/b_plus_tree_internal_page.cpp \
src/include/storage/page/b_plus_tree_leaf_page.h \
src/storage/page/b_plus_tree_leaf_page.cpp \
src/include/storage/index/b_plus_tree.h \
src/storage/index/b_plus_tree.cpp \
src/include/storage/index/index_iterator.h \
src/storage/index/index_iterator.cpp
;;
1)
zip $out -urq \
src/include/buffer/lru_replacer.h \
src/buffer/lru_replacer.cpp \
src/include/buffer/buffer_pool_manager.h \
src/buffer/buffer_pool_manager.cpp
;;
0)
zip $out -urq src/include/primer/p0_starter.h
;;
*)
echo "Invalid input: $1"
print_help
exit 1
;;
esac
echo "Files has been writen into $out.zip..."
unzip -l $out.zip
遇到的问题
- 用vscode调试可以参考
- 中间遇到问题一直想要调试,但是一直跳过断点,原因是要进入debug模式,必须给cmake加参数,估计不加
-g
就没了在加了cmake参数之后,报错也详细了,之前就只有Segementation Fault
- 从数组中取元素返回的竟然是引用?
- 对于结构的成员默认初始化这样