Skip to content

Commit 891804a

Browse files
authored
Merge branch 'master' into fix-comment-f24-p1
2 parents 26dd4e5 + 8de6f6b commit 891804a

276 files changed

Lines changed: 20671 additions & 46746 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build_support/build-web-shell.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ cp bin/bustub-wasm-shell.js "deploy/${BUSTUB_SHELL_DIRECTORY}"
2828
cp bin/bustub-wasm-shell.wasm "deploy/${BUSTUB_SHELL_DIRECTORY}"
2929
cp -a ../tools/wasm-shell/extra_files/index.html "deploy/${BUSTUB_SHELL_DIRECTORY}"
3030
cp ../logo/bustub.svg "deploy/${BUSTUB_SHELL_DIRECTORY}"
31-
sed -i '' "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
32-
sed -i '' "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
33-
sed -i '' "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
31+
# Change `sed -i` to `sed -i ''` if you are on a Mac.
32+
sed -i "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
33+
sed -i "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
34+
sed -i "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_SHELL_DIRECTORY}/index.html"
3435

3536
make -j$(nproc) wasm-bpt-printer
3637
mkdir -p "deploy/${BUSTUB_BPT_DIRECTORY}"
3738
cp bin/bustub-wasm-bpt-printer.js "deploy/${BUSTUB_BPT_DIRECTORY}"
3839
cp bin/bustub-wasm-bpt-printer.wasm "deploy/${BUSTUB_BPT_DIRECTORY}"
3940
cp -a ../tools/wasm-bpt-printer/extra_files/index.html "deploy/${BUSTUB_BPT_DIRECTORY}"
4041
cp ../logo/bustub.svg "deploy/${BUSTUB_BPT_DIRECTORY}"
41-
sed -i '' "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
42-
sed -i '' "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
43-
sed -i '' "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
42+
# Change `sed -i` to `sed -i ''` if you are on a Mac.
43+
sed -i "s|\${BUSTUB_PRIVATE_VERSION}|${BUSTUB_PRIVATE_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
44+
sed -i "s|\${BUSTUB_PUBLIC_VERSION}|${BUSTUB_PUBLIC_VERSION}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
45+
sed -i "s|\${BUSTUB_BUILD_TIME}|${BUSTUB_BUILD_TIME}|" "deploy/${BUSTUB_BPT_DIRECTORY}/index.html"
4446

4547
ls -alh "deploy/${BUSTUB_SHELL_DIRECTORY}"
4648
ls -alh "deploy/${BUSTUB_BPT_DIRECTORY}"

