]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: add clear_cache and get_cache_object_count commands
authorMohamad Gebai <mgebai@suse.com>
Sun, 12 Aug 2018 15:43:15 +0000 (18:43 +0300)
committerMohamad Gebai <mgebai@suse.com>
Wed, 10 Oct 2018 15:45:51 +0000 (11:45 -0400)
Fixes: http://tracker.ceph.com/issues/24176
Signed-off-by: Mohamad Gebai <mgebai@suse.com>
src/common/shared_cache.hpp
src/os/ObjectStore.h
src/os/bluestore/BlueStore.h
src/osd/OSD.cc
src/osd/PG.h
src/osd/PrimaryLogPG.cc
src/osd/PrimaryLogPG.h

index 283bff401c5aa657554dbef710e3bb57a6dce33f..7db8108c25509dc801d387297298ceb65c3d3cf9 100644 (file)
@@ -123,6 +123,10 @@ public:
     }
   }
 
+  int get_count() {
+    return lru.size();
+  }
+
   /// adjust container comparator (for purposes of get_next sort order)
   void reset_comparator(C comp) {
     // get_next uses weak_refs; that's the only container we need to
index 736cab460d3bacc3dd235f4e3aed7f935998d0cc..1ccfee6eb5c52575482934eed7bc8f3da052adf8 100644 (file)
@@ -1481,6 +1481,9 @@ public:
   virtual void generate_db_histogram(Formatter *f) { }
   virtual void flush_cache() { }
   virtual void dump_perf_counters(Formatter *f) {}
+  virtual int get_cache_obj_count() {
+    return -1;
+  }
 
   virtual string get_type() = 0;
 
index 6c15953dd2da0d4cfcbca678eaaa4f411fe58c7a..0f548e16f5d8ef707fb7d2f979c1b28b73564fe0 100644 (file)
@@ -2333,6 +2333,13 @@ public:
   int _fsck(bool deep, bool repair);
 
   void set_cache_shards(unsigned num) override;
+  int get_cache_obj_count() {
+    int count = 0;
+    for (auto i: cache_shards) {
+      count += i->_get_num_onodes();
+    }
+    return count;
+  }
 
   int validate_hobject_key(const hobject_t &obj) const override {
     return 0;
index 3d4d6c35c8995d1f819fe47254b4f88ff18b9429..4deb1430ffe83894ba38399087046579d1a3f6e8 100644 (file)
@@ -6020,6 +6020,12 @@ COMMAND("compact",
 COMMAND("smart name=devid,type=CephString,req=False",
         "runs smartctl on this osd devices.  ",
         "osd", "rw", "cli,rest")
+COMMAND("clear_cache",
+        "Clear OSD caches",
+        "osd", "rw", "cli,rest")
+COMMAND("get_cache_object_count",
+        "Get OSD caches object count",
+        "osd", "r", "cli,rest")
 };
 
 void OSD::do_command(
@@ -6496,6 +6502,46 @@ int OSD::_do_command(
     probe_smart(devid, ds);
   }
 
+  else if (prefix == "clear_cache") {
+    dout(20) << "clearing all caches" << dendl;
+    // Clear the objectstore's cache
+    store->flush_cache();
+    // Clear osd map cache
+    {
+      Mutex::Locker l(service.map_cache_lock);
+      service.map_cache.clear();
+    }
+    // Clear the objectcontext cache (per PG)
+    vector<PGRef> pgs;
+    _get_pgs(&pgs);
+    for (auto& pg: pgs) {
+      pg->clear_cache();
+    }
+  }
+
+  else if (prefix == "get_cache_object_count") {
+    int store_cache_count = store->get_cache_obj_count();
+    int obj_ctx_count = 0;
+    int osd_map_count = service.map_cache.get_count();
+    vector<PGRef> pgs;
+    _get_pgs(&pgs);
+    for (auto& pg: pgs) {
+      obj_ctx_count += pg->get_cache_obj_count();
+    }
+    if (f) {
+      f->open_object_section("caches_object_count");
+      f->dump_int("object_ctx", obj_ctx_count);
+      f->dump_int("objectstore_onode", store_cache_count);
+      f->dump_int("osd_map", osd_map_count);
+      f->close_section();
+      f->flush(ds);
+    } else {
+      ds << "object_ctx: " << obj_ctx_count;
+      ds << "objectstore_onode: " << store_cache_count;
+      ds << "osd_map: " << osd_map_count;
+    }
+  }
+
   else {
     ss << "unrecognized command '" << prefix << "'";
     r = -EINVAL;
index 3aa6b180ea503ee104b6899b78db0cdcf1bd5907..dd1ba00ce320fffd80c8e68261117cf57a092afd 100644 (file)
@@ -458,6 +458,8 @@ public:
     OpRequestRef& op,
     ThreadPool::TPHandle &handle
   ) = 0;
+  virtual void clear_cache() = 0;
+  virtual int get_cache_obj_count() = 0;
 
   virtual void snap_trimmer(epoch_t epoch_queued) = 0;
   virtual int do_command(
index 14aa42c13cdd4943ee62b57bb6ab7f3d598a6d8a..0c9ecbe8075977f24f99c66d8e077579bd390b52 100644 (file)
@@ -11954,6 +11954,11 @@ void PrimaryLogPG::clear_async_reads()
   }
 }
 
+void PrimaryLogPG::clear_cache()
+{
+  object_contexts.clear();
+}
+
 void PrimaryLogPG::on_shutdown()
 {
   dout(10) << __func__ << dendl;
index 262341d32d03b7a54d584b471ab4ba7b981297cc..3707bb984730befdbecc19f972a89f45ff9da6a3 100644 (file)
@@ -1435,6 +1435,10 @@ public:
     ConnectionRef conn,
     ceph_tid_t tid) override;
 
+  void clear_cache();
+  int get_cache_obj_count() {
+    return object_contexts.get_count();
+  }
   void do_request(
     OpRequestRef& op,
     ThreadPool::TPHandle &handle) override;