Skip to content

Commit 99f002c

Browse files
authored
Fix starter code for p1 (cmu-db#167)
1 parent 261b0f8 commit 99f002c

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/buffer/buffer_pool_manager_instance.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#include "buffer/buffer_pool_manager_instance.h"
1414

15-
#include <list>
16-
1715
#include "common/macros.h"
1816

1917
namespace bustub {
@@ -89,7 +87,8 @@ void BufferPoolManagerInstance::FlushAllPagesImpl() {
8987
}
9088

9189
page_id_t BufferPoolManagerInstance::AllocatePage() {
92-
const page_id_t next_page_id = next_page_id_ += num_instances_;
90+
const page_id_t next_page_id = next_page_id_;
91+
next_page_id_ += num_instances_;
9392
ValidatePageId(next_page_id);
9493
return next_page_id;
9594
}

src/buffer/parallel_ buffer_pool_manager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
#include "buffer/parallel_buffer_pool_manager.h"
1414

15-
#include <list>
16-
1715
namespace bustub {
1816

1917
ParallelBufferPoolManager::ParallelBufferPoolManager(size_t num_instances, size_t pool_size, DiskManager *disk_manager,

src/include/storage/page/page.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace bustub {
2727
*/
2828
class Page {
2929
// There is book-keeping information inside the page that should only be relevant to the buffer pool manager.
30-
friend class BufferPoolManager;
30+
friend class BufferPoolManagerInstance;
3131

3232
public:
3333
/** Constructor. Zeros out the page data. */

test/buffer/parallel_buffer_pool_manager_test.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,31 @@ TEST(ParallelBufferPoolManagerTest, DISABLED_SampleTest) {
117117
EXPECT_EQ(nullptr, bpm->NewPage(&page_id_temp));
118118
}
119119

120-
// Scenario: After unpinning pages {0, 1, 2, 3, 4} and pinning another 4 new pages,
121-
// there would still be one buffer page left for reading page 0.
120+
// Write world out to page 4
121+
auto page4 = bpm->FetchPage(4);
122+
snprintf(page4->GetData(), PAGE_SIZE, "World");
123+
EXPECT_EQ(0, strcmp(page4->GetData(), "World"));
124+
bpm->UnpinPage(4, true);
125+
126+
// Scenario: After unpinning pages {0, 1, 2, 3, 4} and pinning pages {0, 1, 2, 3},
127+
// there would still be one buffer page left for reading page 4.
128+
122129
for (int i = 0; i < 5; ++i) {
123130
EXPECT_EQ(true, bpm->UnpinPage(i, true));
124131
}
125132
for (int i = 0; i < 4; ++i) {
126-
EXPECT_NE(nullptr, bpm->NewPage(&page_id_temp));
133+
EXPECT_NE(nullptr, bpm->FetchPage(i));
127134
}
128135

129136
// Scenario: We should be able to fetch the data we wrote a while ago.
130-
page0 = bpm->FetchPage(0);
131-
EXPECT_EQ(0, strcmp(page0->GetData(), "Hello"));
137+
page4 = bpm->FetchPage(4);
138+
EXPECT_EQ(0, strcmp(page4->GetData(), "World"));
132139

133-
// Scenario: If we unpin page 0 and then make a new page, all the buffer pages should
134-
// now be pinned. Fetching page 0 should fail.
135-
EXPECT_EQ(true, bpm->UnpinPage(0, true));
140+
// Scenario: If we unpin page 4 and then make a new page, all the buffer pages should
141+
// now be pinned. Fetching page 4 should fail.
142+
EXPECT_EQ(true, bpm->UnpinPage(4, true));
136143
EXPECT_NE(nullptr, bpm->NewPage(&page_id_temp));
137-
EXPECT_EQ(nullptr, bpm->FetchPage(0));
144+
EXPECT_EQ(nullptr, bpm->FetchPage(4));
138145

139146
// Shutdown the disk manager and remove the temporary file we created.
140147
disk_manager->ShutDown();

0 commit comments

Comments
 (0)