Skip to content
Snippets Groups Projects
Commit 1806f816 authored by Vladimir Davydov's avatar Vladimir Davydov
Browse files

box: add error code for SSLError

Applier uses box_error_code() to for better logging:
 - It remembers tha last raised error code and skips logging if the new
   error code is the same.
 - It logs "will retry every X seconds" only for retryable error codes
   (for example, ER_SYSTEM) while for non-retryable errors (for example,
   ER_PROC_LUA) the message isn't logged.

box_error_code() returns ER_PROC_LUA for SSLError, which is confusing
and would result in inconsistent logging in applier if we made SSLError
retryable. Let's add a separate error code for this error (ER_SSL) and
introduce a test case that checks that box_error_code() works as
expected for all kinds of errors.

Follow-up commit a7028dde ("Add SSL iostream stub").
Needed for https://github.com/tarantool/tarantool-ee/issues/107

NO_DOC=internal
NO_CHANGELOG=internal

(cherry picked from commit b85cf605)
parent 3ff2aec1
No related branches found
No related tags found
No related merge requests found
......@@ -295,6 +295,7 @@ struct errcode_record {
/*240 */_(ER_COMPLEX_FOREIGN_KEY_FAILED, "Foreign key constraint '%s' failed: %s") \
/*241 */_(ER_WRONG_SPACE_UPGRADE_OPTIONS, "Wrong space upgrade options: %s") \
/*242 */_(ER_NO_ELECTION_QUORUM, "Not enough peers connected to start elections: %d out of minimal required %d")\
/*243 */_(ER_SSL, "%s") \
/*
* !IMPORTANT! Please follow instructions at start of the file
......
......@@ -36,6 +36,7 @@
#include "trigger.h"
#include "vclock/vclock.h"
#include "schema.h"
#include "ssl_error.h"
/* {{{ public API */
......@@ -213,6 +214,8 @@ ClientError::get_errcode(const struct error *e)
return ER_MEMORY_ISSUE;
if (type_cast(SystemError, e))
return ER_SYSTEM;
if (type_cast(SSLError, e))
return ER_SSL;
if (type_cast(CollationError, e))
return ER_CANT_CREATE_COLLATION;
if (type_cast(XlogGapError, e))
......
......@@ -5,13 +5,28 @@
*/
#include "ssl_error.h"
#include <stdarg.h>
#include <stddef.h>
#include "diag.h"
#include "reflection.h"
#include "trivia/config.h"
#include "trivia/util.h"
#if defined(ENABLE_SSL)
# error unimplemented
#endif
const struct type_info type_SSLError = make_type("SSLError", NULL);
struct error *
BuildSSLError(const char *file, unsigned line, const char *format, ...)
{
void *ptr = xmalloc(sizeof(SSLError));
SSLError *err = new(ptr) SSLError(file, line);
va_list ap;
va_start(ap, format);
error_vformat_msg(err, format, ap);
va_end(ap);
return err;
}
......@@ -22,12 +22,18 @@ extern "C" {
extern const struct type_info type_SSLError;
/** Builds an instance of SSLError with the given message. */
struct error *
BuildSSLError(const char *file, unsigned line, const char *format, ...);
#if defined(__cplusplus)
} /* extern "C" */
class SSLError: public Exception {
public:
SSLError(): Exception(&type_SSLError, NULL, 0) {}
SSLError(const char *file, unsigned line)
: Exception(&type_SSLError, file, line) {}
SSLError() : SSLError(NULL, 0) {}
virtual void raise() { throw this; }
};
......
......@@ -461,6 +461,7 @@ t;
| 240: box.error.COMPLEX_FOREIGN_KEY_FAILED
| 241: box.error.WRONG_SPACE_UPGRADE_OPTIONS
| 242: box.error.NO_ELECTION_QUORUM
| 243: box.error.SSL
| ...
test_run:cmd("setopt delimiter ''");
......
......@@ -64,7 +64,7 @@ target_link_libraries(xmalloc.test unit)
add_executable(datetime.test datetime.c)
target_link_libraries(datetime.test tzcode core cdt unit)
add_executable(error.test error.c core_test_utils.c)
target_link_libraries(error.test unit core)
target_link_libraries(error.test unit core box_error)
add_executable(interval.test interval.c core_test_utils.c)
target_link_libraries(interval.test core unit)
......
......@@ -3,11 +3,17 @@
*
* Copyright 2010-2021, Tarantool AUTHORS, please see AUTHORS file.
*/
#include "box/error.h"
#include "diag.h"
#include "error_payload.h"
#include "fiber.h"
#include "memory.h"
#include "mp_uuid.h"
#include "msgpuck.h"
#include "random.h"
#include "ssl_error.h"
#include "unit.h"
#include "vclock/vclock.h"
#include <float.h>
......@@ -441,13 +447,47 @@ test_payload_move(void)
footer();
}
static void
test_error_code(void)
{
header();
plan(9);
diag_set(ClientError, ER_READONLY);
is(box_error_code(box_error_last()), ER_READONLY, "ClientError");
diag_set(OutOfMemory, 42, "foo", "bar");
is(box_error_code(box_error_last()), ER_MEMORY_ISSUE, "OutOfMemory");
diag_set(SystemError, "foo");
is(box_error_code(box_error_last()), ER_SYSTEM, "SystemError");
diag_set(SocketError, "foo", "bar");
is(box_error_code(box_error_last()), ER_SYSTEM, "SocketError");
diag_set(TimedOut);
is(box_error_code(box_error_last()), ER_SYSTEM, "TimedOut");
diag_set(SSLError, "foo");
is(box_error_code(box_error_last()), ER_SSL, "SSLError");
diag_set(CollationError, "foo");
is(box_error_code(box_error_last()), ER_CANT_CREATE_COLLATION,
"CollationError");
struct vclock vclock;
vclock_create(&vclock);
diag_set(XlogGapError, &vclock, &vclock);
is(box_error_code(box_error_last()), ER_XLOG_GAP, "XlogGapError");
diag_set(FiberIsCancelled);
is(box_error_code(box_error_last()), ER_PROC_LUA, "FiberIsCancelled");
check_plan();
footer();
}
int
main(void)
{
header();
plan(9);
plan(10);
random_init();
memory_init();
fiber_init(fiber_c_invoke);
test_payload_field_str();
test_payload_field_uint();
......@@ -458,7 +498,10 @@ main(void)
test_payload_field_mp();
test_payload_clear();
test_payload_move();
test_error_code();
fiber_free();
memory_free();
random_free();
footer();
......
*** main ***
1..9
1..10
*** test_payload_field_str ***
1..15
ok 1 - no fields in the beginning
......@@ -158,4 +158,17 @@ ok 8 - subtests
ok 7 - key
ok 9 - subtests
*** test_payload_move: done ***
*** test_error_code ***
1..9
ok 1 - ClientError
ok 2 - OutOfMemory
ok 3 - SystemError
ok 4 - SocketError
ok 5 - TimedOut
ok 6 - SSLError
ok 7 - CollationError
ok 8 - XlogGapError
ok 9 - FiberIsCancelled
ok 10 - subtests
*** test_error_code: done ***
*** main: done ***
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment