Skip to content

Commit

Permalink
Cherry-pick GC fixes from cmu-db#1349, third part. Compiles. Brought …
Browse files Browse the repository at this point in the history
…in tests, need to verify.
  • Loading branch information
mbutrovich committed Jul 3, 2018
1 parent 3520fbb commit fe15d74
Show file tree
Hide file tree
Showing 4 changed files with 1,054 additions and 98 deletions.
96 changes: 96 additions & 0 deletions test/concurrency/testing_transaction_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@ storage::DataTable *TestingTransactionUtil::CreateTable(
return table;
}

void TestingTransactionUtil::AddSecondaryIndex(storage::DataTable *table) {
// Create unique index on the value column
std::vector<oid_t> key_attrs = {1};
auto tuple_schema = table->GetSchema();
bool unique = false;
auto key_schema = catalog::Schema::CopySchema(tuple_schema, key_attrs);
key_schema->SetIndexedColumns(key_attrs);
auto index_metadata2 = new index::IndexMetadata(
"unique_btree_index", 1235, TEST_TABLE_OID, CATALOG_DATABASE_OID,
IndexType::BWTREE, IndexConstraintType::UNIQUE, tuple_schema, key_schema,
key_attrs, unique);

std::shared_ptr<index::Index> secondary_key_index(
index::IndexFactory::GetIndex(index_metadata2));

table->AddIndex(secondary_key_index);
}

std::unique_ptr<const planner::ProjectInfo>
TestingTransactionUtil::MakeProjectInfoFromTuple(const storage::Tuple *tuple) {
TargetList target_list;
Expand Down Expand Up @@ -479,5 +497,83 @@ bool TestingTransactionUtil::ExecuteScan(
}
return true;
}

ResultType TestingTransactionUtil::UpdateTuple(storage::DataTable *table,
const int key) {
srand(15721);

auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
TransactionScheduler scheduler(1, table, &txn_manager);
scheduler.Txn(0).Update(key, rand() % 15721);
scheduler.Txn(0).Commit();
scheduler.Run();

return scheduler.schedules[0].txn_result;
}

ResultType TestingTransactionUtil::InsertTuple(storage::DataTable *table,
const int key) {
srand(15721);

auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
TransactionScheduler scheduler(1, table, &txn_manager);
scheduler.Txn(0).Insert(key, rand() % 15721);
scheduler.Txn(0).Commit();
scheduler.Run();

return scheduler.schedules[0].txn_result;
}

ResultType TestingTransactionUtil::BulkInsertTuples(storage::DataTable *table,
const size_t num_tuples) {
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
TransactionScheduler scheduler(1, table, &txn_manager);
for (size_t i = 0; i < num_tuples; i++) {
scheduler.Txn(0).Insert(i, i);
}
scheduler.Txn(0).Commit();
scheduler.Run();

return scheduler.schedules[0].txn_result;
}

ResultType TestingTransactionUtil::BulkDeleteTuples(storage::DataTable *table,
const size_t num_tuples) {
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
TransactionScheduler scheduler(1, table, &txn_manager);
for (size_t i = 0; i < num_tuples; i++) {
scheduler.Txn(0).Delete(i, false);
}
scheduler.Txn(0).Commit();
scheduler.Run();

return scheduler.schedules[0].txn_result;
}

ResultType TestingTransactionUtil::DeleteTuple(storage::DataTable *table,
const int key) {
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
TransactionScheduler scheduler(1, table, &txn_manager);
scheduler.Txn(0).Delete(key);
scheduler.Txn(0).Commit();
scheduler.Run();

return scheduler.schedules[0].txn_result;
}

ResultType TestingTransactionUtil::SelectTuple(storage::DataTable *table,
const int key,
std::vector<int> &results) {
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
TransactionScheduler scheduler(1, table, &txn_manager);
scheduler.Txn(0).Read(key);
scheduler.Txn(0).Commit();
scheduler.Run();

results = scheduler.schedules[0].results;

return scheduler.schedules[0].txn_result;
}

} // namespace test
} // namespace peloton
10 changes: 3 additions & 7 deletions test/gc/garbage_collection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ int GarbageNum(storage::DataTable *table) {
// get tuple recycled by GC
int RecycledNum(storage::DataTable *table) {
int count = 0;
auto table_id = table->GetOid();
while (!gc::GCManagerFactory::GetInstance().ReturnFreeSlot(table_id).IsNull())
while (
!gc::GCManagerFactory::GetInstance().GetRecycledTupleSlot(table).IsNull())
count++;

LOG_INFO("recycled version num = %d", count);
Expand Down Expand Up @@ -289,11 +289,7 @@ TEST_F(GarbageCollectionTests, DeleteTest) {

// there should be two versions to be recycled by the GC:
// the deleted version and the empty version.
// however, the txn will explicitly pass one version (the deleted
// version) to the GC manager.
// The GC itself should be responsible for recycling the
// empty version.
EXPECT_EQ(1, recycle_num);
EXPECT_EQ(2, recycle_num);

gc_manager.StopGC();
gc::GCManagerFactory::Configure(0);
Expand Down
Loading

0 comments on commit fe15d74

Please sign in to comment.