From: Kefu Chai Date: Sat, 26 May 2018 05:35:26 +0000 (+0800) Subject: common/Throttle: extract ThrottleInterface X-Git-Tag: v14.0.1~1115^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a28559842b450555991b0826fa4f7e91cd96a5f2;p=ceph.git common/Throttle: extract ThrottleInterface the Message classes are shared by OSD and other components of Ceph, and the throttle in Policy class is different in seastar and non-seastar world. we will have different implementations for the seastar applications and non-seastar apps, to consolidate these two implementations, we need to introduce a common interface for them. Signed-off-by: Kefu Chai --- diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 297111831d0..025d0185824 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -33,6 +33,7 @@ #include "common/ceph_argparse.h" #include "common/pick_address.h" +#include "common/Throttle.h" #include "common/Timer.h" #include "common/errno.h" #include "common/Preforker.h" diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index 6487679eac2..95d03ecd8d4 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -31,6 +31,7 @@ #include "msg/Messenger.h" +#include "common/Throttle.h" #include "common/Timer.h" #include "common/TracepointProvider.h" #include "common/ceph_argparse.h" diff --git a/src/common/Throttle.h b/src/common/Throttle.h index 0c03e60569a..6558c401fd0 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -13,6 +13,7 @@ #include #include "include/Context.h" +#include "common/ThrottleInterface.h" #include "common/Timer.h" #include "common/convenience.h" #include "common/perf_counters.h" @@ -25,7 +26,7 @@ * excessive requests for more of them are delayed, until some slots are put * back, so @p get_current() drops below the limit after fulfills the requests. */ -class Throttle { +class Throttle final : public ThrottleInterface { CephContext *cct; const std::string name; PerfCountersRef logger; @@ -36,7 +37,7 @@ class Throttle { public: Throttle(CephContext *cct, const std::string& n, int64_t m = 0, bool _use_perf = true); - ~Throttle(); + ~Throttle() override; private: void _reset_max(int64_t m); @@ -87,7 +88,7 @@ public: * @param c number of slots to take * @returns the total number of taken slots */ - int64_t take(int64_t c = 1); + int64_t take(int64_t c = 1) override; /** * get the specified amount of slots from the stock, but will wait if the @@ -111,7 +112,7 @@ public: * @param c number of slots to return * @returns number of requests being hold after this */ - int64_t put(int64_t c = 1); + int64_t put(int64_t c = 1) override; /** * reset the zero to the stock */ diff --git a/src/common/ThrottleInterface.h b/src/common/ThrottleInterface.h new file mode 100644 index 00000000000..49182a1172b --- /dev/null +++ b/src/common/ThrottleInterface.h @@ -0,0 +1,23 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include + +class ThrottleInterface { +public: + virtual ~ThrottleInterface() {} + /** + * take the specified number of slots from the stock regardless the throttling + * @param c number of slots to take + * @returns the total number of taken slots + */ + virtual int64_t take(int64_t c = 1) = 0; + /** + * put slots back to the stock + * @param c number of slots to return + * @returns number of requests being hold after this + */ + virtual int64_t put(int64_t c = 1) = 0; +}; diff --git a/src/msg/DispatchQueue.h b/src/msg/DispatchQueue.h index 55698819361..e95712d5d79 100644 --- a/src/msg/DispatchQueue.h +++ b/src/msg/DispatchQueue.h @@ -20,6 +20,7 @@ #include #include "include/assert.h" #include "include/xlist.h" +#include "common/Throttle.h" #include "common/Mutex.h" #include "common/Cond.h" #include "common/Thread.h" diff --git a/src/msg/Message.h b/src/msg/Message.h index a3ea35364d3..be3f599f18c 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -25,7 +25,7 @@ #include "include/types.h" #include "include/buffer.h" -#include "common/Throttle.h" +#include "common/ThrottleInterface.h" #include "common/zipkin_trace.h" #include "msg_types.h" @@ -283,10 +283,10 @@ protected: // release our size in bytes back to this throttler when our payload // is adjusted or when we are destroyed. - Throttle *byte_throttler = nullptr; + ThrottleInterface *byte_throttler = nullptr; // release a count back to this throttler when we are destroyed - Throttle *msg_throttler = nullptr; + ThrottleInterface *msg_throttler = nullptr; // keep track of how big this message was when we reserved space in // the msgr dispatch_throttler, so that we can properly release it @@ -333,10 +333,12 @@ public: } CompletionHook* get_completion_hook() { return completion_hook; } void set_completion_hook(CompletionHook *hook) { completion_hook = hook; } - void set_byte_throttler(Throttle *t) { byte_throttler = t; } - Throttle *get_byte_throttler() { return byte_throttler; } - void set_message_throttler(Throttle *t) { msg_throttler = t; } - Throttle *get_message_throttler() { return msg_throttler; } + void set_byte_throttler(ThrottleInterface *t) { + byte_throttler = t; + } + void set_message_throttler(ThrottleInterface *t) { + msg_throttler = t; + } void set_dispatch_throttle_size(uint64_t s) { dispatch_throttle_size = s; } uint64_t get_dispatch_throttle_size() const { return dispatch_throttle_size; } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index fdd7b8012a6..b1ea9175f8c 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -35,6 +35,7 @@ #include "include/mempool.h" #include "common/bloom_filter.hpp" #include "common/Finisher.h" +#include "common/Throttle.h" #include "common/perf_counters.h" #include "common/PriorityCache.h" #include "compressor/Compressor.h" diff --git a/src/os/kstore/KStore.h b/src/os/kstore/KStore.h index 4e1ca5cf7c3..3f8e959964f 100644 --- a/src/os/kstore/KStore.h +++ b/src/os/kstore/KStore.h @@ -28,6 +28,7 @@ #include "include/memory.h" #include "common/Finisher.h" #include "common/RWLock.h" +#include "common/Throttle.h" #include "common/WorkQueue.h" #include "os/ObjectStore.h" #include "common/perf_counters.h" diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 5e9c1edf4e6..14da2fe4ca1 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -33,9 +33,10 @@ #include "common/admin_socket.h" #include "common/ceph_time.h" #include "common/ceph_timer.h" -#include "common/Finisher.h" #include "common/shunique_lock.h" #include "common/zipkin_trace.h" +#include "common/Finisher.h" +#include "common/Throttle.h" #include "messages/MOSDOp.h" #include "msg/Dispatcher.h"