From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 1/8] vinyl: add helper to check whether dump is in progress Date: Tue, 4 Sep 2018 20:23:44 +0300 Message-Id: <7710f093f36b8bcd3fd985590ec8377ae98c4703.1536080993.git.vdavydov.dev@gmail.com> In-Reply-To: References: <20180904115404.el6kdswgitsnopgf@esperanza> In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Needed solely to improve code readability. No functional changes. --- src/box/vy_scheduler.c | 17 +++++++---------- src/box/vy_scheduler.h | 13 +++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c index 580c3129..367c8a20 100644 --- a/src/box/vy_scheduler.c +++ b/src/box/vy_scheduler.c @@ -488,8 +488,7 @@ vy_scheduler_unpin_lsm(struct vy_scheduler *scheduler, struct vy_lsm *lsm) void vy_scheduler_trigger_dump(struct vy_scheduler *scheduler) { - assert(scheduler->dump_generation <= scheduler->generation); - if (scheduler->dump_generation < scheduler->generation) { + if (vy_scheduler_dump_in_progress(scheduler)) { /* Dump is already in progress, nothing to do. */ return; } @@ -520,13 +519,13 @@ vy_scheduler_dump(struct vy_scheduler *scheduler) fiber_cond_wait(&scheduler->dump_cond); /* Trigger dump. */ - if (scheduler->generation == scheduler->dump_generation) + if (!vy_scheduler_dump_in_progress(scheduler)) scheduler->dump_start = ev_monotonic_now(loop()); - int64_t generation = ++scheduler->generation; + scheduler->generation++; fiber_cond_signal(&scheduler->scheduler_cond); /* Wait for dump to complete. */ - while (scheduler->dump_generation < generation) { + while (vy_scheduler_dump_in_progress(scheduler)) { if (scheduler->is_throttled) { /* Dump error occurred. */ struct error *e = diag_last_error(&scheduler->diag); @@ -611,8 +610,7 @@ vy_scheduler_begin_checkpoint(struct vy_scheduler *scheduler) return -1; } - assert(scheduler->dump_generation <= scheduler->generation); - if (scheduler->generation == scheduler->dump_generation) { + if (!vy_scheduler_dump_in_progress(scheduler)) { /* * We are about to start a new dump round. * Remember the current time so that we can update @@ -638,7 +636,7 @@ vy_scheduler_wait_checkpoint(struct vy_scheduler *scheduler) * Wait until all in-memory trees created before * checkpoint started have been dumped. */ - while (scheduler->dump_generation < scheduler->generation) { + while (vy_scheduler_dump_in_progress(scheduler)) { if (scheduler->is_throttled) { /* A dump error occurred, abort checkpoint. */ struct error *e = diag_last_error(&scheduler->diag); @@ -1730,8 +1728,7 @@ vy_scheduler_peek_dump(struct vy_scheduler *scheduler, struct vy_task **ptask) { retry: *ptask = NULL; - assert(scheduler->dump_generation <= scheduler->generation); - if (scheduler->dump_generation == scheduler->generation) { + if (!vy_scheduler_dump_in_progress(scheduler)) { /* * All memory trees of past generations have * been dumped, nothing to do. diff --git a/src/box/vy_scheduler.h b/src/box/vy_scheduler.h index deefacd7..89f8f170 100644 --- a/src/box/vy_scheduler.h +++ b/src/box/vy_scheduler.h @@ -31,6 +31,7 @@ * SUCH DAMAGE. */ +#include #include #include #include @@ -151,6 +152,18 @@ struct vy_scheduler { }; /** + * Return true if memory dump is in progress, i.e. there are + * in-memory trees that are being dumped right now or should + * be scheduled for dump as soon as possible. + */ +static inline bool +vy_scheduler_dump_in_progress(struct vy_scheduler *scheduler) +{ + assert(scheduler->dump_generation <= scheduler->generation); + return scheduler->dump_generation < scheduler->generation; +} + +/** * Create a scheduler instance. */ void -- 2.11.0