From 1a97bacc3204adbf01b2580a2cfa2bb87271defa Mon Sep 17 00:00:00 2001 From: LingBin Date: Sun, 24 Nov 2019 19:32:41 -0600 Subject: [PATCH] Replace boost::split() with strings::Split() in storage options (#2277) --- be/src/olap/options.cpp | 75 ++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/be/src/olap/options.cpp b/be/src/olap/options.cpp index 58f1ae1aa4..8717ae30d1 100644 --- a/be/src/olap/options.cpp +++ b/be/src/olap/options.cpp @@ -17,26 +17,35 @@ #include "olap/options.h" -#include -#include -#include +#include #include "common/logging.h" - #include "olap/utils.h" +#include "gutil/strings/split.h" + namespace doris { +static std::string CAPACITY_UC = "CAPACITY"; +static std::string MEDIUM_UC = "MEDIUM"; +static std::string SSD_UC = "SSD"; +static std::string HDD_UC = "HDD"; + +// TODO: should be a general util method +std::string to_upper(const std::string& str) { + std::string out = str; + std::transform(out.begin(), out.end(), out.begin(), ::toupper); + return out; +} + // compatible with old multi path configuration: -// /path1,2014;/path2,2048 +// /path1,1024;/path2,2048 OLAPStatus parse_root_path(const std::string& root_path, StorePath* path) { try { - std::vector tmp_vec; - boost::split(tmp_vec, root_path, boost::is_any_of(","), - boost::token_compress_on); + std::vector tmp_vec = strings::Split(root_path, ",", strings::SkipWhitespace()); // parse root path name - boost::trim(tmp_vec[0]); + StripWhiteSpace(&tmp_vec[0]); tmp_vec[0].erase(tmp_vec[0].find_last_not_of("/") + 1); if (tmp_vec[0].empty() || tmp_vec[0][0] != '/') { LOG(WARNING) << "invalid store path. path=" << tmp_vec[0]; @@ -45,33 +54,38 @@ OLAPStatus parse_root_path(const std::string& root_path, StorePath* path) { path->path = tmp_vec[0]; // parse root path capacity and storage medium - std::string capacity_str, medium_str; + std::string capacity_str; + std::string medium_str; boost::filesystem::path boost_path = tmp_vec[0]; - std::string extension = - boost::filesystem::canonical(boost_path).extension().string(); + std::string extension = boost::filesystem::canonical(boost_path).extension().string(); if (!extension.empty()) { - medium_str = extension.substr(1); + medium_str = to_upper(extension.substr(1)); } for (int i = 1; i < tmp_vec.size(); i++) { // : or - std::string property, value; - std::size_t found = tmp_vec[i].find(':'); - if (found != std::string::npos) { - property = boost::trim_copy(tmp_vec[i].substr(0, found)); - value = boost::trim_copy(tmp_vec[i].substr(found + 1)); + std::string property; + std::string value; + std::pair pair = strings::Split( + tmp_vec[i], strings::delimiter::Limit(":", 1)); + if (!pair.second.empty()) { + property = to_upper(pair.first); + value = pair.second; } else { // only supports setting capacity - property = "capacity"; - value = boost::trim_copy(tmp_vec[i]); + property = CAPACITY_UC; + value = tmp_vec[i]; } - if (boost::iequals(property, "capacity")) { + + StripWhiteSpace(&property); + StripWhiteSpace(&value); + if (property == CAPACITY_UC) { capacity_str = value; - } else if (boost::iequals(property, "medium")) { + } else if (property == MEDIUM_UC) { // property 'medium' has a higher priority than the extension of // path, so it can override medium_str - medium_str = value; + medium_str = to_upper(value); } else { LOG(WARNING) << "invalid property of store path, " << property; return OLAP_ERR_INPUT_PARAMETER_ERROR; @@ -80,8 +94,8 @@ OLAPStatus parse_root_path(const std::string& root_path, StorePath* path) { path->capacity_bytes = -1; if (!capacity_str.empty()) { - if (!valid_signed_number(capacity_str) || - strtol(capacity_str.c_str(), NULL, 10) < 0) { + if (!valid_signed_number(capacity_str) + || strtol(capacity_str.c_str(), NULL, 10) < 0) { LOG(WARNING) << "invalid capacity of store path, capacity=" << capacity_str; return OLAP_ERR_INPUT_PARAMETER_ERROR; @@ -92,9 +106,9 @@ OLAPStatus parse_root_path(const std::string& root_path, StorePath* path) { path->storage_medium = TStorageMedium::HDD; if (!medium_str.empty()) { - if (boost::iequals(medium_str, "ssd")) { + if (medium_str == SSD_UC) { path->storage_medium = TStorageMedium::SSD; - } else if (boost::iequals(medium_str, "hdd")) { + } else if (medium_str == HDD_UC) { path->storage_medium = TStorageMedium::HDD; } else { LOG(WARNING) << "invalid storage medium. medium=" << medium_str; @@ -112,10 +126,9 @@ OLAPStatus parse_root_path(const std::string& root_path, StorePath* path) { OLAPStatus parse_conf_store_paths(const std::string& config_path, std::vector* paths) { try { - std::vector item_vec; - boost::split(item_vec, config_path, boost::is_any_of(";"), - boost::token_compress_on); - for (auto& item : item_vec) { + std::vector path_vec = strings::Split( + config_path, ";", strings::SkipWhitespace()); + for (auto& item : path_vec) { StorePath path; auto res = parse_root_path(item, &path); if (res != OLAP_SUCCESS) {