From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 8/9] wal: pass struct instead of vclock to checkpoint methods Date: Wed, 28 Nov 2018 19:14:46 +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/box.cc | 10 +++++----- src/box/wal.c | 22 ++++++---------------- src/box/wal.h | 20 +++++++++++++++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 7cb96cd6..24ddd941 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2288,15 +2288,15 @@ box_checkpoint() if ((rc = engine_begin_checkpoint())) goto end; - struct vclock vclock; - if ((rc = wal_begin_checkpoint(&vclock))) + struct wal_checkpoint checkpoint; + if ((rc = wal_begin_checkpoint(&checkpoint))) goto end; - if ((rc = engine_commit_checkpoint(&vclock))) + if ((rc = engine_commit_checkpoint(&checkpoint.vclock))) goto end; - wal_commit_checkpoint(&vclock); - gc_add_checkpoint(&vclock); + wal_commit_checkpoint(&checkpoint); + gc_add_checkpoint(&checkpoint.vclock); end: if (rc) engine_abort_checkpoint(); diff --git a/src/box/wal.c b/src/box/wal.c index 31385642..bbb8376c 100644 --- a/src/box/wal.c +++ b/src/box/wal.c @@ -490,12 +490,6 @@ wal_flush(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) { @@ -527,11 +521,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)) { @@ -545,15 +539,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; } @@ -567,18 +559,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 1e070625..3f0fae07 100644 --- a/src/box/wal.h +++ b/src/box/wal.h @@ -160,16 +160,26 @@ wal_mode(); void wal_flush(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