RecreateTargetConn
This commit is contained in:
parent
559a50f82c
commit
f8afa41c28
@ -41,8 +41,11 @@ void MasterSvrMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_
|
|||||||
f8::MsgHdr* context_hdr = GetHdrByContextId(msg.context_id());
|
f8::MsgHdr* context_hdr = GetHdrByContextId(msg.context_id());
|
||||||
if (context_hdr) {
|
if (context_hdr) {
|
||||||
if (msg.error_code() == 0) {
|
if (msg.error_code() == 0) {
|
||||||
std::string key = msg.host() + ":" + a8::XValue(msg.port()).GetString();
|
TargetConn* conn = TargetConnMgr::Instance()->RecreateTargetConn(
|
||||||
TargetConn* conn = TargetConnMgr::Instance()->GetConnByKey(key);
|
msg.host(),
|
||||||
|
msg.port()
|
||||||
|
);
|
||||||
|
assert(conn);
|
||||||
if (conn) {
|
if (conn) {
|
||||||
conn->ForwardClientMsg(hdr);
|
conn->ForwardClientMsg(hdr);
|
||||||
}
|
}
|
||||||
|
@ -40,3 +40,21 @@ TargetConn* TargetConnMgr::GetConnById(int instance_id)
|
|||||||
return itr != id_hash_.end() ? itr->second : nullptr;
|
return itr != id_hash_.end() ? itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TargetConn* TargetConnMgr::RecreateTargetConn(const std::string& host, int port)
|
||||||
|
{
|
||||||
|
std::string key = host + ":" + a8::XValue(port).GetString();
|
||||||
|
TargetConn* conn = GetConnByKey(key);
|
||||||
|
if (conn) {
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
while (GetConnById(++curr_id_)) {};
|
||||||
|
int instance_id = curr_id_;
|
||||||
|
std::string remote_ip = host;
|
||||||
|
int remote_port = port;
|
||||||
|
|
||||||
|
conn->Init(instance_id, remote_ip, remote_port);
|
||||||
|
id_hash_[conn->instance_id] = conn;
|
||||||
|
key_hash_[key] = conn;
|
||||||
|
conn->Open();
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
@ -14,9 +14,10 @@ class TargetConnMgr : public a8::Singleton<TargetConnMgr>
|
|||||||
|
|
||||||
TargetConn* GetConnByKey(const std::string& key);
|
TargetConn* GetConnByKey(const std::string& key);
|
||||||
TargetConn* GetConnById(int instance_id);
|
TargetConn* GetConnById(int instance_id);
|
||||||
|
TargetConn* RecreateTargetConn(const std::string& host, int port);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
unsigned short curr_id_ = 1000;
|
||||||
std::map<std::string, TargetConn*> key_hash_;
|
std::map<std::string, TargetConn*> key_hash_;
|
||||||
std::map<int, TargetConn*> id_hash_;
|
std::map<int, TargetConn*> id_hash_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user