Skip to content

Commit

Permalink
[yugabyte#7530] YB-Master HTML page should show the tablespace and ta…
Browse files Browse the repository at this point in the history
…blespace replication info for a table

Summary:
Today the YB-Master HTML page has a field showing the replication info for a table.
Currently it only displays the correct replication info if the table's placement policy
was either set using yb-admin or if it defaults to cluster config.

This patch contains changes to display the tablespace replication info
if the table is associated with a tablespace. It also displays the
tablespace oid if the table is associated with a custom tablespace.

Test Plan: Manual test of YB-Master UI page before and after tablespace task ran.

Reviewers: rahuldesirazu

Reviewed By: rahuldesirazu

Subscribers: yql, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D11576
  • Loading branch information
deeps1991 committed Jun 7, 2021
1 parent 3672fcd commit 0feef28
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/yb/master/catalog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,13 @@ std::shared_ptr<YsqlTablespaceManager> CatalogManager::GetTablespaceManager() {
return tablespace_manager_;
}

Result<boost::optional<TablespaceId>> CatalogManager::GetTablespaceForTable(
const scoped_refptr<TableInfo>& table) {

auto tablespace_manager = GetTablespaceManager();
return tablespace_manager->GetTablespaceForTable(table);
}

Result<boost::optional<ReplicationInfoPB>> CatalogManager::GetTablespaceReplicationInfoWithRetry(
const TablespaceId& tablespace_id) {

Expand Down
3 changes: 3 additions & 0 deletions src/yb/master/catalog_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ class CatalogManager :
const ReplicationInfoPB& table_replication_info,
const TablespaceId& tablespace_id);

Result<boost::optional<TablespaceId>> GetTablespaceForTable(
const scoped_refptr<TableInfo>& table);

void ProcessTabletPathInfo(const std::string& ts_uuid, const TabletPathInfoPB& report);

void CheckTableDeleted(const TableInfoPtr& table);
Expand Down
41 changes: 31 additions & 10 deletions src/yb/master/master-path-handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ DEFINE_int32(
"(we presume it has been removed from the cluster). If -1, this flag is ignored and node is "
"never hidden from the UI");

DECLARE_int32(ysql_tablespace_info_refresh_secs);

namespace yb {

namespace {
Expand Down Expand Up @@ -1105,16 +1107,35 @@ void MasterPathHandlers::HandleTablePage(const Webserver::WebRequest& req,
<< EscapeForHtmlToString(l->pb.state_msg())
<< "</td></tr>\n";

// TODO(deepthi.srinivasan): For now, pass empty tablespace_id as tablespaces feature
// is disabled anyway. Later when tablespaces are enabled, create and call the
// appropriate API to display placement information pertaining to tablespaces.
auto replication_info = CHECK_RESULT(
master_->catalog_manager()->GetTableReplicationInfo(
l->pb.replication_info(), "" /* tablespace_id */));
*output << " <tr><td>Replication Info:</td><td>"
<< " <pre class=\"prettyprint\">" << replication_info.DebugString() << "</pre>"
<< " </td></tr>\n";
*output << "</table>\n";
TablespaceId tablespace_id;
auto result = master_->catalog_manager()->GetTablespaceForTable(table);
if (result.ok()) {
// If the table is associated with a tablespace, display tablespace, otherwise
// just display replication info.
if (result.get()) {
tablespace_id = result.get().value();
*output << " <tr><td>Tablespace OID:</td><td>"
<< GetPgsqlTablespaceOid(tablespace_id)
<< " </td></tr>\n";
}
auto replication_info = CHECK_RESULT(master_->catalog_manager()->GetTableReplicationInfo(
l->pb.replication_info(), tablespace_id));
*output << " <tr><td>Replication Info:</td><td>"
<< " <pre class=\"prettyprint\">" << replication_info.DebugString() << "</pre>"
<< " </td></tr>\n </table>\n";
} else {
// The table was associated with a tablespace, but that tablespace was not found.
*output << " <tr><td>Replication Info:</td><td>";
if (FLAGS_ysql_tablespace_info_refresh_secs > 0) {
*output << " Tablespace information not available now, please try again after "
<< FLAGS_ysql_tablespace_info_refresh_secs << " seconds. ";
} else {
*output << " Tablespace information is not available as the periodic task "
<< " used to refresh it is disabled.";

}
*output << " </td></tr>\n </table>\n";
}

Status s = SchemaFromPB(l->pb.schema(), &schema);
if (s.ok()) {
Expand Down
24 changes: 16 additions & 8 deletions src/yb/master/ysql_tablespace_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Result<boost::optional<ReplicationInfoPB>> YsqlTablespaceManager::GetTablespaceR
tablespace_id + " not found");
}

Result<boost::optional<ReplicationInfoPB>> YsqlTablespaceManager::GetTableReplicationInfo(
const scoped_refptr<TableInfo>& table) {
Result<boost::optional<TablespaceId>> YsqlTablespaceManager::GetTablespaceForTable(
const scoped_refptr<TableInfo>& table) {

if (!GetAtomicFlag(&FLAGS_enable_ysql_tablespaces_for_placement) ||
!table->UsesTablespacesForPlacement()) {
Expand All @@ -83,17 +83,25 @@ Result<boost::optional<ReplicationInfoPB>> YsqlTablespaceManager::GetTableReplic
return STATUS(InternalError, "Tablespace information not found for table " + table->id());
}

if (!iter->second) {
return iter->second;
}

Result<boost::optional<ReplicationInfoPB>> YsqlTablespaceManager::GetTableReplicationInfo(
const scoped_refptr<TableInfo>& table) {

// Lookup tablespace for the given table.
auto tablespace_id = VERIFY_RESULT(GetTablespaceForTable(table));

if (!tablespace_id) {
return boost::none;
}

// Lookup the placement info associated with the above tablespace.
const TablespaceId& tablespace_id = iter->second.value();
const auto tablespace_iter = tablespace_id_to_replication_info_map_->find(tablespace_id);
if (tablespace_iter == tablespace_id_to_replication_info_map_->end()) {
return STATUS(InternalError, "Placement policy not found for " + tablespace_id);
const auto iter = tablespace_id_to_replication_info_map_->find(tablespace_id.value());
if (iter == tablespace_id_to_replication_info_map_->end()) {
return STATUS(InternalError, "Placement policy not found for " + tablespace_id.value());
}
return tablespace_iter->second;
return iter->second;
}

bool YsqlTablespaceManager::NeedsRefreshToFindTablePlacement(
Expand Down
3 changes: 3 additions & 0 deletions src/yb/master/ysql_tablespace_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class YsqlTablespaceManager {
Result<boost::optional<ReplicationInfoPB>> GetTablespaceReplicationInfo(
const TablespaceId& tablespace_id);

Result<boost::optional<TablespaceId>> GetTablespaceForTable(
const scoped_refptr<TableInfo>& table);

Result<boost::optional<ReplicationInfoPB>> GetTableReplicationInfo(
const scoped_refptr<TableInfo>& table);

Expand Down

0 comments on commit 0feef28

Please sign in to comment.