From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id AE1AB4696C6 for ; Tue, 28 Apr 2020 19:13:11 +0300 (MSK) Received: by mail-lj1-f174.google.com with SMTP id u15so22099043ljd.3 for ; Tue, 28 Apr 2020 09:13:11 -0700 (PDT) From: Cyrill Gorcunov Date: Tue, 28 Apr 2020 19:11:26 +0300 Message-Id: <20200428161137.20536-7-gorcunov@gmail.com> In-Reply-To: <20200428161137.20536-1-gorcunov@gmail.com> References: <20200428161137.20536-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 06/17] recovery: recover_remaining_wals -- don't throw exception List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Prepare for transition to plain C. Signed-off-by: Cyrill Gorcunov --- src/box/box.cc | 6 ++++-- src/box/recovery.cc | 24 +++++++++++++++--------- src/box/recovery.h | 2 +- src/box/relay.cc | 13 +++++++++---- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 1c6fa582c..ff095d767 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2282,7 +2282,8 @@ local_recovery(const struct tt_uuid *instance_uuid, memtx_engine_recover_snapshot_xc(memtx, checkpoint_vclock); engine_begin_final_recovery_xc(); - recover_remaining_wals(recovery, &wal_stream.base, NULL, false); + if (recover_remaining_wals(recovery, &wal_stream.base, NULL, false) != 0) + diag_raise(); engine_end_recovery_xc(); /* * Leave hot standby mode, if any, only after @@ -2303,7 +2304,8 @@ local_recovery(const struct tt_uuid *instance_uuid, fiber_sleep(0.1); } recovery_stop_local(recovery); - recover_remaining_wals(recovery, &wal_stream.base, NULL, true); + if (recover_remaining_wals(recovery, &wal_stream.base, NULL, true) != 0) + diag_raise(); /* * Advance replica set vclock to reflect records * applied in hot standby mode. diff --git a/src/box/recovery.cc b/src/box/recovery.cc index f724600ed..1b78fc915 100644 --- a/src/box/recovery.cc +++ b/src/box/recovery.cc @@ -316,14 +316,16 @@ recover_xlog(struct recovery *r, struct xstream *stream, * This function will not close r->current_wal if * recovery was successful. */ -void +int recover_remaining_wals(struct recovery *r, struct xstream *stream, const struct vclock *stop_vclock, bool scan_dir) { struct vclock *clock; - if (scan_dir) - xdir_scan_xc(&r->wal_dir); + if (scan_dir) { + if (xdir_scan(&r->wal_dir) == -1) + return -1; + } if (xlog_cursor_is_open(&r->cursor)) { /* If there's a WAL open, recover from it first. */ @@ -358,24 +360,27 @@ recover_remaining_wals(struct recovery *r, struct xstream *stream, } if (recovery_open_log(r, clock) != 0) - diag_raise(); + return -1; say_info("recover from `%s'", r->cursor.name); recover_current_wal: if (recover_xlog(r, stream, stop_vclock) < 0) - diag_raise(); + return -1; } if (xlog_cursor_is_eof(&r->cursor)) { if (recovery_close_log(r) != 0) - diag_raise(); + return -1; } - if (stop_vclock != NULL && vclock_compare(&r->vclock, stop_vclock) != 0) - tnt_raise(XlogGapError, &r->vclock, stop_vclock); + if (stop_vclock != NULL && vclock_compare(&r->vclock, stop_vclock) != 0) { + diag_set(XlogGapError, &r->vclock, stop_vclock); + return -1; + } region_free(&fiber()->gc); + return 0; } void @@ -514,7 +519,8 @@ hot_standby_f(va_list ap) do { start = vclock_sum(&r->vclock); - recover_remaining_wals(r, stream, NULL, scan_dir); + if (recover_remaining_wals(r, stream, NULL, scan_dir) != 0) + diag_raise(); end = vclock_sum(&r->vclock); /* diff --git a/src/box/recovery.h b/src/box/recovery.h index 6e68abc0b..a2fb99070 100644 --- a/src/box/recovery.h +++ b/src/box/recovery.h @@ -102,7 +102,7 @@ recovery_finalize(struct recovery *r); * This function will not close r->current_wal if * recovery was successful. */ -void +int recover_remaining_wals(struct recovery *r, struct xstream *stream, const struct vclock *stop_vclock, bool scan_dir); diff --git a/src/box/relay.cc b/src/box/relay.cc index 2ad02cb8a..2e17d0476 100644 --- a/src/box/relay.cc +++ b/src/box/relay.cc @@ -341,8 +341,10 @@ relay_final_join_f(va_list ap) /* Send all WALs until stop_vclock */ assert(relay->stream.write != NULL); - recover_remaining_wals(relay->r, &relay->stream, - &relay->stop_vclock, true); + if (recover_remaining_wals(relay->r, &relay->stream, + &relay->stop_vclock, true) != 0) { + diag_raise(); + } assert(vclock_compare(&relay->r->vclock, &relay->stop_vclock) == 0); return 0; } @@ -499,8 +501,11 @@ relay_process_wal_event(struct wal_watcher *watcher, unsigned events) return; } try { - recover_remaining_wals(relay->r, &relay->stream, NULL, - (events & WAL_EVENT_ROTATE) != 0); + bool scan_dir = (events & WAL_EVENT_ROTATE) ? true : false; + if (recover_remaining_wals(relay->r, &relay->stream, NULL, + scan_dir) != 0) { + diag_raise(); + } } catch (Exception *e) { relay_set_error(relay, e); fiber_cancel(fiber()); -- 2.20.1