Skip to content

Commit 8fe155f

Browse files
authored
p4: misc fixes for tests (#664)
* p4: misc fixes for tests Signed-off-by: Alex Chi <[email protected]> * check plan Signed-off-by: Alex Chi <[email protected]> --------- Signed-off-by: Alex Chi <[email protected]>
1 parent 64b4e8e commit 8fe155f

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

test/txn/txn_common.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,15 @@ void CheckUndoLogNum(BustubInstance &instance, const std::string &txn_var_name,
206206
}
207207

208208
void CheckUndoLogColumn(BustubInstance &instance, const std::string &txn_var_name, Transaction *txn,
209-
size_t expected_columns) {
209+
size_t expected_columns, bool enable_length_check = true) {
210210
fmt::println(stderr, "- {} var={} id={} status={} read_ts={}", Header("check_undo_log"), txn_var_name,
211211
txn->GetTransactionIdHumanReadable(), txn->GetTransactionState(), txn->GetReadTs());
212212
auto undo_log_num = txn->GetUndoLogNum();
213213
if (undo_log_num != 1) {
214214
fmt::println(stderr, "Error: expected to have {} undo logs in txn, found {}", 1, undo_log_num);
215+
std::cerr << "hint: please refer to the writeup delete and update section. you should generate a partial tuple, "
216+
"keep adding things to the tuple when updating, and never remove things from it."
217+
<< std::endl;
215218
std::terminate();
216219
}
217220
auto undo_log = txn->GetUndoLog(0);
@@ -225,6 +228,16 @@ void CheckUndoLogColumn(BustubInstance &instance, const std::string &txn_var_nam
225228
<< std::endl;
226229
std::terminate();
227230
}
231+
if (enable_length_check) {
232+
if (undo_log.tuple_.GetLength() > expected_columns * 4 /* integer width */) {
233+
fmt::println(stderr, "Error: tuple length not correct? expecting <column> * 4, found {} while having {} columns",
234+
undo_log.tuple_.GetLength(), cnt);
235+
std::cerr << "hint: probably your implementation stores `modified_fields` correctly but did not actually "
236+
"use it in the tuple reconstruction process."
237+
<< std::endl;
238+
std::terminate();
239+
}
240+
}
228241
}
229242

230243
#define WithTxn(txn, func) \

test/txn/txn_index_concurrent_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentInsertTest) { // NOLINT
6565
for (int j = 0; j < thread_cnt; j++) {
6666
if (operation_result[j][i]) {
6767
if (winner != -1) {
68-
fmt::println(stderr, "multiple winner for inserting {}: [{}]", i, fmt::join(operation_result[j], ","));
68+
fmt::println(stderr, "multiple winner for inserting {}", i);
6969
std::terminate();
7070
}
7171
winner = j;

tools/terrier_bench/terrier.cpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,30 @@ void TaskComputeDbSize(const uint64_t duration_ms, std::atomic<int> &db_size, bu
449449
}
450450
}
451451

452+
void PrintPlan(bustub::BustubInstance &instance, const std::string &query, bool ensure_index_scan = true) {
453+
{
454+
std::stringstream ss;
455+
bustub::SimpleStreamWriter writer_ss(ss);
456+
auto *txn = instance.txn_manager_->Begin();
457+
instance.ExecuteSqlTxn("EXPLAIN (o) " + query, writer_ss, txn);
458+
fmt::println(stderr, "> {}\n[PLAN]\n{}", query, ss.str());
459+
if (ensure_index_scan) {
460+
if (!bustub::StringUtil::Contains(ss.str(), "IndexScan")) {
461+
fmt::println(stderr, "ERROR: index scan not found in plan.");
462+
std::terminate();
463+
}
464+
}
465+
}
466+
}
467+
452468
// NOLINTNEXTLINE
453469
auto main(int argc, char **argv) -> int {
454470
const auto isolation_lvl = bustub::IsolationLevel::SNAPSHOT_ISOLATION;
455471
argparse::ArgumentParser program("bustub-terrier-bench");
456472
program.add_argument("--duration").help("run terrier bench for n milliseconds");
457473
program.add_argument("--terriers").help("number of terriers in the bench");
458474
program.add_argument("--threads").help("number of threads in the bench");
475+
program.add_argument("--commit-threshold").help("number of commits to pass the benchmark");
459476
program.add_argument("--bench-1")
460477
.default_value(false)
461478
.implicit_value(true)
@@ -468,6 +485,7 @@ auto main(int argc, char **argv) -> int {
468485
size_t bustub_terrier_num = 10;
469486
size_t bustub_thread_cnt = 2;
470487
const size_t bpm_size = 4096; // ensure benchmark does not hit BPM
488+
size_t commit_threshold = 100;
471489

472490
try {
473491
program.parse_args(argc, argv);
@@ -483,6 +501,10 @@ auto main(int argc, char **argv) -> int {
483501
bustub_terrier_num = std::stoi(program.get("--terriers"));
484502
}
485503

504+
if (program.present("--commit-threshold")) {
505+
commit_threshold = std::stoi(program.get("--commit-threshold"));
506+
}
507+
486508
if (program.present("--threads")) {
487509
bustub_thread_cnt = std::stoi(program.get("--threads"));
488510
}
@@ -509,25 +531,25 @@ auto main(int argc, char **argv) -> int {
509531
fmt::println(stderr, "x: create schema for benchmark #1");
510532
bustub->ExecuteSql(schema, writer);
511533
fmt::println(stderr, "x: please ensure plans are correct for all queries");
512-
bustub->ExecuteSql("explain (o) UPDATE terriers SET token = token + 1 WHERE terrier = 0", writer);
513-
bustub->ExecuteSql("explain (o) UPDATE terriers SET token = token - 1 WHERE terrier = 0", writer);
514-
bustub->ExecuteSql("explain (o) DELETE FROM terriers WHERE terrier = 0", writer);
515-
bustub->ExecuteSql("explain (o) INSERT INTO terriers VALUES (0, 0)", writer);
516-
bustub->ExecuteSql("explain (o) SELECT * from terriers", writer);
534+
PrintPlan(*bustub, "UPDATE terriers SET token = token + 1 WHERE terrier = 0");
535+
PrintPlan(*bustub, "UPDATE terriers SET token = token - 1 WHERE terrier = 0");
536+
PrintPlan(*bustub, "DELETE FROM terriers WHERE terrier = 0");
537+
PrintPlan(*bustub, "INSERT INTO terriers VALUES (0, 0)", false);
538+
PrintPlan(*bustub, "SELECT * from terriers", false);
517539
}
518540
if (bench_2) {
519541
auto schema = "CREATE TABLE terriers(terrier int PRIMARY KEY, token int, network int);";
520542
fmt::println(stderr, "x: create schema for benchmark #2");
521543
bustub->ExecuteSql(schema, writer);
522544
fmt::println(stderr, "x: please ensure plans are correct for all queries");
523-
bustub->ExecuteSql("explain (o) UPDATE terriers SET token = token + 1 WHERE terrier = 0", writer);
524-
bustub->ExecuteSql("explain (o) UPDATE terriers SET token = token - 1 WHERE terrier = 0", writer);
525-
bustub->ExecuteSql("explain (o) UPDATE terriers SET network = 1, token = token + 1000 WHERE terrier = 0", writer);
526-
bustub->ExecuteSql("explain (o) UPDATE terriers SET network = 1, token = token - 1000 WHERE terrier = 0", writer);
527-
bustub->ExecuteSql("explain (o) SELECT network from terriers WHERE terrier = 0", writer);
528-
bustub->ExecuteSql("explain (o) DELETE FROM terriers WHERE terrier = 0", writer);
529-
bustub->ExecuteSql("explain (o) INSERT INTO terriers VALUES (0, 0, 0)", writer);
530-
bustub->ExecuteSql("explain (o) SELECT * from terriers", writer);
545+
PrintPlan(*bustub, "UPDATE terriers SET token = token + 1 WHERE terrier = 0");
546+
PrintPlan(*bustub, "UPDATE terriers SET token = token - 1 WHERE terrier = 0");
547+
PrintPlan(*bustub, "UPDATE terriers SET network = 1, token = token + 1000 WHERE terrier = 0");
548+
PrintPlan(*bustub, "UPDATE terriers SET network = 1, token = token - 1000 WHERE terrier = 0");
549+
PrintPlan(*bustub, "SELECT network from terriers WHERE terrier = 0");
550+
PrintPlan(*bustub, "DELETE FROM terriers WHERE terrier = 0");
551+
PrintPlan(*bustub, "INSERT INTO terriers VALUES (0, 0, 0)", false);
552+
PrintPlan(*bustub, "SELECT * from terriers", false);
531553
}
532554

533555
const int initial_token = 10000;
@@ -635,13 +657,15 @@ auto main(int argc, char **argv) -> int {
635657

636658
total_metrics.Report(db_size);
637659

638-
if (total_metrics.committed_transfer_txn_cnt_ <= 100) {
639-
fmt::println(stderr, "too many txn are aborted");
660+
if (total_metrics.committed_transfer_txn_cnt_ <= commit_threshold) {
661+
fmt::println(stderr, "too many txn are aborted: {} txn committed, expect more than {}",
662+
total_metrics.committed_transfer_txn_cnt_, commit_threshold);
640663
exit(1);
641664
}
642665

643-
if (bench_2 && total_metrics.committed_join_txn_cnt_ <= 100) {
644-
fmt::println(stderr, "too many txn are aborted");
666+
if (bench_2 && total_metrics.committed_join_txn_cnt_ <= commit_threshold) {
667+
fmt::println(stderr, "too many txn are aborted: {} txn committed, expect more than {}",
668+
total_metrics.committed_join_txn_cnt_, commit_threshold);
645669
exit(1);
646670
}
647671

0 commit comments

Comments
 (0)