Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit ecb95bb

Browse files
Modify CreateTable for tests + modify LayoutTuner
1 parent 0ff874d commit ecb95bb

File tree

6 files changed

+128
-95
lines changed

6 files changed

+128
-95
lines changed

src/include/storage/layout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ class Layout : public Printable {
141141
};
142142

143143
} // namespace storage
144-
} // namespace peloton
144+
} // namespace peloton

src/include/tuning/layout_tuner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class LayoutTuner {
8787
* Update layout of table
8888
*
8989
* @param table The table
90+
* @return true if the update succeeds, false otherwise
9091
*/
91-
void UpdateDefaultPartition(storage::DataTable *table);
92+
bool UpdateDefaultPartition(storage::DataTable *table);
9293

9394
private:
9495
/**

src/tuning/layout_tuner.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Sample GetClustererSample(const Sample& sample, oid_t column_count) {
7676
return clusterer_sample;
7777
}
7878

79-
void LayoutTuner::UpdateDefaultPartition(storage::DataTable* table) {
79+
bool LayoutTuner::UpdateDefaultPartition(storage::DataTable *table) {
8080
oid_t column_count = table->GetSchema()->GetColumnCount();
8181

8282
// Set up clusterer
@@ -87,7 +87,9 @@ void LayoutTuner::UpdateDefaultPartition(storage::DataTable* table) {
8787

8888
// Check if we have any samples
8989
if (samples.empty()) {
90-
return;
90+
LOG_DEBUG("Table[%u] contains no LayoutSamples. Layout not tuned.",
91+
table->GetOid());
92+
return false;
9193
}
9294

9395
for (auto sample : samples) {
@@ -120,12 +122,13 @@ void LayoutTuner::UpdateDefaultPartition(storage::DataTable* table) {
120122
nullptr) {
121123
txn_manager.AbortTransaction(txn);
122124
LOG_DEBUG("Layout Update to failed.");
123-
return;
125+
return false;
124126
}
125127
txn_manager.CommitTransaction(txn);
126128

127129
UNUSED_ATTRIBUTE auto layout = table->GetDefaultLayout();
128130
LOG_TRACE("Updated Layout: %s", layout.GetInfo().c_str());
131+
return true;
129132
}
130133

131134
void LayoutTuner::Tune() {
@@ -142,7 +145,8 @@ void LayoutTuner::Tune() {
142145
table->TransformTileGroup(tile_group_offset, theta);
143146

144147
// Update partitioning periodically
145-
UpdateDefaultPartition(table);
148+
// TODO Lin/Tianyu - Add Failure Handling/Retry logic.
149+
UNUSED_ATTRIBUTE bool update_result = UpdateDefaultPartition(table);
146150

147151
// Sleep a bit
148152
std::this_thread::sleep_for(std::chrono::microseconds(sleep_duration));

test/codegen/table_scan_translator_test.cpp

Lines changed: 20 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -36,90 +36,18 @@ class TableScanTranslatorTest : public PelotonCodeGenTest {
3636
CreateAndLoadAllColsTable();
3737
}
3838

39-
void ExecuteTileGroupTest(peloton::LayoutType layout_type) {
40-
const int tuples_per_tilegroup = 100;
41-
const int tile_group_count = 5;
42-
const int tuple_count = tuples_per_tilegroup * tile_group_count;
43-
const oid_t col_count = 100;
44-
const bool is_inlined = true;
45-
46-
/////////////////////////////////////////////////////////
47-
// Define the schema.
48-
/////////////////////////////////////////////////////////
49-
50-
std::vector<catalog::Column> columns;
51-
52-
for (oid_t col_itr = 0; col_itr <= col_count; col_itr++) {
53-
auto column = catalog::Column(
54-
type::TypeId::INTEGER, type::Type::GetTypeSize(type::TypeId::INTEGER),
55-
"FIELD" + std::to_string(col_itr), is_inlined);
56-
57-
columns.push_back(column);
58-
}
59-
60-
std::unique_ptr<catalog::Schema> table_schema =
61-
std::unique_ptr<catalog::Schema>(new catalog::Schema(columns));
62-
std::string table_name("TEST_TABLE");
63-
64-
/////////////////////////////////////////////////////////
65-
// Create table.
66-
/////////////////////////////////////////////////////////
67-
68-
bool is_catalog = false;
69-
auto *catalog = catalog::Catalog::GetInstance();
70-
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
71-
const bool allocate = true;
72-
auto txn = txn_manager.BeginTransaction();
73-
74-
// Insert table in catalog
75-
catalog->CreateTable(test_db_name, DEFAULT_SCHEMA_NAME, table_name,
76-
std::move(table_schema), txn, is_catalog,
77-
tuples_per_tilegroup, layout_type);
78-
// Get table reference
79-
auto table = catalog->GetTableWithName(test_db_name, DEFAULT_SCHEMA_NAME,
80-
table_name, txn);
81-
txn_manager.EndTransaction(txn);
82-
83-
/////////////////////////////////////////////////////////
84-
// Load in the data
85-
/////////////////////////////////////////////////////////
86-
87-
// Insert tuples into tile_group.
88-
89-
txn = txn_manager.BeginTransaction();
90-
auto table_schema_ptr = table->GetSchema();
91-
auto testing_pool = TestingHarness::GetInstance().GetTestingPool();
92-
93-
for (oid_t row_id = 0; row_id < tuple_count; row_id++) {
94-
int populate_value = row_id;
95-
96-
storage::Tuple tuple(table_schema_ptr, allocate);
97-
98-
for (oid_t col_id = 0; col_id <= col_count; col_id++) {
99-
auto value =
100-
type::ValueFactory::GetIntegerValue(populate_value + col_id);
101-
tuple.SetValue(col_id, value, testing_pool);
102-
}
103-
104-
ItemPointer *index_entry_ptr = nullptr;
105-
ItemPointer tuple_slot_id =
106-
table->InsertTuple(&tuple, txn, &index_entry_ptr);
107-
108-
EXPECT_TRUE(tuple_slot_id.block != INVALID_OID);
109-
EXPECT_TRUE(tuple_slot_id.offset != INVALID_OID);
110-
111-
txn_manager.PerformInsert(txn, tuple_slot_id, index_entry_ptr);
112-
}
113-
114-
txn_manager.CommitTransaction(txn);
39+
void ScanLayoutTable(oid_t tuples_per_tilegroup, oid_t tilegroup_count,
40+
oid_t column_count) {
41+
auto table = GetLayoutTable();
42+
oid_t tuple_count = tuples_per_tilegroup * tilegroup_count;
11543

11644
/////////////////////////////////////////////////////////
11745
// Do a seq scan on the table with the given layout
11846
/////////////////////////////////////////////////////////
11947

12048
// Column ids to be scanned.
12149
std::vector<oid_t> column_ids;
122-
for (oid_t col_id = 0; col_id < col_count; col_id++) {
50+
for (oid_t col_id = 0; col_id < column_count; col_id++) {
12351
column_ids.push_back(col_id);
12452
}
12553

@@ -143,7 +71,7 @@ class TableScanTranslatorTest : public PelotonCodeGenTest {
14371
for (oid_t tuple_id = 0; tuple_id < tuple_count; tuple_id++) {
14472
auto &tuple = results[tuple_id];
14573
int tuple_id_value = tuple_id;
146-
for (oid_t col_id = 0; col_id < col_count; col_id++) {
74+
for (oid_t col_id = 0; col_id < column_count; col_id++) {
14775
auto value =
14876
type::ValueFactory::GetIntegerValue(tuple_id_value + col_id);
14977
EXPECT_EQ(CmpBool::CmpTrue,
@@ -706,15 +634,27 @@ TEST_F(TableScanTranslatorTest, ScanRowLayout) {
706634
// Creates a table with LayoutType::ROW and
707635
// invokes the TableScanTranslator
708636
//
709-
ExecuteTileGroupTest(LayoutType::ROW);
637+
oid_t tuples_per_tilegroup = 100;
638+
oid_t tilegroup_count = 5;
639+
oid_t column_count = 100;
640+
bool is_inlined = true;
641+
CreateAndLoadTableWithLayout(LayoutType::ROW, tuples_per_tilegroup,
642+
tilegroup_count, column_count, is_inlined);
643+
ScanLayoutTable(tuples_per_tilegroup, tilegroup_count, column_count);
710644
}
711645

712646
TEST_F(TableScanTranslatorTest, ScanColumnLayout) {
713647
//
714648
// Creates a table with LayoutType::COLUMN and
715649
// invokes the TableScanTranslator
716650
//
717-
ExecuteTileGroupTest(LayoutType::COLUMN);
651+
oid_t tuples_per_tilegroup = 100;
652+
oid_t tilegroup_count = 5;
653+
oid_t column_count = 100;
654+
bool is_inlined = true;
655+
CreateAndLoadTableWithLayout(LayoutType::COLUMN, tuples_per_tilegroup,
656+
tilegroup_count, column_count, is_inlined);
657+
ScanLayoutTable(tuples_per_tilegroup, tilegroup_count, column_count);
718658
}
719659

720660
TEST_F(TableScanTranslatorTest, MultiLayoutScan) {

test/codegen/testing_codegen_util.cpp

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace test {
3232
// PELOTON CODEGEN TEST
3333
//===----------------------------------------------------------------------===//
3434

35-
PelotonCodeGenTest::PelotonCodeGenTest(oid_t tuples_per_tilegroup) {
35+
PelotonCodeGenTest::PelotonCodeGenTest(oid_t tuples_per_tilegroup,
36+
peloton::LayoutType layout_type) {
3637
auto *catalog = catalog::Catalog::GetInstance();
3738
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
3839
auto txn = txn_manager.BeginTransaction();
@@ -41,9 +42,10 @@ PelotonCodeGenTest::PelotonCodeGenTest(oid_t tuples_per_tilegroup) {
4142
catalog->CreateDatabase(test_db_name, txn);
4243
test_db = catalog->GetDatabaseWithName(test_db_name, txn);
4344
// Create test table
44-
CreateTestTables(txn, tuples_per_tilegroup);
45+
CreateTestTables(txn, tuples_per_tilegroup, layout_type);
4546

4647
txn_manager.CommitTransaction(txn);
48+
layout_table = nullptr;
4749
}
4850

4951
PelotonCodeGenTest::~PelotonCodeGenTest() {
@@ -103,13 +105,14 @@ std::unique_ptr<catalog::Schema> PelotonCodeGenTest::CreateTestSchema(
103105

104106
// Create all the test tables, but don't load any data
105107
void PelotonCodeGenTest::CreateTestTables(concurrency::TransactionContext *txn,
106-
oid_t tuples_per_tilegroup) {
108+
oid_t tuples_per_tilegroup,
109+
peloton::LayoutType layout_type) {
107110
auto *catalog = catalog::Catalog::GetInstance();
108111
for (int i = 0; i < 4; i++) {
109112
auto table_schema = CreateTestSchema();
110113
catalog->CreateTable(test_db_name, DEFAULT_SCHEMA_NAME, test_table_names[i],
111114
std::move(table_schema), txn, false,
112-
tuples_per_tilegroup);
115+
tuples_per_tilegroup, layout_type);
113116
test_table_oids.push_back(catalog
114117
->GetTableObject(test_db_name,
115118
DEFAULT_SCHEMA_NAME,
@@ -120,7 +123,7 @@ void PelotonCodeGenTest::CreateTestTables(concurrency::TransactionContext *txn,
120123
auto table_schema = CreateTestSchema(true);
121124
catalog->CreateTable(test_db_name, DEFAULT_SCHEMA_NAME, test_table_names[i],
122125
std::move(table_schema), txn, false,
123-
tuples_per_tilegroup);
126+
tuples_per_tilegroup, layout_type);
124127
test_table_oids.push_back(catalog
125128
->GetTableObject(test_db_name,
126129
DEFAULT_SCHEMA_NAME,
@@ -175,6 +178,80 @@ void PelotonCodeGenTest::LoadTestTable(oid_t table_id, uint32_t num_rows,
175178
txn_manager.CommitTransaction(txn);
176179
}
177180

181+
void PelotonCodeGenTest::CreateAndLoadTableWithLayout(
182+
peloton::LayoutType layout_type, oid_t tuples_per_tilegroup,
183+
oid_t tile_group_count, oid_t column_count, bool is_inlined) {
184+
oid_t tuple_count = tuples_per_tilegroup * tile_group_count;
185+
/////////////////////////////////////////////////////////
186+
// Define the schema.
187+
/////////////////////////////////////////////////////////
188+
189+
std::vector<catalog::Column> columns;
190+
191+
for (oid_t col_itr = 0; col_itr <= column_count; col_itr++) {
192+
auto column = catalog::Column(
193+
type::TypeId::INTEGER, type::Type::GetTypeSize(type::TypeId::INTEGER),
194+
"FIELD" + std::to_string(col_itr), is_inlined);
195+
196+
columns.push_back(column);
197+
}
198+
199+
std::unique_ptr<catalog::Schema> table_schema =
200+
std::unique_ptr<catalog::Schema>(new catalog::Schema(columns));
201+
std::string table_name("LAYOUT_TABLE");
202+
203+
/////////////////////////////////////////////////////////
204+
// Create table.
205+
/////////////////////////////////////////////////////////
206+
207+
bool is_catalog = false;
208+
auto *catalog = catalog::Catalog::GetInstance();
209+
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
210+
const bool allocate = true;
211+
auto txn = txn_manager.BeginTransaction();
212+
213+
// Insert table in catalog
214+
catalog->CreateTable(test_db_name, DEFAULT_SCHEMA_NAME, table_name,
215+
std::move(table_schema), txn, is_catalog,
216+
tuples_per_tilegroup, layout_type);
217+
// Get table reference
218+
layout_table = catalog->GetTableWithName(test_db_name, DEFAULT_SCHEMA_NAME,
219+
table_name, txn);
220+
txn_manager.EndTransaction(txn);
221+
222+
/////////////////////////////////////////////////////////
223+
// Load in the data
224+
/////////////////////////////////////////////////////////
225+
226+
// Insert tuples into tile_group.
227+
228+
txn = txn_manager.BeginTransaction();
229+
auto table_schema_ptr = layout_table->GetSchema();
230+
auto testing_pool = TestingHarness::GetInstance().GetTestingPool();
231+
232+
for (oid_t row_id = 0; row_id < tuple_count; row_id++) {
233+
int populate_value = row_id;
234+
235+
storage::Tuple tuple(table_schema_ptr, allocate);
236+
237+
for (oid_t col_id = 0; col_id <= column_count; col_id++) {
238+
auto value = type::ValueFactory::GetIntegerValue(populate_value + col_id);
239+
tuple.SetValue(col_id, value, testing_pool);
240+
}
241+
242+
ItemPointer *index_entry_ptr = nullptr;
243+
ItemPointer tuple_slot_id =
244+
layout_table->InsertTuple(&tuple, txn, &index_entry_ptr);
245+
246+
EXPECT_TRUE(tuple_slot_id.block != INVALID_OID);
247+
EXPECT_TRUE(tuple_slot_id.offset != INVALID_OID);
248+
249+
txn_manager.PerformInsert(txn, tuple_slot_id, index_entry_ptr);
250+
}
251+
252+
txn_manager.CommitTransaction(txn);
253+
}
254+
178255
void PelotonCodeGenTest::ExecuteSync(
179256
codegen::Query &query,
180257
std::unique_ptr<executor::ExecutorContext> executor_context,

test/include/codegen/testing_codegen_util.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class PelotonCodeGenTest : public PelotonTest {
5252
"table4", "table5"};
5353
std::vector<oid_t> test_table_oids;
5454

55-
PelotonCodeGenTest(oid_t tuples_per_tilegroup = DEFAULT_TUPLES_PER_TILEGROUP);
55+
PelotonCodeGenTest(oid_t tuples_per_tilegroup = DEFAULT_TUPLES_PER_TILEGROUP,
56+
peloton::LayoutType layout_type = LayoutType::ROW);
5657

5758
virtual ~PelotonCodeGenTest();
5859

@@ -64,21 +65,30 @@ class PelotonCodeGenTest : public PelotonTest {
6465
return *GetDatabase().GetTableWithOid(static_cast<uint32_t>(table_id));
6566
}
6667

68+
// Get the layout table
69+
storage::DataTable *GetLayoutTable() const { return layout_table; }
70+
6771
// Create the schema (common among all tables)
6872
catalog::Column GetTestColumn(uint32_t col_id) const;
6973

7074
std::unique_ptr<catalog::Schema> CreateTestSchema(
7175
bool add_primary = false) const;
7276

7377
// Create the test tables
74-
void CreateTestTables(
75-
concurrency::TransactionContext *txn,
76-
oid_t tuples_per_tilegroup = DEFAULT_TUPLES_PER_TILEGROUP);
78+
void CreateTestTables(concurrency::TransactionContext *txn,
79+
oid_t tuples_per_tilegroup,
80+
peloton::LayoutType layout_type);
7781

7882
// Load the given table with the given number of rows
7983
void LoadTestTable(oid_t table_id, uint32_t num_rows,
8084
bool insert_nulls = false);
8185

86+
// Load tables with the specified layout
87+
void CreateAndLoadTableWithLayout(peloton::LayoutType layout_type,
88+
oid_t tuples_per_tilegroup,
89+
oid_t tile_group_count, oid_t column_count,
90+
bool is_inlined);
91+
8292
static void ExecuteSync(
8393
codegen::Query &query,
8494
std::unique_ptr<executor::ExecutorContext> executor_context,
@@ -117,6 +127,7 @@ class PelotonCodeGenTest : public PelotonTest {
117127

118128
private:
119129
storage::Database *test_db;
130+
storage::DataTable *layout_table;
120131
};
121132

122133
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)