in utils/kvrocks2redis/config.cc [53:116]
Status Config::parseConfigFromString(const std::string &input) {
auto [original_key, value] = GET_OR_RET(ParseConfigLine(input));
if (original_key.empty()) return Status::OK();
std::vector<std::string> args = util::Split(value, " \t\r\n");
auto key = util::ToLower(original_key);
size_t size = args.size();
if (size == 1 && key == "daemonize") {
daemonize = GET_OR_RET(yesnotoi(args[0]).Prefixed("key 'daemonize'"));
} else if (size == 1 && key == "data-dir") {
data_dir = args[0];
if (data_dir.empty()) {
return {Status::NotOK, "'data-dir' was not specified"};
}
if (data_dir.back() != '/') {
data_dir += "/";
}
db_dir = data_dir + "db";
} else if (size == 1 && key == "output-dir") {
output_dir = args[0];
if (output_dir.empty()) {
return {Status::NotOK, "'output-dir' was not specified"};
}
if (output_dir.back() != '/') {
output_dir += "/";
}
pidfile = output_dir + "kvrocks2redis.pid";
next_seq_file_path = output_dir + "last_next_seq.txt";
} else if (size == 1 && key == "log-level") {
for (size_t i = 0; i < kNumLogLevel; i++) {
if (util::ToLower(args[0]) == kLogLevels[i]) {
loglevel = kLogLevelVals[i];
break;
}
}
} else if (size == 1 && key == "pidfile") {
pidfile = args[0];
} else if (size == 1 && key == "cluster-enable") {
// Renamed to cluster-enabled, keeping the old one for compatibility.
cluster_enabled = GET_OR_RET(yesnotoi(args[0]).Prefixed("key 'cluster-enable'"));
} else if (size == 1 && key == "cluster-enabled") {
cluster_enabled = GET_OR_RET(yesnotoi(args[0]).Prefixed("key 'cluster-enabled'"));
} else if (size >= 2 && strncasecmp(key.data(), "namespace.", 10) == 0) {
std::string ns = original_key.substr(10);
if (ns.size() > INT8_MAX) {
return {Status::NotOK, fmt::format("namespace size exceed limit {}", INT8_MAX)};
}
tokens[ns].host = args[0];
tokens[ns].port = GET_OR_RET(ParseInt<std::uint16_t>(args[1]).Prefixed("kvrocks port number"));
if (size >= 3) {
tokens[ns].auth = args[2];
}
tokens[ns].db_number = size == 4 ? std::atoi(args[3].c_str()) : 0;
} else {
return {Status::NotOK, "unknown configuration directive or wrong number of arguments"};
}
return Status::OK();
}