| 361 | } |
| 362 | |
| 363 | ConfigurationResult buildConfiguration(std::vector<StringRef> const& modeTokens, |
| 364 | std::map<std::string, std::string>& outConf) { |
| 365 | for (auto it : modeTokens) { |
| 366 | std::string mode = it.toString(); |
| 367 | auto m = configForToken(mode); |
| 368 | if (!m.size()) { |
| 369 | TraceEvent(SevWarnAlways, "UnknownOption").detail("Option", mode); |
| 370 | return ConfigurationResult::UNKNOWN_OPTION; |
| 371 | } |
| 372 | |
| 373 | for (auto t = m.begin(); t != m.end(); ++t) { |
| 374 | if (outConf.count(t->first)) { |
| 375 | TraceEvent(SevWarnAlways, "ConflictingOption").detail("Option", t->first); |
| 376 | return ConfigurationResult::CONFLICTING_OPTIONS; |
| 377 | } |
| 378 | outConf[t->first] = t->second; |
| 379 | } |
| 380 | } |
| 381 | auto p = configKeysPrefix.toString(); |
| 382 | if (!outConf.count(p + "storage_replication_policy") && outConf.count(p + "storage_replicas")) { |
| 383 | int storageCount = stoi(outConf[p + "storage_replicas"]); |
| 384 | Reference<IReplicationPolicy> storagePolicy = Reference<IReplicationPolicy>( |
| 385 | new PolicyAcross(storageCount, "zoneid", Reference<IReplicationPolicy>(new PolicyOne()))); |
| 386 | BinaryWriter policyWriter(IncludeVersion(ProtocolVersion::withReplicationPolicy())); |
| 387 | serializeReplicationPolicy(policyWriter, storagePolicy); |
| 388 | outConf[p + "storage_replication_policy"] = policyWriter.toValue().toString(); |
| 389 | } |
| 390 | |
| 391 | if (!outConf.count(p + "log_replication_policy") && outConf.count(p + "log_replicas")) { |
| 392 | int logCount = stoi(outConf[p + "log_replicas"]); |
| 393 | Reference<IReplicationPolicy> logPolicy = Reference<IReplicationPolicy>( |
| 394 | new PolicyAcross(logCount, "zoneid", Reference<IReplicationPolicy>(new PolicyOne()))); |
| 395 | BinaryWriter policyWriter(IncludeVersion(ProtocolVersion::withReplicationPolicy())); |
| 396 | serializeReplicationPolicy(policyWriter, logPolicy); |
| 397 | outConf[p + "log_replication_policy"] = policyWriter.toValue().toString(); |
| 398 | } |
| 399 | if (outConf.count(p + "istss")) { |
| 400 | // redo config parameters to be tss config instead of normal config |
| 401 | |
| 402 | // save param values from parsing as a normal config |
| 403 | bool isNew = outConf.count(p + "initialized"); |
| 404 | Optional<std::string> count; |
| 405 | Optional<std::string> storageEngine; |
| 406 | if (outConf.count(p + "count")) { |
| 407 | count = Optional<std::string>(outConf[p + "count"]); |
| 408 | } |
| 409 | if (outConf.count(p + "storage_engine")) { |
| 410 | storageEngine = Optional<std::string>(outConf[p + "storage_engine"]); |
| 411 | } |
| 412 | |
| 413 | // A new tss setup must have count + storage engine. An adjustment must have at least one. |
| 414 | if ((isNew && (!count.present() || !storageEngine.present())) || |
| 415 | (!isNew && !count.present() && !storageEngine.present())) { |
| 416 | return ConfigurationResult::INCOMPLETE_CONFIGURATION; |
| 417 | } |
| 418 | |
| 419 | // clear map and only reset tss parameters |
| 420 | outConf.clear(); |
no test coverage detected