From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v2 09/10] wal: pass struct instead of vclock to checkpoint methods Date: Sat, 8 Dec 2018 18:48:13 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Currently, we only need to pass a vclock between TX and WAL during checkpointing. However, in order to implement auto-checkpointing triggered when WAL size exceeds a certain threshold, we will need to pass some extra info so that we can properly reset the counter accounting the WAL size in the WAL thread. To make it possible, let's move wal_checkpoint struct, which is used internally by WAL to pass a checkpoint vclock, to the header and require the caller to pass it to wal_begin/commit_checkpoint instead of just a vclock. --- src/box/gc.c | 10 +++++----- src/box/wal.c | 22 ++++++---------------- src/box/wal.h | 20 +++++++++++++++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/box/gc.c b/src/box/gc.c index e8074078..6a7e371f 100644 --- a/src/box/gc.c +++ b/src/box/gc.c @@ -355,7 +355,7 @@ static int gc_do_checkpoint(void) { int rc; - struct vclock vclock; + struct wal_checkpoint checkpoint; assert(!gc.checkpoint_is_in_progress); gc.checkpoint_is_in_progress = true; @@ -373,19 +373,19 @@ gc_do_checkpoint(void) rc = engine_begin_checkpoint(); if (rc != 0) goto out; - rc = wal_begin_checkpoint(&vclock); + rc = wal_begin_checkpoint(&checkpoint); if (rc != 0) goto out; - rc = engine_commit_checkpoint(&vclock); + rc = engine_commit_checkpoint(&checkpoint.vclock); if (rc != 0) goto out; - wal_commit_checkpoint(&vclock); + wal_commit_checkpoint(&checkpoint); /* * Finally, track the newly created checkpoint in the garbage * collector state. */ - gc_add_checkpoint(&vclock); + gc_add_checkpoint(&checkpoint.vclock); out: if (rc != 0) engine_abort_checkpoint(); diff --git a/src/box/wal.c b/src/box/wal.c index 644f58c8..8e56e6ae 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -497,12 +497,6 @@ wal_sync(void) cbus_flush(&wal_thread.wal_pipe, &wal_thread.tx_prio_pipe, NULL); } -struct wal_checkpoint -{ - struct cbus_call_msg base; - struct vclock vclock; -}; - static int wal_begin_checkpoint_f(struct cbus_call_msg *data) { @@ -534,11 +528,11 @@ wal_begin_checkpoint_f(struct cbus_call_msg *data) } int -wal_begin_checkpoint(struct vclock *vclock) +wal_begin_checkpoint(struct wal_checkpoint *checkpoint) { struct wal_writer *writer = &wal_writer_singleton; if (writer->wal_mode == WAL_NONE) { - vclock_copy(vclock, &writer->vclock); + vclock_copy(&checkpoint->vclock, &writer->vclock); return 0; } if (!stailq_empty(&writer->rollback)) { @@ -552,15 +546,13 @@ wal_begin_checkpoint(struct vclock *vclock) diag_set(ClientError, ER_CHECKPOINT_ROLLBACK); return -1; } - struct wal_checkpoint msg; bool cancellable = fiber_set_cancellable(false); int rc = cbus_call(&wal_thread.wal_pipe, &wal_thread.tx_prio_pipe, - &msg.base, wal_begin_checkpoint_f, NULL, + &checkpoint->base, wal_begin_checkpoint_f, NULL, TIMEOUT_INFINITY); fiber_set_cancellable(cancellable); if (rc != 0) return -1; - vclock_copy(vclock, &msg.vclock); return 0; } @@ -574,18 +566,16 @@ wal_commit_checkpoint_f(struct cbus_call_msg *data) } void -wal_commit_checkpoint(const struct vclock *vclock) +wal_commit_checkpoint(struct wal_checkpoint *checkpoint) { struct wal_writer *writer = &wal_writer_singleton; if (writer->wal_mode == WAL_NONE) { - vclock_copy(&writer->checkpoint_vclock, vclock); + vclock_copy(&writer->checkpoint_vclock, &checkpoint->vclock); return; } - struct wal_checkpoint msg; - vclock_copy(&msg.vclock, vclock); bool cancellable = fiber_set_cancellable(false); cbus_call(&wal_thread.wal_pipe, &wal_thread.tx_prio_pipe, - &msg.base, wal_commit_checkpoint_f, NULL, + &checkpoint->base, wal_commit_checkpoint_f, NULL, TIMEOUT_INFINITY); fiber_set_cancellable(cancellable); } diff --git a/src/box/wal.h b/src/box/wal.h index 3d616353..2564f718 100644 --- a/src/box/wal.h +++ b/src/box/wal.h @@ -160,16 +160,26 @@ wal_mode(); void wal_sync(void); +struct wal_checkpoint { + struct cbus_call_msg base; + /** + * VClock of the last record written to the rotated WAL. + * This is the vclock that is supposed to be used to + * identify the new checkpoint. + */ + struct vclock vclock; +}; + /** * Prepare WAL for checkpointing. * * This function flushes all pending changes and rotates the - * current WAL. The vclock of the last record written to the - * rotated WAL is returned in @vclock. This is the vclock that - * is supposed to be used to identify the new checkpoint. + * current WAL. Checkpoint info is returned in @checkpoint. + * It is supposed to be passed to wal_commit_checkpoint() + * upon successful checkpoint creation. */ int -wal_begin_checkpoint(struct vclock *vclock); +wal_begin_checkpoint(struct wal_checkpoint *checkpoint); /** * This function is called upon successful checkpoint creation. @@ -177,7 +187,7 @@ wal_begin_checkpoint(struct vclock *vclock); * vclock. */ void -wal_commit_checkpoint(const struct vclock *vclock); +wal_commit_checkpoint(struct wal_checkpoint *checkpoint); /** * Remove WAL files that are not needed by consumers reading -- 2.11.0