From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v3 09/11] vinyl: pass flags to vy_recovery_new Date: Sat, 14 Jul 2018 23:49:24 +0300 Message-Id: <3935024ac678c53bd60d46ae438c6a6d40471b22.1531598427.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Currently, this function takes a single boolean argument, but I'm planning to add another one. Since two bool arguments look rather confusing, let's turn this arguments into flags. Needed for #461 --- src/box/vinyl.c | 8 +++++--- src/box/vy_log.c | 19 +++++++++---------- src/box/vy_log.h | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index ef458921..a802b169 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -3226,7 +3226,8 @@ vinyl_engine_join(struct engine *engine, const struct vclock *vclock, * Send all runs stored in it to the replica. */ struct vy_recovery *recovery; - recovery = vy_recovery_new(vclock_sum(vclock), true); + recovery = vy_recovery_new(vclock_sum(vclock), + VY_RECOVERY_LOAD_CHECKPOINT); if (recovery == NULL) { say_error("failed to recover vylog to join a replica"); goto out_join_cord; @@ -3429,7 +3430,7 @@ vinyl_engine_collect_garbage(struct engine *engine, int64_t lsn) /* Cleanup run files. */ int64_t signature = checkpoint_last(NULL); - struct vy_recovery *recovery = vy_recovery_new(signature, false); + struct vy_recovery *recovery = vy_recovery_new(signature, 0); if (recovery == NULL) { say_error("failed to recover vylog for garbage collection"); return 0; @@ -3458,7 +3459,8 @@ vinyl_engine_backup(struct engine *engine, const struct vclock *vclock, /* Backup run files. */ struct vy_recovery *recovery; - recovery = vy_recovery_new(vclock_sum(vclock), true); + recovery = vy_recovery_new(vclock_sum(vclock), + VY_RECOVERY_LOAD_CHECKPOINT); if (recovery == NULL) { say_error("failed to recover vylog for backup"); return -1; diff --git a/src/box/vy_log.c b/src/box/vy_log.c index 2ee5553d..10648106 100644 --- a/src/box/vy_log.c +++ b/src/box/vy_log.c @@ -178,7 +178,7 @@ struct vy_log { static struct vy_log vy_log; static struct vy_recovery * -vy_recovery_new_locked(int64_t signature, bool only_checkpoint); +vy_recovery_new_locked(int64_t signature, int flags); static int vy_recovery_process_record(struct vy_recovery *recovery, @@ -915,7 +915,7 @@ vy_log_begin_recovery(const struct vclock *vclock) } struct vy_recovery *recovery; - recovery = vy_recovery_new(vclock_sum(&vy_log.last_checkpoint), false); + recovery = vy_recovery_new(vclock_sum(&vy_log.last_checkpoint), 0); if (recovery == NULL) return NULL; @@ -998,7 +998,7 @@ vy_log_rotate(const struct vclock *vclock) latch_lock(&vy_log.latch); struct vy_recovery *recovery; - recovery = vy_recovery_new_locked(prev_signature, false); + recovery = vy_recovery_new_locked(prev_signature, 0); if (recovery == NULL) goto fail; @@ -2031,7 +2031,7 @@ static ssize_t vy_recovery_new_f(va_list ap) { int64_t signature = va_arg(ap, int64_t); - bool only_checkpoint = va_arg(ap, int); + int flags = va_arg(ap, int); struct vy_recovery **p_recovery = va_arg(ap, struct vy_recovery **); say_verbose("loading vylog %lld", (long long)signature); @@ -2088,7 +2088,7 @@ vy_recovery_new_f(va_list ap) say_verbose("load vylog record: %s", vy_log_record_str(&record)); if (record.type == VY_LOG_SNAPSHOT) { - if (only_checkpoint) + if ((flags & VY_RECOVERY_LOAD_CHECKPOINT) != 0) break; continue; } @@ -2123,7 +2123,7 @@ fail: * Must be called with the log latch held. */ static struct vy_recovery * -vy_recovery_new_locked(int64_t signature, bool only_checkpoint) +vy_recovery_new_locked(int64_t signature, int flags) { int rc; struct vy_recovery *recovery; @@ -2141,8 +2141,7 @@ vy_recovery_new_locked(int64_t signature, bool only_checkpoint) } /* Load the log from coio so as not to stall tx thread. */ - rc = coio_call(vy_recovery_new_f, signature, - (int)only_checkpoint, &recovery); + rc = coio_call(vy_recovery_new_f, signature, flags, &recovery); if (rc != 0) { diag_log(); say_error("failed to load `%s'", vy_log_filename(signature)); @@ -2152,12 +2151,12 @@ vy_recovery_new_locked(int64_t signature, bool only_checkpoint) } struct vy_recovery * -vy_recovery_new(int64_t signature, bool only_checkpoint) +vy_recovery_new(int64_t signature, int flags) { /* Lock out concurrent writers while we are loading the log. */ latch_lock(&vy_log.latch); struct vy_recovery *recovery; - recovery = vy_recovery_new_locked(signature, only_checkpoint); + recovery = vy_recovery_new_locked(signature, flags); latch_unlock(&vy_log.latch); return recovery; } diff --git a/src/box/vy_log.h b/src/box/vy_log.h index da0745b2..98cbf6ee 100644 --- a/src/box/vy_log.h +++ b/src/box/vy_log.h @@ -525,18 +525,26 @@ vy_log_begin_recovery(const struct vclock *vclock); int vy_log_end_recovery(void); +/** Flags passed to vy_recovery_new(). */ +enum vy_recovery_flag { + /** + * Do not load records written to the log after checkpoint, + * i.e. get a consistent view of vinyl database at the time + * of the last checkpoint. + */ + VY_RECOVERY_LOAD_CHECKPOINT = 1 << 0, +}; + /** * Create a recovery context from the metadata log created * by checkpoint with the given signature. * - * If @only_checkpoint is set, do not load records appended to - * the log after checkpoint (i.e. get a consistent view of - * Vinyl at the time of the checkpoint). + * For valid values of @flags, see vy_recovery_flag. * * Returns NULL on failure. */ struct vy_recovery * -vy_recovery_new(int64_t signature, bool only_checkpoint); +vy_recovery_new(int64_t signature, int flags); /** * Free a recovery context created by vy_recovery_new(). -- 2.11.0