Skip to content

Commit

Permalink
修复double write buffer 在关闭buffer pool时未清理相关page的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hnwyllmm committed Apr 15, 2024
1 parent 6af83fd commit 175f449
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 276 deletions.
19 changes: 12 additions & 7 deletions benchmark/bplus_tree_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ See the Mulan PSL v2 for more details. */
#include "common/math/integer_generator.h"
#include "storage/buffer/disk_buffer_pool.h"
#include "storage/index/bplus_tree.h"
#include "storage/clog/vacuous_log_handler.h"

using namespace std;
using namespace common;
Expand Down Expand Up @@ -48,7 +49,7 @@ class BenchmarkBase : public Fixture
public:
BenchmarkBase() {}

virtual ~BenchmarkBase() { BufferPoolManager::set_instance(nullptr); }
virtual ~BenchmarkBase() { }

virtual string Name() const = 0;

Expand All @@ -62,21 +63,24 @@ class BenchmarkBase : public Fixture
string btree_filename = this->Name() + ".btree";
LoggerFactory::init_default(log_name.c_str(), LOG_LEVEL_TRACE);

std::call_once(init_bpm_flag, []() { BufferPoolManager::set_instance(&bpm); });

::remove(btree_filename.c_str());

const int internal_max_size = 200;
const int leaf_max_size = 200;

const char *filename = btree_filename.c_str();

RC rc = handler_.create(filename, INTS, sizeof(int32_t) /*attr_len*/, internal_max_size, leaf_max_size);
RC rc = handler_.create(log_handler_,
bpm, filename,
INTS,
sizeof(int32_t) /*attr_len*/,
internal_max_size,
leaf_max_size);
if (rc != RC::SUCCESS) {
throw runtime_error("failed to create btree handler");
}
LOG_INFO(
"test %s setup done. threads=%d, thread index=%d", this->Name().c_str(), state.threads(), state.thread_index());
LOG_INFO("test %s setup done. threads=%d, thread index=%d",
this->Name().c_str(), state.threads(), state.thread_index());
}

virtual void TearDown(const State &state)
Expand Down Expand Up @@ -181,7 +185,8 @@ class BenchmarkBase : public Fixture
}

protected:
BplusTreeHandler handler_;
BplusTreeHandler handler_;
VacuousLogHandler log_handler_;
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
19 changes: 12 additions & 7 deletions benchmark/record_manager_concurrency_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BenchmarkBase : public Fixture
public:
BenchmarkBase() {}

virtual ~BenchmarkBase() { BufferPoolManager::set_instance(nullptr); }
virtual ~BenchmarkBase() { }

virtual string Name() const = 0;

Expand All @@ -90,8 +90,6 @@ class BenchmarkBase : public Fixture
string record_filename = this->record_filename();
LoggerFactory::init_default(log_name.c_str(), LOG_LEVEL_INFO);

std::call_once(init_bpm_flag, []() { BufferPoolManager::set_instance(&bpm); });

::remove(record_filename.c_str());

RC rc = bpm.create_file(record_filename.c_str());
Expand All @@ -106,7 +104,7 @@ class BenchmarkBase : public Fixture
throw runtime_error("failed to open record file");
}

rc = handler_.init(buffer_pool_);
rc = handler_.init(*buffer_pool_, log_handler_);
if (rc != RC::SUCCESS) {
LOG_WARN("failed to init record file handler. rc=%s", strrc(rc));
throw runtime_error("failed to init record file handler");
Expand All @@ -122,6 +120,9 @@ class BenchmarkBase : public Fixture
}

handler_.close();
// TODO 很怪,引入double write buffer后,必须要求先close buffer pool,再执行bpm.close_file。
// 以后必须修理好bpm、buffer pool、double write buffer之间的关系
buffer_pool_->close_file();
bpm.close_file(this->record_filename().c_str());
buffer_pool_ = nullptr;
LOG_INFO("test %s teardown done. threads=%d, thread index=%d",
Expand Down Expand Up @@ -201,14 +202,18 @@ class BenchmarkBase : public Fixture
TestConditionFilter condition_filter(begin, end);
RecordFileScanner scanner;
VacuousTrx trx;
RC rc = scanner.open_scan(nullptr /*table*/, *buffer_pool_, &trx, true /*readonly*/, &condition_filter);
RC rc = scanner.open_scan(nullptr /*table*/,
*buffer_pool_,
&trx,
log_handler_,
ReadWriteMode::READ_ONLY,
&condition_filter);
if (rc != RC::SUCCESS) {
stat.scan_open_failed_count++;
} else {
Record record;
int32_t count = 0;
while (scanner.has_next()) {
rc = scanner.next(record);
while (OB_SUCC(rc = scanner.next(record))) {
ASSERT(rc == RC::SUCCESS, "failed to get record, rc=%s", strrc(rc));
count++;
}
Expand Down
3 changes: 1 addition & 2 deletions src/observer/common/rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ See the Mulan PSL v2 for more details. */
DEFINE_RC(VARIABLE_NOT_VALID) \
DEFINE_RC(LOGBUF_FULL) \
DEFINE_RC(LOG_FILE_FULL) \
DEFINE_RC(LOG_ENTRY_INVALID) \
DEFINE_RC(DBLWR_RECOVER_ERRO)
DEFINE_RC(LOG_ENTRY_INVALID)

enum class RC
{
Expand Down
Loading

0 comments on commit 175f449

Please sign in to comment.