Repository: kudu
Updated Branches:
  refs/heads/master 885d8bdaf -> b552d9118


Add modify_external_catalogs flag to table delete tool

The 'hms fix' tool helps recover from metadata inconsistencies between
Kudu and the HMS. However, there might be some unforeseen edge cases
that the tool doesn't cover. To that end, this patch introduces a flag
to control the deletion of tables in the Kudu catalog independently of
HMS' catalog.

Change-Id: I0a128fb53c974a5c839786204d56408681b434e8
Reviewed-on: http://gerrit.cloudera.org:8080/11197
Tested-by: Kudu Jenkins
Reviewed-by: Dan Burkert <danburk...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/b552d911
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/b552d911
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/b552d911

Branch: refs/heads/master
Commit: b552d9118717a00023264e30f1d749db98a388f9
Parents: 885d8bd
Author: Hao Hao <hao....@cloudera.com>
Authored: Fri Aug 10 17:28:56 2018 -0700
Committer: Hao Hao <hao....@cloudera.com>
Committed: Fri Sep 7 21:31:35 2018 +0000

----------------------------------------------------------------------
 src/kudu/client/client-internal.cc             |  4 +++-
 src/kudu/client/client-internal.h              |  3 ++-
 src/kudu/client/client.cc                      | 13 +++++++----
 src/kudu/client/client.h                       | 26 +++++++++++++++------
 src/kudu/client/table_alterer-internal.cc      |  2 +-
 src/kudu/client/table_alterer-internal.h       |  2 +-
 src/kudu/integration-tests/master_hms-itest.cc | 17 +++++++++++---
 src/kudu/master/catalog_manager.cc             | 18 +++++++-------
 src/kudu/master/master.proto                   |  6 ++++-
 src/kudu/tools/kudu-tool-test.cc               | 12 +++++-----
 src/kudu/tools/tool_action_common.cc           |  4 ----
 src/kudu/tools/tool_action_common.h            |  4 ----
 src/kudu/tools/tool_action_hms.cc              |  6 ++---
 src/kudu/tools/tool_action_table.cc            | 13 ++++++-----
 14 files changed, 79 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/client/client-internal.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-internal.cc 
