]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/: pull NamedState and PGStateHistory out into PGStateUtils
authorSamuel Just <sjust@redhat.com>
Thu, 21 Mar 2019 19:36:39 +0000 (12:36 -0700)
committersjust@redhat.com <sjust@redhat.com>
Wed, 1 May 2019 18:22:11 +0000 (11:22 -0700)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/osd/CMakeLists.txt
src/osd/PG.cc
src/osd/PG.h
src/osd/PGStateUtils.cc [new file with mode: 0644]
src/osd/PGStateUtils.h [new file with mode: 0644]
src/osd/PeeringState.cc
src/osd/PeeringState.h
src/osd/PrimaryLogPG.h

index 74eb6b9b6827900e7fdae21deb914961322c506a..0ab2876ad5ab7af3be4bb024cb4e0b7aee74f77f 100644 (file)
@@ -34,6 +34,7 @@ set(osd_srcs
   mClockClientQueue.cc
   OpQueueItem.cc
   PeeringState.cc
+  PGStateUtils.cc
   ${CMAKE_SOURCE_DIR}/src/common/TrackedOp.cc
   ${CMAKE_SOURCE_DIR}/src/objclass/class_api.cc
   ${CMAKE_SOURCE_DIR}/src/mgr/OSDPerfMetricTypes.cc
index 9850c76835e805912b45d2a1a6a5f87b049e64b1..fd84d6564f6257e1876d624a18d387d0927ab138 100644 (file)
@@ -90,66 +90,6 @@ static ostream& _prefix(std::ostream *_dout, T *t)
   return t->gen_prefix(*_dout);
 }
 
