[PATCH v2 10/11] vinyl: pass flags to vy_recovery_new
Vladimir Davydov
vdavydov.dev at gmail.com
Fri Jun 8 20:34:28 MSK 2018
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 d2e3da7e..8cc2ab0e 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -3229,7 +3229,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;
@@ -3432,7 +3433,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;
@@ -3461,7 +3462,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 8330a26c..e44db5b8 100644
--- a/src/box/vy_log.c
+++ b/src/box/vy_log.c
@@ -176,7 +176,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,
@@ -898,7 +898,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;
@@ -980,7 +980,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;
@@ -2007,7 +2007,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);
@@ -2064,7 +2064,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;
}
@@ -2099,7 +2099,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;
@@ -2117,8 +2117,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));
@@ -2128,12 +2127,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 0a216de8..cdac293e 100644
--- a/src/box/vy_log.h
+++ b/src/box/vy_log.h
@@ -520,18 +520,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
More information about the Tarantool-patches
mailing list