Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a custom placement policy per table through yb-admin_cl… #5368

Merged
merged 4 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/yb/client/client-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,9 @@ void GetTableSchemaRpc::Finished(const Status& status) {
if (resp_.has_index_info()) {
info_->index_info.emplace(resp_.index_info());
}
if (resp_.has_replication_info()) {
info_->replication_info.emplace(resp_.replication_info());
}
CHECK_GT(info_->table_id.size(), 0) << "Running against a too-old master";
info_->colocated = resp_.colocated();
}
Expand Down
4 changes: 4 additions & 0 deletions src/yb/client/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ const bool YBTable::colocated() const {
return info_.colocated;
}

const boost::optional<master::ReplicationInfoPB>& YBTable::replication_info() const {
return info_.replication_info;
}

std::string YBTable::ToString() const {
return strings::Substitute(
"$0 $1 IndexInfo: $2 IndexMap $3", (IsIndex() ? "Index Table" : "Normal Table"), id(),
Expand Down
4 changes: 4 additions & 0 deletions src/yb/client/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct YBTableInfo {
boost::optional<IndexInfo> index_info;
YBTableType table_type;
bool colocated;
boost::optional<master::ReplicationInfoPB> replication_info;
};

// A YBTable represents a table on a particular cluster. It holds the current
Expand Down Expand Up @@ -101,6 +102,9 @@ class YBTable : public std::enable_shared_from_this<YBTable> {
// Is the table colocated?
const bool colocated() const;

// Returns the replication info for the table.
const boost::optional<master::ReplicationInfoPB>& replication_info() const;

std::string ToString() const;
//------------------------------------------------------------------------------------------------
// CQL support
Expand Down
13 changes: 12 additions & 1 deletion src/yb/client/table_alterer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ YBTableAlterer* YBTableAlterer::SetTableProperties(const TableProperties& table_
return this;
}

YBTableAlterer* YBTableAlterer::replication_info(const master::ReplicationInfoPB& ri) {
replication_info_.emplace(ri);
return this;
}

YBTableAlterer* YBTableAlterer::SetWalRetentionSecs(const uint32_t wal_retention_secs) {
wal_retention_secs_ = wal_retention_secs;
return this;
Expand Down Expand Up @@ -97,7 +102,8 @@ Status YBTableAlterer::ToRequest(master::AlterTableRequestPB* req) {
return status_;
}

if (!rename_to_ && steps_.empty() && !table_properties_ && !wal_retention_secs_) {
if (!rename_to_ && steps_.empty() && !table_properties_ && !wal_retention_secs_ &&
!replication_info_) {
return STATUS(InvalidArgument, "No alter steps provided");
}

Expand Down Expand Up @@ -169,6 +175,11 @@ Status YBTableAlterer::ToRequest(master::AlterTableRequestPB* req) {
req->set_wal_retention_secs(*wal_retention_secs_);
}

if (replication_info_) {
// TODO: Maybe add checks for the sanity of the replication_info.
req->mutable_replication_info()->CopyFrom(replication_info_.get());
}

return Status::OK();
}

Expand Down
7 changes: 6 additions & 1 deletion src/yb/client/table_alterer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class YBTableAlterer {

YBTableAlterer* SetWalRetentionSecs(const uint32_t wal_retention_secs);

// Set the timeout for the operation. This includes any waiting
// Set the timeout for the operation. This includes any waiting
// after the alter has been submitted (i.e if the alter is slow
// to be performed on a large table, it may time out and then
// later be successful).
Expand All @@ -73,6 +73,9 @@ class YBTableAlterer {
// If not provided, defaults to true.
YBTableAlterer* wait(bool wait);

// Set replication info for the table.
YBTableAlterer* replication_info(const master::ReplicationInfoPB& ri);

// Alters the table.
//
// The return value may indicate an error in the alter operation, or a
Expand Down Expand Up @@ -111,6 +114,8 @@ class YBTableAlterer {

boost::optional<uint32_t> wal_retention_secs_;

boost::optional<master::ReplicationInfoPB> replication_info_;

DISALLOW_COPY_AND_ASSIGN(YBTableAlterer);
};

Expand Down
1 change: 1 addition & 0 deletions src/yb/integration-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ ADD_YB_TEST(log_version-test)
ADD_YB_TEST(load_balancer-test)
ADD_YB_TEST(load_balancer_multi_table-test)
ADD_YB_TEST(load_balancer_respect_affinity-test)
ADD_YB_TEST(load_balancer_placement_policy-test)

set(YB_TEST_LINK_LIBS_SAVED ${YB_TEST_LINK_LIBS})
set(YB_TEST_LINK_LIBS ${YB_TEST_LINK_LIBS} cassandra cql_test_util)
Expand Down
Loading