Repository: kudu
Updated Branches:
  refs/heads/master 8363b7450 -> 9b52ae148


[scanner] LOG(INFO) --> VLOG(1) on scanner expiration

Made code up-to-date with the TODO comment: replaced LOG(INFO) with
VLOG(1) in the event of scanner expiration.

Change-Id: I78f0b07131aaf4dc4a2cb72bed1ce1647a201b68
Reviewed-on: http://gerrit.cloudera.org:8080/6416
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <[email protected]>


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

Branch: refs/heads/master
Commit: 5df142fa35bf04231ee92b622482a1be0b18b294
Parents: 8363b74
Author: Alexey Serbin <[email protected]>
Authored: Fri Mar 17 14:38:48 2017 -0700
Committer: Adar Dembo <[email protected]>
Committed: Sat Mar 18 00:02:44 2017 +0000

----------------------------------------------------------------------
 src/kudu/tserver/scanners.cc | 42 +++++++++++++++++++++++----------------
 src/kudu/tserver/scanners.h  | 12 ++++++-----
 2 files changed, 32 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/5df142fa/src/kudu/tserver/scanners.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/scanners.cc b/src/kudu/tserver/scanners.cc
index e8e79d5..7d9a821 100644
--- a/src/kudu/tserver/scanners.cc
+++ b/src/kudu/tserver/scanners.cc
@@ -16,17 +16,19 @@
 // under the License.
 #include "kudu/tserver/scanners.h"
 
-#include <gflags/gflags.h>
 #include <mutex>
 
+#include <gflags/gflags.h>
+
 #include "kudu/common/iterator.h"
 #include "kudu/common/scan_spec.h"
 #include "kudu/gutil/hash/string_hash.h"
 #include "kudu/gutil/map-util.h"
+#include "kudu/gutil/strings/substitute.h"
 #include "kudu/tserver/scanner_metrics.h"
 #include "kudu/util/flag_tags.h"
-#include "kudu/util/thread.h"
 #include "kudu/util/metrics.h"
+#include "kudu/util/thread.h"
 
 DEFINE_int32(scanner_ttl_ms, 60000,
              "Number of milliseconds of inactivity allowed for a scanner"
@@ -43,6 +45,8 @@ METRIC_DEFINE_gauge_size(server, active_scanners,
                          kudu::MetricUnit::kScanners,
                          "Number of scanners that are currently active");
 
+using strings::Substitute;
+
 namespace kudu {
 
 using tablet::TabletPeer;
@@ -153,31 +157,35 @@ void 
ScannerManager::ListScanners(std::vector<SharedScanner>* scanners) {
 
 void ScannerManager::RemoveExpiredScanners() {
   MonoDelta scanner_ttl = MonoDelta::FromMilliseconds(FLAGS_scanner_ttl_ms);
+  const MonoTime now = MonoTime::Now();
 
   for (ScannerMapStripe* stripe : scanner_maps_) {
     std::lock_guard<RWMutex> l(stripe->lock_);
     for (auto it = stripe->scanners_by_id_.begin(); it != 
stripe->scanners_by_id_.end();) {
-      SharedScanner& scanner = it->second;
-      MonoDelta time_live =
-          scanner->TimeSinceLastAccess(MonoTime::Now());
-      if (time_live > scanner_ttl) {
-        // TODO: once we have a metric for the number of scanners expired, 
make this a
-        // VLOG(1).
-        LOG(INFO) << "Expiring scanner id: " << it->first << ", of tablet " << 
scanner->tablet_id()
-                  << ", after " << time_live.ToMicroseconds()
-                  << " us of inactivity, which is > TTL ("
-                  << scanner_ttl.ToMicroseconds() << " us).";
-        it = stripe->scanners_by_id_.erase(it);
-        if (metrics_) {
-          metrics_->scanners_expired->Increment();
-        }
-      } else {
+      const SharedScanner& scanner = it->second;
+      MonoDelta idle_time = scanner->TimeSinceLastAccess(now);
+      if (idle_time <= scanner_ttl) {
         ++it;
+        continue;
+      }
+
+      // The scanner has expired because of inactivity.
+      VLOG(1) << Substitute("Expiring scanner id: $0, of tablet $1, "
+                            "after $2 ms of inactivity, which is > TTL ($3 
ms).",
+                            it->first,
+                            scanner->tablet_id(),
+                            idle_time.ToMilliseconds(),
+                            scanner_ttl.ToMilliseconds());
+      it = stripe->scanners_by_id_.erase(it);
+      if (metrics_) {
+        metrics_->scanners_expired->Increment();
       }
     }
   }
 }
 
+const std::string Scanner::kNullTabletId = "null tablet";
+
 Scanner::Scanner(string id, const scoped_refptr<TabletPeer>& tablet_peer,
                  string requestor_string, ScannerMetrics* metrics)
     : id_(std::move(id)),

http://git-wip-us.apache.org/repos/asf/kudu/blob/5df142fa/src/kudu/tserver/scanners.h
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/scanners.h b/src/kudu/tserver/scanners.h
index 3e28d69..370d5bc 100644
--- a/src/kudu/tserver/scanners.h
+++ b/src/kudu/tserver/scanners.h
@@ -167,9 +167,9 @@ class ScopedUnregisterScanner {
 // An open scanner on the server side.
 class Scanner {
  public:
-  explicit Scanner(std::string id,
-                   const scoped_refptr<tablet::TabletPeer>& tablet_peer,
-                   std::string requestor_string, ScannerMetrics* metrics);
+  Scanner(std::string id,
+          const scoped_refptr<tablet::TabletPeer>& tablet_peer,
+          std::string requestor_string, ScannerMetrics* metrics);
   ~Scanner();
 
   // Attach an actual iterator and a ScanSpec to this Scanner.
@@ -214,9 +214,9 @@ class Scanner {
   // Return the ScanSpec associated with this Scanner.
   const ScanSpec& spec() const;
 
-  const std::string tablet_id() const {
+  const std::string& tablet_id() const {
     // scanners-test passes a null tablet_peer.
-    return tablet_peer_ ? tablet_peer_->tablet_id() : "null tablet";
+    return tablet_peer_ ? tablet_peer_->tablet_id() : kNullTabletId;
   }
 
   const scoped_refptr<tablet::TabletPeer>& tablet_peer() const { return 
tablet_peer_; }
@@ -275,6 +275,8 @@ class Scanner {
  private:
   friend class ScannerManager;
 
+  static const std::string kNullTabletId;
+
   // The unique ID of this scanner.
   const std::string id_;
 

Reply via email to