kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [1/2] incubator-kudu git commit: Make the meta cache return Status::NetworkError if no addresses were found
Date Thu, 12 May 2016 03:55:47 GMT
Repository: incubator-kudu
Updated Branches:
  refs/heads/master 568c12c19 -> 999e7c908


Make the meta cache return Status::NetworkError if no addresses were found

This adds a new flag 'fail_dns_resolution' to net-util.cc so that we can fail
dns resolution on purpose and makes it so that the meta cache returns Status:NetworkError
in this case, instead of NotFound as before.

This also adds a test that makes sure that we get Status::NetworkError() back
if we set the flag and that normal resolution resumes once it's set to the default
value.

Changing this error type allows to have a clearer error handling path as there is
one less status type to handle.

Change-Id: I95b553f1db1b76f9e8117b6628c7bf64013d1ad9
Reviewed-on: http://gerrit.cloudera.org:8080/3027
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <todd@apache.org>


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

Branch: refs/heads/master
Commit: aa20b7b07edb912e04b6ad1b500a48b350994741
Parents: 568c12c
Author: David Alves <david.alves@cloudera.com>
Authored: Wed May 11 12:42:38 2016 -0700
Committer: David Ribeiro Alves <david.alves@cloudera.com>
Committed: Wed May 11 21:28:14 2016 +0000

----------------------------------------------------------------------
 src/kudu/client/client-test.cc | 29 +++++++++++++++++++++++++++++
 src/kudu/client/meta_cache.cc  |  2 +-
 src/kudu/util/net/net_util.cc  |  8 ++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/aa20b7b0/src/kudu/client/client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index ad5e14c..9c98d79 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -59,6 +59,7 @@
 #include "kudu/util/thread.h"
 
 DECLARE_bool(enable_data_block_fsync);
+DECLARE_bool(fail_dns_resolution);
 DECLARE_bool(log_inject_latency);
 DECLARE_int32(heartbeat_interval_ms);
 DECLARE_int32(log_inject_latency_ms_mean);
@@ -1530,6 +1531,34 @@ TEST_F(ClientTest, TestWriteTimeout) {
   }
 }
 
+TEST_F(ClientTest, TestFailedDnsResolution) {
+  shared_ptr<KuduSession> session = client_->NewSession();
+  ASSERT_OK(session->SetFlushMode(KuduSession::MANUAL_FLUSH));
+
+  // First time disable dns resolution.
+  // Set the timeout to be short since we know it can't succeed
+  {
+    google::FlagSaver saver;
+    FLAGS_fail_dns_resolution = true;
+    session->SetTimeoutMillis(100);
+    ASSERT_OK(ApplyInsertToSession(session.get(), client_table_, 1, 1, "row"));
+    Status s = session->Flush();
+    ASSERT_TRUE(s.IsIOError()) << "unexpected status: " << s.ToString();
+    gscoped_ptr<KuduError> error = GetSingleErrorFromSession(session.get());
+    ASSERT_TRUE(error->status().IsTimedOut()) << error->status().ToString();
+    ASSERT_STR_CONTAINS(error->status().ToString(),
+                        "Network error: Failed to resolve address for TS");
+  }
+
+  // Now re-enable dns resolution, the write should succeed.
+  {
+    google::FlagSaver saver;
+    FLAGS_fail_dns_resolution = false;
+    ASSERT_OK(ApplyInsertToSession(session.get(), client_table_, 1, 1, "row"));
+    ASSERT_OK(session->Flush());
+  }
+}
+
 // Test which does an async flush and then drops the reference
 // to the Session. This should still call the callback.
 TEST_F(ClientTest, TestAsyncFlushResponseAfterSessionDropped) {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/aa20b7b0/src/kudu/client/meta_cache.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/meta_cache.cc b/src/kudu/client/meta_cache.cc
index 80ad940..79a5ae1 100644
--- a/src/kudu/client/meta_cache.cc
+++ b/src/kudu/client/meta_cache.cc
@@ -75,7 +75,7 @@ void RemoteTabletServer::DnsResolutionFinished(const HostPort& hp,
   Status s = result_status;
 
   if (s.ok() && addrs->empty()) {
-    s = Status::NotFound("No addresses for " + hp.ToString());
+    s = Status::NetworkError("No addresses for " + hp.ToString());
   }
 
   if (!s.ok()) {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/aa20b7b0/src/kudu/util/net/net_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/net/net_util.cc b/src/kudu/util/net/net_util.cc
index b2851ee..e2613f8 100644
--- a/src/kudu/util/net/net_util.cc
+++ b/src/kudu/util/net/net_util.cc
@@ -21,6 +21,7 @@
 #include <netdb.h>
 
 #include <algorithm>
+#include <gflags/gflags.h>
 #include <unordered_set>
 #include <utility>
 #include <vector>
@@ -36,6 +37,7 @@
 #include "kudu/util/debug/trace_event.h"
 #include "kudu/util/errno.h"
 #include "kudu/util/faststring.h"
+#include "kudu/util/flag_tags.h"
 #include "kudu/util/net/net_util.h"
 #include "kudu/util/net/sockaddr.h"
 #include "kudu/util/stopwatch.h"
@@ -46,6 +48,9 @@
 #define HOST_NAME_MAX 64
 #endif
 
+DEFINE_bool(fail_dns_resolution, false, "Wether to fail all dns resolution, for tests.");
+TAG_FLAG(fail_dns_resolution, hidden);
+
 using std::unordered_set;
 using std::vector;
 using strings::Substitute;
@@ -124,6 +129,9 @@ Status HostPort::ResolveAddresses(vector<Sockaddr>* addresses) const
{
     VLOG(2) << "Resolved address " << sockaddr.ToString()
             << " for host/port " << ToString();
   }
+  if (PREDICT_FALSE(FLAGS_fail_dns_resolution)) {
+    addresses->clear();
+  }
   return Status::OK();
 }
 


Mime
View raw message