[tools] Fail ksck if fetching consensus state fails

Commonly, users run ksck as someone other than the kudu superuser.
This means that ksck can't gather consensus state. It still does its
other checks, and will exit with an OK status if there are no
problems with them, just printing some easily-missed warnings at
the top of the output. This patch changes ksck so it fails when
it cannot gather all the information it needs to do all the checks.

Note that if the user specifies consensus=false, they can run ksck
without missing consensus checks causing a failure.

Change-Id: Id3efc9342c3cb3f9652bb8c9789fe20ecf12ff55
Reviewed-on: http://gerrit.cloudera.org:8080/9316
Reviewed-by: Alexey Serbin <aser...@cloudera.com>
Tested-by: Kudu Jenkins


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

Branch: refs/heads/master
Commit: cd419906204b77a5b548f61f93b72d5388b7c037
Parents: a7f5e83
Author: Will Berkeley <wdberke...@apache.org>
Authored: Tue Feb 13 15:41:06 2018 -0800
Committer: Will Berkeley <wdberke...@gmail.com>
Committed: Wed Feb 14 21:13:57 2018 +0000

----------------------------------------------------------------------
 src/kudu/tools/ksck.cc | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/cd419906/src/kudu/tools/ksck.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tools/ksck.cc b/src/kudu/tools/ksck.cc
index 0385b7f..f2bf4ce 100644
--- a/src/kudu/tools/ksck.cc
+++ b/src/kudu/tools/ksck.cc
@@ -199,24 +199,24 @@ Status Ksck::FetchInfoFromTabletServers() {
   }
   Warn() << Substitute("Fetched info from $0 Tablet Servers, $1 weren't 
reachable",
                        servers_count - bad_servers.Load(), bad_servers.Load()) 
<< endl;
-  return Status::NetworkError("Not all Tablet Servers are reachable");
+  return Status::NetworkError("Could not gather complete information from all 
tablet servers");
 }
 
 Status Ksck::ConnectToTabletServer(const shared_ptr<KsckTabletServer>& ts) {
   VLOG(1) << "Going to connect to Tablet Server: " << ts->uuid();
   Status s = ts->FetchInfo();
-  if (s.ok()) {
-    VLOG(1) << "Connected to Tablet Server: " << ts->uuid();
-    if (FLAGS_consensus) {
-      Status t = ts->FetchConsensusState();
-      if (!t.ok()) {
-        Warn() << Substitute("Errors gathering consensus info for Tablet 
Server $0: $1",
-                             ts->ToString(), t.ToString()) << endl;
-      }
-    }
-  } else {
+  if (!s.ok()) {
     Warn() << Substitute("Unable to connect to Tablet Server $0: $1",
                          ts->ToString(), s.ToString()) << endl;
+    return s;
+  }
+  VLOG(1) << "Connected to Tablet Server: " << ts->uuid();
+  if (FLAGS_consensus) {
+    s = ts->FetchConsensusState();
+    if (!s.ok()) {
+      Warn() << Substitute("Errors gathering consensus info for Tablet Server 
$0: $1",
+                           ts->ToString(), s.ToString()) << endl;
+    }
   }
   return s;
 }

Reply via email to