src/buffer/buffer_pool_manager.cpp

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ BufferPoolManager::BufferPoolManager(size_t num_frames, DiskManager *disk_manage
7272
next_page_id_(0),
7373
bpm_latch_(std::make_shared<std::mutex>()),
7474
replacer_(std::make_shared<LRUKReplacer>(num_frames, k_dist)),
75-
disk_scheduler_(std::make_unique<DiskScheduler>(disk_manager)),
75+
disk_scheduler_(std::make_shared<DiskScheduler>(disk_manager)),
7676
log_manager_(log_manager) {
7777
// Not strictly necessary...
7878
std::scoped_lock latch(*bpm_latch_);
@@ -112,12 +112,6 @@ auto BufferPoolManager::Size() const -> size_t { return num_frames_; }
112112
* You will maintain a thread-safe, monotonically increasing counter in the form of a `std::atomic<page_id_t>`.
113113
* See the documentation on [atomics](https://en.cppreference.com/w/cpp/atomic/atomic) for more information.
114114
*
115-
* Also, make sure to read the documentation for `DeletePage`! You can assume that you will never run out of disk
116-
* space (via `DiskScheduler::IncreaseDiskSpace`), so this function _cannot_ fail.
117-
*
118-
* Once you have allocated the new page via the counter, make sure to call `DiskScheduler::IncreaseDiskSpace` so you
119-
* have enough space on disk!
120-
*
121115
* TODO(P1): Add implementation.
122116
*
123117
* @return The page ID of the newly allocated page.
@@ -136,14 +130,7 @@ auto BufferPoolManager::NewPage() -> page_id_t { UNIMPLEMENTED("TODO(P1): Add im
136130
* function. You will probably want to implement this function _after_ you have implemented `CheckedReadPage` and
137131
* `CheckedWritePage`.
138132
*
139-
* Ideally, we would want to ensure that all space on disk is used efficiently. That would mean the space that deleted
140-
* pages on disk used to occupy should somehow be made available to new pages allocated by `NewPage`.
141-
*
142-
* If you would like to attempt this, you are free to do so. However, for this implementation, you are allowed to
143-
* assume you will not run out of disk space and simply keep allocating disk space upwards in `NewPage`.
144-
*
145-
* For (nonexistent) style points, you can still call `DeallocatePage` in case you want to implement something slightly
146-
* more space-efficient in the future.
133+
* You should call `DeallocatePage` in the disk scheduler to make the space available for new pages.
147134
*
148135
* TODO(P1): Add implementation.
149136
*
@@ -274,11 +261,14 @@ auto BufferPoolManager::ReadPage(page_id_t page_id, AccessType access_type) -> R
274261
}
275262

276263
/**
277-
* @brief Flushes a page's data out to disk.
264+
* @brief Flushes a page's data out to disk unsafely.
278265
*
279266
* This function will write out a page's data to disk if it has been modified. If the given page is not in memory, this
280267
* function will return `false`.
281268
*
269+
* You should not take a lock on the page in this function.
270+
* This means that you should carefully consider when to toggle the `is_dirty_` bit.
271+
*
282272
* ### Implementation
283273
*
284274
* You should probably leave implementing this function until after you have completed `CheckedReadPage` and
@@ -289,10 +279,47 @@ auto BufferPoolManager::ReadPage(page_id_t page_id, AccessType access_type) -> R
289279
* @param page_id The page ID of the page to be flushed.
290280
* @return `false` if the page could not be found in the page table, otherwise `true`.
291281
*/
282+
auto BufferPoolManager::FlushPageUnsafe(page_id_t page_id) -> bool { UNIMPLEMENTED("TODO(P1): Add implementation."); }
283+
284+
/**
285+
* @brief Flushes a page's data out to disk safely.
286+
*
287+
* This function will write out a page's data to disk if it has been modified. If the given page is not in memory, this
288+
* function will return `false`.
289+
*
290+
* You should take a lock on the page in this function to ensure that a consistent state is flushed to disk.
291+
*
292+
* ### Implementation
293+
*
294+
* You should probably leave implementing this function until after you have completed `CheckedReadPage`,
295+
* `CheckedWritePage`, and `Flush` in the page guards, as it will likely be much easier to understand what to do.
296+
*
297+
* TODO(P1): Add implementation
298+
*
299+
* @param page_id The page ID of the page to be flushed.
300+
* @return `false` if the page could not be found in the page table, otherwise `true`.
301+
*/
292302
auto BufferPoolManager::FlushPage(page_id_t page_id) -> bool { UNIMPLEMENTED("TODO(P1): Add implementation."); }
293303

294304
/**
295-
* @brief Flushes all page data that is in memory to disk.
305+
* @brief Flushes all page data that is in memory to disk unsafely.
306+
*
307+
* You should not take locks on the pages in this function.
308+
* This means that you should carefully consider when to toggle the `is_dirty_` bit.
309+
*
310+
* ### Implementation
311+
*
312+
* You should probably leave implementing this function until after you have completed `CheckedReadPage`,
313+
* `CheckedWritePage`, and `FlushPage`, as it will likely be much easier to understand what to do.
314+
*
315+
* TODO(P1): Add implementation
316+
*/
317+
void BufferPoolManager::FlushAllPagesUnsafe() { UNIMPLEMENTED("TODO(P1): Add implementation."); }
318+
319+
/**
320+
* @brief Flushes all page data that is in memory to disk safely.
321+
*
322+
* You should take locks on the pages in this function to ensure that a consistent state is flushed to disk.
296323
*
297324
* ### Implementation
298325
*

src/common/util/string_util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "common/util/string_util.h"
2323
#include "fmt/format.h"
24+
#include "fmt/ranges.h"
2425

2526
namespace bustub {
2627

src/execution/aggregation_executor.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include <memory>
14-
#include <vector>
14+
#include "common/macros.h"
1515

1616
#include "execution/executors/aggregation_executor.h"
1717

@@ -25,18 +25,21 @@ namespace bustub {
2525
*/
2626
AggregationExecutor::AggregationExecutor(ExecutorContext *exec_ctx, const AggregationPlanNode *plan,
2727
std::unique_ptr<AbstractExecutor> &&child_executor)
28-
: AbstractExecutor(exec_ctx) {}
28+
: AbstractExecutor(exec_ctx) {
29+
UNIMPLEMENTED("TODO(P3): Add implementation.");
30+
}
2931

3032
/** Initialize the aggregation */
31-
void AggregationExecutor::Init() {}
33+
void AggregationExecutor::Init() { UNIMPLEMENTED("TODO(P3): Add implementation."); }
3234

3335
/**
3436
* Yield the next tuple from the insert.
3537
* @param[out] tuple The next tuple produced by the aggregation
3638
* @param[out] rid The next tuple RID produced by the aggregation
3739
* @return `true` if a tuple was produced, `false` if there are no more tuples
3840
*/
39-
auto AggregationExecutor::Next(Tuple *tuple, RID *rid) -> bool { return false; }
41+
42+
auto AggregationExecutor::Next(Tuple *tuple, RID *rid) -> bool { UNIMPLEMENTED("TODO(P3): Add implementation."); }
4043

4144
/** Do not use or remove this function, otherwise you will get zero points. */
4245
auto AggregationExecutor::GetChildExecutor() const -> const AbstractExecutor * { return child_executor_.get(); }

src/execution/delete_executor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include <memory>
14+
#include "common/macros.h"
1415

1516
#include "execution/executors/delete_executor.h"
1617

@@ -24,10 +25,12 @@ namespace bustub {
2425
*/
2526
DeleteExecutor::DeleteExecutor(ExecutorContext *exec_ctx, const DeletePlanNode *plan,
2627
std::unique_ptr<AbstractExecutor> &&child_executor)
27-
: AbstractExecutor(exec_ctx) {}
28+
: AbstractExecutor(exec_ctx) {
29+
UNIMPLEMENTED("TODO(P3): Add implementation.");
30+
}
2831

2932
/** Initialize the delete */
30-
void DeleteExecutor::Init() { throw NotImplementedException("DeleteExecutor is not implemented"); }
33+
void DeleteExecutor::Init() { UNIMPLEMENTED("TODO(P3): Add implementation."); }
3134

3235
/**
3336
* Yield the number of rows deleted from the table.
@@ -38,6 +41,8 @@ void DeleteExecutor::Init() { throw NotImplementedException("DeleteExecutor is n
3841
* NOTE: DeleteExecutor::Next() does not use the `rid` out-parameter.
3942
* NOTE: DeleteExecutor::Next() returns true with the number of deleted rows produced only once.
4043
*/
41-
auto DeleteExecutor::Next([[maybe_unused]] Tuple *tuple, RID *rid) -> bool { return false; }
44+
auto DeleteExecutor::Next([[maybe_unused]] Tuple *tuple, RID *rid) -> bool {
45+
UNIMPLEMENTED("TODO(P3): Add implementation.");
46+
}
4247

4348
} // namespace bustub

src/execution/executor_factory.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "execution/executors/nested_loop_join_executor.h"
3131
#include "execution/executors/projection_executor.h"
3232
#include "execution/executors/seq_scan_executor.h"
33-
#include "execution/executors/sort_executor.h"
3433
#include "execution/executors/topn_check_executor.h"
3534
#include "execution/executors/topn_executor.h"
3635
#include "execution/executors/topn_per_group_executor.h"
@@ -45,7 +44,6 @@
4544
#include "execution/plans/topn_plan.h"
4645
#include "execution/plans/values_plan.h"
4746
#include "execution/plans/window_plan.h"
48-
#include "storage/index/generic_key.h"
4947

5048
namespace bustub {
5149

@@ -132,7 +130,7 @@ auto ExecutorFactory::CreateExecutor(ExecutorContext *exec_ctx, const AbstractPl
132130
case PlanType::NestedIndexJoin: {
133131
auto nested_index_join_plan = dynamic_cast<const NestedIndexJoinPlanNode *>(plan.get());
134132
auto left = ExecutorFactory::CreateExecutor(exec_ctx, nested_index_join_plan->GetChildPlan());
135-
return std::make_unique<NestIndexJoinExecutor>(exec_ctx, nested_index_join_plan, std::move(left));
133+
return std::make_unique<NestedIndexJoinExecutor>(exec_ctx, nested_index_join_plan, std::move(left));
136134
}
137135

138136
// Create a new hash join executor

src/execution/external_merge_sort_executor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "execution/executors/external_merge_sort_executor.h"
14-
#include <iostream>
15-
#include <optional>
1614
#include <vector>
17-
#include "common/config.h"
15+
#include "common/macros.h"
1816
#include "execution/plans/sort_plan.h"
1917

2018
namespace bustub {
2119

2220
template <size_t K>
2321
ExternalMergeSortExecutor<K>::ExternalMergeSortExecutor(ExecutorContext *exec_ctx, const SortPlanNode *plan,
2422
std::unique_ptr<AbstractExecutor> &&child_executor)
25-
: AbstractExecutor(exec_ctx), cmp_(plan->GetOrderBy()) {}
23+
: AbstractExecutor(exec_ctx), cmp_(plan->GetOrderBy()) {
24+
UNIMPLEMENTED("TODO(P3): Add implementation.");
25+
}
2626

2727
/** Initialize the external merge sort */
2828
template <size_t K>
2929
void ExternalMergeSortExecutor<K>::Init() {
30-
throw NotImplementedException("ExternalMergeSortExecutor is not implemented");
30+
UNIMPLEMENTED("TODO(P3): Add implementation.");
3131
}
3232

3333
/**
@@ -38,7 +38,7 @@ void ExternalMergeSortExecutor<K>::Init() {
3838
*/
3939
template <size_t K>
4040
auto ExternalMergeSortExecutor<K>::Next(Tuple *tuple, RID *rid) -> bool {
41-
return false;
41+
UNIMPLEMENTED("TODO(P3): Add implementation.");
4242
}
4343

4444
template class ExternalMergeSortExecutor<2>;

src/execution/hash_join_executor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "execution/executors/hash_join_executor.h"
14+
#include "common/macros.h"
1415

1516
namespace bustub {
1617

@@ -26,20 +27,21 @@ HashJoinExecutor::HashJoinExecutor(ExecutorContext *exec_ctx, const HashJoinPlan
2627
std::unique_ptr<AbstractExecutor> &&right_child)
2728
: AbstractExecutor(exec_ctx) {
2829
if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) {
29-
// Note for Fall 2024: You ONLY need to implement left join and inner join.
30+
// Note for Spring 2025: You ONLY need to implement left join and inner join.
3031
throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType()));
3132
}
33+
UNIMPLEMENTED("TODO(P3): Add implementation.");
3234
}
3335

3436
/** Initialize the join */
35-
void HashJoinExecutor::Init() { throw NotImplementedException("HashJoinExecutor is not implemented"); }
37+
void HashJoinExecutor::Init() { UNIMPLEMENTED("TODO(P3): Add implementation."); }
3638

3739
/**
3840
* Yield the next tuple from the join.
3941
* @param[out] tuple The next tuple produced by the join.
4042
* @param[out] rid The next tuple RID, not used by hash join.
4143
* @return `true` if a tuple was produced, `false` if there are no more tuples.
4244
*/
43-
auto HashJoinExecutor::Next(Tuple *tuple, RID *rid) -> bool { return false; }
45+
auto HashJoinExecutor::Next(Tuple *tuple, RID *rid) -> bool { UNIMPLEMENTED("TODO(P3): Add implementation."); }
4446

4547
} // namespace bustub

src/execution/index_scan_executor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "execution/executors/index_scan_executor.h"
14+
#include "common/macros.h"
1415

1516
namespace bustub {
1617

@@ -20,10 +21,12 @@ namespace bustub {
2021
* @param plan the index scan plan to be executed
2122
*/
2223
IndexScanExecutor::IndexScanExecutor(ExecutorContext *exec_ctx, const IndexScanPlanNode *plan)
23-
: AbstractExecutor(exec_ctx) {}
24+
: AbstractExecutor(exec_ctx) {
25+
UNIMPLEMENTED("TODO(P3): Add implementation.");
26+
}
2427

25-
void IndexScanExecutor::Init() { throw NotImplementedException("IndexScanExecutor is not implemented"); }
28+
void IndexScanExecutor::Init() { UNIMPLEMENTED("TODO(P3): Add implementation."); }
2629

27-
auto IndexScanExecutor::Next(Tuple *tuple, RID *rid) -> bool { return false; }
30+
auto IndexScanExecutor::Next(Tuple *tuple, RID *rid) -> bool { UNIMPLEMENTED("TODO(P3): Add implementation."); }
2831

2932
} // namespace bustub

src/execution/insert_executor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include <memory>
14+
#include "common/macros.h"
1415

1516
#include "execution/executors/insert_executor.h"
1617

@@ -24,10 +25,12 @@ namespace bustub {
2425
*/
2526
InsertExecutor::InsertExecutor(ExecutorContext *exec_ctx, const InsertPlanNode *plan,
2627
std::unique_ptr<AbstractExecutor> &&child_executor)
27-
: AbstractExecutor(exec_ctx) {}
28+
: AbstractExecutor(exec_ctx) {
29+
UNIMPLEMENTED("TODO(P3): Add implementation.");
30+
}
2831

2932
/** Initialize the insert */
30-
void InsertExecutor::Init() { throw NotImplementedException("InsertExecutor is not implemented"); }
33+
void InsertExecutor::Init() { UNIMPLEMENTED("TODO(P3): Add implementation."); }
3134

3235
/**
3336
* Yield the number of rows inserted into the table.
@@ -38,6 +41,8 @@ void InsertExecutor::Init() { throw NotImplementedException("InsertExecutor is n
3841
* NOTE: InsertExecutor::Next() does not use the `rid` out-parameter.
3942
* NOTE: InsertExecutor::Next() returns true with number of inserted rows produced only once.
4043
*/
41-
auto InsertExecutor::Next([[maybe_unused]] Tuple *tuple, RID *rid) -> bool { return false; }
44+
auto InsertExecutor::Next([[maybe_unused]] Tuple *tuple, RID *rid) -> bool {
45+
UNIMPLEMENTED("TODO(P3): Add implementation.");
46+
}
4247

4348
} // namespace bustub

0 commit comments

Comments
 (0)