Skip to content

Commit

Permalink
[YSQL] yb-admin create_database_snapshot should not require ysql pref…
Browse files Browse the repository at this point in the history
…ix for database name (#4991)

Summary:
Adding option to specify default db type in ParseNamespaceName
 - if there is a prefix then we still respect it, otherwise default to `default_if_no_prefix`

Test Plan:
Running
```
yb-admin -master_addresses 127.0.0.1:7100 create_database_snapshot test
```
Should no longer produce any errors about wrong database types.

Reviewers: neha

Reviewed By: neha

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D8858
  • Loading branch information
hulien22 committed Jul 27, 2020
1 parent ec32889 commit 4cb2cc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion ent/src/yb/tools/yb-admin_cli_ent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ void ClusterAdminCli::RegisterCommandHandlers(ClusterAdminClientClass* client) {
return ClusterAdminCli::kInvalidArguments;
}

const TypedNamespaceName database = VERIFY_RESULT(ParseNamespaceName(args[2]));
const TypedNamespaceName database =
VERIFY_RESULT(ParseNamespaceName(args[2], YQL_DATABASE_PGSQL));
SCHECK_EQ(
database.db_type, YQL_DATABASE_PGSQL, InvalidArgument,
Format("Wrong database type: $0", YQLDatabase_Name(database.db_type)));
Expand Down
12 changes: 8 additions & 4 deletions src/yb/tools/yb-admin_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ const char* DatabasePrefix(YQLDatabase db) {
return kDBTypePrefixUnknown;
}

Result<TypedNamespaceName> ResolveNamespaceName(const Slice& prefix, const Slice& name) {
Result<TypedNamespaceName> ResolveNamespaceName(
const Slice& prefix,
const Slice& name,
const YQLDatabase default_if_no_prefix = YQL_DATABASE_CQL) {
auto db_type = YQL_DATABASE_UNKNOWN;
if (!prefix.empty()) {
static const std::array<pair<const char*, YQLDatabase>, 3> type_prefixes{
Expand All @@ -209,7 +212,7 @@ Result<TypedNamespaceName> ResolveNamespaceName(const Slice& prefix, const Slice
return STATUS_FORMAT(InvalidArgument, "Invalid db type name '$0'", prefix);
}
} else {
db_type = (name == common::kRedisKeyspaceName ? YQL_DATABASE_REDIS : YQL_DATABASE_CQL);
db_type = (name == common::kRedisKeyspaceName ? YQL_DATABASE_REDIS : default_if_no_prefix);
}
return TypedNamespaceName{.db_type = db_type, .name = name.cdata()};
}
Expand Down Expand Up @@ -1748,9 +1751,10 @@ string RightPadToUuidWidth(const string &s) {
return RightPadToWidth(s, kNumCharactersInUuid);
}

Result<TypedNamespaceName> ParseNamespaceName(const std::string& full_namespace_name) {
Result<TypedNamespaceName> ParseNamespaceName(const std::string& full_namespace_name,
const YQLDatabase default_if_no_prefix) {
const auto parts = SplitByDot(full_namespace_name);
return ResolveNamespaceName(parts.prefix, parts.value);
return ResolveNamespaceName(parts.prefix, parts.value, default_if_no_prefix);
}

} // namespace tools
Expand Down
4 changes: 3 additions & 1 deletion src/yb/tools/yb-admin_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ static constexpr const char* kColumnSep = " \t";

std::string RightPadToUuidWidth(const std::string &s);

Result<TypedNamespaceName> ParseNamespaceName(const std::string& full_namespace_name);
Result<TypedNamespaceName> ParseNamespaceName(
const std::string& full_namespace_name,
const YQLDatabase default_if_no_prefix = YQL_DATABASE_CQL);

} // namespace tools
} // namespace yb
Expand Down

0 comments on commit 4cb2cc2

Please sign in to comment.