| 2909 | } |
| 2910 | |
| 2911 | bool ImpalaServer::IsIdleConnection( |
| 2912 | const ThriftServer::ConnectionContext& connection_context) { |
| 2913 | // The set of sessions associated with this connection. |
| 2914 | std::set<TUniqueId> session_ids; |
| 2915 | { |
| 2916 | TUniqueId connection_id = connection_context.connection_id; |
| 2917 | unique_lock<mutex> l(connection_to_sessions_map_lock_); |
| 2918 | ConnectionToSessionMap::iterator it = connection_to_sessions_map_.find(connection_id); |
| 2919 | |
| 2920 | // Not every connection must have an associated session |
| 2921 | if (it == connection_to_sessions_map_.end()) return false; |
| 2922 | |
| 2923 | session_ids = it->second; |
| 2924 | |
| 2925 | // Sessions are not removed from the map even after they are closed and an entry |
| 2926 | // won't be added to the map unless a session is established. The code below relies |
| 2927 | // on this invariant to not mark a connection with no session yet as idle. |
| 2928 | DCHECK(!session_ids.empty()); |
| 2929 | } |
| 2930 | |
| 2931 | // Check if all the sessions associated with the connection are idle. |
| 2932 | { |
| 2933 | lock_guard<mutex> map_lock(session_state_map_lock_); |
| 2934 | for (const TUniqueId& session_id : session_ids) { |
| 2935 | const auto it = session_state_map_.find(session_id); |
| 2936 | if (it == session_state_map_.end()) continue; |
| 2937 | |
| 2938 | // If any session associated with this connection is not idle, |
| 2939 | // the connection is not idle. |
| 2940 | lock_guard<mutex> state_lock(it->second->lock); |
| 2941 | if (!it->second->expired) return false; |
| 2942 | } |
| 2943 | } |
| 2944 | return true; |
| 2945 | } |
| 2946 | |
| 2947 | void ImpalaServer::RegisterSessionTimeout(int32_t session_timeout) { |
| 2948 | if (session_timeout <= 0) return; |
no test coverage detected