Skip to content

Commit

Permalink
#2293 [YSQ]: Fix number of tablets created for system tables
Browse files Browse the repository at this point in the history
Summary:
Due to a regression in f154c1f, we are creating only 1 tablet for system tables such as transactions, cdc_state and metrics.

This diff fixes it to create default number of tablets.

Test Plan:
Jenkins
Created cluster using yb-ctl and verified that transactions table has multiple tablets.

Reviewers: dmitry, mihnea, kannan

Reviewed By: kannan

Subscribers: yql, kannan, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D7202
  • Loading branch information
ndeodhar authored and ttyusupov committed Sep 14, 2019
1 parent e6faf60 commit 2b84e00
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
44 changes: 44 additions & 0 deletions src/yb/client/ql-tablet-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ DECLARE_bool(flush_rocksdb_on_shutdown);
DECLARE_int32(memstore_size_mb);
DECLARE_int64(global_memstore_size_mb_max);
DECLARE_bool(TEST_allow_stop_writes);
DECLARE_int32(yb_num_shards_per_tserver);

namespace yb {
namespace client {
Expand Down Expand Up @@ -337,6 +338,25 @@ class QLTabletTest : public QLDmlTestBase {
return tablets;
}

Status WaitForTableCreation(const YBTableName& table_name,
master::IsCreateTableDoneResponsePB *resp) {
return LoggedWaitFor([=]() -> Result<bool> {
master::IsCreateTableDoneRequestPB req;
req.mutable_table()->set_table_name(table_name.table_name());
req.mutable_table()->mutable_namespace_()->set_name(table_name.namespace_name());
resp->Clear();

auto master_proxy = std::make_shared<master::MasterServiceProxy>(
&client_->proxy_cache(),
cluster_->leader_mini_master()->bound_rpc_addr());
rpc::RpcController rpc;
rpc.set_timeout(MonoDelta::FromSeconds(30));

Status s = master_proxy->IsCreateTableDone(req, resp, &rpc);
return s.ok() && !resp->has_error();
}, MonoDelta::FromSeconds(30), "Table Creation");
}

void TestDeletePartialKey(int num_range_keys_in_delete);

TableHandle table1_;
Expand Down Expand Up @@ -402,6 +422,30 @@ TEST_F(QLTabletTest, OverlappedImport) {
ASSERT_NOK(Import());
}

// Test expected number of tablets for transactions table - added for #2293.
TEST_F(QLTabletTest, TransactionsTableTablets) {
YBSchemaBuilder builder;
builder.AddColumn(kKeyColumn)->Type(INT32)->HashPrimaryKey()->NotNull();
builder.AddColumn(kValueColumn)->Type(INT32);

// Create transactional table.
TableProperties table_properties;
table_properties.SetTransactional(true);
builder.SetTableProperties(table_properties);

TableHandle table;
ASSERT_OK(table.Create(kTable1Name, 8, client_.get(), &builder));

// Wait for transactions table to be created.
YBTableName table_name(master::kSystemNamespaceName, kTransactionsTableName);
master::IsCreateTableDoneResponsePB resp;
ASSERT_OK(WaitForTableCreation(table_name, &resp));
ASSERT_TRUE(resp.done());

auto tablets = GetTabletInfos(table_name);
ASSERT_EQ(tablets.size(), cluster_->num_tablet_servers() * FLAGS_yb_num_shards_per_tserver);
}

void DoStepDowns(MiniCluster* cluster) {
for (int j = 0; j != 5; ++j) {
StepDownAllTablets(cluster);
Expand Down
19 changes: 7 additions & 12 deletions src/yb/master/catalog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1820,18 +1820,13 @@ Status CatalogManager::CreateTable(const CreateTableRequestPB* orig_req,
if (num_tablets <= 0) {
// Use default as client could have gotten the value before any tserver had heartbeated
// to (a new) master leader.
if (IsSystemNamespace(ns->name())) {
num_tablets = 1;
LOG(INFO) << "Setting default tablets to " << num_tablets << " for table in system namespace";
} else {
TSDescriptorVector ts_descs;
master_->ts_manager()->GetAllLiveDescriptorsInCluster(
&ts_descs, replication_info.live_replicas().placement_uuid(), blacklistState.tservers_);
num_tablets = ts_descs.size() * (is_pg_table ? FLAGS_ysql_num_shards_per_tserver
: FLAGS_yb_num_shards_per_tserver);
LOG(INFO) << "Setting default tablets to " << num_tablets << " with "
<< ts_descs.size() << " primary servers";
}
TSDescriptorVector ts_descs;
master_->ts_manager()->GetAllLiveDescriptorsInCluster(
&ts_descs, replication_info.live_replicas().placement_uuid(), blacklistState.tservers_);
num_tablets = ts_descs.size() * (is_pg_table ? FLAGS_ysql_num_shards_per_tserver
: FLAGS_yb_num_shards_per_tserver);
LOG(INFO) << "Setting default tablets to " << num_tablets << " with "
<< ts_descs.size() << " primary servers";
}

// Create partitions.
Expand Down

0 comments on commit 2b84e00

Please sign in to comment.