1
0
Fork 0

Bug fix 3.4/simran (#7883)

This commit is contained in:
Jan 2019-01-04 17:08:37 +01:00 committed by GitHub
parent adf76491b0
commit 4df4b418f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 162 additions and 21 deletions

View File

@ -1119,8 +1119,9 @@ void RestoreFeature::collectOptions(std::shared_ptr<options::ProgramOptions> opt
new UInt64Parameter(&_options.chunkSize));
options->addOption("--threads",
"maximum number of collections to process in parallel. From v3.4.0",
new UInt32Parameter(&_options.threadCount));
"maximum number of collections to process in parallel",
new UInt32Parameter(&_options.threadCount))
.setIntroducedIn(30400);
options->addOption("--include-system-collections",
"include system collections",
@ -1138,9 +1139,10 @@ void RestoreFeature::collectOptions(std::shared_ptr<options::ProgramOptions> opt
options->addOption("--input-directory", "input directory",
new StringParameter(&_options.inputPath));
options->addOption("--cleanup-duplicate-attributes", "clean up duplicate attributes in input documents instead of making the restore operation fail (since v3.3.22 and v3.4.2)",
options->addOption("--cleanup-duplicate-attributes", "clean up duplicate attributes (use first specified value) in input documents instead of making the restore operation fail",
new BooleanParameter(&_options.cleanupDuplicateAttributes),
arangodb::options::makeFlags(arangodb::options::Flags::Hidden));
arangodb::options::makeFlags(arangodb::options::Flags::Hidden))
.setIntroducedIn(30322).setIntroducedIn(30402);
options->addOption("--import-data", "import data into collection",
new BooleanParameter(&_options.importData));
@ -1155,12 +1157,14 @@ void RestoreFeature::collectOptions(std::shared_ptr<options::ProgramOptions> opt
new BooleanParameter(&_options.overwrite));
options->addOption("--number-of-shards",
"override value for numberOfShards (from v3.3.22 and v3.4.2; can be specified multiple times, e.g. --numberOfShards 2 --numberOfShards myCollection=3)",
new VectorParameter<StringParameter>(&_options.numberOfShards));
"override value for numberOfShards (can be specified multiple times, e.g. --numberOfShards 2 --numberOfShards myCollection=3)",
new VectorParameter<StringParameter>(&_options.numberOfShards))
.setIntroducedIn(30322).setIntroducedIn(30402);
options->addOption("--replication-factor",
"override value for replicationFactor (from v3.3.22 and v3.4.2; can be specified multiple times, e.g. --replicationFactor 2 --replicationFactor myCollection=3)",
new VectorParameter<StringParameter>(&_options.replicationFactor));
"override value for replicationFactor (can be specified multiple times, e.g. --replicationFactor 2 --replicationFactor myCollection=3)",
new VectorParameter<StringParameter>(&_options.replicationFactor))
.setIntroducedIn(30322).setIntroducedIn(30402);
options->addOption(
"--ignore-distribute-shards-like-errors",
@ -1173,14 +1177,16 @@ void RestoreFeature::collectOptions(std::shared_ptr<options::ProgramOptions> opt
// deprecated options
options->addOption("--default-number-of-shards",
"default value for numberOfShards if not specified in dump (deprecated since v3.3.22 and v3.4.2)",
"default value for numberOfShards if not specified in dump",
new UInt64Parameter(&_options.defaultNumberOfShards),
arangodb::options::makeFlags(arangodb::options::Flags::Hidden));
arangodb::options::makeFlags(arangodb::options::Flags::Hidden))
.setDeprecatedIn(30322).setDeprecatedIn(30402);
options->addOption("--default-replication-factor",
"default value for replicationFactor if not specified in dump (deprecated since v3.3.22 and v3.4.2)",
"default value for replicationFactor if not specified in dump",
new UInt64Parameter(&_options.defaultReplicationFactor),
arangodb::options::makeFlags(arangodb::options::Flags::Hidden));
arangodb::options::makeFlags(arangodb::options::Flags::Hidden))
.setDeprecatedIn(30322).setDeprecatedIn(30402);
}
void RestoreFeature::validateOptions(std::shared_ptr<options::ProgramOptions> options) {

View File

@ -50,6 +50,46 @@ void Option::toVPack(VPackBuilder& builder) const {
parameter->toVPack(builder);
}
// format a version string
std::string Option::toVersionString(uint32_t version) const {
if (version == 0) {
return "-";
}
std::string result("v");
// intentionally using integer division here...
result += std::to_string(version / 10000) + ".";
version -= (version / 10000) * 10000;
result += std::to_string(version / 100) + ".";
version -= (version / 100) * 100;
result += std::to_string(version);
return result;
}
// format multiple version strings
std::string Option::toVersionString(std::vector<uint32_t> const& versions) const {
std::string result;
for (auto const& it : versions) {
if (!result.empty()) {
result += ", ";
}
result += toVersionString(it);
}
return result;
}
// returns the version in which the option was introduced as a proper
// version string - if the version is unknown this will return "-"
std::string Option::introducedInString() const {
return toVersionString(introducedInVersions);
}
// returns the version in which the option was deprecated as a proper
// version string - if the version is unknown this will return "-"
std::string Option::deprecatedInString() const {
return toVersionString(deprecatedInVersions);
}
// print help for an option
// the special search string "." will show help for all sections, even if hidden
void Option::printHelp(std::string const& search, size_t tw, size_t ow, bool) const {
@ -66,6 +106,12 @@ void Option::printHelp(std::string const& search, size_t tw, size_t ow, bool) co
value.append(description);
}
value += " (default: " + parameter->valueString() + ")";
if (hasIntroducedIn()) {
value += " (introduced in " + introducedInString() + ")";
}
if (hasDeprecatedIn()) {
value += " (deprecated in " + deprecatedInString() + ")";
}
}
auto parts = wordwrap(value, tw - ow - 6);
size_t const n = parts.size();

