mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-31 18:24:25 +03:00
- Initialize member cluster ID only on connection to cluster and forget
it on disconnect. - Don't rely on own index from the view because the view may come from another member (IST/SST), instead always determine own index from own ID. Refs codership/wsrep-lib#13
This commit is contained in:
@ -565,14 +565,38 @@ wsrep::server_state::causal_read(int timeout) const
|
||||
return provider_->causal_read(timeout);
|
||||
}
|
||||
|
||||
void wsrep::server_state::on_connect(const wsrep::gtid& gtid)
|
||||
void wsrep::server_state::on_connect(const wsrep::view& view)
|
||||
{
|
||||
// Sanity checks
|
||||
if (id_.is_undefined() == false)
|
||||
{
|
||||
wsrep::log_warning() << "Unexpected connection in connected state. "
|
||||
<< "Received view: " << view
|
||||
<< "Previous ID: " << id_;
|
||||
assert(0);
|
||||
}
|
||||
|
||||
if (view.own_index() < 0 ||
|
||||
size_t(view.own_index()) >= view.members().size())
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Invalid view on connect: own index out of range: " << view;
|
||||
wsrep::log_error() << os.str();
|
||||
assert(0);
|
||||
throw wsrep::runtime_error(os.str());
|
||||
}
|
||||
|
||||
id_ = view.members()[view.own_index()].id();
|
||||
|
||||
wsrep::log_info() << "Server "
|
||||
<< name_
|
||||
<< " connected to cluster at position "
|
||||
<< gtid;
|
||||
<< view.state_id()
|
||||
<< " with ID "
|
||||
<< id_;
|
||||
|
||||
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
|
||||
connected_gtid_ = gtid;
|
||||
connected_gtid_ = view.state_id();
|
||||
state(lock, s_connected);
|
||||
}
|
||||
|
||||
@ -599,22 +623,7 @@ void wsrep::server_state::on_view(const wsrep::view& view,
|
||||
if (view.status() == wsrep::view::primary)
|
||||
{
|
||||
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
|
||||
if (view.own_index() >= 0)
|
||||
{
|
||||
if (id_.is_undefined())
|
||||
{
|
||||
// No identifier was passed during server state initialization
|
||||
// and the ID was generated by the provider.
|
||||
id_ = view.members()[view.own_index()].id();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Own identifier must not change between views.
|
||||
// assert(id_ == view.members()[view.own_index()].id());
|
||||
}
|
||||
}
|
||||
assert(view.final() == false);
|
||||
|
||||
//
|
||||
// Reached primary from connected state. This may mean the following
|
||||
//
|
||||
@ -703,6 +712,7 @@ void wsrep::server_state::on_view(const wsrep::view& view,
|
||||
{
|
||||
close_transactions_at_disconnect(*high_priority_service);
|
||||
}
|
||||
id_ = id::undefined();
|
||||
state(lock, s_disconnected);
|
||||
}
|
||||
else if (state_ != s_disconnecting)
|
||||
|
Reference in New Issue
Block a user