From: Vladimir Davydov <vdavydov.dev@gmail.com> To: kostja@tarantool.org Cc: tarantool-patches@freelists.org Subject: [PATCH v2 06/11] vinyl: enable quota upon recovery completion explicitly Date: Fri, 28 Sep 2018 20:40:04 +0300 [thread overview] Message-ID: <804b312f11dfa0397f9a5314796ef7dc7781d3c5.1538155645.git.vdavydov.dev@gmail.com> (raw) In-Reply-To: <cover.1538155645.git.vdavydov.dev@gmail.com> In-Reply-To: <cover.1538155645.git.vdavydov.dev@gmail.com> Currently, we create a quota object with the limit maximized, and only set the configured limit when local recovery is complete, so as to make sure that no dump is triggered during recovery. As a result, we have to store the configured limit in vy_env::memory, which looks ugly, because this member is never used afterwards. Let's introduce a new method vy_quota_enable to enable quota so that we can set the limit right on quota object construction. This implies that we add a boolean flag to vy_quota and only check the limit if it is set. There's another reason to add such a method. Soon we will implement quota consumption rate limiting. Rate limiting requires a periodic timer that would replenish quota. It only makes sense to start such a timer upon recovery completion, which again leads us to an explicit method for enabling quota. vy_env::memory will be removed by the following patch along with a few other pointless members of vy_env. Needed for #1862 --- src/box/vinyl.c | 4 ++-- src/box/vy_quota.c | 18 +++++++++++++++--- src/box/vy_quota.h | 21 ++++++++++++++++++++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 4ca2953b..2ed14c94 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -2518,7 +2518,7 @@ vy_env_new(const char *path, size_t memory, vy_squash_schedule, e) != 0) goto error_lsm_env; - vy_quota_create(&e->quota, vy_env_quota_exceeded_cb); + vy_quota_create(&e->quota, memory, vy_env_quota_exceeded_cb); vy_regulator_create(&e->regulator, &e->quota, vy_env_trigger_dump_cb); @@ -2572,7 +2572,7 @@ static void vy_env_complete_recovery(struct vy_env *env) { vy_scheduler_start(&env->scheduler); - vy_quota_set_limit(&env->quota, env->memory); + vy_quota_enable(&env->quota); vy_regulator_start(&env->regulator); } diff --git a/src/box/vy_quota.c b/src/box/vy_quota.c index 99811ae9..4b3527b4 100644 --- a/src/box/vy_quota.c +++ b/src/box/vy_quota.c @@ -49,6 +49,8 @@ static inline bool vy_quota_may_use(struct vy_quota *q, size_t size) { + if (!q->is_enabled) + return true; if (q->used + size > q->limit) return false; return true; @@ -81,7 +83,7 @@ vy_quota_do_unuse(struct vy_quota *q, size_t size) static inline void vy_quota_check_limit(struct vy_quota *q) { - if (q->used > q->limit) + if (q->is_enabled && q->used > q->limit) q->quota_exceeded_cb(q); } @@ -105,9 +107,11 @@ vy_quota_signal(struct vy_quota *q) } void -vy_quota_create(struct vy_quota *q, vy_quota_exceeded_f quota_exceeded_cb) +vy_quota_create(struct vy_quota *q, size_t limit, + vy_quota_exceeded_f quota_exceeded_cb) { - q->limit = SIZE_MAX; + q->is_enabled = false; + q->limit = limit; q->used = 0; q->too_long_threshold = TIMEOUT_INFINITY; q->quota_exceeded_cb = quota_exceeded_cb; @@ -115,6 +119,14 @@ vy_quota_create(struct vy_quota *q, vy_quota_exceeded_f quota_exceeded_cb) } void +vy_quota_enable(struct vy_quota *q) +{ + assert(!q->is_enabled); + q->is_enabled = true; + vy_quota_check_limit(q); +} + +void vy_quota_destroy(struct vy_quota *q) { (void)q; diff --git a/src/box/vy_quota.h b/src/box/vy_quota.h index d46b6748..f249512b 100644 --- a/src/box/vy_quota.h +++ b/src/box/vy_quota.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. */ +#include <stdbool.h> #include <stddef.h> #include <small/rlist.h> #include <tarantool_ev.h> @@ -59,6 +60,8 @@ struct vy_quota_wait_node { * in the vinyl engine. It is NOT multi-threading safe. */ struct vy_quota { + /** Set if the quota was enabled. */ + bool is_enabled; /** * Memory limit. Once hit, new transactions are * throttled until memory is reclaimed. @@ -84,9 +87,25 @@ struct vy_quota { struct rlist wait_queue; }; +/** + * Initialize a quota object. + * + * Note, the limit won't be imposed until vy_quota_enable() + * is called. + */ void -vy_quota_create(struct vy_quota *q, vy_quota_exceeded_f quota_exceeded_cb); +vy_quota_create(struct vy_quota *q, size_t limit, + vy_quota_exceeded_f quota_exceeded_cb); +/** + * Enable the configured limit for a quota object. + */ +void +vy_quota_enable(struct vy_quota *q); + +/** + * Destroy a quota object. + */ void vy_quota_destroy(struct vy_quota *q); -- 2.11.0
next prev parent reply other threads:[~2018-09-28 17:40 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-09-28 17:39 [PATCH v2 00/11] vinyl: transaction throttling infrastructure Vladimir Davydov 2018-09-28 17:39 ` [PATCH v2 01/11] vinyl: add helper to start scheduler and enable quota on startup Vladimir Davydov 2018-09-29 4:37 ` [tarantool-patches] " Konstantin Osipov 2018-09-28 17:40 ` [PATCH v2 02/11] vinyl: factor load regulator out of quota Vladimir Davydov 2018-09-29 5:00 ` [tarantool-patches] " Konstantin Osipov 2018-09-29 11:36 ` Vladimir Davydov [not found] ` <20180929114308.GA19162@chai> 2018-10-01 10:27 ` Vladimir Davydov 2018-10-01 10:31 ` Vladimir Davydov 2018-10-02 18:16 ` [tarantool-patches] " Konstantin Osipov 2018-10-03 8:49 ` Vladimir Davydov 2018-09-28 17:40 ` [PATCH v2 03/11] vinyl: minor refactoring of quota methods Vladimir Davydov 2018-09-29 5:01 ` [tarantool-patches] " Konstantin Osipov 2018-09-28 17:40 ` [PATCH v2 04/11] vinyl: move transaction size sanity check to quota Vladimir Davydov 2018-09-29 5:02 ` [tarantool-patches] " Konstantin Osipov 2018-09-28 17:40 ` [PATCH v2 05/11] vinyl: implement quota wait queue without fiber_cond Vladimir Davydov 2018-09-29 5:05 ` [tarantool-patches] " Konstantin Osipov 2018-09-29 11:44 ` Vladimir Davydov 2018-09-28 17:40 ` Vladimir Davydov [this message] 2018-09-29 5:06 ` [tarantool-patches] Re: [PATCH v2 06/11] vinyl: enable quota upon recovery completion explicitly Konstantin Osipov 2018-09-28 17:40 ` [PATCH v2 07/11] vinyl: zap vy_env::memory, read_threads, and write_threads Vladimir Davydov 2018-09-29 5:06 ` [tarantool-patches] " Konstantin Osipov 2018-09-28 17:40 ` [PATCH v2 08/11] vinyl: do not try to trigger dump in regulator if already in progress Vladimir Davydov 2018-09-28 17:40 ` [PATCH v2 09/11] vinyl: do not account zero dump bandwidth Vladimir Davydov 2018-10-12 13:27 ` Vladimir Davydov 2018-10-16 18:25 ` [tarantool-patches] " Konstantin Osipov 2018-10-17 8:44 ` Vladimir Davydov 2018-10-23 7:02 ` Konstantin Osipov 2018-09-28 17:40 ` [PATCH v2 10/11] vinyl: implement basic transaction throttling Vladimir Davydov 2018-09-28 17:40 ` [PATCH v2 11/11] vinyl: introduce quota consumer priorities Vladimir Davydov 2018-10-06 13:24 ` Konstantin Osipov 2018-10-08 11:10 ` Vladimir Davydov 2018-10-09 13:25 ` Vladimir Davydov 2018-10-11 7:02 ` Konstantin Osipov 2018-10-11 8:29 ` Vladimir Davydov 2018-10-03 9:06 ` [PATCH v2 00/11] vinyl: transaction throttling infrastructure Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=804b312f11dfa0397f9a5314796ef7dc7781d3c5.1538155645.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH v2 06/11] vinyl: enable quota upon recovery completion explicitly' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox