Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH v2 04/11] vinyl: move transaction size sanity check to quota
Date: Fri, 28 Sep 2018 20:40:02 +0300	[thread overview]
Message-ID: <c533c6a781e0151448f4539cec50312d71319f1d.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>

There's a sanity check in vinyl_engine_prepare, which checks if the
transaction size is less than the configured limit and fails without
waiting for quota if it isn't. Let's move this check to vy_quota_use,
because it's really a business of the quota object. This implies that
vy_quota_use has to set diag to differentiate this error from timeout.
---
 src/box/vinyl.c    | 14 +-------------
 src/box/vy_quota.c | 18 ++++++++++++++++--
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 1c0192cb..4ca2953b 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -2331,16 +2331,6 @@ vinyl_engine_prepare(struct engine *engine, struct txn *txn)
 		return -1;
 
 	/*
-	 * The configured memory limit will never allow us to commit
-	 * this transaction. Fail early.
-	 */
-	if (tx->write_size > env->quota.limit) {
-		diag_set(OutOfMemory, tx->write_size,
-			 "lsregion", "vinyl transaction");
-		return -1;
-	}
-
-	/*
 	 * Do not abort join/subscribe on quota timeout - replication
 	 * is asynchronous anyway and there's box.info.replication
 	 * available for the admin to track the lag so let the applier
@@ -2354,10 +2344,8 @@ vinyl_engine_prepare(struct engine *engine, struct txn *txn)
 	 * the transaction to be sent to read view or aborted, we call
 	 * it before checking for conflicts.
 	 */
-	if (vy_quota_use(&env->quota, tx->write_size, timeout) != 0) {
-		diag_set(ClientError, ER_VY_QUOTA_TIMEOUT);
+	if (vy_quota_use(&env->quota, tx->write_size, timeout) != 0)
 		return -1;
-	}
 
 	size_t mem_used_before = lsregion_used(&env->mem_env.allocator);
 
diff --git a/src/box/vy_quota.c b/src/box/vy_quota.c
index 64ce56c0..2afed6b7 100644
--- a/src/box/vy_quota.c
+++ b/src/box/vy_quota.c
@@ -35,6 +35,9 @@
 #include <stddef.h>
 #include <tarantool_ev.h>
 
+#include "diag.h"
+#include "error.h"
+#include "errcode.h"
 #include "fiber.h"
 #include "fiber_cond.h"
 #include "say.h"
@@ -139,6 +142,15 @@ vy_quota_use(struct vy_quota *q, size_t size, double timeout)
 		return 0;
 	}
 
+	/*
+	 * Fail early if the configured memory limit never allows
+	 * us to commit the transaction.
+	 */
+	if (size > q->limit) {
+		diag_set(OutOfMemory, size, "lsregion", "vinyl transaction");
+		return -1;
+	}
+
 	/* Wait for quota. */
 	double wait_start = ev_monotonic_now(loop());
 	double deadline = wait_start + timeout;
@@ -152,8 +164,10 @@ vy_quota_use(struct vy_quota *q, size_t size, double timeout)
 		 */
 		if (q->used + size > q->limit)
 			q->quota_exceeded_cb(q);
-		if (fiber_cond_wait_deadline(&q->cond, deadline) != 0)
-			return -1; /* timed out */
+		if (fiber_cond_wait_deadline(&q->cond, deadline) != 0) {
+			diag_set(ClientError, ER_VY_QUOTA_TIMEOUT);
+			return -1;
+		}
 	} while (!vy_quota_may_use(q, size));
 
 	double wait_time = ev_monotonic_now(loop()) - wait_start;
-- 
2.11.0

  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 ` Vladimir Davydov [this message]
2018-09-29  5:02   ` [tarantool-patches] Re: [PATCH v2 04/11] vinyl: move transaction size sanity check to quota 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 ` [PATCH v2 06/11] vinyl: enable quota upon recovery completion explicitly Vladimir Davydov
2018-09-29  5:06   ` [tarantool-patches] " 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=c533c6a781e0151448f4539cec50312d71319f1d.1538155645.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v2 04/11] vinyl: move transaction size sanity check to quota' \
    /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