Skip to content

Commit

Permalink
Remove unneeded table in RUBiS.
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyihe committed Feb 9, 2020
1 parent 8d3fdfb commit 9ded896
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 74 deletions.
24 changes: 4 additions & 20 deletions benchmark/Rubis_bench.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public:
#endif
typedef OIndex<bid_key, bid_row> bid_tbl_type;
typedef OIndex<buynow_key, buynow_row> buynow_tbl_type;
typedef OIndex<idx_item_bid_key, idx_item_bid_row> itb_idx_type;

explicit rubis_db()
#if TPCC_SPLIT_TABLE
Expand All @@ -56,8 +55,7 @@ public:
: tbl_items_(),
#endif
tbl_bids_(),
tbl_buynow_(),
idx_itb_() {}
tbl_buynow_() {}

#if TPCC_SPLIT_TABLE
item_const_tbl_type& tbl_items_const() {
Expand All @@ -77,9 +75,6 @@ public:
buynow_tbl_type& tbl_buynow() {
return tbl_buynow_;
}
itb_idx_type& idx_itembids() {
return idx_itb_;
}

void thread_init_all() {
#if TPCC_SPLIT_TABLE
Expand All @@ -90,7 +85,6 @@ public:
#endif
tbl_bids_.thread_init();
tbl_buynow_.thread_init();
idx_itb_.thread_init();
}

private:
Expand All @@ -102,7 +96,6 @@ private:
#endif
bid_tbl_type tbl_bids_;
buynow_tbl_type tbl_buynow_;
itb_idx_type idx_itb_;
};

enum class TxnType : int { PlaceBid = 0, BuyNow, ViewItem };
Expand Down Expand Up @@ -281,35 +274,26 @@ void rubis_loader<DBParams>::load() {

for (uint64_t i = 0; i < constants::num_bids_per_item; ++i) {
auto bid_id = db.tbl_bids().gen_key();
bid_key bk(bid_id);
bid_key bk(iid, ig.generate_user_id(), bid_id);
bid_row br{};
br.item_id = iid;
br.user_id = ig.generate_user_id();
br.max_bid = 40;
br.bid = 40;
br.quantity = 1;
br.date = ig.generate_random_date();

db.tbl_bids().nontrans_put(bk, br);

idx_item_bid_key ibk(iid, bid_id);
idx_item_bid_row ibr{};

db.idx_itembids().nontrans_put(ibk, ibr);
}
}

