master: fix the value of table metric 'live_row_count'

When the tablet doesn't support live row counting, the
'live_row_count' metric of the tablet is '-1'. But when
master aggregates all tablets' metric of a table, it sums
up all '-1's, and the result value is confusing to users.
It's better to set it '-1' to be consistent with tablet metric.

Change-Id: I3f837466a0420dafef4f9426929b7b1622702ffc
Reviewed-on: http://gerrit.cloudera.org:8080/14446
Tested-by: Kudu Jenkins
Reviewed-by: Yingchun Lai <405403881@qq.com>
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>
diff --git a/src/kudu/master/catalog_manager.cc b/src/kudu/master/catalog_manager.cc
index 6108981..411906c 100644
--- a/src/kudu/master/catalog_manager.cc
+++ b/src/kudu/master/catalog_manager.cc
@@ -5573,7 +5573,12 @@
                               const tablet::ReportedTabletStatsPB& new_stats) {
   if (metrics_) {
     metrics_->on_disk_size->IncrementBy(new_stats.on_disk_size() - old_stats.on_disk_size());
-    metrics_->live_row_count->IncrementBy(new_stats.live_row_count() - old_stats.live_row_count());
+    if (new_stats.live_row_count() >= 0) {
+      metrics_->live_row_count->IncrementBy(
+          new_stats.live_row_count() - old_stats.live_row_count());
+    } else {
+      metrics_->live_row_count->set_value(-1);
+    }
   }
 }
 
diff --git a/src/kudu/master/table_metrics.cc b/src/kudu/master/table_metrics.cc
index 079379a..b259034 100644
--- a/src/kudu/master/table_metrics.cc
+++ b/src/kudu/master/table_metrics.cc
@@ -27,7 +27,8 @@
     "including metadata.");
 METRIC_DEFINE_gauge_int64(table, live_row_count, "Table Live Row count",
     kudu::MetricUnit::kRows,
-    "Pre-replication aggregated number of live rows in this table.");
+    "Pre-replication aggregated number of live rows in this table. "
+    "When the table doesn't support live row counting, -1 will be returned.");
 
 #define GINIT(x) x(METRIC_##x.Instantiate(entity, 0))