Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage configuration compatibility. #3019

Merged
merged 8 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
90 changes: 72 additions & 18 deletions dbms/src/Server/StorageConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ static std::string getCanonicalPath(std::string path)
return path;
}

static String getNormalizedPath(const String & s) { return getCanonicalPath(Poco::Path{s}.toString()); }
static String getNormalizedPath(const String & s)
{
return getCanonicalPath(Poco::Path{s}.toString());
}

void TiFlashStorageConfig::parse(const String & storage, Poco::Logger * log)
void TiFlashStorageConfig::parseStoragePath(const String & storage, Poco::Logger * log)
{
std::istringstream ss(storage);
cpptoml::parser p(ss);
Expand Down Expand Up @@ -130,16 +133,30 @@ void TiFlashStorageConfig::parse(const String & storage, Poco::Logger * log)
kvstore_data_path[i] = getNormalizedPath(kvstore_data_path[i]);
LOG_INFO(log, "Raft data candidate path: " << kvstore_data_path[i]);
}
}

void TiFlashStorageConfig::parseMisc(const String & storage_section, Poco::Logger * log)
{
std::istringstream ss(storage_section);
cpptoml::parser p(ss);
auto table = p.parse();

// rate limiter
if (auto rate_limit = table->get_qualified_as<UInt64>("bg_task_io_rate_limit"); rate_limit)
bg_task_io_rate_limit = *rate_limit;
JinheLin marked this conversation as resolved.
Show resolved Hide resolved
if (table->contains("bg_task_io_rate_limit"))
{
LOG_WARNING(log, "The configuration \"bg_task_io_rate_limit\" is deprecated. Check [storage.io_rate_limit] section for new style.");
}

if (auto version = table->get_qualified_as<UInt64>("format_version"); version)
{
format_version = *version;
}

if (auto lazily_init = table->get_qualified_as<Int32>("lazily_init_store"); lazily_init)
{
lazily_init_store = (*lazily_init != 0);
}

LOG_INFO(log, fmt::format("format_version {} lazily_init_store {}", format_version, lazily_init_store));
}

Strings TiFlashStorageConfig::getAllNormalPaths() const
Expand Down Expand Up @@ -169,7 +186,8 @@ bool TiFlashStorageConfig::parseFromDeprecatedConfiguration(Poco::Util::LayeredC
Poco::trimInPlace(paths);
if (paths.empty())
throw Exception(
"The configuration \"path\" is empty! [path=" + config.getString("path") + "]", ErrorCodes::INVALID_CONFIG_PARAMETER);
"The configuration \"path\" is empty! [path=" + config.getString("path") + "]",
ErrorCodes::INVALID_CONFIG_PARAMETER);
Strings all_normal_path;
Poco::StringTokenizer string_tokens(paths, ",");
for (auto it = string_tokens.begin(); it != string_tokens.end(); it++)
Expand Down Expand Up @@ -231,15 +249,21 @@ std::tuple<size_t, TiFlashStorageConfig> TiFlashStorageConfig::parseSettings(Poc
size_t global_capacity_quota = 0; // "0" by default, means no quota, use the whole disk capacity.
TiFlashStorageConfig storage_config;

// Always try to parse storage miscellaneous configuration when [storage] section exist.
if (config.has("storage"))
{
storage_config.parse(config.getString("storage"), log);
storage_config.parseMisc(config.getString("storage"), log);
}

if (config.has("storage.main"))
{
if (config.has("path"))
LOG_WARNING(log, "The configuration \"path\" is ignored when \"storage\" is defined.");
if (config.has("capacity"))
LOG_WARNING(log, "The configuration \"capacity\" is ignored when \"storage\" is defined.");

storage_config.parseStoragePath(config.getString("storage"), log);

if (config.has("raft.kvstore_path"))
{
Strings & kvstore_paths = storage_config.kvstore_data_path;
Expand All @@ -252,8 +276,8 @@ std::tuple<size_t, TiFlashStorageConfig> TiFlashStorageConfig::parseSettings(Poc
for (size_t i = 0; i < kvstore_paths.size(); ++i)
{
LOG_WARNING(log,
"Raft data candidate path: "
<< kvstore_paths[i] << ". The path is overwritten by deprecated configuration for backward compatibility.");
"Raft data candidate path: "
<< kvstore_paths[i] << ". The path is overwritten by deprecated configuration for backward compatibility.");
}
}
}
Expand Down Expand Up @@ -315,7 +339,7 @@ void StorageIORateLimitConfig::parse(const String & storage_io_rate_limit, Poco:
readConfig("foreground_write_weight", fg_write_weight);
readConfig("background_write_weight", bg_write_weight);
readConfig("foreground_read_weight", fg_read_weight);
readConfig("background_read_weight", bg_read_weight);
readConfig("background_read_weight", bg_read_weight);
readConfig("emergency_pct", emergency_pct);
readConfig("high_pct", high_pct);
readConfig("medium_pct", medium_pct);
Expand All @@ -335,16 +359,40 @@ std::string StorageIORateLimitConfig::toString() const
"fg_write_weight {} bg_write_weight {} fg_read_weight {} bg_read_weight {} fg_write_max_bytes_per_sec {} "
"bg_write_max_bytes_per_sec {} fg_read_max_bytes_per_sec {} bg_read_max_bytes_per_sec {} emergency_pct {} high_pct {} "
"medium_pct {} tune_base {} min_bytes_per_sec {} auto_tune_sec {}",
max_bytes_per_sec, max_read_bytes_per_sec, max_write_bytes_per_sec, use_max_bytes_per_sec, fg_write_weight, bg_write_weight,
fg_read_weight, bg_read_weight, getFgWriteMaxBytesPerSec(), getBgWriteMaxBytesPerSec(), getFgReadMaxBytesPerSec(),
getBgReadMaxBytesPerSec(), emergency_pct, high_pct, medium_pct, tune_base, min_bytes_per_sec, auto_tune_sec);
max_bytes_per_sec,
max_read_bytes_per_sec,
max_write_bytes_per_sec,
use_max_bytes_per_sec,
fg_write_weight,
bg_write_weight,
fg_read_weight,
bg_read_weight,
getFgWriteMaxBytesPerSec(),
getBgWriteMaxBytesPerSec(),
getFgReadMaxBytesPerSec(),
getBgReadMaxBytesPerSec(),
emergency_pct,
high_pct,
medium_pct,
tune_base,
min_bytes_per_sec,
auto_tune_sec);
}