View File

@ -67,6 +67,46 @@ struct Option {
return ((static_cast<std::underlying_type<Flags>::type>(flag) & flags) != 0);
}
// format a version string
std::string toVersionString(uint32_t version) const;
// format multiple version strings, comma-separated
std::string toVersionString(std::vector<uint32_t> const& version) const;
// specifies in which version the option was introduced. version numbers
// should be specified such as 30402 (version 3.4.2)
// a version number of 0 means "unknown"
Option& setIntroducedIn(uint32_t version) {
introducedInVersions.push_back(version);
return *this;
}
// specifies in which version the option was deprecated. version numbers
// should be specified such as 30402 (version 3.4.2)
// a version number of 0 means "unknown"
Option& setDeprecatedIn(uint32_t version) {
deprecatedInVersions.push_back(version);
return *this;
}
// returns whether or not we know in which version(s) an option was added
bool hasIntroducedIn() const {
return !introducedInVersions.empty();
}
// returns whether or not we know in which version(s) an option was added
bool hasDeprecatedIn() const {
return !deprecatedInVersions.empty();
}
// returns the version in which the option was introduced as a proper
// version string - if the version is unknown this will return "-"
std::string introducedInString() const;
// returns the version in which the option was deprecated as a proper
// version string - if the version is unknown this will return "-"
std::string deprecatedInString() const;
// get display name for the option
std::string displayName() const { return "--" + fullName(); }
@ -113,6 +153,9 @@ struct Option {
/// @brief option flags
std::underlying_type<Flags>::type const flags;
std::vector<uint32_t> introducedInVersions;
std::vector<uint32_t> deprecatedInVersions;
};
} // namespace options

View File

@ -150,6 +150,26 @@ VPackBuilder ProgramOptions::toVPack(bool onlyTouched, bool detailed,
VPackValue(section.enterpriseOnly ||
option.hasFlag(arangodb::options::Flags::Enterprise)));
builder.add("requiresValue", VPackValue(option.parameter->requiresValue()));
builder.add(VPackValue("introducedIn"));
if (option.hasIntroducedIn()) {
builder.openArray();
for (auto const& it : option.introducedInVersions) {
builder.add(VPackValue(option.toVersionString(it)));
}
builder.close();
} else {
builder.add(VPackValue(VPackValueType::Null));
}
builder.add(VPackValue("deprecatedIn"));
if (option.hasDeprecatedIn()) {
builder.openArray();
for (auto const& it : option.deprecatedInVersions) {
builder.add(VPackValue(option.toVersionString(it)));
}
builder.close();
} else {
builder.add(VPackValue(VPackValueType::Null));
}
std::string values = option.parameter->description();
if (!values.empty()) {
builder.add("values", VPackValue(values));
@ -290,6 +310,32 @@ bool ProgramOptions::requiresValue(std::string const& name) const {
return (*it2).second.parameter->requiresValue();
}
// returns the option by name. will throw if the option cannot be found
Option& ProgramOptions::getOption(std::string const& name) {
std::string stripped = name;
size_t const pos = stripped.find(',');
if (pos != std::string::npos) {
// remove shorthand
stripped = stripped.substr(0, pos);
}
auto parts = Option::splitName(stripped);
auto it = _sections.find(parts.first);
if (it == _sections.end()) {
throw std::logic_error(
std::string("option '") + stripped + "' not found");
}
auto it2 = (*it).second.options.find(parts.second);
if (it2 == (*it).second.options.end()) {
throw std::logic_error(
std::string("option '") + stripped + "' not found");
}
return (*it2).second;
}
// returns an option description
std::string ProgramOptions::getDescription(std::string const& name) {

View File

@ -117,11 +117,6 @@ class ProgramOptions {
// set context for error reporting
void setContext(std::string const& value) { _context = value; }
// sets the old options map
void setOldOptions(std::unordered_map<std::string, std::string> const& old) {
_oldOptions = old;
}
// sets a single old option and its replacement name
void addOldOption(std::string const& old, std::string const& replacement) {
_oldOptions[Option::stripPrefix(old)] = replacement;
@ -156,16 +151,18 @@ class ProgramOptions {
}
// adds an option to the program options
void addOption(std::string const& name, std::string const& description, Parameter* parameter,
std::underlying_type<Flags>::type flags = makeFlags(Flags::Normal)) {
Option& addOption(std::string const& name, std::string const& description, Parameter* parameter,
std::underlying_type<Flags>::type flags = makeFlags(Flags::Normal)) {
addOption(Option(name, description, parameter, flags));
return getOption(name);
}
// adds an obsolete and hidden option to the program options
void addObsoleteOption(std::string const& name,
std::string const& description, bool requiresValue) {
Option& addObsoleteOption(std::string const& name,
std::string const& description, bool requiresValue) {
addOption(Option(name, description, new ObsoleteParameter(requiresValue),
makeFlags(Flags::Hidden, Flags::Obsolete)));
return getOption(name);
}
// prints usage information
@ -202,6 +199,9 @@ class ProgramOptions {
// check whether or not an option requires a value
bool requiresValue(std::string const& name) const;
// returns the option by name. will throw if the option cannot be found
Option& getOption(std::string const& name);
// returns a pointer to an option value, specified by option name
// returns a nullptr if the option is unknown