From f461ab428e100d9513a9beb50d643fa43936bc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 19 Oct 2018 13:44:21 +0300 Subject: [PATCH] Fix backend DCB writeq throttling The callbacks iterated over all threads when only the local ones must be iterated. This prevents a deadlock from occurring when multiple threads start throttling at the same time. Also fixed the gwbuf_append debug assertion. --- server/core/buffer.cc | 5 +++-- server/core/dcb.cc | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/core/buffer.cc b/server/core/buffer.cc index a40fc93c2..beb1832a0 100644 --- a/server/core/buffer.cc +++ b/server/core/buffer.cc @@ -450,6 +450,9 @@ int gwbuf_compare(const GWBUF* lhs, const GWBUF* rhs) GWBUF* gwbuf_append(GWBUF* head, GWBUF* tail) { + mxb_assert(!head || head->owner == RoutingWorker::get_current_id()); + mxb_assert(!tail || tail->owner == RoutingWorker::get_current_id()); + if (!head) { return tail; @@ -459,8 +462,6 @@ GWBUF* gwbuf_append(GWBUF* head, GWBUF* tail) return head; } - mxb_assert(head->owner == RoutingWorker::get_current_id() - && tail->owner == RoutingWorker::get_current_id()); head->tail->next = tail; head->tail = tail->tail; diff --git a/server/core/dcb.cc b/server/core/dcb.cc index 24c26baa9..0838ec4f1 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -3768,11 +3768,11 @@ static int downstream_throttle_callback(DCB* dcb, DCB_REASON reason, void* userd { if (reason == DCB_REASON_HIGH_WATER) { - dcb_foreach(backend_dcb_remove_func, dcb->session); + dcb_foreach_local(backend_dcb_remove_func, dcb->session); } else if (reason == DCB_REASON_LOW_WATER) { - dcb_foreach(backend_dcb_add_func, dcb->session); + dcb_foreach_local(backend_dcb_add_func, dcb->session); } return 0;