UInt64 StorageIORateLimitConfig::readWeight() const { return fg_read_weight + bg_read_weight; }
UInt64 StorageIORateLimitConfig::readWeight() const
{
return fg_read_weight + bg_read_weight;
}

UInt64 StorageIORateLimitConfig::writeWeight() const { return fg_write_weight + bg_write_weight; }
UInt64 StorageIORateLimitConfig::writeWeight() const
{
return fg_write_weight + bg_write_weight;
}

UInt64 StorageIORateLimitConfig::totalWeight() const { return readWeight() + writeWeight(); }
UInt64 StorageIORateLimitConfig::totalWeight() const
{
return readWeight() + writeWeight();
}

UInt64 StorageIORateLimitConfig::getFgWriteMaxBytesPerSec() const
{
Expand Down Expand Up @@ -386,9 +434,15 @@ UInt64 StorageIORateLimitConfig::getBgReadMaxBytesPerSec() const
: max_read_bytes_per_sec / readWeight() * bg_read_weight;
}

UInt64 StorageIORateLimitConfig::getWriteMaxBytesPerSec() const { return getBgWriteMaxBytesPerSec() + getFgWriteMaxBytesPerSec(); }
UInt64 StorageIORateLimitConfig::getWriteMaxBytesPerSec() const
{
return getBgWriteMaxBytesPerSec() + getFgWriteMaxBytesPerSec();
}

UInt64 StorageIORateLimitConfig::getReadMaxBytesPerSec() const { return getBgReadMaxBytesPerSec() + getFgReadMaxBytesPerSec(); }
UInt64 StorageIORateLimitConfig::getReadMaxBytesPerSec() const
{
return getBgReadMaxBytesPerSec() + getFgReadMaxBytesPerSec();
}

bool StorageIORateLimitConfig::operator==(const StorageIORateLimitConfig & config) const
{
Expand Down
35 changes: 18 additions & 17 deletions dbms/src/Server/StorageConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class LayeredConfiguration;

namespace DB
{

struct StorageIORateLimitConfig
{
public:
Expand Down Expand Up @@ -46,20 +45,20 @@ struct StorageIORateLimitConfig
Int32 auto_tune_sec;

StorageIORateLimitConfig()
: max_bytes_per_sec(0),
max_read_bytes_per_sec(0),
max_write_bytes_per_sec(0),
use_max_bytes_per_sec(true),
fg_write_weight(25),
bg_write_weight(25),
fg_read_weight(25),
bg_read_weight(25),
emergency_pct(96),
high_pct(85),
medium_pct(60),
tune_base(2),
min_bytes_per_sec(2 * 1024 * 1024),
auto_tune_sec(5)
: max_bytes_per_sec(0)
, max_read_bytes_per_sec(0)
, max_write_bytes_per_sec(0)
, use_max_bytes_per_sec(true)
, fg_write_weight(25)
, bg_write_weight(25)
, fg_read_weight(25)
, bg_read_weight(25)
, emergency_pct(96)
, high_pct(85)
, medium_pct(60)
, tune_base(2)
, min_bytes_per_sec(2 * 1024 * 1024)
, auto_tune_sec(5)
{}

void parse(const String & storage_io_rate_limit, Poco::Logger * log);
Expand Down Expand Up @@ -88,9 +87,9 @@ struct TiFlashStorageConfig
std::vector<size_t> latest_capacity_quota;
Strings kvstore_data_path;

UInt64 bg_task_io_rate_limit = 0;
UInt64 format_version = 0;
bool lazily_init_store = true;

public:
TiFlashStorageConfig() {}

Expand All @@ -99,9 +98,11 @@ struct TiFlashStorageConfig
static std::tuple<size_t, TiFlashStorageConfig> parseSettings(Poco::Util::LayeredConfiguration & config, Poco::Logger * log);

private:
void parse(const String & storage_section, Poco::Logger * log);
void parseStoragePath(const String & storage_section, Poco::Logger * log);

bool parseFromDeprecatedConfiguration(Poco::Util::LayeredConfiguration & config, Poco::Logger * log);

void parseMisc(const String & config, Poco::Logger * log);
};


Expand Down
Loading