Skip to content

Commit

Permalink
Merge branch 'master' into cpp-standards-2
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanthduvvada authored Aug 22, 2024
2 parents f5ece1d + e956eb0 commit d6eff30
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/include/common/bustub_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class BusTubInstance {
public:
explicit BusTubInstance(const std::filesystem::path &db_file_name, size_t bpm_size = 128);


explicit BusTubInstance(size_t bpm_size = 128);

~BusTubInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/planner/plan_window_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ auto Planner::PlanSelectWindow(const SelectStatement &statement, AbstractPlanNod
if (window_call.start_ != WindowBoundary::UNBOUNDED_PRECEDING ||
(window_call.end_ != WindowBoundary::CURRENT_ROW_ROWS &&
window_call.end_ != WindowBoundary::CURRENT_ROW_RANGE)) {
throw Exception("Bustub currently only support window function with default window frame settings");
throw Exception("BusTub currently only support window function with default window frame settings");
}
std::vector<AbstractExpressionRef> partition_by;
for (auto &item : window_call.partition_by_) {
Expand Down
34 changes: 17 additions & 17 deletions test/concurrency/common_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace bustub {

auto Insert(Transaction *txn, BustubInstance &instance, int v1) -> void {
auto Insert(Transaction *txn, BusTubInstance &instance, int v1) -> void {
std::stringstream ss;
auto writer = bustub::SimpleStreamWriter(ss, true, ",");
fmt::print(stderr, "insert data with v1 = {} in txn {} {}\n", v1, txn->GetTransactionId(), txn->GetIsolationLevel());
Expand All @@ -38,7 +38,7 @@ auto Insert(Transaction *txn, BustubInstance &instance, int v1) -> void {
/// This overloaded function will then bound each pair from @v1_vec & @v2_vec as a insert value
/// If flag is set to `true`, v1_vec should contain exactly one element,
/// The insert pair will be {v1_vec[0], v2_vec[0]}, {v1_vec[0], v2_vec[1]} ...
auto Insert(Transaction *txn, BustubInstance &instance, const std::vector<int> &v1_vec, const std::vector<int> &v2_vec,
auto Insert(Transaction *txn, BusTubInstance &instance, const std::vector<int> &v1_vec, const std::vector<int> &v2_vec,
bool flag = false) -> void {
// Check if the input vectors have the same size.
if (!flag) {
Expand Down Expand Up @@ -95,7 +95,7 @@ auto Insert(Transaction *txn, BustubInstance &instance, const std::vector<int> &
ASSERT_EQ(ss.str(), fmt::format("{},\n", v2_vec.size()));
}

auto Delete(Transaction *txn, BustubInstance &instance, int v1) -> void {
auto Delete(Transaction *txn, BusTubInstance &instance, int v1) -> void {
std::stringstream ss;
auto writer = bustub::SimpleStreamWriter(ss, true, ",");
fmt::print(stderr, "delete data with v1 = {} in txn {} {}\n", v1, txn->GetTransactionId(), txn->GetIsolationLevel());
Expand All @@ -109,7 +109,7 @@ auto Delete(Transaction *txn, BustubInstance &instance, int v1) -> void {
/// @param d_size The size you expect to be deleted from t1, will be used as sanity check, default value is 3
/// This overloaded function performs a vectorized self-constructed deletion to better test the implementation
/// You should calculate the number of elements that logically should be deleted, and pass it in as @d_size.
auto Delete(Transaction *txn, BustubInstance &instance, const std::vector<int> &d_vec, int d_size = 3) -> void {
auto Delete(Transaction *txn, BusTubInstance &instance, const std::vector<int> &d_vec, int d_size = 3) -> void {
if (d_vec.empty()) {
fmt::print(stderr, "Input vec must not be empty\n");
return;
Expand Down Expand Up @@ -148,7 +148,7 @@ auto ExpectResult(const std::string &actual_result, const std::string &expected_
return actual_result_rows == expected_result_rows;
}

auto Scan(Transaction *txn, BustubInstance &instance, const std::vector<int> &v1) -> void {
auto Scan(Transaction *txn, BusTubInstance &instance, const std::vector<int> &v1) -> void {
std::stringstream ss;
auto writer = bustub::SimpleStreamWriter(ss, true, ",");
fmt::print(stderr, "scan data expect v1 in range {} in txn {} {}\n", v1, txn->GetTransactionId(),
Expand All @@ -166,28 +166,28 @@ auto Scan(Transaction *txn, BustubInstance &instance, const std::vector<int> &v1
}
}

void Commit(BustubInstance &instance, Transaction *&txn) {
void Commit(BusTubInstance &instance, Transaction *&txn) {
fmt::print(stderr, "commit txn {} in {}\n", txn->GetTransactionId(), txn->GetIsolationLevel());
instance.txn_manager_->Commit(txn);
delete txn;
txn = nullptr;
}

void Abort(BustubInstance &instance, Transaction *&txn) {
void Abort(BusTubInstance &instance, Transaction *&txn) {
fmt::print(stderr, "abort txn {} in {}\n", txn->GetTransactionId(), txn->GetIsolationLevel());
instance.txn_manager_->Abort(txn);
delete txn;
txn = nullptr;
}

auto Begin(BustubInstance &instance, IsolationLevel level) -> Transaction * {
auto Begin(BusTubInstance &instance, IsolationLevel level) -> Transaction * {
auto txn = instance.txn_manager_->Begin(nullptr, level);
fmt::print(stderr, "start txn {} in {}\n", txn->GetTransactionId(), txn->GetIsolationLevel());
return txn;
}

auto GetDbForVisibilityTest(const std::string &name) -> std::shared_ptr<BustubInstance> {
auto instance = std::make_unique<BustubInstance>();
auto GetDbForVisibilityTest(const std::string &name) -> std::shared_ptr<BusTubInstance> {
auto instance = std::make_unique<BusTubInstance>();
auto writer = bustub::SimpleStreamWriter(std::cout, true);
fmt::print(stderr, "--- TEST CASE {} ---\n", name);
fmt::print(stderr, "prepare\n");
Expand All @@ -196,8 +196,8 @@ auto GetDbForVisibilityTest(const std::string &name) -> std::shared_ptr<BustubIn
return instance;
}

auto GetDbForCommitAbortTest(const std::string &name) -> std::shared_ptr<BustubInstance> {
auto instance = std::make_unique<BustubInstance>();
auto GetDbForCommitAbortTest(const std::string &name) -> std::shared_ptr<BusTubInstance> {
auto instance = std::make_unique<BusTubInstance>();
auto writer = bustub::SimpleStreamWriter(std::cout, true);
fmt::print(stderr, "--- TEST CASE {} ---\n", name);
fmt::print(stderr, "prepare\n");
Expand All @@ -213,8 +213,8 @@ enum class ExpectedOutcome {
BlockOnWrite,
};

auto GetDbForIsolationTest() -> std::shared_ptr<BustubInstance> {
auto instance = std::make_unique<BustubInstance>();
auto GetDbForIsolationTest() -> std::shared_ptr<BusTubInstance> {
auto instance = std::make_unique<BusTubInstance>();
auto writer = bustub::SimpleStreamWriter(std::cout, true);
fmt::print(stderr, "0: prepare\n");
// in case you implemented scan filter pushdown... disable it by forcing starter rule!
Expand All @@ -226,7 +226,7 @@ auto GetDbForIsolationTest() -> std::shared_ptr<BustubInstance> {
return instance;
}

auto StartReadTxn(IsolationLevel read_txn_level, BustubInstance &instance, bool read_before_write) -> Transaction * {
auto StartReadTxn(IsolationLevel read_txn_level, BusTubInstance &instance, bool read_before_write) -> Transaction * {
fmt::print(stderr, "1: read txn: {}\n", read_txn_level);
auto txn_r = instance.txn_manager_->Begin(nullptr, read_txn_level);
if (read_before_write) {
Expand All @@ -253,7 +253,7 @@ auto StartReadTxn(IsolationLevel read_txn_level, BustubInstance &instance, bool
return txn_r;
}

auto StartWriteTxn(IsolationLevel write_txn_level, BustubInstance &instance, bool is_delete) -> Transaction * {
auto StartWriteTxn(IsolationLevel write_txn_level, BusTubInstance &instance, bool is_delete) -> Transaction * {
auto writer = bustub::SimpleStreamWriter(std::cout, true);
fmt::print(stderr, "2: write txn: {}\n", write_txn_level);
auto txn_w = instance.txn_manager_->Begin(nullptr, write_txn_level);
Expand All @@ -273,7 +273,7 @@ auto StartWriteTxn(IsolationLevel write_txn_level, BustubInstance &instance, boo
return txn_w;
}

auto TryRead(Transaction *txn_r, BustubInstance &instance, ExpectedOutcome o, bool is_delete,
auto TryRead(Transaction *txn_r, BusTubInstance &instance, ExpectedOutcome o, bool is_delete,
std::atomic<bool> &check_done) -> bool {
bool ret = false;
std::stringstream result;
Expand Down
10 changes: 5 additions & 5 deletions test/recovery/recovery_test.cpp.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class RecoveryTest : public ::testing::Test {

// NOLINTNEXTLINE
TEST_F(RecoveryTest, DISABLED_RedoTest) {
auto *bustub_instance = new BustubInstance("test.bustub");
auto *bustub_instance = new BusTubInstance("test.bustub");

ASSERT_FALSE(enable_logging);
LOG_INFO("Skip system recovering...");
Expand Down Expand Up @@ -92,7 +92,7 @@ TEST_F(RecoveryTest, DISABLED_RedoTest) {
delete bustub_instance;

LOG_INFO("System restart...");
bustub_instance = new BustubInstance("test.bustub");
bustub_instance = new BusTubInstance("test.bustub");

ASSERT_FALSE(enable_logging);
LOG_INFO("Check if tuple is not in table before recovery");
Expand Down Expand Up @@ -139,7 +139,7 @@ TEST_F(RecoveryTest, DISABLED_RedoTest) {

// NOLINTNEXTLINE
TEST_F(RecoveryTest, DISABLED_UndoTest) {
auto *bustub_instance = new BustubInstance("test.bustub");
auto *bustub_instance = new BusTubInstance("test.bustub");

ASSERT_FALSE(enable_logging);
LOG_INFO("Skip system recovering...");
Expand Down Expand Up @@ -176,7 +176,7 @@ TEST_F(RecoveryTest, DISABLED_UndoTest) {
delete bustub_instance;

LOG_INFO("System restarted..");
bustub_instance = new BustubInstance("test.bustub");
bustub_instance = new BusTubInstance("test.bustub");

LOG_INFO("Check if tuple exists before recovery");
Tuple old_tuple;
Expand Down Expand Up @@ -218,7 +218,7 @@ TEST_F(RecoveryTest, DISABLED_UndoTest) {

// NOLINTNEXTLINE
TEST_F(RecoveryTest, DISABLED_CheckpointTest) {
auto *bustub_instance = new BustubInstance("test.bustub");
auto *bustub_instance = new BusTubInstance("test.bustub");

EXPECT_FALSE(enable_logging);
LOG_INFO("Skip system recovering...");
Expand Down
8 changes: 4 additions & 4 deletions tools/bpm_bench/bpm_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,23 @@ struct BpmMetrics {
}
};

struct BustubBenchPageHeader {
struct BusTubBenchPageHeader {
uint64_t seed_;
uint64_t page_id_;
char data_[0];
};

/// Modify the page and save some data inside
auto ModifyPage(char *data, size_t page_idx, uint64_t seed) -> void {
auto *pg = reinterpret_cast<BustubBenchPageHeader *>(data);
auto *pg = reinterpret_cast<BusTubBenchPageHeader *>(data);
pg->seed_ = seed;
pg->page_id_ = page_idx;
pg->data_[pg->seed_ % 4000] = pg->seed_ % 256;
}

/// Check the page and verify the data inside
auto CheckPageConsistentNoSeed(const char *data, size_t page_idx) -> void {
const auto *pg = reinterpret_cast<const BustubBenchPageHeader *>(data);
const auto *pg = reinterpret_cast<const BusTubBenchPageHeader *>(data);
if (pg->page_id_ != page_idx) {
fmt::println(stderr, "page header not consistent: page_id_={} page_idx={}", pg->page_id_, page_idx);
std::terminate();
Expand All @@ -127,7 +127,7 @@ auto CheckPageConsistentNoSeed(const char *data, size_t page_idx) -> void {

/// Check the page and verify the data inside
auto CheckPageConsistent(const char *data, size_t page_idx, uint64_t seed) -> void {
const auto *pg = reinterpret_cast<const BustubBenchPageHeader *>(data);
const auto *pg = reinterpret_cast<const BusTubBenchPageHeader *>(data);
if (pg->seed_ != seed) {
fmt::println(stderr, "page seed not consistent: seed_={} seed={}", pg->seed_, seed);
std::terminate();
Expand Down
2 changes: 1 addition & 1 deletion tools/wasm-bpt-printer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ if(EMSCRIPTEN)
add_executable(wasm-bpt-printer ${WASM_SHELL_SOURCES})
target_link_libraries(wasm-bpt-printer bustub)
set_target_properties(wasm-bpt-printer PROPERTIES OUTPUT_NAME bustub-wasm-bpt-printer)
target_link_options(wasm-bpt-printer PRIVATE -sEXPORTED_FUNCTIONS=['_BustubInit','_BustubApplyCommand','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
target_link_options(wasm-bpt-printer PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubApplyCommand','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
endif()
4 changes: 2 additions & 2 deletions tools/wasm-bpt-printer/extra_files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
const viz = new Viz()

Module['onRuntimeInitialized'] = function () {
const initialize = Module.cwrap('BustubInit', 'number', ['number', 'number'])
const executeQuery = Module.cwrap('BustubApplyCommand', 'number', ['string', 'number', 'number'])
const initialize = Module.cwrap('BusTubInit', 'number', ['number', 'number'])
const executeQuery = Module.cwrap('BusTubApplyCommand', 'number', ['string', 'number', 'number'])
window.executeQuery = (x) => {
const bufferSize = 64 * 1024
let output = "\0".repeat(bufferSize)
Expand Down
4 changes: 2 additions & 2 deletions tools/wasm-bpt-printer/wasm-bpt-printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::unique_ptr<bustub::Schema> key_schema = nullptr;

extern "C" {

auto BustubInit(int leaf_max_size, int internal_max_size) -> int {
auto BusTubInit(int leaf_max_size, int internal_max_size) -> int {
// create KeyComparator and index schema
std::string create_stmt = "a bigint";
try {
Expand All @@ -68,7 +68,7 @@ auto BustubInit(int leaf_max_size, int internal_max_size) -> int {
return 0;
}

auto BustubApplyCommand(const char *input, char *output, uint16_t len) -> int {
auto BusTubApplyCommand(const char *input, char *output, uint16_t len) -> int {
GenericKey<8> index_key;
int64_t key = 0;
RID rid;
Expand Down
2 changes: 1 addition & 1 deletion tools/wasm-shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ if(EMSCRIPTEN)
add_executable(wasm-shell ${WASM_SHELL_SOURCES})
target_link_libraries(wasm-shell bustub)
set_target_properties(wasm-shell PROPERTIES OUTPUT_NAME bustub-wasm-shell)
target_link_options(wasm-shell PRIVATE -sEXPORTED_FUNCTIONS=['_BustubInit','_BustubExecuteQuery','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
target_link_options(wasm-shell PRIVATE -sEXPORTED_FUNCTIONS=['_BusTubInit','_BusTubExecuteQuery','_free'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','allocateUTF8','UTF8ToString'])
endif()
4 changes: 2 additions & 2 deletions tools/wasm-shell/extra_files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
let is_ready = false

Module['onRuntimeInitialized'] = function () {
const executeQuery = Module.cwrap('BustubExecuteQuery', 'number', ['string', 'number', 'number', 'number'])
const initialize = Module.cwrap('BustubInit', 'number', [])
const executeQuery = Module.cwrap('BusTubExecuteQuery', 'number', ['string', 'number', 'number', 'number'])
const initialize = Module.cwrap('BusTubInit', 'number', [])
window.executeQuery = (x) => {
const bufferSize = 64 * 1024
let output = "\0".repeat(bufferSize)
Expand Down
8 changes: 4 additions & 4 deletions tools/wasm-shell/wasm-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#include "linenoise/linenoise.h"
#include "utf8proc/utf8proc.h"

static std::unique_ptr<bustub::BustubInstance> instance = nullptr;
static std::unique_ptr<bustub::BusTubInstance> instance = nullptr;

extern "C" {

auto BustubInit() -> int {
auto BusTubInit() -> int {
std::cout << "Initialize BusTub..." << std::endl;
auto bustub = std::make_unique<bustub::BustubInstance>();
auto bustub = std::make_unique<bustub::BusTubInstance>();
bustub->GenerateMockTable();

if (bustub->buffer_pool_manager_ != nullptr) {
Expand All @@ -31,7 +31,7 @@ auto BustubInit() -> int {
return 0;
}

auto BustubExecuteQuery(const char *input, char *prompt, char *output, uint16_t len) -> int {
auto BusTubExecuteQuery(const char *input, char *prompt, char *output, uint16_t len) -> int {
std::string input_string(input);
std::cout << input_string << std::endl;
std::string output_string;
Expand Down

0 comments on commit d6eff30

Please sign in to comment.