for (uint64_t n = 0; n < constants::buynow_prepop; ++n) {
auto id = db.tbl_buynow().gen_key();
buynow_key bnk(id);
buynow_key bnk(ig.generate_user_id(), ig.generate_user_id(), id);
buynow_row bnr{};
bnr.buyer_id = ig.generate_user_id();
bnr.quantity = 1;
bnr.date = ig.generate_random_date();
bnr.item_id = ig.generate_user_id();

db.tbl_buynow().nontrans_put(bnk, bnr);
}
}

}
}
42 changes: 13 additions & 29 deletions benchmark/Rubis_structs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CREATE TABLE bids (
max_bid FLOAT UNSIGNED NOT NULL,
date DATETIME,
PRIMARY KEY(id)
PRIMARY KEY(id, user_id, item_id)
);
CREATE TABLE buy_now (
Expand All @@ -42,7 +42,7 @@ CREATE TABLE buy_now (
item_id INTEGER UNSIGNED NOT NULL,
qty INTEGER UNSIGNED NOT NULL,
date DATETIME,
PRIMARY KEY(id),
PRIMARY KEY(id, buyer_id, item_id),
INDEX buyer (buyer_id),
INDEX item (item_id)
);
Expand Down Expand Up @@ -133,9 +133,12 @@ struct item_row {
#endif

struct bid_key_bare {
uint64_t item_id;
uint64_t user_id;
uint64_t bid_id;

explicit bid_key_bare(uint64_t id) : bid_id(bswap(id)) {}
explicit bid_key_bare(uint64_t iid, uint64_t uid, uint64_t bid)
: item_id(bswap(iid)), user_id(bswap(uid)), bid_id(bswap(bid)) {}
friend masstree_key_adapter<bid_key_bare>;
private:
bid_key_bare() = default;
Expand All @@ -145,26 +148,25 @@ typedef masstree_key_adapter<bid_key_bare> bid_key;

struct bid_row {
enum class NamedColumn : int {
user_id = 0,
item_id,
quantity,
quantity = 0,
bid,
max_bid,
date
};

uint64_t user_id;
uint64_t item_id;
uint32_t quantity;
uint32_t bid;
uint32_t max_bid;
uint32_t date;
};

struct buynow_key_bare {
uint64_t item_id;
uint64_t user_id;
uint64_t buynow_id;

explicit buynow_key_bare(uint64_t id) : buynow_id(bswap(id)) {}
explicit buynow_key_bare(uint64_t iid, uint64_t uid, uint64_t bid)
: item_id(bswap(iid)), user_id(bswap(uid)), buynow_id(bswap(bid)) {}
friend masstree_key_adapter<buynow_key_bare>;
private:
buynow_key_bare() = default;
Expand All @@ -174,30 +176,12 @@ typedef masstree_key_adapter<buynow_key_bare> buynow_key;

struct buynow_row {
enum class NamedColumn : int {
buyer_id = 0,
item_id,
quantity,
quantity = 0,
date
};

uint64_t buyer_id;
uint64_t item_id;
uint32_t quantity;
uint32_t date;
};

struct idx_item_bid_key_bare {
uint64_t item_id;
uint64_t bid;

explicit idx_item_bid_key_bare(uint64_t iid, uint32_t bid) : item_id(bswap(iid)), bid((uint64_t)bswap(bid)) {}
friend masstree_key_adapter<idx_item_bid_key_bare>;
private:
idx_item_bid_key_bare() = default;
};

typedef masstree_key_adapter<idx_item_bid_key_bare> idx_item_bid_key;

using idx_item_bid_row = dummy_row;

}
}
27 changes: 2 additions & 25 deletions benchmark/Rubis_txns.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ size_t rubis_runner<DBParams>::run_txn_placebid(uint64_t item_id, uint64_t user_
}
#endif

bid_key bk(db.tbl_bids().gen_key());
bid_key bk(item_id, user_id, db.tbl_bids().gen_key());
auto br = Sto::tx_alloc<bid_row>();
br->item_id = item_id;
br->user_id = user_id;
br->max_bid = max_bid;
br->bid = bid;
br->quantity = qty;
Expand Down Expand Up @@ -143,10 +141,8 @@ size_t rubis_runner<DBParams>::run_txn_buynow(uint64_t item_id, uint64_t user_id
}
#endif

buynow_key bnk(db.tbl_buynow().gen_key());
buynow_key bnk(item_id, user_id, db.tbl_buynow().gen_key());
auto bnr = Sto::tx_alloc<buynow_row>();
bnr->buyer_id = user_id;
bnr->item_id = item_id;
bnr->quantity = qty;
bnr->date = curr_date;

Expand All @@ -171,25 +167,6 @@ size_t rubis_runner<DBParams>::run_txn_viewitem(uint64_t item_id) {

++execs;

size_t count = 0;
uint32_t max_bid = 0;

auto scan_callback = [&count, &max_bid](const idx_item_bid_key& k, const idx_item_bid_row&) {
max_bid = (uint32_t)bswap(k.bid);
count += 1;
return true;
};
if (count > 0) {
always_assert(max_bid > 0, "max_bid must be non-zero.");
}

idx_item_bid_key k0(item_id, 0);
idx_item_bid_key k1(item_id, std::numeric_limits<uint32_t>::max());

abort = db.idx_itembids().template range_scan<decltype(scan_callback), false>(k0, k1, scan_callback,
RowAccess::ObserveExists, /*no phantom protection, one-shot*/false);
TXN_DO(abort);

#if TPCC_SPLIT_TABLE
std::tie(abort, result, row, value) = db.tbl_items_comm().select_row(item_key(item_id), RowAccess::ObserveValue);
#else
Expand Down

0 comments on commit 9ded896

Please sign in to comment.