From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH v2 6/6] error: move XlogGapError to box/error.h Date: Fri, 29 Jun 2018 19:48:33 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: All box exceptions belong to box/error.h. Let's move XlogGapError there as well. This will facilitate conversion of recovery.cc to C when we finally get to it. While we are at it, let's also move BuildXlogError function declaration from diag.h to box/error.h, closer to its definition. --- src/box/CMakeLists.txt | 2 +- src/box/error.cc | 36 ++++++++++++++++++++++++++++++++---- src/box/error.h | 16 ++++++++++++++++ src/box/recovery.cc | 21 --------------------- src/diag.h | 2 -- 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index 6b1ae3e8..f4899091 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -21,7 +21,7 @@ set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${lua_sources}) include_directories(${ZSTD_INCLUDE_DIRS}) -add_library(box_error STATIC error.cc errcode.c) +add_library(box_error STATIC error.cc errcode.c vclock.c) target_link_libraries(box_error core stat) add_library(vclock STATIC vclock.c) diff --git a/src/box/error.cc b/src/box/error.cc index 6b14dff0..c4f782a4 100644 --- a/src/box/error.cc +++ b/src/box/error.cc @@ -31,8 +31,11 @@ #include "error.h" #include -#include -#include +#include "fiber.h" +#include "rmean.h" +#include "trigger.h" +#include "vclock.h" +#include "schema.h" /* {{{ public API */ @@ -176,8 +179,33 @@ BuildXlogError(const char *file, unsigned line, const char *format, ...) } } -#include "schema.h" -#include "trigger.h" +const struct type_info type_XlogGapError = + make_type("XlogGapError", &type_XlogError); + +XlogGapError::XlogGapError(const char *file, unsigned line, + const struct vclock *from, const struct vclock *to) + : XlogError(&type_XlogGapError, file, line) +{ + char *s_from = vclock_to_string(from); + char *s_to = vclock_to_string(to); + snprintf(errmsg, sizeof(errmsg), + "Missing .xlog file between LSN %lld %s and %lld %s", + (long long) vclock_sum(from), s_from ? s_from : "", + (long long) vclock_sum(to), s_to ? s_to : ""); + free(s_from); + free(s_to); +} + +struct error * +BuildXlogGapError(const char *file, unsigned line, + const struct vclock *from, const struct vclock *to) +{ + try { + return new XlogGapError(file, line, from, to); + } catch (OutOfMemory *e) { + return e; + } +} struct rlist on_access_denied = RLIST_HEAD_INITIALIZER(on_access_denied); diff --git a/src/box/error.h b/src/box/error.h index c791e6c6..b8c7cf73 100644 --- a/src/box/error.h +++ b/src/box/error.h @@ -36,6 +36,8 @@ extern "C" { #endif /* defined(__cplusplus) */ +struct vclock; + struct error * BuildClientError(const char *file, unsigned line, uint32_t errcode, ...); @@ -44,6 +46,12 @@ BuildAccessDeniedError(const char *file, unsigned int line, const char *access_type, const char *object_type, const char *object_name, const char *user_name); +struct error * +BuildXlogError(const char *file, unsigned line, const char *format, ...); + +struct error * +BuildXlogGapError(const char *file, unsigned line, + const struct vclock *from, const struct vclock *to); /** \cond public */ @@ -250,6 +258,14 @@ struct XlogError: public Exception virtual void raise() { throw this; } }; +struct XlogGapError: public XlogError +{ + XlogGapError(const char *file, unsigned line, + const struct vclock *from, const struct vclock *to); + + virtual void raise() { throw this; } +}; + #endif /* defined(__cplusplus) */ #endif /* TARANTOOL_BOX_ERROR_H_INCLUDED */ diff --git a/src/box/recovery.cc b/src/box/recovery.cc index 722b86c5..c007b1fa 100644 --- a/src/box/recovery.cc +++ b/src/box/recovery.cc @@ -74,27 +74,6 @@ * IRR -> RR # recovery_follow_local() */ -const struct type_info type_XlogGapError = - make_type("XlogGapError", &type_XlogError); - -struct XlogGapError: public XlogError { - /** Used by BuildXlogGapError() */ - XlogGapError(const char *file, unsigned line, - const struct vclock *from, const struct vclock *to) - :XlogError(&type_XlogGapError, file, line) - { - char *s_from = vclock_to_string(from); - char *s_to = vclock_to_string(to); - snprintf(errmsg, sizeof(errmsg), - "Missing .xlog file between LSN %lld %s and %lld %s", - (long long) vclock_sum(from), s_from ? s_from : "", - (long long) vclock_sum(to), s_to ? s_to : ""); - free(s_from); - free(s_to); - } - virtual void raise() { throw this; } -}; - /* {{{ Initial recovery */ /** diff --git a/src/diag.h b/src/diag.h index 0ccf86d0..a0b71f04 100644 --- a/src/diag.h +++ b/src/diag.h @@ -248,8 +248,6 @@ BuildIllegalParams(const char *file, unsigned line, const char *format, ...); struct error * BuildSystemError(const char *file, unsigned line, const char *format, ...); struct error * -BuildXlogError(const char *file, unsigned line, const char *format, ...); -struct error * BuildCollationError(const char *file, unsigned line, const char *format, ...); struct index_def; -- 2.11.0