b/src/kudu/client/client-internal.cc
index ecea7e9..0fb45ad 100644
--- a/src/kudu/client/client-internal.cc
+++ b/src/kudu/client/client-internal.cc
@@ -509,11 +509,13 @@ Status KuduClient::Data::WaitForCreateTableToFinish(
 
 Status KuduClient::Data::DeleteTable(KuduClient* client,
                                      const string& table_name,
-                                     const MonoTime& deadline) {
+                                     const MonoTime& deadline,
+                                     bool modify_external_catalogs) {
   DeleteTableRequestPB req;
   DeleteTableResponsePB resp;
 
   req.mutable_table()->set_table_name(table_name);
+  req.set_modify_external_catalogs(modify_external_catalogs);
   return SyncLeaderMasterRpc<DeleteTableRequestPB, DeleteTableResponsePB>(
       deadline, client, req, &resp,
       "DeleteTable", &MasterServiceProxy::DeleteTable, {});

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/client/client-internal.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-internal.h 
b/src/kudu/client/client-internal.h
index 9c2ecfe..5958533 100644
--- a/src/kudu/client/client-internal.h
+++ b/src/kudu/client/client-internal.h
@@ -115,7 +115,8 @@ class KuduClient::Data {
 
   Status DeleteTable(KuduClient* client,
                      const std::string& table_name,
-                     const MonoTime& deadline);
+                     const MonoTime& deadline,
+                     bool modify_external_catalogs = true);
 
   Status AlterTable(KuduClient* client,
                     const master::AlterTableRequestPB& req,

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/client/client.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client.cc b/src/kudu/client/client.cc
index 1c22df0..9230a30 100644
--- a/src/kudu/client/client.cc
+++ b/src/kudu/client/client.cc
@@ -398,8 +398,13 @@ Status KuduClient::IsCreateTableInProgress(const string& 
table_name,
 }
 
 Status KuduClient::DeleteTable(const string& table_name) {
+  return DeleteTableInCatalogs(table_name, true);
+}
+
+Status KuduClient::DeleteTableInCatalogs(const string& table_name,
+                                         bool modify_external_catalogs) {
   MonoTime deadline = MonoTime::Now() + default_admin_operation_timeout();
-  return data_->DeleteTable(this, table_name, deadline);
+  return data_->DeleteTable(this, table_name, deadline, 
modify_external_catalogs);
 }
 
 KuduTableAlterer* KuduClient::NewTableAlterer(const string& table_name) {
@@ -1161,9 +1166,9 @@ KuduTableAlterer* KuduTableAlterer::wait(bool wait) {
   return this;
 }
 
-KuduTableAlterer* KuduTableAlterer::alter_external_catalogs(
-    bool alter_external_catalogs) {
-  data_->alter_external_catalogs_ = alter_external_catalogs;
+KuduTableAlterer* KuduTableAlterer::modify_external_catalogs(
+    bool modify_external_catalogs) {
+  data_->modify_external_catalogs_ = modify_external_catalogs;
   return this;
 }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/client/client.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/client.h b/src/kudu/client/client.h
index aec3aef..640afce 100644
--- a/src/kudu/client/client.h
+++ b/src/kudu/client/client.h
@@ -65,7 +65,6 @@ class KuduTableAlterer;
 namespace tools {
 class LeaderMasterProxy;
 std::string GetMasterAddresses(const client::KuduClient&);
-void SetAlterExternalCatalogs(client::KuduTableAlterer*, bool);
 } // namespace tools
 
 namespace client {
@@ -342,6 +341,17 @@ class KUDU_EXPORT KuduClient : public 
sp::enable_shared_from_this<KuduClient> {
   /// @return Operation status.
   Status DeleteTable(const std::string& table_name);
 
+  /// Delete/drop a table in internal catalogs and possibly external catalogs.
+  ///
+  /// @param [in] table_name
+  ///   Name of the table to drop.
+  /// @param [in] modify_external_catalogs
+  ///   Whether to apply the deletion to external catalogs, such as the Hive 
Metastore,
+  ///   which the Kudu master has been configured to integrate with.
+  /// @return Operation status.
+  Status KUDU_NO_EXPORT DeleteTableInCatalogs(const std::string& table_name,
+                                              bool modify_external_catalogs);
+
   /// Create a KuduTableAlterer object.
   ///
   /// @param [in] table_name
@@ -1200,6 +1210,14 @@ class KUDU_EXPORT KuduTableAlterer {
   /// @return Raw pointer to this alterer object.
   KuduTableAlterer* wait(bool wait);
 
+  /// Whether to apply the alteration to external catalogs, such as the Hive
+  /// Metastore, which the Kudu master has been configured to integrate with.
+  ///
+  /// @param [in] modify_external_catalogs
+  ///   Whether to apply the alteration to external catalogs.
+  /// @return Raw pointer to this alterer object.
+  KuduTableAlterer* KUDU_NO_EXPORT modify_external_catalogs(bool 
modify_external_catalogs);
+
   /// @return Status of the ALTER TABLE operation. The return value
   ///   may indicate an error in the alter operation,
   ///   or a misuse of the builder (e.g. add_column() with default_value=NULL).
@@ -1211,18 +1229,12 @@ class KUDU_EXPORT KuduTableAlterer {
 
   friend class KuduClient;
 
-  friend void tools::SetAlterExternalCatalogs(KuduTableAlterer*, bool);
   FRIEND_TEST(kudu::MasterHmsTest, TestAlterTable);
   FRIEND_TEST(kudu::MasterHmsUpgradeTest, TestRenameExistingTables);
 
   KuduTableAlterer(KuduClient* client,
                    const std::string& name);
 
-  // Whether to apply the alteration to external catalogs, such as the Hive
-  // Metastore, which the Kudu master has been configured to integrate with.
-  // This method returns a raw pointer to this alterer object.
-  KuduTableAlterer* alter_external_catalogs(bool alter_external_catalogs);
-
   // Owned.
   Data* data_;
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/client/table_alterer-internal.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/table_alterer-internal.cc 
b/src/kudu/client/table_alterer-internal.cc
index 12adcaf..650d0e0 100644
--- a/src/kudu/client/table_alterer-internal.cc
+++ b/src/kudu/client/table_alterer-internal.cc
@@ -61,7 +61,7 @@ Status KuduTableAlterer::Data::ToRequest(AlterTableRequestPB* 
req) {
   }
 
   req->Clear();
-  req->set_alter_external_catalogs(alter_external_catalogs_);
+  req->set_modify_external_catalogs(modify_external_catalogs_);
   req->mutable_table()->set_table_name(table_name_);
   if (rename_to_.is_initialized()) {
     req->set_new_table_name(rename_to_.get());

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/client/table_alterer-internal.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/table_alterer-internal.h 
b/src/kudu/client/table_alterer-internal.h
index 6f2e4c3..353b79d 100644
--- a/src/kudu/client/table_alterer-internal.h
+++ b/src/kudu/client/table_alterer-internal.h
@@ -79,7 +79,7 @@ class KuduTableAlterer::Data {
 
   // Whether to apply the alteration to external catalogs, such as the Hive
   // Metastore. The default value is true.
-  bool alter_external_catalogs_ = true;
+  bool modify_external_catalogs_ = true;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(Data);

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/integration-tests/master_hms-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/master_hms-itest.cc 
b/src/kudu/integration-tests/master_hms-itest.cc
index 7ba3c8c..2fb632f 100644
--- a/src/kudu/integration-tests/master_hms-itest.cc
+++ b/src/kudu/integration-tests/master_hms-itest.cc
@@ -376,7 +376,7 @@ TEST_F(MasterHmsTest, TestAlterTable) {
 
   // Only alter the table in Kudu, the corresponding table in the HMS will not 
be altered.
   
table_alterer.reset(client_->NewTableAlterer("default.a")->RenameTo("default.b")
-                             ->alter_external_catalogs(false));
+                             ->modify_external_catalogs(false));
   ASSERT_OK(table_alterer->Alter());
   bool exists;
   ASSERT_OK(client_->TableExists("default.b", &exists));
@@ -420,6 +420,17 @@ TEST_F(MasterHmsTest, TestDeleteTable) {
     ASSERT_OK(client_->DeleteTable("default.c"));
   });
   NO_FATALS(CheckTableDoesNotExist("default", "c"));
+
+  // Create a Kudu table, then only drop it from Kudu. Ensure the HMS
+  // entry is not removed.
+  ASSERT_OK(CreateKuduTable("default", "d"));
+  NO_FATALS(CheckTable("default", "d"));
+  hive::Table hms_table_d;
+  ASSERT_OK(hms_client_->GetTable("default", "d", &hms_table_d));
+  ASSERT_OK(client_->DeleteTableInCatalogs("default.d", false));
+  s = client_->OpenTable(Substitute("$0.$1", "default", "d"), &table);
+  ASSERT_TRUE(s.IsNotFound()) << s.ToString();
+  ASSERT_OK(hms_client_->GetTable("default", "d", &hms_table_d));
 }
 
 TEST_F(MasterHmsTest, TestNotificationLogListener) {
@@ -598,10 +609,10 @@ TEST_F(MasterHmsUpgradeTest, TestRenameExistingTables) {
 
   // Rename the tables using a Kudu catalog only rename.
   unique_ptr<KuduTableAlterer> 
alterer(client_->NewTableAlterer("default.UPPERCASE"));
-  
ASSERT_OK(alterer->RenameTo("default.uppercase")->alter_external_catalogs(false)->Alter());
+  
ASSERT_OK(alterer->RenameTo("default.uppercase")->modify_external_catalogs(false)->Alter());
 
   alterer.reset(client_->NewTableAlterer("default.illegal-chars⁉"));
-  
ASSERT_OK(alterer->RenameTo("default.illegal_chars")->alter_external_catalogs(false)->Alter());
+  
ASSERT_OK(alterer->RenameTo("default.illegal_chars")->modify_external_catalogs(false)->Alter());
 
   tables.clear();
   client_->ListTables(&tables);

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/master/catalog_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/catalog_manager.cc 
b/src/kudu/master/catalog_manager.cc
index 5ed429e..0dd8003 100644
--- a/src/kudu/master/catalog_manager.cc
+++ b/src/kudu/master/catalog_manager.cc
@@ -1750,12 +1750,12 @@ Status CatalogManager::DeleteTableRpc(const 
DeleteTableRequestPB& req,
   leader_lock_.AssertAcquiredForReading();
   RETURN_NOT_OK(CheckOnline());
 
-  // If the HMS integration is enabled, then don't directly remove the table
-  // from the Kudu catalog. Instead, delete the table from the HMS and wait for
-  // the notification log listener to apply the corresponding event to the
-  // catalog. By 'serializing' the drop through the HMS, race conditions are
-  // avoided.
-  if (hms_catalog_) {
+  // If the HMS integration is enabled and the table should be deleted in the 
HMS,
+  // then don't directly remove the table from the Kudu catalog. Instead, 
delete
+  // the table from the HMS and wait for the notification log listener to apply
+  // the corresponding event to the catalog. By 'serializing' the drop through
+  // the HMS, race conditions are avoided.
+  if (hms_catalog_ && req.modify_external_catalogs()) {
     // Wait for the notification log listener to catch up. This reduces the
     // likelihood of attempting to delete a table which has just been deleted 
or
     // renamed in the HMS.
@@ -1781,8 +1781,8 @@ Status CatalogManager::DeleteTableRpc(const 
DeleteTableRequestPB& req,
     return WaitForNotificationLogListenerCatchUp(resp, rpc);
   }
 
-  // If the HMS integration isn't enabled, then delete the table directly from
-  // the Kudu catalog.
+  // If the HMS integration isn't enabled or the deletion should only happen 
in Kudu,
+  // then delete the table directly from the Kudu catalog.
   return DeleteTable(req, resp, boost::none);
 }
 
@@ -2158,7 +2158,7 @@ Status CatalogManager::AlterTableRpc(const 
AlterTableRequestPB& req,
   // in the HMS and wait for the notification log listener to apply
   // that event to the catalog. By 'serializing' the rename through the
   // HMS, race conditions are avoided.
-  if (hms_catalog_ && req.has_new_table_name() && 
req.alter_external_catalogs()) {
+  if (hms_catalog_ && req.has_new_table_name() && 
req.modify_external_catalogs()) {
     // Look up the table and lock it.
     scoped_refptr<TableInfo> table;
     TableMetadataLock l;

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/master/master.proto
----------------------------------------------------------------------
diff --git a/src/kudu/master/master.proto b/src/kudu/master/master.proto
index a2eff06..4eb6156 100644
--- a/src/kudu/master/master.proto
+++ b/src/kudu/master/master.proto
@@ -443,6 +443,10 @@ message IsCreateTableDoneResponsePB {
 
 message DeleteTableRequestPB {
   required TableIdentifierPB table = 1;
+
+  // Whether to apply the deletion to external catalogs, such as the Hive 
Metastore,
+  // which the Kudu master has been configured to integrate with.
+  optional bool modify_external_catalogs = 2 [default = true];
 }
 
 message DeleteTableResponsePB {
@@ -567,7 +571,7 @@ message AlterTableRequestPB {
 
   // Whether to apply the alteration to external catalogs, such as the Hive 
Metastore,
   // which the Kudu master has been configured to integrate with.
-  optional bool alter_external_catalogs = 5 [default = true];
+  optional bool modify_external_catalogs = 5 [default = true];
 }
 
 message AlterTableResponsePB {

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/tools/kudu-tool-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/kudu-tool-test.cc b/src/kudu/tools/kudu-tool-test.cc
index 8669695..059753b 100644
--- a/src/kudu/tools/kudu-tool-test.cc
+++ b/src/kudu/tools/kudu-tool-test.cc
@@ -2147,7 +2147,7 @@ TEST_F(ToolTest, TestDeleteTable) {
   ASSERT_EQ(exist, true);
 
   // Delete the table.
-  NO_FATALS(RunActionStdoutNone(Substitute("table delete $0 $1",
+  NO_FATALS(RunActionStdoutNone(Substitute("table delete $0 $1 
--nomodify_external_catalogs",
                                            master_addr, kTableName)));
 
   // Check that the table does not exist.
@@ -2178,7 +2178,7 @@ TEST_F(ToolTest, TestRenameTable) {
   ASSERT_OK(client->OpenTable(kNewTableName, &table));
 
   NO_FATALS(RunActionStdoutNone(
-        Substitute("table rename_table $0 $1 $2 --noalter_external_catalogs",
+        Substitute("table rename_table $0 $1 $2 --nomodify_external_catalogs",
           master_addr, kNewTableName, kTableName)));
   ASSERT_OK(client->OpenTable(kTableName, &table));
 }
@@ -2275,7 +2275,7 @@ TEST_F(ToolTest, TestListTables) {
         JoinStringsIterator(table_names.begin(), table_names.begin() + num, 
","));
     }
     vector<string> lines;
-    NO_FATALS(RunActionStdoutLines(
+    NO_FATALS(RunActionStdoutLines(
         Substitute("table list $0 $1 -list_tablets", master_addr, filter), 
&lines));
 
     map<string, pair<string, string>> output;
@@ -2788,10 +2788,10 @@ TEST_P(ToolTestKerberosParameterized, 
TestCheckAndManualFixHmsMetadata) {
 
   // Rename the incompatible names.
   NO_FATALS(RunActionStdoutNone(Substitute(
-          "table rename-table --noalter-external-catalogs $0 "
+          "table rename-table --nomodify-external-catalogs $0 "
           "default.hive-incompatible-name default.hive_compatible_name", 
master_addr)));
   NO_FATALS(RunActionStdoutNone(Substitute(
-          "table rename-table --noalter-external-catalogs $0 "
+          "table rename-table --nomodify-external-catalogs $0 "
           "no_database default.with_database", master_addr)));
 
   // Create the missing database.
@@ -2801,7 +2801,7 @@ TEST_P(ToolTestKerberosParameterized, 
TestCheckAndManualFixHmsMetadata) {
 
   // Rename the conflicting table.
   NO_FATALS(RunActionStdoutNone(Substitute(
-          "table rename-table --noalter-external-catalogs $0 "
+          "table rename-table --nomodify-external-catalogs $0 "
           "default.conflicting_legacy_table 
default.non_conflicting_legacy_table", master_addr)));
 
   // Run the automatic fixer to create missing HMS table entries.

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/tools/tool_action_common.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_common.cc 
b/src/kudu/tools/tool_action_common.cc
index e615915..ecc06a5 100644
--- a/src/kudu/tools/tool_action_common.cc
+++ b/src/kudu/tools/tool_action_common.cc
@@ -444,10 +444,6 @@ Status SetServerFlag(const string& address, uint16_t 
default_port,
   }
 }
 
-void SetAlterExternalCatalogs(client::KuduTableAlterer* alterer, bool 
alter_external_catalogs) {
-  alterer->alter_external_catalogs(alter_external_catalogs);
-}
-
 string GetMasterAddresses(const client::KuduClient& client) {
   return HostPort::ToCommaSeparatedString(client.data_->master_hostports());
 }

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/tools/tool_action_common.h
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_common.h 
b/src/kudu/tools/tool_action_common.h
index d3a4524..5d1e5a0 100644
--- a/src/kudu/tools/tool_action_common.h
+++ b/src/kudu/tools/tool_action_common.h
@@ -41,7 +41,6 @@ class faststring;
 
 namespace client {
 class KuduClient;
-class KuduTableAlterer;
 } // namespace client
 
 namespace master {
@@ -134,9 +133,6 @@ Status PrintServerFlags(const std::string& address, 
uint16_t default_port);
 Status SetServerFlag(const std::string& address, uint16_t default_port,
                      const std::string& flag, const std::string& value);
 
-// Set the non-public 'alter_external_catalogs' option on a KuduTableAlterer.
-void SetAlterExternalCatalogs(client::KuduTableAlterer* alterer, bool 
alter_external_catalogs);
-
 // Get the configured master addresses on the most recently connected to 
leader master.
 std::string GetMasterAddresses(const client::KuduClient& client);
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/tools/tool_action_hms.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_hms.cc 
b/src/kudu/tools/tool_action_hms.cc
index 65ae2e0..ccf2557 100644
--- a/src/kudu/tools/tool_action_hms.cc
+++ b/src/kudu/tools/tool_action_hms.cc
@@ -97,8 +97,8 @@ Status RenameTableInKuduCatalog(KuduClient* kudu_client,
                                 const string& name,
                                 const string& new_name) {
   unique_ptr<KuduTableAlterer> alterer(kudu_client->NewTableAlterer(name));
-  SetAlterExternalCatalogs(alterer.get(), false);
   return alterer->RenameTo(new_name)
+                ->modify_external_catalogs(false)
                 ->Alter();
 }
 
@@ -392,7 +392,7 @@ Status CheckHmsMetadata(const RunnerContext& context) {
          << "Suggestion: rename the Kudu table(s) to be Hive-compatible, then 
run the fix tool:"
          << endl;
     for (const auto& table : report.invalid_name_tables) {
-      cout << "\t$ kudu table rename_table --alter_external_catalogs=false "
+      cout << "\t$ kudu table rename_table --modify_external_catalogs=false "
            << master_addrs << " " << table->name() << " 
<database-name>.<table-name>" << endl;
     }
     cout << endl;
@@ -585,7 +585,7 @@ Status FixHmsMetadata(const RunnerContext& context) {
                        << ", because a Kudu table with name" << hms_table_name
                        << " already exists";
             LOG(INFO) << "Suggestion: rename the conflicting table name 
manually:\n"
-                      << "\t$ kudu table rename_table 
--alter_external_catalogs=false "
+                      << "\t$ kudu table rename_table 
--modify_external_catalogs=false "
                       << master_addrs << " " << hms_table_name << " 
<database-name>.<table-name>'";
             success = false;
             continue;

http://git-wip-us.apache.org/repos/asf/kudu/blob/b552d911/src/kudu/tools/tool_action_table.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/tool_action_table.cc 
b/src/kudu/tools/tool_action_table.cc
index 69521c2..c15c69d 100644
--- a/src/kudu/tools/tool_action_table.cc
+++ b/src/kudu/tools/tool_action_table.cc
@@ -38,9 +38,9 @@
 #include "kudu/util/status.h"
 
 DECLARE_string(tables);
-DEFINE_bool(alter_external_catalogs, true,
-            "Whether to alter external catalogs, such as the Hive Metastore, "
-            "when renaming a table.");
+DEFINE_bool(modify_external_catalogs, true,
+            "Whether to modify external catalogs, such as the Hive Metastore, "
+            "when renaming or dropping a table.");
 DEFINE_bool(list_tablets, false,
             "Include tablet and replica UUIDs in the output");
 
@@ -127,7 +127,7 @@ Status DeleteTable(const RunnerContext& context) {
   const string& table_name = FindOrDie(context.required_args, kTableNameArg);
   client::sp::shared_ptr<KuduClient> client;
   RETURN_NOT_OK(CreateKuduClient(context, &client));
-  return client->DeleteTable(table_name);
+  return client->DeleteTableInCatalogs(table_name, 
FLAGS_modify_external_catalogs);
 }
 
 Status RenameTable(const RunnerContext& context) {
@@ -137,8 +137,8 @@ Status RenameTable(const RunnerContext& context) {
   client::sp::shared_ptr<KuduClient> client;
   RETURN_NOT_OK(CreateKuduClient(context, &client));
   unique_ptr<KuduTableAlterer> alterer(client->NewTableAlterer(table_name));
-  SetAlterExternalCatalogs(alterer.get(), FLAGS_alter_external_catalogs);
   return alterer->RenameTo(new_table_name)
+                ->modify_external_catalogs(FLAGS_modify_external_catalogs)
                 ->Alter();
 }
 
@@ -168,6 +168,7 @@ unique_ptr<Mode> BuildTableMode() {
       .Description("Delete a table")
       .AddRequiredParameter({ kMasterAddressesArg, kMasterAddressesArgDesc })
       .AddRequiredParameter({ kTableNameArg, "Name of the table to delete" })
+      .AddOptionalParameter("modify_external_catalogs")
       .Build();
 
   unique_ptr<Action> rename_table =
@@ -176,7 +177,7 @@ unique_ptr<Mode> BuildTableMode() {
       .AddRequiredParameter({ kMasterAddressesArg, kMasterAddressesArgDesc })
       .AddRequiredParameter({ kTableNameArg, "Name of the table to rename" })
       .AddRequiredParameter({ kNewTableNameArg, "New table name" })
-      .AddOptionalParameter("alter_external_catalogs")
+      .AddOptionalParameter("modify_external_catalogs")
       .Build();
 
   unique_ptr<Action> rename_column =

Reply via email to