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

Settings refactoring #1432

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ void Catalog::Bootstrap() {
// TODO: change pg_proc to per database
ProcCatalog::GetInstance(txn);

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

Expand Down Expand Up @@ -958,7 +959,8 @@ ResultType Catalog::AddUniqueConstraint(concurrency::TransactionContext *txn,
->GetSchema();

// Create index
std::stringstream index_name(table_object->GetTableName());
std::stringstream index_name;
index_name << table_object->GetTableName();
for (auto column_id : column_ids)
index_name << "_" + schema->GetColumn(column_id).GetName();
index_name << "_UNIQ";
Expand Down Expand Up @@ -1033,7 +1035,8 @@ ResultType Catalog::AddForeignKeyConstraint(concurrency::TransactionContext *txn
->GetTableCatalogEntry(txn, src_table_oid);
auto src_schema = src_table->GetSchema();

std::stringstream index_name(src_table_object->GetTableName());
std::stringstream index_name;
index_name << src_table_object->GetTableName();
for (auto col_id : src_col_ids)
index_name << "_" << src_schema->GetColumn(col_id).GetName();
index_name << "_fkey";
Expand Down
191 changes: 167 additions & 24 deletions src/catalog/settings_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,99 @@
namespace peloton {
namespace catalog {

SettingsCatalogEntry::SettingsCatalogEntry(executor::LogicalTile *tile,
int tuple_id)
: name_(tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::NAME))
.ToString()),
value_type_(StringToTypeId(
tile->GetValue(tuple_id, static_cast<int>(
SettingsCatalog::ColumnId::VALUE_TYPE))
.ToString())),
desc_(tile->GetValue(
tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::DESCRIPTION))
.ToString()),
is_mutable_(
tile->GetValue(tuple_id, static_cast<int>(
SettingsCatalog::ColumnId::IS_MUTABLE))
.GetAs<bool>()),
is_persistent_(
tile->GetValue(
tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::IS_PERSISTENT))
.GetAs<bool>()) {
switch (value_type_) {
case type::TypeId::INTEGER: {
value_ = type::ValueFactory::GetIntegerValue(std::stoi(
tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::VALUE))
.ToString()));
default_value_ = type::ValueFactory::GetIntegerValue(std::stoi(
tile->GetValue(
tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::DEFAULT_VALUE))
.ToString()));
min_value_ = type::ValueFactory::GetIntegerValue(std::stoi(
tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::MIN_VALUE))
.ToString()));
max_value_ = type::ValueFactory::GetIntegerValue(std::stoi(
tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::MAX_VALUE))
.ToString()));
break;
}
case type::TypeId::DECIMAL: {
value_ = type::ValueFactory::GetDecimalValue(std::stof(
tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::VALUE))
.ToString()));
default_value_ = type::ValueFactory::GetDecimalValue(std::stof(
tile->GetValue(
tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::DEFAULT_VALUE))
.ToString()));
min_value_ = type::ValueFactory::GetDecimalValue(std::stof(
tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::MIN_VALUE))
.ToString()));
max_value_ = type::ValueFactory::GetDecimalValue(std::stof(
tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::MAX_VALUE))
.ToString()));
break;
}
case type::TypeId::BOOLEAN: {
value_ = type::ValueFactory::GetBooleanValue(
(tile->GetValue(tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::VALUE))
.ToString() == "true")
? true
: false);
default_value_ = type::ValueFactory::GetBooleanValue(
(tile->GetValue(
tuple_id,
static_cast<int>(SettingsCatalog::ColumnId::DEFAULT_VALUE))
.ToString() == "true")
? true
: false);
break;
}
case type::TypeId::VARCHAR: {
value_ = tile->GetValue(
tuple_id, static_cast<int>(SettingsCatalog::ColumnId::VALUE));
default_value_ = tile->GetValue(
tuple_id, static_cast<int>(SettingsCatalog::ColumnId::DEFAULT_VALUE));
break;
}
default:
LOG_ERROR("Unsupported type for setting value: %s",
TypeIdToString(value_type_).c_str());
PELOTON_ASSERT(false);
}
}