-void PGStateHistory::enter(PG* pg, const utime_t entime, const char* state)
-{
-  // Ignore trimming state machine for now
-  if (::strstr(state, "Trimming") != NULL) {
-    return;
-  } else if (pi != nullptr) {
-    pi->enter_state(entime, state);
-  } else {
-    // Store current state since we can't reliably take the PG lock here
-    if ( tmppi == nullptr) {
-      tmppi = std::unique_ptr<PGStateInstance>(new PGStateInstance);
-    }
-
-    thispg = pg;
-    tmppi->enter_state(entime, state);
-  }
-}
-
-void PGStateHistory::exit(const char* state) {
-  // Ignore trimming state machine for now
-  // Do nothing if PG is being destroyed!
-  if (::strstr(state, "Trimming") != NULL || pg_in_destructor) {
-    return;
-  } else {
-    bool ilocked = false;
-    if(!thispg->is_locked()) {
-      thispg->lock();
-      ilocked = true;
-    }
-    if (pi == nullptr) {
-      buffer.push_back(std::unique_ptr<PGStateInstance>(tmppi.release()));
-      pi = buffer.back().get();
-      pi->setepoch(thispg->get_osdmap_epoch());
-    }
-
-    pi->exit_state(ceph_clock_now());
-    if (::strcmp(state, "Reset") == 0) {
-      this->reset();
-    }
-    if(ilocked) {
-      thispg->unlock();
-    }
-  }
-}
-
-void PGStateHistory::dump(Formatter* f) const {
-  f->open_array_section("history");
-  for (auto pi = buffer.begin(); pi != buffer.end(); ++pi) {
-    f->open_object_section("states");
-    f->dump_stream("epoch") << (*pi)->this_epoch;
-    for (auto she : (*pi)->state_history) {
-      f->dump_string("state", std::get<2>(she));
-      f->dump_stream("enter") << std::get<0>(she);
-      f->dump_stream("exit") << std::get<1>(she);
-    }
-    f->close_section();
-  }
-  f->close_section();
-}
-
 void PG::get(const char* tag)
 {
   int after = ++ref;
index 8d94f867a7ad61d21aa4d164dceee187a594bbc4..52b02012c38794fd82591fbde661fe098d932b86 100644 (file)
@@ -23,7 +23,6 @@
 #include <boost/statechart/transition.hpp>
 #include <boost/statechart/event_base.hpp>
 #include <boost/scoped_ptr.hpp>
-#include <boost/circular_buffer.hpp>
 #include <boost/container/flat_set.hpp>
 #include "include/mempool.h"
 
@@ -51,7 +50,6 @@
 #include <atomic>
 #include <list>
 #include <memory>
-#include <stack>
 #include <string>
 #include <tuple>
 
@@ -78,64 +76,6 @@ namespace Scrub {
   class Store;
 }
 
-using state_history_entry = std::tuple<utime_t, utime_t, const char*>;
-using embedded_state = std::pair<utime_t, const char*>;
-
-struct PGStateInstance {
-  // Time spent in pg states
-
-  void setepoch(const epoch_t current_epoch) {
-    this_epoch = current_epoch;
-  }
-
-  void enter_state(const utime_t entime, const char* state) {
-    embedded_states.push(std::make_pair(entime, state));
-  }
-
-  void exit_state(const utime_t extime) {
-    embedded_state this_state = embedded_states.top();
-    state_history.push_back(state_history_entry{
-        this_state.first, extime, this_state.second});
-    embedded_states.pop();
-  }
-
-  epoch_t this_epoch;
-  utime_t enter_time;
-  std::vector<state_history_entry> state_history;
-  std::stack<embedded_state> embedded_states;
-};
-
-class PGStateHistory {
-  // Member access protected with the PG lock
-public:
-  PGStateHistory() : buffer(10) {}
-
-  void enter(PG* pg, const utime_t entime, const char* state);
-
-  void exit(const char* state);
-
-  void reset() {
-    pi = nullptr;
-  }
-
-  void set_pg_in_destructor() { pg_in_destructor = true; }
-
-  void dump(Formatter* f) const;
-
-  string get_current_state() {
-    if (pi == nullptr) return "unknown";
-    return std::get<1>(pi->embedded_states.top());
-  }
-
-private:
-  bool pg_in_destructor = false;
-  PG* thispg = nullptr;
-  std::unique_ptr<PGStateInstance> tmppi;
-  PGStateInstance* pi = nullptr;
-  boost::circular_buffer<std::unique_ptr<PGStateInstance>> buffer;
-
-};
-
 #ifdef PG_DEBUG_REFS
 #include "common/tracked_int_ptr.hpp"
   uint64_t get_with_id(PG *pg);
@@ -257,6 +197,7 @@ struct PGPool {
  */
 
 class PG : public DoutPrefixProvider {
+  friend class NamedState;
   friend class PeeringState;
 public:
   using PeeringCtx = PeeringState::PeeringCtx;
diff --git a/src/osd/PGStateUtils.cc b/src/osd/PGStateUtils.cc
new file mode 100644 (file)
index 0000000..e6807a7
--- /dev/null
@@ -0,0 +1,77 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "PGStateUtils.h"
+#include "PG.h"
+
+/*------NamedState----*/
+NamedState::NamedState(
+  PG *pg_, const char *state_name_)
+  : state_name(state_name_), enter_time(ceph_clock_now()), pg(pg_) {
+  pg->pgstate_history.enter(pg, enter_time, state_name);
+}
+
+NamedState::~NamedState() {
+  pg->pgstate_history.exit(state_name);
+}
+
+/*---------PGStateHistory---------*/
+void PGStateHistory::enter(PG* pg, const utime_t entime, const char* state)
+{
+  // Ignore trimming state machine for now
+  if (::strstr(state, "Trimming") != NULL) {
+    return;
+  } else if (pi != nullptr) {
+    pi->enter_state(entime, state);
+  } else {
+    // Store current state since we can't reliably take the PG lock here
+    if ( tmppi == nullptr) {
+      tmppi = std::unique_ptr<PGStateInstance>(new PGStateInstance);
+    }
+
+    thispg = pg;
+    tmppi->enter_state(entime, state);
+  }
+}
+
+void PGStateHistory::exit(const char* state) {
+  // Ignore trimming state machine for now
+  // Do nothing if PG is being destroyed!
+  if (::strstr(state, "Trimming") != NULL || pg_in_destructor) {
+    return;
+  } else {
+    bool ilocked = false;
+    if(!thispg->is_locked()) {
+      thispg->lock();
+      ilocked = true;
+    }
+    if (pi == nullptr) {
+      buffer.push_back(std::unique_ptr<PGStateInstance>(tmppi.release()));
+      pi = buffer.back().get();
+      pi->setepoch(thispg->get_osdmap_epoch());
+    }
+
+    pi->exit_state(ceph_clock_now());
+    if (::strcmp(state, "Reset") == 0) {
+      this->reset();
+    }
+    if(ilocked) {
+      thispg->unlock();
+    }
+  }
+}
+
+void PGStateHistory::dump(Formatter* f) const {
+  f->open_array_section("history");
+  for (auto pi = buffer.begin(); pi != buffer.end(); ++pi) {
+    f->open_object_section("states");
+    f->dump_stream("epoch") << (*pi)->this_epoch;
+    for (auto she : (*pi)->state_history) {
+      f->dump_string("state", std::get<2>(she));
+      f->dump_stream("enter") << std::get<0>(she);
+      f->dump_stream("exit") << std::get<1>(she);
+    }
+    f->close_section();
+  }
+  f->close_section();
+}
diff --git a/src/osd/PGStateUtils.h b/src/osd/PGStateUtils.h
new file mode 100644 (file)
index 0000000..8f38ede
--- /dev/null
@@ -0,0 +1,79 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include "include/utime.h"
+
+#include <stack>
+#include <vector>
+#include <boost/circular_buffer.hpp>
+
+class PG;
+
+struct NamedState {
+  const char *state_name;
+  utime_t enter_time;
+  PG* pg;
+  const char *get_state_name() { return state_name; }
+  NamedState(PG *pg_, const char *state_name_);
+  virtual ~NamedState();
+};
+
+using state_history_entry = std::tuple<utime_t, utime_t, const char*>;
+using embedded_state = std::pair<utime_t, const char*>;
+
+struct PGStateInstance {
+  // Time spent in pg states
+
+  void setepoch(const epoch_t current_epoch) {
+    this_epoch = current_epoch;
+  }
+
+  void enter_state(const utime_t entime, const char* state) {
+    embedded_states.push(std::make_pair(entime, state));
+  }
+
+  void exit_state(const utime_t extime) {
+    embedded_state this_state = embedded_states.top();
+    state_history.push_back(state_history_entry{
+        this_state.first, extime, this_state.second});
+    embedded_states.pop();
+  }
+
+  epoch_t this_epoch;
+  utime_t enter_time;
+  std::vector<state_history_entry> state_history;
+  std::stack<embedded_state> embedded_states;
+};
+
+class PGStateHistory {
+  // Member access protected with the PG lock
+public:
+  PGStateHistory() : buffer(10) {}
+
+  void enter(PG* pg, const utime_t entime, const char* state);
+
+  void exit(const char* state);
+
+  void reset() {
+    pi = nullptr;
+  }
+
+  void set_pg_in_destructor() { pg_in_destructor = true; }
+
+  void dump(Formatter* f) const;
+
+  string get_current_state() {
+    if (pi == nullptr) return "unknown";
+    return std::get<1>(pi->embedded_states.top());
+  }
+
+private:
+  bool pg_in_destructor = false;
+  PG* thispg = nullptr;
+  std::unique_ptr<PGStateInstance> tmppi;
+  PGStateInstance* pi = nullptr;
+  boost::circular_buffer<std::unique_ptr<PGStateInstance>> buffer;
+
+};
index a580c2fdd43b4d3134f0d96d6146c6bfb4d3ec0c..2631cc3c662506590a6bb690fb020f50c0134996 100644 (file)
@@ -28,17 +28,6 @@ void PeeringState::PeeringMachine::send_query(
                     << "state<" << get_state_name() << ">: ")
 #define psdout(x) ldout(context< PeeringMachine >().cct, x)
 
-/*------NamedState----*/
-PeeringState::NamedState::NamedState(
-  PG *pg_, const char *state_name_)
-  : state_name(state_name_), enter_time(ceph_clock_now()), pg(pg_) {
-  pg->pgstate_history.enter(pg, enter_time, state_name);
-}
-
-PeeringState::NamedState::~NamedState() {
-  pg->pgstate_history.exit(state_name);
-}
-
 /*------Crashed-------*/
 PeeringState::Crashed::Crashed(my_context ctx)
   : my_base(ctx),
index 2cfbde01331c916499ae3bc7f6ff85382c0e9895..b3e054f9d8c41008bd2cb60d5c25cc6d02e03118 100644 (file)
@@ -11,6 +11,7 @@
 #include <boost/statechart/transition.hpp>
 #include <boost/statechart/event_base.hpp>
 
+#include "PGStateUtils.h"
 #include "PGPeeringEvent.h"
 #include "os/ObjectStore.h"
 #include "OSDMap.h"
@@ -20,15 +21,6 @@ class PG;
   /* Encapsulates PG recovery process */
 class PeeringState {
 public:
-  struct NamedState {
-    const char *state_name;
-    utime_t enter_time;
-    PG* pg;
-    const char *get_state_name() { return state_name; }
-    NamedState(PG *pg_, const char *state_name_);
-    virtual ~NamedState();
-  };
-
   // [primary only] content recovery state
   struct BufferedRecoveryMessages {
     map<int, map<spg_t, pg_query_t> > query_map;
index 14d8eb8c7020a1b4765bee708687828d61c256c1..9aed6243b1ec7afcc5ea756a3368f2b5da67c2f1 100644 (file)
@@ -1589,7 +1589,6 @@ private:
     }
   } snap_trimmer_machine;
 
-  using NamedState = PeeringState::NamedState;
   struct WaitReservation;
   struct Trimming : boost::statechart::state< Trimming, SnapTrimmer, WaitReservation >, NamedState {
     typedef boost::mpl::list <