From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 3B01A2CCB8 for ; Fri, 19 Apr 2019 08:44:14 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id khqe_7KYILJN for ; Fri, 19 Apr 2019 08:44:14 -0400 (EDT) Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id E75002CCB4 for ; Fri, 19 Apr 2019 08:44:13 -0400 (EDT) From: Georgy Kirichenko Subject: [tarantool-patches] [PATCH 07/10] Remove fiber from a journal_entry structure Date: Fri, 19 Apr 2019 15:44:03 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Georgy Kirichenko Use a trigger to handle journal entry write done event. This relaxes friction between fiber and transaction life cycles. Prerequisites: #1254 --- src/box/journal.c | 4 ++-- src/box/journal.h | 16 ++++++++++++++-- src/box/wal.c | 36 +++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/box/journal.c b/src/box/journal.c index 5cffc7452..b0f4d48b5 100644 --- a/src/box/journal.c +++ b/src/box/journal.c @@ -30,7 +30,6 @@ */ #include "journal.h" #include -#include #include /** @@ -66,11 +65,12 @@ journal_entry_new(size_t n_rows, struct region *region) diag_set(OutOfMemory, size, "region", "struct journal_entry"); return NULL; } + rlist_create(&entry->done_trigger); entry->approx_len = 0; entry->n_rows = n_rows; entry->res = -1; - entry->fiber = fiber(); rlist_create(&entry->on_error); + entry->done = false; return entry; } diff --git a/src/box/journal.h b/src/box/journal.h index 94be0b007..4a2fb3585 100644 --- a/src/box/journal.h +++ b/src/box/journal.h @@ -34,6 +34,7 @@ #include #include "trigger.h" #include "salad/stailq.h" +#include "trigger.h" #if defined(__cplusplus) extern "C" { @@ -56,9 +57,14 @@ struct journal_entry { */ int64_t res; /** - * The fiber issuing the request. + * Turns to true when entry is processed by wal. + */ + bool done; + /** + * Triggers fired when journal entry processing is done + * despite of its success. */ - struct fiber *fiber; + struct rlist done_trigger; /** * A trigger list to call if write failed. Triggers are going to be * fired before any other processing and are a good place to implement @@ -109,6 +115,12 @@ struct journal { void (*destroy)(struct journal *journal); }; +static inline void +journal_entry_on_done(struct journal_entry *entry, struct trigger *trigger) +{ + trigger_add(&entry->done_trigger, trigger); +} + /** * Depending on the step of recovery and instance configuration * points at a concrete implementation of the journal. diff --git a/src/box/wal.c b/src/box/wal.c index 8dfa3ef27..6ccc1220a 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -258,8 +258,10 @@ tx_schedule_queue(struct stailq *queue) * are many ready fibers. */ struct journal_entry *req; - stailq_foreach_entry(req, queue, fifo) - fiber_wakeup(req->fiber); + stailq_foreach_entry(req, queue, fifo) { + req->done = true; + trigger_run(&req->done_trigger, NULL); + } } /** @@ -1116,6 +1118,14 @@ wal_writer_f(va_list ap) return 0; } +static void +on_wal_write_done(struct trigger *trigger, void *event) +{ + (void) event; + struct fiber_cond *cond = (struct fiber_cond *)trigger->data; + fiber_cond_signal(cond); +} + /** * WAL writer main entry point: queue a single request * to be written to disk and wait until this task is completed. @@ -1167,15 +1177,19 @@ wal_write(struct journal *journal, struct journal_entry *entry) batch->approx_len += entry->approx_len; writer->wal_pipe.n_input += entry->n_rows * XROW_IOVMAX; cpipe_flush_input(&writer->wal_pipe); - /** - * It's not safe to spuriously wakeup this fiber - * since in that case it will ignore a possible - * error from WAL writer and not roll back the - * transaction. - */ - bool cancellable = fiber_set_cancellable(false); - fiber_yield(); /* Request was inserted. */ - fiber_set_cancellable(cancellable); + + struct fiber_cond done_cond; + fiber_cond_create(&done_cond); + + struct trigger done_trigger; + trigger_create(&done_trigger, on_wal_write_done, &done_cond, NULL); + journal_entry_on_done(entry, &done_trigger); + while (!entry->done) + fiber_cond_wait(&done_cond); + + fiber_cond_destroy(&done_cond); + trigger_clear(&done_trigger); + return entry->res; } -- 2.21.0