From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) (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 A0C074696C7 for ; Tue, 28 Apr 2020 19:13:46 +0300 (MSK) Received: by mail-lf1-f65.google.com with SMTP id h6so17425202lfc.0 for ; Tue, 28 Apr 2020 09:13:46 -0700 (PDT) From: Cyrill Gorcunov Date: Tue, 28 Apr 2020 19:11:29 +0300 Message-Id: <20200428161137.20536-10-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 09/17] recovery: recovery_new -- 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 | 2 ++ src/box/recovery.cc | 22 ++++++++++------------ src/box/relay.cc | 12 ++++++++---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 7551ca753..4371c1986 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -2224,6 +2224,8 @@ local_recovery(const struct tt_uuid *instance_uuid, recovery = recovery_new(cfg_gets("wal_dir"), cfg_geti("force_recovery"), checkpoint_vclock); + if (recovery == NULL) + diag_raise(); /* * Make sure we report the actual recovery position diff --git a/src/box/recovery.cc b/src/box/recovery.cc index 24036b7c1..1c7665f87 100644 --- a/src/box/recovery.cc +++ b/src/box/recovery.cc @@ -77,24 +77,21 @@ /* {{{ Initial recovery */ /** - * Throws an exception in case of error. + * Returns NULL in case of error. */ struct recovery * recovery_new(const char *wal_dirname, bool force_recovery, const struct vclock *vclock) { - struct recovery *r = (struct recovery *) - calloc(1, sizeof(*r)); + struct recovery *r; + r = (struct recovery *)calloc(1, sizeof(*r)); if (r == NULL) { - tnt_raise(OutOfMemory, sizeof(*r), "malloc", - "struct recovery"); + diag_set(OutOfMemory, sizeof(*r), "calloc", + "struct recovery"); + return NULL; } - auto guard = make_scoped_guard([=]{ - free(r); - }); - xdir_create(&r->wal_dir, wal_dirname, XLOG, &INSTANCE_UUID, &xlog_opts_default); r->wal_dir.force_recovery = force_recovery; @@ -108,12 +105,13 @@ recovery_new(const char *wal_dirname, bool force_recovery, * UUID, see replication/cluster.test for * details. */ - xdir_check_xc(&r->wal_dir); + if (xdir_check(&r->wal_dir) != 0) { + free(r); + return NULL; + } r->watcher = NULL; rlist_create(&r->on_close_log); - - guard.is_active = false; return r; } diff --git a/src/box/relay.cc b/src/box/relay.cc index 2e17d0476..a5bcd9580 100644 --- a/src/box/relay.cc +++ b/src/box/relay.cc @@ -363,8 +363,10 @@ relay_final_join(int fd, uint64_t sync, struct vclock *start_vclock, relay_delete(relay); }); - relay->r = recovery_new(cfg_gets("wal_dir"), false, - start_vclock); + relay->r = recovery_new(cfg_gets("wal_dir"), false, start_vclock); + if (relay->r == NULL) + diag_raise(); + vclock_copy(&relay->stop_vclock, stop_vclock); int rc = cord_costart(&relay->cord, "final_join", @@ -717,8 +719,10 @@ relay_subscribe(struct replica *replica, int fd, uint64_t sync, }); vclock_copy(&relay->local_vclock_at_subscribe, &replicaset.vclock); - relay->r = recovery_new(cfg_gets("wal_dir"), false, - replica_clock); + relay->r = recovery_new(cfg_gets("wal_dir"), false, replica_clock); + if (relay->r == NULL) + diag_raise(); + vclock_copy(&relay->tx.vclock, replica_clock); relay->version_id = replica_version_id; -- 2.20.1