mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-28 20:02:00 +03:00
codership/wsrep-lib#34 Refactored view handling
Extracted on_primary_view(), on_non_primary_view() out of on_view().
This commit is contained in:
@ -609,6 +609,12 @@ namespace wsrep
|
||||
// Close transactions when handling disconnect from the group.
|
||||
void close_transactions_at_disconnect(wsrep::high_priority_service&);
|
||||
|
||||
// Handle primary view
|
||||
void on_primary_view(const wsrep::view&,
|
||||
wsrep::high_priority_service*);
|
||||
// Handle non-primary view
|
||||
void on_non_primary_view(const wsrep::view&,
|
||||
wsrep::high_priority_service*);
|
||||
// Common actions on final view
|
||||
void go_final(wsrep::unique_lock<wsrep::mutex>&,
|
||||
const wsrep::view&, wsrep::high_priority_service*);
|
||||
|
@ -665,44 +665,10 @@ void wsrep::server_state::on_connect(const wsrep::view& view)
|
||||
state(lock, s_connected);
|
||||
}
|
||||
|
||||
void wsrep::server_state::go_final(wsrep::unique_lock<wsrep::mutex>& lock,
|
||||
void wsrep::server_state::on_primary_view(
|
||||
const wsrep::view& view,
|
||||
wsrep::high_priority_service* hps)
|
||||
{
|
||||
(void)view; // avoid compiler warning "unused parameter 'view'"
|
||||
assert(view.final());
|
||||
assert(hps);
|
||||
if (hps)
|
||||
{
|
||||
close_transactions_at_disconnect(*hps);
|
||||
}
|
||||
state(lock, s_disconnected);
|
||||
id_ = wsrep::id::undefined();
|
||||
}
|
||||
|
||||
void wsrep::server_state::on_view(const wsrep::view& view,
|
||||
wsrep::high_priority_service* high_priority_service)
|
||||
{
|
||||
wsrep::log_info()
|
||||
<< "================================================\nView:\n"
|
||||
<< " id: " << view.state_id() << "\n"
|
||||
<< " seqno: " << view.view_seqno() << "\n"
|
||||
<< " status: " << view.status() << "\n"
|
||||
<< " prococol_version: " << view.protocol_version() << "\n"
|
||||
<< " own_index: " << view.own_index() << "\n"
|
||||
<< " final: " << view.final() << "\n"
|
||||
<< " members";
|
||||
const std::vector<wsrep::view::member>& members(view.members());
|
||||
for (std::vector<wsrep::view::member>::const_iterator i(members.begin());
|
||||
i != members.end(); ++i)
|
||||
{
|
||||
wsrep::log_info() << " id: " << i->id() << " "
|
||||
<< "name: " << i->name();
|
||||
}
|
||||
wsrep::log_info() << "=================================================";
|
||||
current_view_ = view;
|
||||
if (view.status() == wsrep::view::primary)
|
||||
{
|
||||
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
|
||||
assert(view.final() == false);
|
||||
//
|
||||
@ -788,9 +754,12 @@ void wsrep::server_state::on_view(const wsrep::view& view,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (view.status() == wsrep::view::non_primary)
|
||||
{
|
||||
}
|
||||
|
||||
void wsrep::server_state::on_non_primary_view(
|
||||
const wsrep::view& view,
|
||||
wsrep::high_priority_service* high_priority_service)
|
||||
{
|
||||
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
|
||||
wsrep::log_info() << "Non-primary view";
|
||||
if (view.final())
|
||||
@ -801,11 +770,61 @@ void wsrep::server_state::on_view(const wsrep::view& view,
|
||||
{
|
||||
state(lock, s_connected);
|
||||
}
|
||||
}
|
||||
|
||||
void wsrep::server_state::go_final(wsrep::unique_lock<wsrep::mutex>& lock,
|
||||
const wsrep::view& view,
|
||||
wsrep::high_priority_service* hps)
|
||||
{
|
||||
(void)view; // avoid compiler warning "unused parameter 'view'"
|
||||
assert(view.final());
|
||||
assert(hps);
|
||||
if (hps)
|
||||
{
|
||||
close_transactions_at_disconnect(*hps);
|
||||
}
|
||||
else
|
||||
state(lock, s_disconnected);
|
||||
id_ = wsrep::id::undefined();
|
||||
}
|
||||
|
||||
void wsrep::server_state::on_view(const wsrep::view& view,
|
||||
wsrep::high_priority_service* high_priority_service)
|
||||
{
|
||||
wsrep::log_info()
|
||||
<< "================================================\nView:\n"
|
||||
<< " id: " << view.state_id() << "\n"
|
||||
<< " seqno: " << view.view_seqno() << "\n"
|
||||
<< " status: " << view.status() << "\n"
|
||||
<< " prococol_version: " << view.protocol_version() << "\n"
|
||||
<< " own_index: " << view.own_index() << "\n"
|
||||
<< " final: " << view.final() << "\n"
|
||||
<< " members";
|
||||
const std::vector<wsrep::view::member>& members(view.members());
|
||||
for (std::vector<wsrep::view::member>::const_iterator i(members.begin());
|
||||
i != members.end(); ++i)
|
||||
{
|
||||
wsrep::log_info() << " id: " << i->id() << " "
|
||||
<< "name: " << i->name();
|
||||
}
|
||||
wsrep::log_info() << "=================================================";
|
||||
current_view_ = view;
|
||||
switch (view.status())
|
||||
{
|
||||
case wsrep::view::primary:
|
||||
on_primary_view(view, high_priority_service);
|
||||
break;
|
||||
case wsrep::view::non_primary:
|
||||
on_non_primary_view(view, high_priority_service);
|
||||
break;
|
||||
case wsrep::view::disconnected:
|
||||
{
|
||||
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
|
||||
go_final(lock, view, high_priority_service);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
wsrep::log_warning() << "Unrecognized view status: " << view.status();
|
||||
assert(0);
|
||||
}
|
||||
|
||||
server_service_.log_view(high_priority_service, view);
|
||||
|
Reference in New Issue
Block a user