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

[15721] Peloton Self-Driving Infrastructure #1346

Open
wants to merge 132 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
5d737ff
remove dead code
Mar 29, 2018
d43cbe9
add comment on tuple.h
Mar 29, 2018
2c1984f
add in stats_aggregator
Apr 5, 2018
e348c6d
implement memory metric header
Apr 9, 2018
072e953
replace txn latency with query latency
swimj Apr 10, 2018
45b1003
init stats aggregator in a correct way
Apr 10, 2018
62e7f0b
implement memory chaning interface
Apr 10, 2018
1f17bea
insert memory allocation interpolation in tile group header
Apr 10, 2018
8174d2a
hookup result to catalog
Apr 10, 2018
d57225f
Save work
tli2 Apr 8, 2018
53d4646
Wrote code to ship catalogs over. Not tested
tli2 Apr 9, 2018
1963520
Add GetName to all catalogs
tli2 Apr 9, 2018
7bcaed8
fix compilation
tli2 Apr 10, 2018
13022b6
Save work
tli2 Apr 14, 2018
454afb1
Fix duplicate index creation.
tli2 Apr 15, 2018
c1cc44e
fix alloc decre bug
Apr 16, 2018
815bf7e
add stats for tile with table id specified
Apr 16, 2018
754901b
reorder arguments (style)
swimj Apr 18, 2018
f68eafd
begin new stats api
swimj Apr 22, 2018
412ebb9
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
swimj Apr 22, 2018
de6bf06
begin stats_collector skeleton
swimj Apr 23, 2018
912120f
Revert "reorder arguments (style)"
swimj Apr 24, 2018
5ed257d
Begin potential abstract_metric refactor
swimj Apr 24, 2018
b6e6183
Begin potential abstract_metric refactor
swimj Apr 24, 2018
8c94a22
Make collector skeleton consistent with new point/interval metric API
swimj Apr 24, 2018
912e383
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
swimj Apr 24, 2018
783d5aa
differentiate tuple/index RUID
swimj Apr 24, 2018
6135ca2
define collection point type
swimj Apr 24, 2018
3cc0df7
implement point_metric atomic collect
swimj Apr 26, 2018
c1ad72c
modify interface
tli2 Apr 26, 2018
089191e
Fix compilation
tli2 Apr 26, 2018
8875cd2
replace txn latency with query latency
swimj Apr 10, 2018
b21fd1a
Save work
tli2 Apr 8, 2018
69c86f1
Wrote code to ship catalogs over. Not tested
tli2 Apr 9, 2018
a4023da
Add GetName to all catalogs
tli2 Apr 9, 2018
06123cd
fix compilation
tli2 Apr 10, 2018
2cfe609
Cherry-picked brain and query latency related code
tli2 Apr 14, 2018
2261123
fix stats_collector compile with EnumHash
swimj Apr 27, 2018
8f24617
Address some code review comments
tli2 Apr 27, 2018
f3bde6d
write mock end-to-end txn abort collect
swimj Apr 27, 2018
7b0895d
Change stats framework to have thread-local collectors and add thread…
tli2 Apr 28, 2018
5f3064b
Add example for how to write new metric
tli2 Apr 28, 2018
7ce0c13
Start writing stats aggregator
tli2 Apr 28, 2018
5504eba
save work
tli2 Apr 29, 2018
b0b6f83
Finish writing aggregation
tli2 Apr 29, 2018
c8e1059
Add documentation and API enhancements.
tli2 Apr 29, 2018
8e7bd38
Use lower case for file name
tli2 Apr 29, 2018
12401dd
fix constructor bug
tli2 Apr 29, 2018
61a200e
Finish comment...
tli2 Apr 29, 2018
ad09d0c
write IndexMetricRawData
swimj Apr 29, 2018
6f1ff1d
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
swimj Apr 29, 2018
6db57e9
write IndexMetric and plug in to BW tree
swimj Apr 30, 2018
66ff52e
write new table metric
swimj Apr 30, 2018
95a5143
document CounterType enum
swimj Apr 30, 2018
8b9b16a
fix QueryLatencyOld compile
swimj Apr 30, 2018
4a2dc58
start on memory
Apr 30, 2018
b1c82da
format change and a race condition fix
Apr 30, 2018
368c0c3
Add assertion
tli2 Apr 30, 2018
3856066
add back aggregate in cpp and do format check
Apr 30, 2018
d12d166
implement iterator wrapper for lock free array and hookup memory allo…
May 1, 2018
bbb146e
Change code to use concurrent map
tli2 May 1, 2018
481f672
Fix compilation
tli2 May 1, 2018
3b6b968
Address code review comments
tli2 May 1, 2018
b99b061
refactor tuple stats collection, plug in new stats collection system
May 1, 2018
1b33d8e
refactor index metric api
May 1, 2018
649295a
add cpp for stats collector. forgot to do so
May 2, 2018
6b7bb41
write latency metric; minor memory metric fix
swimj May 2, 2018
949dad9
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
swimj May 2, 2018
ce38a43
hook up new query metric
swimj May 3, 2018
53799a6
remove processing logic from thread_level_stats_collector; make index…
swimj May 3, 2018
a399015
reorganize some include dependencies to speed up compile
swimj May 3, 2018
2f024d9
change collector_map_ to static class variable, other small things
swimj May 4, 2018
cf4eaaa
implement latency aggregation
swimj May 4, 2018
67b6eb8
begin implementing WriteToCatalog
swimj May 4, 2018
a81b219
add index metric WriteToCatalog, note some to-dos
swimj May 4, 2018
98fdb11
Add some documentation
tli2 May 4, 2018
72c2e6b
Cosmetic changes and documentation
tli2 May 4, 2018
0b09184
Merge branch 'sync' into 721-Proj3
tli2 May 4, 2018
5b2b44f
Import old code for memory usage fetching
Apr 22, 2018
368d602
Make every compile and add in referenced tile group id set
May 4, 2018
f136fc9
add memory stats interface for Varlen Pool. Also add some include pat…
May 5, 2018
ed26941
Add in code to fetch memory stats. Code compiled.
May 5, 2018
51394a2
Format
May 5, 2018
6706f10
fix stats_test compile
swimj May 5, 2018
37f515f
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
swimj May 5, 2018
25e1862
write more comments
swimj May 5, 2018
c0ab45e
fix query latency metric to respect codegen's async API
swimj May 5, 2018
7524dfc
Add in index metric collections
May 5, 2018
174c1f3
Fix some index metric typos and bugs
May 5, 2018
9a9fc0e
Remove old metric stats and get in new stats.
May 5, 2018
8c92bf5
Remove duplicate include and change header comments
May 5, 2018
6db04f2
Delete a bunch of old metric type.
May 6, 2018
a69ac70
Remove Query Metric Catalog and the fix package include.
May 6, 2018
818c9e0
fix TableMetric/IndexMetric aggregate initialization error
swimj May 9, 2018
9762806
minor changes
swimj May 9, 2018
0290d42
Merge branch 'master' of https://github.com/cmu-db/peloton into 721-P…
tli2 May 9, 2018
d255c82
Fix test merge conflicts
tli2 May 10, 2018
6dc5831
fix some tests (will need to change back soon lol)
tli2 May 11, 2018
900126a
Disable stats test for now
tli2 May 11, 2018
8036414
Fix all tests except for query logger test
tli2 May 11, 2018
bc0bacd
change place to log statistics
May 11, 2018
dd85251
Fix all tests with stats turned on except for query logger
tli2 May 11, 2018
f046a6a
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
tli2 May 11, 2018
fdae6c2
remove if clauses around stats collection of latency metric
May 11, 2018
c7da1a1
add test metric and testing code, add desctructor of Abstract Metric …
May 12, 2018
4a03388
internal type for test stats mode
May 12, 2018
ae71879
test metric done
May 12, 2018
56d0fdf
format
May 12, 2018
43748b9
write update table metric catalog api
swimj May 12, 2018
1f835d1
implement working table metric catalog update
swimj May 12, 2018
8a87b19
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
swimj May 12, 2018
db95e98
address request, address validation and change header
May 12, 2018
a9e8b65
implement database metric write to catalog
swimj May 12, 2018
617851a
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
swimj May 12, 2018
819af2d
Save work
tli2 May 12, 2018
3fafea2
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
tli2 May 12, 2018
53d6e95
implement index metric write to catalog
swimj May 12, 2018
46ac7cb
Add TupleAccess metric
tli2 May 12, 2018
cb3d75d
fix documentation for FetchData()
swimj May 12, 2018
4562be6
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
tli2 May 12, 2018
f61a7fc
Merge branch '721-Proj3' of https://github.com/ChTimTsubasa/peloton i…
tli2 May 12, 2018
f63adc4
combine FetchData with WriteToCatalog“
May 12, 2018
2070d93
seperate varlen & inline memory stats
May 13, 2018
908ce19
Hook up TupleAccessMetric
tli2 May 13, 2018
8044049
Hack job to make collection only work for external transactions
tli2 May 13, 2018
569d947
Try siva's suggestion on fix for query log test
May 13, 2018
9feaf0a
Instantiate TupleAccessMetricCatalog
May 14, 2018
06b093d
Add comments to abstract metrics
May 14, 2018
e55f73a
Change catalog data counter type to BIGINT. Fix IndexMetricSearching …
May 14, 2018
86f23d6
Commit txn that previously not being committed
May 14, 2018
08e606f
Implement some util for concrete stats metric tests. Implement table …
May 15, 2018
e12d0a2
fix table metric, add table and index metric test
swimj May 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions src/brain/catalog_sync_brain_job.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// catalog_sync_brain_job.cpp
//
// Identification: src/brain/catalog_sync_brain_job.cpp
//
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#include "brain/catalog_sync_brain_job.h"

namespace peloton {
namespace brain {
void CatalogSyncBrainJob::OnJobInvocation(BrainEnvironment *env) {
auto &manager = concurrency::TransactionManagerFactory::GetInstance();
for (auto *catalog : catalog::Catalog::GetInstance()->AvailableCatalogs())
SyncCatalog(catalog, env, manager);
}

time_t CatalogSyncBrainJob::TimeFromString(const char *str) {
struct tm tm;
PELOTON_MEMSET(&tm, 0, sizeof(struct tm));
strptime(str, "%Y-%m-%d %H:%M:%S", &tm);
return mktime(&tm);
}

std::string CatalogSyncBrainJob::FetchCatalogQuery(catalog::AbstractCatalog *catalog) {
// We need to special cast these two tables because we cannot put a reasonable
// primary key on them without sequences
if (catalog->GetName() == QUERY_HISTORY_CATALOG_NAME)
return "SELECT * FROM pg_catalog." + std::string(QUERY_HISTORY_CATALOG_NAME)
+ " WHERE timestamp > " + std::to_string(last_history_timestamp_);
else
return "SELECT * FROM pg_catalog." + catalog->GetName();
}

void CatalogSyncBrainJob::UpdateTimestamp(catalog::AbstractCatalog *catalog,
pqxx::field field) {
if (catalog->GetName() == QUERY_HISTORY_CATALOG_NAME
&& field.name() == std::string("timestamp"))
last_history_timestamp_ =
std::max(last_history_timestamp_, field.as<int64_t>());
}

void CatalogSyncBrainJob::SyncCatalog(catalog::AbstractCatalog *catalog,
BrainEnvironment *env,
concurrency::TransactionManager &manager) {
pqxx::result r = env->ExecuteQuery(FetchCatalogQuery(catalog));
for (auto row : r) {
concurrency::TransactionContext *txn =
manager.BeginTransaction(IsolationLevelType::REPEATABLE_READS);
catalog::Schema *catalog_schema = catalog->GetDataTable()->GetSchema();
std::unique_ptr<storage::Tuple> tuple(
new storage::Tuple(catalog_schema, true));
for (auto field : row) {
oid_t column_id = catalog_schema->GetColumnID(field.name());
tuple->SetValue(column_id, PqxxFieldToPelotonValue(field));
UpdateTimestamp(catalog, field);
}
catalog->InsertTuple(std::move(tuple), txn);
// We know this will always succeed on the brain side
manager.CommitTransaction(txn);
}
}

type::Value CatalogSyncBrainJob::PqxxFieldToPelotonValue(pqxx::field &f) {
type::TypeId type = PostgresValueTypeToPelotonValueType(
static_cast<PostgresValueType>(f.type()));
if (f.is_null()) {
return type == peloton::type::TypeId::VARCHAR
? type::ValueFactory::GetVarcharValue("")
: type::ValueFactory::GetNullValueByType(type);
}
switch (type) {
case type::TypeId::BOOLEAN:
return type::ValueFactory::GetBooleanValue(f.as<bool>());
case type::TypeId::TINYINT:
return type::ValueFactory::GetTinyIntValue(static_cast<int8_t>(f.as<
int32_t>()));
case type::TypeId::SMALLINT:
return type::ValueFactory::GetSmallIntValue(static_cast<int16_t>(f.as<
int32_t>()));
case type::TypeId::INTEGER:
return type::ValueFactory::GetIntegerValue(f.as<int32_t>());
case type::TypeId::BIGINT:
return type::ValueFactory::GetBigIntValue(f.as<int64_t>());
case type::TypeId::TIMESTAMP:
return type::ValueFactory::GetTimestampValue(TimeFromString(f.c_str()));
case type::TypeId::DECIMAL:
return type::ValueFactory::GetDecimalValue(f.as<double>());
case type::TypeId::VARCHAR:return type::ValueFactory::GetVarcharValue(f.c_str());
default:
throw ConversionException(StringUtil::Format(
"No corresponding c++ type for postgres type %d",
static_cast<int>(type)));
}
}

} // namespace brain
} // nanespace peloton
2 changes: 1 addition & 1 deletion src/brain/query_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void QueryLogger::LogQuery(std::string query_string, uint64_t timestamp) {
Fingerprint fingerprint{query_string};

// Log query + fingerprint
auto &query_history_catalog = catalog::QueryHistoryCatalog::GetInstance();
auto &query_history_catalog = catalog::QueryHistoryCatalog::GetInstance(txn);
query_history_catalog.InsertQueryHistory(
query_string, fingerprint.GetFingerprint(), timestamp, nullptr, txn);

Expand Down
6 changes: 4 additions & 2 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@
#include "catalog/language_catalog.h"
#include "catalog/proc_catalog.h"
#include "catalog/query_history_catalog.h"
#include "catalog/query_metrics_catalog.h"
#include "catalog/settings_catalog.h"
#include "catalog/system_catalogs.h"
#include "catalog/table_catalog.h"
#include "catalog/table_metrics_catalog.h"
#include "catalog/trigger_catalog.h"
#include "catalog/tuple_access_metrics_catalog.h"
#include "concurrency/transaction_manager_factory.h"
#include "function/date_functions.h"
#include "function/decimal_functions.h"
#include "function/old_engine_string_functions.h"
#include "function/timestamp_functions.h"
#include "index/index_factory.h"
#include "settings/settings_manager.h"
#include "storage/database.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 198 of this file, the flag should be brain_data_collection. Probably the reason why query_logger_test is failing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it. Still failing the test. The log is

174: 2018-05-13 10:48:16 [test/sql/testing_sql_util.cpp:60:ExecuteSQLQuery] INFO - Query: SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;
174: 2018-05-13 10:48:16 [src/codegen/operator/table_scan_translator.cpp:40:TableScanTranslator] DEBUG - Constructing TableScanTranslator ...
174: 2018-05-13 10:48:16 [test/sql/testing_sql_util.cpp:95:ExecuteSQLQuery] INFO - Statement executed. Result: SUCCESS
174: 2018-05-13 10:48:21 [test/sql/testing_sql_util.cpp:60:ExecuteSQLQuery] INFO - Query: SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;
174: 2018-05-13 10:48:21 [test/sql/testing_sql_util.cpp:95:ExecuteSQLQuery] INFO - Statement executed. Result: SUCCESS
174: 2018-05-13 10:48:26 [test/sql/testing_sql_util.cpp:60:ExecuteSQLQuery] INFO - Query: SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;
174: 2018-05-13 10:48:26 [test/sql/testing_sql_util.cpp:95:ExecuteSQLQuery] INFO - Statement executed. Result: SUCCESS
174: 2018-05-13 10:48:31 [test/sql/testing_sql_util.cpp:60:ExecuteSQLQuery] INFO - Query: SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;
174: 2018-05-13 10:48:31 [test/sql/testing_sql_util.cpp:95:ExecuteSQLQuery] INFO - Statement executed. Result: SUCCESS
174: 2018-05-13 10:48:36 [test/sql/testing_sql_util.cpp:60:ExecuteSQLQuery] INFO - Query: SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;
174: 2018-05-13 10:48:36 [test/sql/testing_sql_util.cpp:95:ExecuteSQLQuery] INFO - Statement executed. Result: SUCCESS
174: 2018-05-13 10:48:41 [test/sql/testing_sql_util.cpp:60:ExecuteSQLQuery] INFO - Query: SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;
174: 2018-05-13 10:48:41 [test/sql/testing_sql_util.cpp:95:ExecuteSQLQuery] INFO - Statement executed. Result: SUCCESS
174: /home/tianyi/Documents/project/peloton/test/sql/testing_sql_util.cpp:274: Failure
174: Value of: actual_result.size()
174: Actual: 10
174: Expected: ref_result.size()
174: Which is: 11
174: /home/tianyi/Documents/project/peloton/test/sql/testing_sql_util.cpp:282: Failure
174: Value of: actual_result
174: Actual: { "CREATE TABLE test(a INT);|015a5c39f1d456672ab662e8bf9d13598d5d87f697", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (2);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "BEGIN;|011e0b3628080f24ada46945aaaa12f4ae69ed0a3b", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "COMMIT;|01cf0fba0f1cfd731e80292bd9c5e92abbec9056d1" }
174: Expected: ref_result
174: Which is: { "CREATE TABLE test(a INT);|015a5c39f1d456672ab662e8bf9d13598d5d87f697", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (2);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "BEGIN;|011e0b3628080f24ada46945aaaa12f4ae69ed0a3b", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "COMMIT;|01cf0fba0f1cfd731e80292bd9c5e92abbec9056d1" }
174: 2018-05-13 10:48:46 [test/sql/testing_sql_util.cpp:60:ExecuteSQLQuery] INFO - Query: SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;
174: 2018-05-13 10:48:46 [test/sql/testing_sql_util.cpp:95:ExecuteSQLQuery] INFO - Statement executed. Result: SUCCESS
174: /home/tianyi/Documents/project/peloton/test/sql/testing_sql_util.cpp:274: Failure
174: Value of: actual_result.size()
174: Actual: 12
174: Expected: ref_result.size()
174: Which is: 13
174: /home/tianyi/Documents/project/peloton/test/sql/testing_sql_util.cpp:282: Failure
174: Value of: actual_result
174: Actual: { "CREATE TABLE test(a INT);|015a5c39f1d456672ab662e8bf9d13598d5d87f697", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (2);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "BEGIN;|011e0b3628080f24ada46945aaaa12f4ae69ed0a3b", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "COMMIT;|01cf0fba0f1cfd731e80292bd9c5e92abbec9056d1", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914" }
174: Expected: ref_result
174: Which is: { "CREATE TABLE test(a INT);|015a5c39f1d456672ab662e8bf9d13598d5d87f697", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (2);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "BEGIN;|011e0b3628080f24ada46945aaaa12f4ae69ed0a3b", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "INSERT INTO test VALUES (1);|01494aa495a99247b2fe92808c6ae2df065e2ec101", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "COMMIT;|01cf0fba0f1cfd731e80292bd9c5e92abbec9056d1", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914", "SELECT query_string, fingerprint FROM peloton.pg_catalog.pg_query_history;|01851b97a4b7d3bc7fefc53d3b920878c08c4cc914" }

#include "storage/storage_manager.h"
#include "storage/table_factory.h"
#include "type/ephemeral_pool.h"
Expand Down Expand Up @@ -191,11 +192,12 @@ void Catalog::Bootstrap() {
DatabaseMetricsCatalog::GetInstance(txn);
SettingsCatalog::GetInstance(txn);
LanguageCatalog::GetInstance(txn);
TupleAccessMetricsCatalog::GetInstance(txn);

// TODO: change pg_proc to per database
ProcCatalog::GetInstance(txn);

if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
if (settings::SettingsManager::GetBool(settings::SettingId::brain_data_collection)) {
QueryHistoryCatalog::GetInstance(txn);
}

Expand Down
8 changes: 2 additions & 6 deletions src/catalog/column_stats_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ ColumnStatsCatalog::ColumnStatsCatalog(concurrency::TransactionContext *txn)
"most_common_freqs VARCHAR, "
"histogram_bounds VARCHAR, "
"column_name VARCHAR, "
"has_index BOOLEAN);",
"has_index BOOLEAN,"
"PRIMARY KEY(database_id, table_id, column_id));",
txn) {
// unique key: (database_id, table_id, column_id)
Catalog::GetInstance()->CreateIndex(
CATALOG_DATABASE_NAME, CATALOG_SCHEMA_NAME, COLUMN_STATS_CATALOG_NAME,
{0, 1, 2}, COLUMN_STATS_CATALOG_NAME "_skey0", true, IndexType::BWTREE,
txn);
// non-unique key: (database_id, table_id)
Catalog::GetInstance()->CreateIndex(
CATALOG_DATABASE_NAME, CATALOG_SCHEMA_NAME, COLUMN_STATS_CATALOG_NAME,
Expand Down
70 changes: 68 additions & 2 deletions src/catalog/database_metrics_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// database_metrics_catalog.cpp
//
// Identification: src/catalog/query_metrics_catalog.cpp
// Identification: src/catalog/database_metrics_catalog.cpp
//
// Copyright (c) 2015-17, Carnegie Mellon University Database Group
//
Expand All @@ -19,6 +19,23 @@
namespace peloton {
namespace catalog {

DatabaseMetricsCatalogObject::DatabaseMetricsCatalogObject(
executor::LogicalTile *tile, int tupleId)
: database_oid_(
tile->GetValue(tupleId,
DatabaseMetricsCatalog::ColumnId::DATABASE_OID)
.GetAs<oid_t>()),
txn_committed_(
tile->GetValue(tupleId,
DatabaseMetricsCatalog::ColumnId::TXN_COMMITTED)
.GetAs<int64_t>()),
txn_aborted_(
tile->GetValue(tupleId, DatabaseMetricsCatalog::ColumnId::TXN_ABORTED)
.GetAs<int64_t>()),
time_stamp_(
tile->GetValue(tupleId, DatabaseMetricsCatalog::ColumnId::TIME_STAMP)
.GetAs<int64_t>()) {}

DatabaseMetricsCatalog *DatabaseMetricsCatalog::GetInstance(
concurrency::TransactionContext *txn) {
static DatabaseMetricsCatalog database_metrics_catalog{txn};
Expand All @@ -30,7 +47,7 @@ DatabaseMetricsCatalog::DatabaseMetricsCatalog(
: AbstractCatalog("CREATE TABLE " CATALOG_DATABASE_NAME
"." CATALOG_SCHEMA_NAME "." DATABASE_METRICS_CATALOG_NAME
" ("
"database_oid INT NOT NULL, "
"database_oid INT NOT NULL PRIMARY KEY, "
"txn_committed INT NOT NULL, "
"txn_aborted INT NOT NULL, "
"time_stamp INT NOT NULL);",
Expand Down Expand Up @@ -71,5 +88,54 @@ bool DatabaseMetricsCatalog::DeleteDatabaseMetrics(
return DeleteWithIndexScan(index_offset, values, txn);
}

bool DatabaseMetricsCatalog::UpdateDatabaseMetrics(
oid_t database_oid, oid_t txn_committed, oid_t txn_aborted,
oid_t time_stamp, concurrency::TransactionContext *txn) {
std::vector<oid_t> update_columns(all_column_ids_);
std::vector<type::Value> update_values;

update_values.push_back(
type::ValueFactory::GetIntegerValue(database_oid).Copy());
update_values.push_back(
type::ValueFactory::GetIntegerValue(txn_committed).Copy());
update_values.push_back(
type::ValueFactory::GetIntegerValue(txn_aborted).Copy());
update_values.push_back(
type::ValueFactory::GetIntegerValue(time_stamp).Copy());

std::vector<type::Value> scan_values;
scan_values.push_back(type::ValueFactory::GetIntegerValue(database_oid));
oid_t index_offset = IndexId::PRIMARY_KEY;

return UpdateWithIndexScan(update_columns, update_values, scan_values,
index_offset, txn);
}

std::shared_ptr<DatabaseMetricsCatalogObject>
DatabaseMetricsCatalog::GetDatabaseMetricsObject(
oid_t database_oid, concurrency::TransactionContext *txn) {
if (txn == nullptr) {
throw CatalogException("Transaction is invalid!");
}

// set up query
std::vector<oid_t> column_ids(all_column_ids_);
oid_t index_offset = IndexId::PRIMARY_KEY;
std::vector<type::Value> values;
values.push_back(type::ValueFactory::GetIntegerValue(database_oid).Copy());

auto result_tiles =
GetResultWithIndexScan(column_ids, index_offset, values, txn);

if (result_tiles->size() == 1 && (*result_tiles)[0]->GetTupleCount() == 1) {
auto database_metric_object =
std::make_shared<DatabaseMetricsCatalogObject>(
(*result_tiles)[0].get());
return database_metric_object;
}

return nullptr;
}

} // namespace catalog
} // namespace peloton
Loading