]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: drop QuorumService
authorKefu Chai <kchai@redhat.com>
Sat, 28 Nov 2020 11:35:08 +0000 (19:35 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 6 Dec 2020 15:15:40 +0000 (23:15 +0800)
so far we only implemented ConfigKeyService, so move QuorumService into
the its only child class -- ConfigKeyService.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/doc/mon-janitorial-queue.txt
src/doc/mon-wishlist.txt
src/mon/ConfigKeyService.cc
src/mon/ConfigKeyService.h
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc
src/mon/QuorumService.h [deleted file]

index bc9972b903dd06c20f7c32547f5563a6c9d95585..9114acbe7d7ec99922bbd7d46a8c8a08b4a1152f 100644 (file)
@@ -6,11 +6,6 @@ Low-hanging fruit:
   where possible, get rid of those put().  No one expects helpers to
   put() messages and that may lead to double frees.
 
-Medium complexity:
-
-- get rid of QuorumServices.  It seemed like a neat idea, but we only have
-  one or two and they just add complexity and noise.
-
 Time consuming / complex:
 
 - Split the OSDMonitor.cc file into auxiliary files.  This will mean:
index 3d29a3f6260d2cbcb72242a87b23225cb15f4001..a5fb9422cd78e191317b140d85c2e36fa237a05f 100644 (file)
@@ -8,12 +8,6 @@ Low-hanging fruit
   where possible, get rid of those put().  No one expects helpers to
   put() messages and that may lead to double frees. (issue #9378)
 
-Medium complexity
------------------
-
-* get rid of QuorumServices.  It seemed like a neat idea, but we only have
-  one or two and they just add complexity and noise. (issue #10506)
-
 Time consuming / complex
 ------------------------
 
index 5c02b1038a290fc85febcfd7b424c24a794df7d9..10ddf362ed31349de875f39aa3d4ea425dd1f103 100644 (file)
@@ -67,6 +67,79 @@ static ostream& _prefix(std::ostream *_dout, const Monitor *mon,
 
 const string CONFIG_PREFIX = "mon_config_key";
 
+ConfigKeyService::ConfigKeyService(Monitor *m, Paxos *p)
+  : mon(m),
+    paxos(p),
+    tick_period(g_conf()->mon_tick_interval)
+{}
+
+void ConfigKeyService::start(epoch_t new_epoch)
+{
+  epoch = new_epoch;
+  start_epoch();
+}
+
+void ConfigKeyService::finish()
+{
+  generic_dout(20) << "ConfigKeyService::finish" << dendl;
+  finish_epoch();
+}
+
+epoch_t ConfigKeyService::get_epoch() const {
+  return epoch;
+}
+
+bool ConfigKeyService::dispatch(MonOpRequestRef op) {
+  return service_dispatch(op);
+}
+
+bool ConfigKeyService::in_quorum() const
+{
+  return (mon->is_leader() || mon->is_peon());
+}
+
+void ConfigKeyService::start_tick()
+{
+  generic_dout(10) << __func__ << dendl;
+
+  cancel_tick();
+  if (tick_period <= 0)
+    return;
+
+  tick_event = new C_MonContext{mon, [this](int r) {
+    if (r < 0) {
+      return;
+    }
+    tick();
+  }};
+  mon->timer.add_event_after(tick_period, tick_event);
+}
+
+void ConfigKeyService::set_update_period(double t)
+{
+  tick_period = t;
+}
+
+void ConfigKeyService::cancel_tick()
+{
+  if (tick_event)
+    mon->timer.cancel_event(tick_event);
+  tick_event = nullptr;
+}
+
+void ConfigKeyService::tick()
+{
+  service_tick();
+  start_tick();
+}
+
+void ConfigKeyService::shutdown()
+{
+  generic_dout(0) << "quorum service shutdown" << dendl;
+  cancel_tick();
+  service_shutdown();
+}
+
 int ConfigKeyService::store_get(const string &key, bufferlist &bl)
 {
   return mon->store->get(CONFIG_PREFIX, key, bl);
@@ -272,7 +345,7 @@ bool ConfigKeyService::service_dispatch(MonOpRequestRef op)
 
     // we'll reply to the message once the proposal has been handled
     store_put(key, data,
-             new Monitor::C_Command(mon, op, 0, ss.str(), 0));
+             new Monitor::C_Command(*mon, op, 0, ss.str(), 0));
     // return for now; we'll put the message once it's done.
     return true;
 
@@ -288,7 +361,7 @@ bool ConfigKeyService::service_dispatch(MonOpRequestRef op)
       ss << "no such key '" << key << "'";
       goto out;
     }
-    store_delete(key, new Monitor::C_Command(mon, op, 0, "key deleted", 0));
+    store_delete(key, new Monitor::C_Command(*mon, op, 0, "key deleted", 0));
     // return for now; we'll put the message once it's done
     return true;
 
index e85753daecb2d030c6250dffdd5db9b3cf8c6d72..c2eaddb8e57fb736d094907b81b58f042169864d 100644 (file)
 #ifndef CEPH_MON_CONFIG_KEY_SERVICE_H
 #define CEPH_MON_CONFIG_KEY_SERVICE_H
 
-#include "mon/QuorumService.h"
+#include "include/Context.h"
+#include "mon/MonOpRequest.h"
 #include "mon/MonitorDBStore.h"
 
 class Paxos;
 class Monitor;
 
-class ConfigKeyService : public QuorumService
+class ConfigKeyService
 {
 public:
-  ConfigKeyService(Monitor *m, Paxos *p) :
-    QuorumService(m),
-    paxos(p)
-  { }
-  ~ConfigKeyService() override { }
+  enum {
+    SERVICE_HEALTH     = 0x01,
+    SERVICE_TIMECHECK  = 0x02,
+    SERVICE_CONFIG_KEY = 0x03,
+  };
+  ConfigKeyService(Monitor *m, Paxos *p);
+  ~ConfigKeyService() {}
 
+  void start(epoch_t new_epoch);
+  void finish();
+  void shutdown();
 
-  /**
-   * @defgroup ConfigKeyService_Inherited_h Inherited abstract methods
-   * @{
-   */
-  void init() override { }
-  bool service_dispatch(MonOpRequestRef op) override;
+  void init() { }
+  bool dispatch(MonOpRequestRef op);
+  bool service_dispatch(MonOpRequestRef op);
 
-  void start_epoch() override { }
-  void finish_epoch() override { }
-  void cleanup() override { }
-  void service_tick() override { }
+  void start_epoch() { }
+  void finish_epoch() { }
+  epoch_t get_epoch() const;
+  void cleanup() { }
+  void service_tick() { }
 
   int validate_osd_destroy(const int32_t id, const uuid_d& uuid);
   void do_osd_destroy(int32_t id, uuid_d& uuid);
@@ -50,21 +54,32 @@ public:
       std::stringstream& ss);
   void do_osd_new(const uuid_d& uuid, const std::string& dmcrypt_key);
 
-  int get_type() override {
-    return QuorumService::SERVICE_CONFIG_KEY;
+  int get_type() {
+    return SERVICE_CONFIG_KEY;
   }
 
-  std::string get_name() const override {
+  std::string get_name() const {
     return "config_key";
   }
   void get_store_prefixes(std::set<std::string>& s) const;
-  /**
-   * @} // ConfigKeyService_Inherited_h
-   */
+
 protected:
-  void service_shutdown() override { }
+  void service_shutdown() { }
+
 private:
+  Monitor *mon;
   Paxos *paxos;
+  epoch_t epoch = 0;
+
+  bool in_quorum() const;
+
+  void start_tick();
+  void cancel_tick();
+  void tick();
+  void set_update_period(double t);
+
+  Context *tick_event = nullptr;
+  double tick_period;
 
   int store_get(const std::string &key, ceph::buffer::list &bl);
   void store_put(const std::string &key, ceph::buffer::list &bl, Context *cb = NULL);
index 9b50d8e985925b81e9df6b6f5afe1ab088839805..da934d978d2d9fc9d132ad5f5321f78874d344fd 100644 (file)
@@ -85,9 +85,8 @@
 #include "MgrMonitor.h"
 #include "MgrStatMonitor.h"
 #include "ConfigMonitor.h"
-#include "mon/QuorumService.h"
-#include "mon/HealthMonitor.h"
 #include "mon/ConfigKeyService.h"
+#include "mon/HealthMonitor.h"
 #include "common/config.h"
 #include "common/cmdparse.h"
 #include "include/ceph_assert.h"
index 233a4a7e44f8da97eaaa199580f6053eae520e6e..5043ab1efd68e8051b1120ad1d31761f6ab5cab9 100644 (file)
@@ -98,7 +98,7 @@ enum {
   l_mon_last,
 };
 
-class QuorumService;
+class ConfigKeyService;
 class PaxosService;
 
 class AdminSocketHook;
@@ -684,7 +684,7 @@ public:
   friend class LogMonitor;
   friend class ConfigKeyService;
 
-  std::unique_ptr<QuorumService> config_key_service;
+  std::unique_ptr<ConfigKeyService> config_key_service;
 
   // -- sessions --
   MonSessionMap session_map;
index 9f7b3c611a8e5694548b784cc1bc80cc8c101aee..e6d09366d04d3da0b2452233d61ebb46e79d673b 100644 (file)
@@ -9409,7 +9409,7 @@ int OSDMonitor::prepare_command_osd_new(
     }
 
     if (has_lockbox) {
-      svc = (ConfigKeyService*)(mon.config_key_service.get());
+      svc = mon.config_key_service.get();
       err = svc->validate_osd_new(uuid, dmcrypt_key, ss);
       if (err < 0) {
         return err;
@@ -9594,7 +9594,7 @@ int OSDMonitor::prepare_command_osd_destroy(
     }
   }
 
-  auto svc = (ConfigKeyService*)(mon.config_key_service.get());
+  auto svc = mon.config_key_service.get();
   err = svc->validate_osd_destroy(id, uuid);
   if (err < 0) {
     ceph_assert(err == -ENOENT);
diff --git a/src/mon/QuorumService.h b/src/mon/QuorumService.h
deleted file mode 100644 (file)
index c4d30be..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2013 Inktank, Inc
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-#ifndef CEPH_MON_QUORUM_SERVICE_H
-#define CEPH_MON_QUORUM_SERVICE_H
-
-#include <errno.h>
-
-#include "include/types.h"
-#include "include/Context.h"
-#include "common/RefCountedObj.h"
-#include "common/config.h"
-
-#include "mon/Monitor.h"
-
-class QuorumService
-{
-  Context *tick_event = nullptr;
-  double tick_period;
-
-public:
-  enum {
-    SERVICE_HEALTH                   = 0x01,
-    SERVICE_TIMECHECK                = 0x02,
-    SERVICE_CONFIG_KEY               = 0x03,
-  };
-
-protected:
-  Monitor *mon;
-  epoch_t epoch;
-
-  QuorumService(Monitor *m) :
-    tick_period(g_conf()->mon_tick_interval),
-    mon(m),
-    epoch(0)
-  {
-  }
-
-  void cancel_tick() {
-    if (tick_event)
-      mon->timer.cancel_event(tick_event);
-    tick_event = NULL;
-  }
-
-  void start_tick() {
-    generic_dout(10) << __func__ << dendl;
-
-    cancel_tick();
-    if (tick_period <= 0)
-      return;
-
-    tick_event = new C_MonContext{mon, [this](int r) {
-       if (r < 0)
-         return;
-       tick();
-      }};
-    mon->timer.add_event_after(tick_period, tick_event);
-  }
-
-  void set_update_period(double t) {
-    tick_period = t;
-  }
-
-  bool in_quorum() {
-    return (mon->is_leader() || mon->is_peon());
-  }
-
-  virtual bool service_dispatch(MonOpRequestRef op) = 0;
-  virtual void service_tick() = 0;
-  virtual void service_shutdown() = 0;
-
-  virtual void start_epoch() = 0;
-  virtual void finish_epoch() = 0;
-  virtual void cleanup() = 0;
-
-public:
-  virtual ~QuorumService() { }
-
-  void start(epoch_t new_epoch) {
-    epoch = new_epoch;
-    start_epoch();
-  }
-
-  void finish() {
-    generic_dout(20) << "QuorumService::finish" << dendl;
-    finish_epoch();
-  }
-
-  epoch_t get_epoch() const {
-    return epoch;
-  }
-
-  bool dispatch(MonOpRequestRef op) {
-    return service_dispatch(op);
-  }
-
-  void tick() {
-    service_tick();
-    start_tick();
-  }
-
-  void shutdown() {
-    generic_dout(0) << "quorum service shutdown" << dendl;
-    cancel_tick();
-    service_shutdown();
-  }
-
-  virtual void init() { }
-
-  virtual int get_type() = 0;
-  virtual std::string get_name() const = 0;
-
-};
-
-#endif /* CEPH_MON_QUORUM_SERVICE_H */