Skip to content

Commit

Permalink
修复 bplus_tree_test 单测问题 (#476)
Browse files Browse the repository at this point in the history
### What problem were solved in this pull request?

Problem:
问题1:bplus_tree_test 单测失败,内存非法访问
问题2:bplus_tree_log_test concurrency 单测失败

### What is changed and how it works?

问题1:单测运行时ASAN报内存非法访问。由于BplusTreeMiniTransaction析构时自动调用BplusTreeLogger的析构,接着调用
BplusTreeLogger::commit,这里会访问Frame,而frame已经释放,这样造成的内存非法访问。
问题2:build.sh 没有传入-DCONCURRENCY参数

修复方法:
BplusTreeMiniTransaction 构造函数不给出rc时不自动提交或回滚,BplusTreeLogger也不需要在析构时自动提交。
  • Loading branch information
hnwyllmm authored Nov 14, 2024
1 parent 42925b0 commit 4d90aee
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function build {
local build_type_lower=$(echo "$1" | tr '[:upper:]' '[:lower:]') # 转换为小写
echo "Build type: $build_type_lower" # 输出构建类型

do_build "$build_type_lower" -DCMAKE_BUILD_TYPE="$build_type_lower" # 调用 do_build
do_build $@ -DCMAKE_BUILD_TYPE="$build_type_lower" # 调用 do_build
}


Expand Down
1 change: 1 addition & 0 deletions deps/common/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ int Log::out(const LOG_LEVEL console_level, const LOG_LEVEL log_level, T &msg)
do { \
if (!(expression)) { \
LOG_PANIC(description, ##__VA_ARGS__); \
LOG_PANIC("%s", lbt()); \
assert(expression); \
} \
} while (0)
Expand Down
9 changes: 6 additions & 3 deletions src/observer/storage/buffer/disk_buffer_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Frame *BPFrameManager::get_internal(const FrameId &frame_id)
(void)frames_.get(frame_id, frame);
if (frame != nullptr) {
frame->pin();
LOG_DEBUG("got a frame. frame=%s", frame->to_string().c_str());
}
return frame;
}
Expand All @@ -138,6 +139,7 @@ Frame *BPFrameManager::alloc(int buffer_pool_id, PageNum page_num)
frame->set_page_num(page_num);
frame->pin();
frames_.put(frame_id, frame);
LOG_DEBUG("allocate a new frame. frame=%s", frame->to_string().c_str());
}
return frame;
}
Expand Down Expand Up @@ -372,6 +374,7 @@ RC DiskBufferPool::allocate_page(Frame **frame)

hdr_frame_->set_lsn(lsn);

LOG_DEBUG("allocate a new page without extend buffer pool. page num=%d, buffer pool=%d", i, id());
lock_.unlock();
return get_this_page(i, frame);
}
Expand Down Expand Up @@ -401,8 +404,8 @@ RC DiskBufferPool::allocate_page(Frame **frame)
return rc;
}

LOG_INFO("allocate new page. file=%s, pageNum=%d, pin=%d",
file_name_.c_str(), page_num, allocated_frame->pin_count());
LOG_INFO("allocate new page by extending bufferpool. buffer_pool_id=%d, pageNum=%d, pin=%d",
id(), page_num, allocated_frame->pin_count());

file_header_->allocated_pages++;
file_header_->page_count++;
Expand Down Expand Up @@ -705,7 +708,7 @@ RC DiskBufferPool::allocate_frame(PageNum page_num, Frame **buffer)
Frame *frame = frame_manager_.alloc(id(), page_num);
if (frame != nullptr) {
*buffer = frame;
LOG_DEBUG("allocate frame %p, page num %d", frame, page_num);
LOG_DEBUG("allocate frame %p, page num %d, frame=%s", frame, page_num, frame->to_string().c_str());
return RC::SUCCESS;
}

Expand Down
Binary file added src/observer/storage/index/.bplus_tree.h.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion src/observer/storage/index/bplus_tree_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BplusTreeLogger::BplusTreeLogger(LogHandler &log_handler, int32_t buffer_pool_id
: log_handler_(log_handler), buffer_pool_id_(buffer_pool_id)
{}

BplusTreeLogger::~BplusTreeLogger() { commit(); }
BplusTreeLogger::~BplusTreeLogger() {}

RC BplusTreeLogger::init_header_page(Frame *frame, const IndexFileHeader &header)
{
Expand Down

0 comments on commit 4d90aee

Please sign in to comment.