Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mon/MonClient: persist global_id across re-connecting #13550

Merged
merged 1 commit into from Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/mon/MonClient.cc
Expand Up @@ -114,7 +114,7 @@ int MonClient::get_monmap_privately()
std::uniform_int_distribution<unsigned> ranks(0, monmap.size() - 1);
while (monmap.fsid.is_zero()) {
auto rank = ranks(rng);
auto& pending_con = _add_conn(rank);
auto& pending_con = _add_conn(rank, 0);
auto con = pending_con.get_con();
ldout(cct, 10) << "querying mon." << monmap.get_name(rank) << " "
<< con->get_peer_addr() << dendl;
Expand Down Expand Up @@ -572,15 +572,17 @@ void MonClient::_reopen_session(int rank)
assert(monc_lock.is_locked());
ldout(cct, 10) << __func__ << " rank " << rank << dendl;

// save global_id if any before nuking active_con
const uint64_t global_id = active_con ? active_con->get_global_id() : 0;
active_con.reset();
pending_cons.clear();

_start_hunting();

if (rank >= 0) {
_add_conn(rank);
_add_conn(rank, global_id);
} else {
_add_conns();
_add_conns(global_id);
}

// throw out old queued messages
Expand Down Expand Up @@ -610,11 +612,11 @@ void MonClient::_reopen_session(int rank)
_renew_subs();
}

MonConnection& MonClient::_add_conn(unsigned rank)
MonConnection& MonClient::_add_conn(unsigned rank, uint64_t global_id)
{
auto peer = monmap.get_addr(rank);
auto conn = messenger->get_connection(monmap.get_inst(rank));
MonConnection mc(cct, conn);
MonConnection mc(cct, conn, global_id);
auto inserted = pending_cons.insert(move(make_pair(peer, move(mc))));
ldout(cct, 10) << "picked mon." << monmap.get_name(rank)
<< " con " << conn
Expand All @@ -623,7 +625,7 @@ MonConnection& MonClient::_add_conn(unsigned rank)
return inserted.first->second;
}

void MonClient::_add_conns()
void MonClient::_add_conns(uint64_t global_id)
{
const unsigned num_mons = monmap.size();
vector<unsigned> ranks(num_mons);
Expand All @@ -639,7 +641,7 @@ void MonClient::_add_conns()
n = num_mons;
}
for (unsigned i = 0; i < n; i++) {
_add_conn(ranks[i]);
_add_conn(ranks[i], global_id);
}
}

Expand Down Expand Up @@ -1143,8 +1145,8 @@ AuthAuthorizer* MonClient::build_authorizer(int service_id) const {
#undef dout_prefix
#define dout_prefix *_dout << "monclient" << (have_session() ? ": " : "(hunting): ")

MonConnection::MonConnection(CephContext *cct, ConnectionRef con)
: cct(cct), con(con)
MonConnection::MonConnection(CephContext *cct, ConnectionRef con, uint64_t global_id)
: cct(cct), con(con), global_id(global_id)
{}

MonConnection::~MonConnection()
Expand Down
9 changes: 5 additions & 4 deletions src/mon/MonClient.h
Expand Up @@ -97,7 +97,8 @@ struct MonClientPinger : public Dispatcher {
class MonConnection {
public:
MonConnection(CephContext *cct,
ConnectionRef conn);
ConnectionRef conn,
uint64_t global_id);
~MonConnection();
MonConnection(MonConnection&& rhs) = default;
MonConnection& operator=(MonConnection&&) = default;
Expand Down Expand Up @@ -140,7 +141,7 @@ class MonConnection {
ConnectionRef con;

std::unique_ptr<AuthClientHandler> auth;
uint64_t global_id = 0;
uint64_t global_id;
};

class MonClient : public Dispatcher {
Expand Down Expand Up @@ -205,8 +206,8 @@ class MonClient : public Dispatcher {
void _finish_hunting();
void _finish_auth(int auth_err);
void _reopen_session(int rank = -1);
MonConnection& _add_conn(unsigned rank);
void _add_conns();
MonConnection& _add_conn(unsigned rank, uint64_t global_id);
void _add_conns(uint64_t global_id);
void _send_mon_message(Message *m);

public:
Expand Down