1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-28 20:02:00 +03:00

codership/wsrep-lib#107 Replace exceptions with assertions

Replaced exceptions thrown on debug level sanity checks with
assertions to be more graceful with release builds.
This commit is contained in:
Teemu Ollakka
2019-07-12 16:15:13 +03:00
parent eba8a8f35d
commit fd66bdef0b

View File

@ -75,11 +75,10 @@ void wsrep::client_state::override_error(enum wsrep::client_error error,
enum wsrep::provider::status status) enum wsrep::provider::status status)
{ {
assert(wsrep::this_thread::get_id() == owning_thread_id_); assert(wsrep::this_thread::get_id() == owning_thread_id_);
if (current_error_ != wsrep::e_success && // Error state should not be cleared with success code without
error == wsrep::e_success) // explicit reset_error() call.
{ assert(current_error_ == wsrep::e_success ||
throw wsrep::runtime_error("Overriding error with success"); error != wsrep::e_success);
}
current_error_ = error; current_error_ = error;
current_error_status_ = status; current_error_status_ = status;
} }
@ -494,8 +493,13 @@ void wsrep::client_state::state(
{ 0, 1, 0, 0, 0}, /* result */ { 0, 1, 0, 0, 0}, /* result */
{ 1, 0, 0, 0, 0} /* quit */ { 1, 0, 0, 0, 0} /* quit */
}; };
if (allowed[state_][state]) if (!allowed[state_][state])
{ {
wsrep::log_debug() << "client_state: Unallowed state transition: "
<< state_ << " -> " << state;
assert(0);
}
state_hist_.push_back(state_); state_hist_.push_back(state_);
state_ = state; state_ = state;
if (state_hist_.size() > 10) if (state_hist_.size() > 10)
@ -503,14 +507,6 @@ void wsrep::client_state::state(
state_hist_.erase(state_hist_.begin()); state_hist_.erase(state_hist_.begin());
} }
} }
else
{
std::ostringstream os;
os << "client_state: Unallowed state transition: "
<< state_ << " -> " << state;
throw wsrep::runtime_error(os.str());
}
}
void wsrep::client_state::mode( void wsrep::client_state::mode(
wsrep::unique_lock<wsrep::mutex>& lock WSREP_UNUSED, wsrep::unique_lock<wsrep::mutex>& lock WSREP_UNUSED,
@ -524,16 +520,11 @@ void wsrep::client_state::mode(
{ 1, 1, 0, 0 }, /* toi */ { 1, 1, 0, 0 }, /* toi */
{ 1, 0, 0, 0 } /* rsu */ { 1, 0, 0, 0 } /* rsu */
}; };
if (allowed[mode_][mode]) if (!allowed[mode_][mode])
{ {
wsrep::log_debug() << "client_state: Unallowed mode transition: "
<< mode_ << " -> " << mode;
assert(0);
}
mode_ = mode; mode_ = mode;
} }
else
{
std::ostringstream os;
os << "client_state: Unallowed mode transition: "
<< mode_ << " -> " << mode;
throw wsrep::runtime_error(os.str());
}
}