SettingsCatalog &SettingsCatalog::GetInstance(
concurrency::TransactionContext *txn) {
static SettingsCatalog settings_catalog{txn};
Expand Down Expand Up @@ -102,9 +195,54 @@ bool SettingsCatalog::DeleteSetting(concurrency::TransactionContext *txn,
return DeleteWithIndexScan(txn, index_offset, values);
}

std::string SettingsCatalog::GetSettingValue(concurrency::TransactionContext *txn,
const std::string &name) {
std::vector<oid_t> column_ids({static_cast<int>(ColumnId::VALUE)});
/** @brief Update a setting catalog entry corresponding to a name
* in the pg_settings.
* @param txn TransactionContext for getting the setting.
* @param name name of the setting.
* @param value value for the updating.
* @return setting catalog entry.
*/
bool SettingsCatalog::UpdateSettingValue(concurrency::TransactionContext *txn,
const std::string &name,
const std::string &value,
bool set_default) {
std::vector<oid_t> update_columns(
{static_cast<int>(ColumnId::VALUE)}); // value
oid_t index_offset =
static_cast<int>(IndexId::SECONDARY_KEY_0); // Index of name
// values to execute index scan
std::vector<type::Value> scan_values;
scan_values.push_back(type::ValueFactory::GetVarcharValue(name).Copy());
// values to update
std::vector<type::Value> update_values;
update_values.push_back(type::ValueFactory::GetVarcharValue(value).Copy());

if (set_default) {
update_columns.push_back(static_cast<oid_t>(ColumnId::DEFAULT_VALUE));
update_values.push_back(type::ValueFactory::GetVarcharValue(value).Copy());
}

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

/** @brief Get a setting catalog entry corresponding to a name
* from the pg_settings.
* @param txn TransactionContext for getting the setting.
* @param name name of the setting.
* @return setting catalog entry.
*/
std::shared_ptr<SettingsCatalogEntry>
SettingsCatalog::GetSettingsCatalogEntry(concurrency::TransactionContext *txn,
const std::string &name) {
if (txn == nullptr) {
throw CatalogException("Transaction is invalid!");
}

std::vector<oid_t> column_ids(all_column_ids_);
oid_t index_offset = static_cast<int>(IndexId::SECONDARY_KEY_0);
std::vector<type::Value> values;
values.push_back(type::ValueFactory::GetVarcharValue(name, nullptr).Copy());
Expand All @@ -115,39 +253,44 @@ std::string SettingsCatalog::GetSettingValue(concurrency::TransactionContext *tx
index_offset,
values);

std::string config_value = "";
PELOTON_ASSERT(result_tiles->size() <= 1);
if (result_tiles->size() != 0) {
PELOTON_ASSERT((*result_tiles)[0]->GetTupleCount() <= 1);
if ((*result_tiles)[0]->GetTupleCount() != 0) {
config_value = (*result_tiles)[0]->GetValue(0, 0).ToString();
return std::make_shared<SettingsCatalogEntry>((*result_tiles)[0].get());
}
}
return config_value;

return nullptr;
}

std::string SettingsCatalog::GetDefaultValue(concurrency::TransactionContext *txn,
const std::string &name) {
std::vector<oid_t> column_ids({static_cast<int>(ColumnId::VALUE)});
oid_t index_offset = static_cast<int>(IndexId::SECONDARY_KEY_0);
std::vector<type::Value> values;
values.push_back(type::ValueFactory::GetVarcharValue(name, nullptr).Copy());
/** @brief Get all setting catalog entries from the pg_settings.
* @param txn TransactionContext for getting the settings.
* @return unordered_map containing a name -> setting catalog
* entry mapping.
*/
std::unordered_map<std::string, std::shared_ptr<SettingsCatalogEntry>>
SettingsCatalog::GetSettingsCatalogEntries(concurrency::TransactionContext *txn) {
if (txn == nullptr) {
throw CatalogException("Transaction is invalid!");
}

auto result_tiles =
GetResultWithIndexScan(txn,
column_ids,
index_offset,
values);
std::vector<oid_t> column_ids(all_column_ids_);

std::string config_value = "";
PELOTON_ASSERT(result_tiles->size() <= 1);
if (result_tiles->size() != 0) {
PELOTON_ASSERT((*result_tiles)[0]->GetTupleCount() <= 1);
if ((*result_tiles)[0]->GetTupleCount() != 0) {
config_value = (*result_tiles)[0]->GetValue(0, 0).ToString();
auto result_tiles = this->GetResultWithSeqScan(txn, nullptr, column_ids);

std::unordered_map<std::string, std::shared_ptr<SettingsCatalogEntry>>
setting_entries;
for (auto &tile : (*result_tiles)) {
for (auto tuple_id : *tile) {
auto setting_entry =
std::make_shared<SettingsCatalogEntry>(tile.get(), tuple_id);
setting_entries.insert(
std::make_pair(setting_entry->GetName(), setting_entry));
}
}
return config_value;

return setting_entries;
}

} // namespace catalog
Expand Down
9 changes: 5 additions & 4 deletions src/codegen/code_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ void CodeContext::Compile() {
// make sure the code is verified
if (!is_verified_) Verify();

// Print some IR stats
if (settings::SettingsManager::GetBool(settings::SettingId::print_ir_stats)) {
if (settings::SettingsManager::GetInstance().GetBool(
settings::SettingId::print_ir_stats)) {
char name[] = "inst count";
InstructionCounts inst_count(*name);
inst_count.runOnModule(GetModule());
Expand All @@ -329,7 +329,8 @@ void CodeContext::Compile() {

// Log the module
LOG_TRACE("%s\n", GetIR().c_str());
if (settings::SettingsManager::GetBool(settings::SettingId::dump_ir)) {
if (settings::SettingsManager::GetInstance().GetBool(
settings::SettingId::dump_ir)) {
LOG_DEBUG("%s\n", GetIR().c_str());
}
}
Expand Down Expand Up @@ -407,4 +408,4 @@ std::string CodeContext::GetIR() const {
}

} // namespace codegen
} // namespace peloton
} // namespace peloton
2 changes: 1 addition & 1 deletion src/codegen/operator/block_nested_loop_join_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ BlockNestedLoopJoinTranslator::BlockNestedLoopJoinTranslator(
buffer_ = BufferAccessor(codegen, left_input_desc);

// Determine the number of rows to buffer before flushing it through the join
auto max_buffer_size = settings::SettingsManager::GetDouble(
auto max_buffer_size = settings::SettingsManager::GetInstance().GetDouble(
settings::SettingId::bnlj_buffer_size);
auto row_size = buffer_.GetTupleSize();
max_buf_rows_ =
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void Pipeline::MarkSource(OperatorTranslator *translator,
PELOTON_ASSERT(translator == pipeline_.back());

// Check parallel execution settings
bool parallel_exec_disabled = !settings::SettingsManager::GetBool(
bool parallel_exec_disabled = !settings::SettingsManager::GetInstance().GetBool(
settings::SettingId::parallel_execution);

// Check if the consumer supports parallel execution
Expand Down Expand Up @@ -630,4 +630,4 @@ std::string Pipeline::GetInfo() const {
}

} // namespace codegen
} // namespace peloton
} // namespace peloton
2 changes: 1 addition & 1 deletion src/codegen/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Query::Execute(executor::ExecutorContext &executor_context,
func_args->executor_context = &executor_context;
func_args->consumer_arg = consumer.GetConsumerState();

bool force_interpreter = settings::SettingsManager::GetBool(
bool force_interpreter = settings::SettingsManager::GetInstance().GetBool(
settings::SettingId::codegen_interpreter);

if (is_compiled_ && !force_interpreter) {
Expand Down
23 changes: 14 additions & 9 deletions src/common/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ namespace peloton {
ThreadPool thread_pool;

void PelotonInit::Initialize() {
CONNECTION_THREAD_COUNT = settings::SettingsManager::GetInt(
auto &settings_manager = settings::SettingsManager::GetInstance();

CONNECTION_THREAD_COUNT = settings_manager.GetInt(
settings::SettingId::connection_thread_count);
LOGGING_THREAD_COUNT = 1;
GC_THREAD_COUNT = 1;
Expand All @@ -44,7 +46,7 @@ void PelotonInit::Initialize() {
threadpool::MonoQueuePool::GetInstance().Startup();

// start indextuner thread pool
if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
if (settings_manager.GetBool(settings::SettingId::brain)) {
threadpool::MonoQueuePool::GetBrainInstance().Startup();
}

Expand All @@ -59,27 +61,28 @@ void PelotonInit::Initialize() {
concurrency::EpochManagerFactory::GetInstance().StartEpoch();

// start GC.
gc::GCManagerFactory::Configure(settings::SettingsManager::GetInt(settings::SettingId::gc_num_threads));
gc::GCManagerFactory::Configure(
settings_manager.GetInt(settings::SettingId::gc_num_threads));
gc::GCManagerFactory::GetInstance().StartGC();

// start index tuner
if (settings::SettingsManager::GetBool(settings::SettingId::index_tuner)) {
if (settings_manager.GetBool(settings::SettingId::index_tuner)) {
// Set the default visibility flag for all indexes to false
index::IndexMetadata::SetDefaultVisibleFlag(false);
auto &index_tuner = tuning::IndexTuner::GetInstance();
index_tuner.Start();
}

// start layout tuner
if (settings::SettingsManager::GetBool(settings::SettingId::layout_tuner)) {
if (settings_manager.GetBool(settings::SettingId::layout_tuner)) {
auto &layout_tuner = tuning::LayoutTuner::GetInstance();
layout_tuner.Start();
}

// Initialize catalog
auto pg_catalog = catalog::Catalog::GetInstance();
pg_catalog->Bootstrap(); // Additional catalogs
settings::SettingsManager::GetInstance().InitializeCatalog();
settings_manager.InitializeCatalog();

// begin a transaction
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
Expand All @@ -96,14 +99,16 @@ void PelotonInit::Initialize() {
}

void PelotonInit::Shutdown() {
auto &settings_manager = settings::SettingsManager::GetInstance();

// shut down index tuner
if (settings::SettingsManager::GetBool(settings::SettingId::index_tuner)) {
if (settings_manager.GetBool(settings::SettingId::index_tuner)) {
auto &index_tuner = tuning::IndexTuner::GetInstance();
index_tuner.Stop();
}

// shut down layout tuner
if (settings::SettingsManager::GetBool(settings::SettingId::layout_tuner)) {
if (settings_manager.GetBool(settings::SettingId::layout_tuner)) {
auto &layout_tuner = tuning::LayoutTuner::GetInstance();
layout_tuner.Stop();
}
Expand All @@ -121,7 +126,7 @@ void PelotonInit::Shutdown() {
threadpool::MonoQueuePool::GetInstance().Shutdown();

// stop indextuner thread pool
if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
if (settings_manager.GetBool(settings::SettingId::brain)) {
threadpool::MonoQueuePool::GetBrainInstance().Shutdown();
}

Expand Down
Loading