Skip to content

Commit

Permalink
support force update configs in console
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Dec 10, 2019
1 parent fdf8612 commit 940e7aa
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 49 deletions.
3 changes: 2 additions & 1 deletion share/resources/gflags.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"v",
"heartbeat_interval_secs",
"meta_client_retry_times",
"slow_op_threshhold_ms"
"slow_op_threshhold_ms",
"wal_ttl"
],
"IGNORED": [
"logging",
Expand Down
3 changes: 2 additions & 1 deletion src/graph/ConfigExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ void ConfigExecutor::setVariables() {
return;
}

auto future = ectx()->gflagsManager()->setConfig(module, name, type, value);
bool isForce = sentence_->isForce();
auto future = ectx()->gflagsManager()->setConfig(module, name, type, value, isForce);
auto *runner = ectx()->rctx()->runner();

auto cb = [this] (auto && resp) {
Expand Down
1 change: 1 addition & 0 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ struct GetConfigResp {

struct SetConfigReq {
1: ConfigItem item,
2: bool force,
}

struct ListConfigsReq {
Expand Down
21 changes: 12 additions & 9 deletions src/meta/ClientBasedGflagsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,37 @@ template<typename ValueType>
folly::Future<StatusOr<bool>> ClientBasedGflagsManager::set(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const ValueType& value) {
const ValueType& value,
const bool isForce) {
std::string valueStr;
valueStr.append(reinterpret_cast<const char*>(&value), sizeof(value));
return metaClient_->setConfig(module, name, type, std::move(valueStr));
return metaClient_->setConfig(module, name, type, std::move(valueStr), isForce);
}

template<>
folly::Future<StatusOr<bool>>
ClientBasedGflagsManager::set<std::string>(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const std::string& value) {
return metaClient_->setConfig(module, name, type, value);
const std::string& value,
const bool isForce) {
return metaClient_->setConfig(module, name, type, value, isForce);
}

folly::Future<StatusOr<bool>>
ClientBasedGflagsManager::setConfig(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const VariantType &value) {
const cpp2::ConfigType& type, const VariantType &value,
const bool isForce) {
switch (type) {
case cpp2::ConfigType::INT64:
return set(module, name, type, boost::get<int64_t>(value));
return set(module, name, type, boost::get<int64_t>(value), isForce);
case cpp2::ConfigType::DOUBLE:
return set(module, name, type, boost::get<double>(value));
return set(module, name, type, boost::get<double>(value), isForce);
case cpp2::ConfigType::BOOL:
return set(module, name, type, boost::get<bool>(value));
return set(module, name, type, boost::get<bool>(value), isForce);
case cpp2::ConfigType::STRING:
case cpp2::ConfigType::NESTED:
return set(module, name, type, boost::get<std::string>(value));
return set(module, name, type, boost::get<std::string>(value), isForce);
default:
return Status::Error("parse value type error");
}
Expand Down
6 changes: 4 additions & 2 deletions src/meta/ClientBasedGflagsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class ClientBasedGflagsManager : public GflagsManager {
folly::Future<StatusOr<bool>> setConfig(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const VariantType& value) override;
const VariantType& value,
const bool isForce = false) override;

folly::Future<StatusOr<std::vector<cpp2::ConfigItem>>>
getConfig(const cpp2::ConfigModule& module, const std::string& name) override;
Expand All @@ -36,7 +37,8 @@ class ClientBasedGflagsManager : public GflagsManager {
private:
template<typename ValueType>
folly::Future<StatusOr<bool>> set(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const ValueType& value);
const cpp2::ConfigType& type, const ValueType& value,
const bool isForce);

MetaClient *metaClient_{nullptr};
};
Expand Down
3 changes: 2 additions & 1 deletion src/meta/GflagsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class GflagsManager {
virtual folly::Future<StatusOr<bool>> setConfig(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const VariantType& value) = 0;
const VariantType& value,
const bool isForce) = 0;

virtual folly::Future<StatusOr<std::vector<cpp2::ConfigItem>>>
getConfig(const cpp2::ConfigModule& module, const std::string& name) = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/meta/KVBasedGflagsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Status KVBasedGflagsManager::init() {

folly::Future<StatusOr<bool>>
KVBasedGflagsManager::setConfig(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const VariantType &value) {
UNUSED(module); UNUSED(name); UNUSED(type); UNUSED(value);
const cpp2::ConfigType& type, const VariantType &value,
const bool isForce) {
UNUSED(module); UNUSED(name); UNUSED(type); UNUSED(value); UNUSED(isForce);
LOG(FATAL) << "Unimplement!";
return Status::NotSupported();
}
Expand Down
3 changes: 2 additions & 1 deletion src/meta/KVBasedGflagsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class KVBasedGflagsManager : public GflagsManager {
folly::Future<StatusOr<bool>> setConfig(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const VariantType& value) override;
const VariantType& value,
const bool isForce) override;

folly::Future<StatusOr<std::vector<cpp2::ConfigItem>>>
getConfig(const cpp2::ConfigModule& module, const std::string& name) override;
Expand Down
9 changes: 3 additions & 6 deletions src/meta/client/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,19 +1325,20 @@ MetaClient::getConfig(const cpp2::ConfigModule& module, const std::string& name)

folly::Future<StatusOr<bool>>
MetaClient::setConfig(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const std::string& value) {
const cpp2::ConfigType& type, const std::string& value,
const bool isForce) {
if (!configReady_) {
return Status::Error("Not ready!");
}
cpp2::ConfigItem item;
item.set_module(module);
item.set_name(name);
item.set_type(type);
item.set_mode(cpp2::ConfigMode::MUTABLE);
item.set_value(value);

cpp2::SetConfigReq req;
req.set_item(item);
req.set_force(isForce);
folly::Promise<StatusOr<bool>> promise;
auto future = promise.getFuture();
getResponse(std::move(req), [] (auto client, auto request) {
Expand Down Expand Up @@ -1459,10 +1460,6 @@ void MetaClient::addLoadCfgTask() {
}

void MetaClient::updateGflagsValue(const ConfigItem& item) {
if (item.mode_ != cpp2::ConfigMode::MUTABLE) {
return;
}

std::string metaValue;
switch (item.type_) {
case cpp2::ConfigType::INT64:
Expand Down
2 changes: 1 addition & 1 deletion src/meta/client/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class MetaClient {

folly::Future<StatusOr<bool>>
setConfig(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const std::string& value);
const cpp2::ConfigType& type, const std::string& value, const bool isForce);

folly::Future<StatusOr<std::vector<cpp2::ConfigItem>>>
listConfigs(const cpp2::ConfigModule& module);
Expand Down
37 changes: 19 additions & 18 deletions src/meta/processors/configMan/SetConfigProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void SetConfigProcessor::process(const cpp2::SetConfigReq& req) {
auto module = req.get_item().get_module();
auto name = req.get_item().get_name();
auto type = req.get_item().get_type();
auto mode = req.get_item().get_mode();
auto value = req.get_item().get_value();
auto isForce = req.get_force();

folly::SharedMutex::WriteHolder wHolder(LockUtils::configLock());
cpp2::ErrorCode code = cpp2::ErrorCode::SUCCEEDED;
Expand All @@ -57,21 +57,21 @@ void SetConfigProcessor::process(const cpp2::SetConfigReq& req) {
if (module != cpp2::ConfigModule::ALL) {
// When we set config of a specified module, check if it exists.
// If it exists and is mutable, update it.
code = setOneConfig(module, name, type, mode, value, data);
code = setOneConfig(module, name, type, value, isForce, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
} else {
// When we set config of all module, then try to set it of every module.
code = setOneConfig(cpp2::ConfigModule::GRAPH, name, type, mode, value, data);
code = setOneConfig(cpp2::ConfigModule::GRAPH, name, type, value, isForce, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
code = setOneConfig(cpp2::ConfigModule::META, name, type, mode, value, data);
code = setOneConfig(cpp2::ConfigModule::META, name, type, value, isForce, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
code = setOneConfig(cpp2::ConfigModule::STORAGE, name, type, mode, value, data);
code = setOneConfig(cpp2::ConfigModule::STORAGE, name, type, value, isForce, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
Expand All @@ -80,20 +80,20 @@ void SetConfigProcessor::process(const cpp2::SetConfigReq& req) {
// For those nested options like FLAGS_rocksdb_db_options, if any field has changed,
// we update them and put it back
if (module != cpp2::ConfigModule::ALL) {
code = setNestedConfig(module, name, type, mode, value, data);
code = setNestedConfig(module, name, type, value, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
} else {
code = setNestedConfig(cpp2::ConfigModule::GRAPH, name, type, mode, value, data);
code = setNestedConfig(cpp2::ConfigModule::GRAPH, name, type, value, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
code = setNestedConfig(cpp2::ConfigModule::META, name, type, mode, value, data);
code = setNestedConfig(cpp2::ConfigModule::META, name, type, value, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
code = setNestedConfig(cpp2::ConfigModule::STORAGE, name, type, mode, value, data);
code = setNestedConfig(cpp2::ConfigModule::STORAGE, name, type, value, data);
if (code != cpp2::ErrorCode::SUCCEEDED) {
break;
}
Expand All @@ -113,8 +113,8 @@ void SetConfigProcessor::process(const cpp2::SetConfigReq& req) {
cpp2::ErrorCode SetConfigProcessor::setOneConfig(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const cpp2::ConfigMode& mode,
const std::string& value,
const bool isForce,
std::vector<kvstore::KV>& data) {
std::string configKey = MetaServiceUtils::configKey(module, name);
auto ret = doGet(std::move(configKey));
Expand All @@ -123,33 +123,34 @@ cpp2::ErrorCode SetConfigProcessor::setOneConfig(const cpp2::ConfigModule& modul
}

cpp2::ConfigItem item = MetaServiceUtils::parseConfigValue(ret.value());
if (item.get_mode() == cpp2::ConfigMode::IMMUTABLE) {
cpp2::ConfigMode curMode = item.get_mode();
if (curMode == cpp2::ConfigMode::IMMUTABLE && !isForce) {
return cpp2::ErrorCode::E_CONFIG_IMMUTABLE;
}
std::string configValue = MetaServiceUtils::configValue(type, mode, value);
std::string configValue = MetaServiceUtils::configValue(type, curMode, value);
data.emplace_back(std::move(configKey), std::move(configValue));
return cpp2::ErrorCode::SUCCEEDED;
}

cpp2::ErrorCode SetConfigProcessor::setNestedConfig(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const cpp2::ConfigMode& mode,
const std::string& updateList,
std::vector<kvstore::KV>& data) {
std::vector<kvstore::KV>& data) {
std::string configKey = MetaServiceUtils::configKey(module, name);
auto ret = doGet(std::move(configKey));
if (!ret.ok()) {
return cpp2::ErrorCode::E_NOT_FOUND;
}

cpp2::ConfigItem current = MetaServiceUtils::parseConfigValue(ret.value());
if (current.get_mode() == cpp2::ConfigMode::IMMUTABLE) {
cpp2::ConfigItem item = MetaServiceUtils::parseConfigValue(ret.value());
cpp2::ConfigMode curMode = item.get_mode();
if (curMode == cpp2::ConfigMode::IMMUTABLE) {
return cpp2::ErrorCode::E_CONFIG_IMMUTABLE;
}

Configuration conf;
auto confRet = conf.parseFromString(current.get_value());
auto confRet = conf.parseFromString(item.get_value());
CHECK(confRet.ok());

std::vector<std::string> updateFields;
Expand All @@ -173,7 +174,7 @@ cpp2::ErrorCode SetConfigProcessor::setNestedConfig(const cpp2::ConfigModule& mo
}

if (updated) {
std::string configValue = MetaServiceUtils::configValue(type, mode, conf.dumpToString());
std::string configValue = MetaServiceUtils::configValue(type, curMode, conf.dumpToString());
data.emplace_back(std::move(configKey), std::move(configValue));
}
return cpp2::ErrorCode::SUCCEEDED;
Expand Down
8 changes: 4 additions & 4 deletions src/meta/processors/configMan/SetConfigProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class SetConfigProcessor : public BaseProcessor<cpp2::ExecResp> {
void process(const cpp2::SetConfigReq& req);

cpp2::ErrorCode setOneConfig(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const cpp2::ConfigMode& mode,
const std::string& value, std::vector<kvstore::KV>& data);
const cpp2::ConfigType& type, const std::string& value,
const bool isForce, std::vector<kvstore::KV>& data);

cpp2::ErrorCode setNestedConfig(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const cpp2::ConfigMode& mode,
const std::string& value, std::vector<kvstore::KV>& data);
const cpp2::ConfigType& type, const std::string& value,
std::vector<kvstore::KV>& data);

private:
explicit SetConfigProcessor(kvstore::KVStore* kvstore)
Expand Down
8 changes: 7 additions & 1 deletion src/parser/AdminSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ class ConfigSentence final : public Sentence {
subType_ = std::move(subType);
}

ConfigSentence(SubType subType, ConfigRowItem* item) {
ConfigSentence(SubType subType, ConfigRowItem* item, bool force = false) {
kind_ = Kind::kConfig;
subType_ = std::move(subType);
configItem_.reset(item);
isForce_ = force;
}

std::string toString() const override;
Expand All @@ -300,8 +301,13 @@ class ConfigSentence final : public Sentence {
return configItem_.get();
}

bool isForce() {
return isForce_;
}

private:
SubType subType_{SubType::kUnknown};
bool isForce_{false};
std::unique_ptr<ConfigRowItem> configItem_;
};

Expand Down
7 changes: 5 additions & 2 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class GraphScanner;
%token KW_IF KW_NOT KW_EXISTS KW_WITH KW_FIRSTNAME KW_LASTNAME KW_EMAIL KW_PHONE KW_USER KW_USERS
%token KW_PASSWORD KW_CHANGE KW_ROLE KW_GOD KW_ADMIN KW_GUEST KW_GRANT KW_REVOKE KW_ON
%token KW_ROLES KW_BY KW_DOWNLOAD KW_HDFS
%token KW_CONFIGS KW_GET KW_DECLARE KW_GRAPH KW_META KW_STORAGE
%token KW_CONFIGS KW_GET KW_DECLARE KW_GRAPH KW_META KW_STORAGE KW_FORCE
%token KW_TTL_DURATION KW_TTL_COL KW_DEFAULT
%token KW_ORDER KW_ASC KW_LIMIT KW_OFFSET KW_GROUP
%token KW_COUNT KW_COUNT_DISTINCT KW_SUM KW_AVG KW_MAX KW_MIN KW_STD KW_BIT_AND KW_BIT_OR KW_BIT_XOR
Expand Down Expand Up @@ -1683,9 +1683,12 @@ get_config_sentence
;

set_config_sentence
: KW_UPDATE KW_CONFIGS set_config_item {
: KW_UPDATE KW_CONFIGS set_config_item {
$$ = new ConfigSentence(ConfigSentence::SubType::kSet, $3);
}
| KW_UPDATE KW_CONFIGS set_config_item KW_FORCE {
$$ = new ConfigSentence(ConfigSentence::SubType::kSet, $3, true);
}
;

host_list
Expand Down
2 changes: 2 additions & 0 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ IS ([Ii][Ss])
NULL ([Nn][Uu][Ll][Ll])
SNAPSHOT ([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])
SNAPSHOTS ([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt][Ss])
FORCE ([Ff][Oo][Rr][Cc][Ee])

LABEL ([a-zA-Z][_a-zA-Z0-9]*)
DEC ([0-9])
Expand Down Expand Up @@ -274,6 +275,7 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
{NULL} { return TokenType::KW_NULL; }
{SNAPSHOT} { return TokenType::KW_SNAPSHOT; }
{SNAPSHOTS} { return TokenType::KW_SNAPSHOTS; }
{FORCE} { return TokenType::KW_FORCE; }

"." { return TokenType::DOT; }
"," { return TokenType::COMMA; }
Expand Down

0 comments on commit 940e7aa

Please sign in to comment.