Skip to content

Commit f05ce03

Browse files
authored
p1: check disk scheduler threading (#616)
Signed-off-by: Alex Chi <[email protected]>
1 parent decbe02 commit f05ce03

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/include/storage/disk/disk_manager_memory.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class DiskManagerUnlimitedMemory : public DiskManager {
7676
ProcessLatency(page_id);
7777

7878
std::unique_lock<std::mutex> l(mutex_);
79+
if (!thread_id_.has_value()) {
80+
thread_id_ = std::this_thread::get_id();
81+
}
7982
if (page_id >= static_cast<int>(data_.size())) {
8083
data_.resize(page_id + 1);
8184
}
@@ -100,6 +103,9 @@ class DiskManagerUnlimitedMemory : public DiskManager {
100103
ProcessLatency(page_id);
101104

102105
std::unique_lock<std::mutex> l(mutex_);
106+
if (!thread_id_.has_value()) {
107+
thread_id_ = std::this_thread::get_id();
108+
}
103109
if (page_id >= static_cast<int>(data_.size()) || page_id < 0) {
104110
fmt::println(stderr, "page {} not in range", page_id);
105111
std::terminate();
@@ -148,6 +154,13 @@ class DiskManagerUnlimitedMemory : public DiskManager {
148154

149155
void EnableLatencySimulator(bool enabled) { latency_simulator_enabled_ = enabled; }
150156

157+
auto GetLastReadThreadAndClear() -> std::optional<std::thread::id> {
158+
std::unique_lock<std::mutex> lck(mutex_);
159+
auto t = thread_id_;
160+
thread_id_ = std::nullopt;
161+
return t;
162+
}
163+
151164
private:
152165
bool latency_simulator_enabled_{false};
153166

@@ -159,6 +172,7 @@ class DiskManagerUnlimitedMemory : public DiskManager {
159172
using ProtectedPage = std::pair<Page, std::shared_mutex>;
160173

161174
std::mutex mutex_;
175+
std::optional<std::thread::id> thread_id_;
162176
std::vector<std::shared_ptr<ProtectedPage>> data_;
163177
};
164178

0 commit comments

Comments
 (0)