UltraMonkey-L7 V3(multi-thread implementation)
修訂 | 6ea7bd6f07f1a87e64a426aa9fdc2a585a6bb7c3 (tree) |
---|---|
時間 | 2012-07-31 11:40:39 |
作者 | Hiroaki Nakano <nakano.hiroaki@nttc...> |
Commiter | Hiroaki Nakano |
Merge branch 'ssl_fix_by_CW' into v3.0.4-devel
@@ -129,7 +129,7 @@ public: | ||
129 | 129 | void down_thread_run(); |
130 | 130 | //! realserver remove |
131 | 131 | //! @param[in] target endpoint |
132 | - void realserver_remove(boost::asio::ip::tcp::endpoint &); | |
132 | + void realserver_remove(const boost::asio::ip::tcp::endpoint &); | |
133 | 133 | protected: |
134 | 134 | typedef data_buff_base<boost::asio::ip::tcp> tcp_data; |
135 | 135 | typedef boost::asio::ip::tcp::endpoint endpoint; |
@@ -536,6 +536,7 @@ protected: | ||
536 | 536 | virtual void down_thread_client_handle_async_write_some(const TCP_PROCESS_TYPE_TAG); |
537 | 537 | virtual void down_thread_sorryserver_async_read_some_handler(const boost::system::error_code &error_code, std::size_t len); |
538 | 538 | virtual void down_thread_sorryserver_handle_async_read_some(const TCP_PROCESS_TYPE_TAG); |
539 | + virtual void up_thread_client_ssl_socket_clear_socket_handler(); | |
539 | 540 | |
540 | 541 | //! down thread receive from realserver and raise module event of handle_realserver_recv |
541 | 542 | //! @param[in] process_type is process type |
@@ -131,7 +131,7 @@ public: | ||
131 | 131 | |
132 | 132 | virtual std::size_t read_some(const boost::asio::mutable_buffers_1 &buffers, boost::system::error_code &error_code) { |
133 | 133 | boost::mutex::scoped_lock lock(ssl_mutex); |
134 | - if (write_con > 0) { | |
134 | + if (write_con > 0 || handshake_con > 0) { | |
135 | 135 | error_code = boost::asio::error::try_again; |
136 | 136 | return 0; |
137 | 137 | } |
@@ -150,7 +150,7 @@ public: | ||
150 | 150 | virtual size_t write_some(const boost::asio::const_buffers_1 &buffer, boost::system::error_code &error_code) { |
151 | 151 | boost::mutex::scoped_lock lock(ssl_mutex); |
152 | 152 | |
153 | - if (read_con > 0) { | |
153 | + if (read_con > 0 || handshake_con > 0) { | |
154 | 154 | error_code = boost::asio::error::try_again; |
155 | 155 | return 0; |
156 | 156 | } |
@@ -268,6 +268,10 @@ protected: | ||
268 | 268 | bool downqos_alert_flag; //! downstream QoS alert flag |
269 | 269 | bool sessionpool_alert_flag; //! sessionpool alert flag |
270 | 270 | |
271 | + bool adm_cmd_wait_flag; //! wait for l7vsadm done | |
272 | + boost::mutex adm_cmd_wait_flag_mutex; | |
273 | + boost::condition adm_cmd_wait_flag_cond; | |
274 | + | |
271 | 275 | void load_parameter(l7vs::error_code &); |
272 | 276 | |
273 | 277 | virtual void handle_replication_interrupt( |
@@ -595,7 +595,9 @@ void tcp_session::set_virtual_service_message(const TCP_VIRTUAL_SERVICE_MESSAGE_ | ||
595 | 595 | fmt % boost::this_thread::get_id(); |
596 | 596 | Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); |
597 | 597 | } |
598 | - break; | |
598 | + //break; | |
599 | + realserver_remove(endpoint_); | |
600 | + return; | |
599 | 601 | case SORRY_STATE_ENABLE: |
600 | 602 | //----Debug log---------------------------------------------------------------------- |
601 | 603 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) { |
@@ -895,7 +897,19 @@ void tcp_session::up_thread_run() | ||
895 | 897 | |
896 | 898 | if (ssl_flag) { |
897 | 899 | client_ssl_socket.wait_async_event_all_end(); |
898 | - client_ssl_socket.clear_socket(); | |
900 | + upthread_status = UPTHREAD_LOCK; | |
901 | + parent_dispatcher.post(boost::bind(&tcp_session::up_thread_client_ssl_socket_clear_socket_handler,this)); | |
902 | + boost::mutex::scoped_lock lock(upthread_status_mutex); | |
903 | + while (unlikely(upthread_status == UPTHREAD_LOCK)) { | |
904 | + to_time(LOCKTIMEOUT, xt); | |
905 | + upthread_status_cond.timed_wait(lock, xt); | |
906 | + tcp_thread_message *msg = up_thread_message_que.pop(); | |
907 | + if (msg) { // message is alive. | |
908 | + up_thread_next_call_function.second(LOCAL_PROC); | |
909 | + delete msg; | |
910 | + msg = NULL; | |
911 | + } | |
912 | + } // lockmode while loop end. | |
899 | 913 | } |
900 | 914 | |
901 | 915 | upthread_status = UPTHREAD_SLEEP; |
@@ -1191,7 +1205,7 @@ void tcp_session::up_thread_client_accept_fail_event(const TCP_PROCESS_TYPE_TAG | ||
1191 | 1205 | |
1192 | 1206 | boost::format fmt("Thread ID[%d] tcp_ssl_socket::handshake[%s]"); |
1193 | 1207 | fmt % boost::this_thread::get_id() % handshake_error_code.message(); |
1194 | - Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 71, fmt.str(), __FILE__, __LINE__); | |
1208 | + Logger::putLogError(LOG_CAT_L7VSD_SESSION, 71, fmt.str(), __FILE__, __LINE__); | |
1195 | 1209 | |
1196 | 1210 | } |
1197 | 1211 | up_thread_next_call_function = up_thread_function_array[func_tag]; |
@@ -1199,22 +1213,40 @@ void tcp_session::up_thread_client_accept_fail_event(const TCP_PROCESS_TYPE_TAG | ||
1199 | 1213 | |
1200 | 1214 | //! real server remove |
1201 | 1215 | //! @param[in] target endpoint |
1202 | -void tcp_session::realserver_remove(endpoint &target_endpoint) | |
1216 | +void tcp_session::realserver_remove(const endpoint &target_endpoint) | |
1203 | 1217 | { |
1218 | + | |
1219 | + if (target_endpoint != realserver_endpoint && target_endpoint != connecting_endpoint) return; | |
1220 | + | |
1204 | 1221 | tcp_thread_message *up_msg = new tcp_thread_message; |
1205 | - up_thread_function_pair up_func = up_thread_function_array[UP_FUNC_REALSERVER_CHECK]; | |
1222 | + up_thread_function_pair up_func = up_thread_function_array[UP_FUNC_EXIT]; | |
1206 | 1223 | up_msg->message = up_func.second; |
1207 | 1224 | up_msg->endpoint_info = target_endpoint; |
1208 | 1225 | #ifdef DEBUG |
1209 | - up_msg->func_tag_name = func_tag_to_string(UP_FUNC_REALSERVER_CHECK); | |
1226 | + up_msg->func_tag_name = func_tag_to_string(UP_FUNC_EXIT); | |
1210 | 1227 | { |
1211 | 1228 | boost::format fmt("Thread ID[%d] up_queue.push : %s"); |
1212 | - fmt % boost::this_thread::get_id() % func_tag_to_string(UP_FUNC_REALSERVER_CHECK); | |
1229 | + fmt % boost::this_thread::get_id() % func_tag_to_string(UP_FUNC_EXIT); | |
1213 | 1230 | Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); |
1214 | 1231 | } |
1215 | 1232 | #endif |
1216 | 1233 | while (!up_thread_message_que.push(up_msg)) {} |
1217 | 1234 | upthread_status_cond.notify_one(); |
1235 | + | |
1236 | + tcp_thread_message *down_msg = new tcp_thread_message; | |
1237 | + down_thread_function_pair down_func = down_thread_function_array[DOWN_FUNC_EXIT]; | |
1238 | + down_msg->message = down_func.second; | |
1239 | + down_msg->endpoint_info = target_endpoint; | |
1240 | +#ifdef DEBUG | |
1241 | + down_msg->func_tag_name = func_tag_to_string(DOWN_FUNC_EXIT); | |
1242 | + { | |
1243 | + boost::format fmt("Thread ID[%d] down_queue.push : %s"); | |
1244 | + fmt % boost::this_thread::get_id() % func_tag_to_string(DOWN_FUNC_EXIT); | |
1245 | + Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); | |
1246 | + } | |
1247 | +#endif | |
1248 | + while (!down_thread_message_que.push(down_msg)) {} | |
1249 | + downthread_status_cond.notify_one(); | |
1218 | 1250 | } |
1219 | 1251 | |
1220 | 1252 |
@@ -3874,7 +3906,7 @@ void tcp_session::down_thread_realserver_handle_async_read_some(const tcp_sessio | ||
3874 | 3906 | realserver_socket->async_read_some(boost::asio::buffer(down_thread_data_dest_side.get_data()), handler); |
3875 | 3907 | else |
3876 | 3908 | func_tag = DOWN_FUNC_REALSERVER_DISCONNECT; |
3877 | - realserver_socket_mutex.lock(); | |
3909 | + realserver_socket_mutex.unlock(); | |
3878 | 3910 | } else { //recv error |
3879 | 3911 | func_tag = DOWN_FUNC_REALSERVER_DISCONNECT; |
3880 | 3912 | boost::format fmt("Thread ID[%d] down_thread_realserver_handle_async_read_some recv error:%s"); |
@@ -4017,6 +4049,30 @@ void tcp_session::down_thread_sorryserver_async_read_some_handler(const boost::s | ||
4017 | 4049 | downthread_status_cond.notify_one(); |
4018 | 4050 | } |
4019 | 4051 | |
4052 | +void tcp_session::up_thread_client_ssl_socket_clear_socket_handler() | |
4053 | +{ | |
4054 | + if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_SESSION))) { | |
4055 | + boost::format formatter("Thread ID[%d] FUNC IN up_thread_client_ssl_socket_clear_socket_handler"); | |
4056 | + formatter % boost::this_thread::get_id(); | |
4057 | + Logger::putLogDebug(LOG_CAT_L7VSD_SESSION, 999, formatter.str(), __FILE__, __LINE__); | |
4058 | + } | |
4059 | + | |
4060 | + client_ssl_socket.clear_socket(); | |
4061 | + | |
4062 | + tcp_thread_message *mes = new tcp_thread_message(); | |
4063 | + mes->message = up_que_function_map[UP_FUNC_PAUSE_OFF_EVENT]; | |
4064 | +#ifdef DEBUG | |
4065 | + mes->func_tag_name = func_tag_to_string(UP_FUNC_PAUSE_OFF_EVENT); | |
4066 | + { | |
4067 | + boost::format fmt("Thread ID[%d] up_queue.push : %s"); | |
4068 | + fmt % boost::this_thread::get_id() % func_tag_to_string(UP_FUNC_PAUSE_OFF_EVENT); | |
4069 | + Logger::putLogInfo(LOG_CAT_L7VSD_SESSION, 999, fmt.str(), __FILE__, __LINE__); | |
4070 | + } | |
4071 | +#endif | |
4072 | + while (!up_thread_message_que.push(mes)) {} | |
4073 | + upthread_status_cond.notify_one(); | |
4074 | +} | |
4075 | + | |
4020 | 4076 | void tcp_session::down_thread_sorryserver_handle_async_read_some(tcp_session::TCP_PROCESS_TYPE_TAG) |
4021 | 4077 | { |
4022 | 4078 |
@@ -69,6 +69,7 @@ l7vs::virtualservice_base::virtualservice_base(const l7vs::l7vsd &invsd, | ||
69 | 69 | upqos_alert_flag = false; |
70 | 70 | downqos_alert_flag = false; |
71 | 71 | sessionpool_alert_flag = false; |
72 | + adm_cmd_wait_flag = false; | |
72 | 73 | |
73 | 74 | rs_list.clear(); |
74 | 75 | protomod = NULL; |
@@ -352,6 +352,13 @@ void l7vs::virtualservice_tcp::handle_accept(const l7vs::session_thread_control | ||
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
355 | + { | |
356 | + boost::mutex::scoped_lock lock(adm_cmd_wait_flag_mutex); | |
357 | + if (unlikely(adm_cmd_wait_flag)){ | |
358 | + adm_cmd_wait_flag_cond.wait(lock); | |
359 | + } | |
360 | + } | |
361 | + | |
355 | 362 | session_thread_control *stc_ptr_noconst = const_cast<session_thread_control *>(stc_ptr); |
356 | 363 | |
357 | 364 | if (unlikely(err == boost::asio::error::operation_aborted)) { // nomal exit case |
@@ -1290,9 +1297,6 @@ void l7vs::virtualservice_tcp::add_realserver(const l7vs::virtualservice_element | ||
1290 | 1297 | } |
1291 | 1298 | } |
1292 | 1299 | |
1293 | - //pause active sessions | |
1294 | - active_sessions.do_all(boost::bind(&session_thread_control::session_pause_on, _1)); | |
1295 | - | |
1296 | 1300 | //add realserver |
1297 | 1301 | for (std::vector<realserver_element>::iterator itr = in_element.realserver_vector.begin(); |
1298 | 1302 | itr != in_element.realserver_vector.end(); |
@@ -1305,9 +1309,6 @@ void l7vs::virtualservice_tcp::add_realserver(const l7vs::virtualservice_element | ||
1305 | 1309 | rs_list.push_back(rs); |
1306 | 1310 | } |
1307 | 1311 | |
1308 | - //run active sessions | |
1309 | - active_sessions.do_all(boost::bind(&session_thread_control::session_pause_off, _1)); | |
1310 | - | |
1311 | 1312 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_VIRTUALSERVICE))) { |
1312 | 1313 | boost::format formatter("out_function: void virtualservice_tcp::add_realserver( " |
1313 | 1314 | "const l7vs::virtualservice_element& in," |
@@ -1384,8 +1385,11 @@ void l7vs::virtualservice_tcp::edit_realserver(const l7vs::virtualservice_elemen | ||
1384 | 1385 | } |
1385 | 1386 | } |
1386 | 1387 | |
1387 | - //pause active sessions | |
1388 | - active_sessions.do_all(boost::bind(&session_thread_control::session_pause_on, _1)); | |
1388 | + //lock adm_cmd_wait_flag on | |
1389 | + adm_cmd_wait_flag_mutex.lock(); | |
1390 | + adm_cmd_wait_flag = true; | |
1391 | + adm_cmd_wait_flag_cond.notify_one(); | |
1392 | + adm_cmd_wait_flag_mutex.unlock(); | |
1389 | 1393 | |
1390 | 1394 | //edit realserver |
1391 | 1395 | for (std::vector<realserver_element>::iterator itr = in_element.realserver_vector.begin(); |
@@ -1406,8 +1410,11 @@ void l7vs::virtualservice_tcp::edit_realserver(const l7vs::virtualservice_elemen | ||
1406 | 1410 | } |
1407 | 1411 | } |
1408 | 1412 | |
1409 | - //run active sessions | |
1410 | - active_sessions.do_all(boost::bind(&session_thread_control::session_pause_off, _1)); | |
1413 | + //lock adm_cmd_wait_flag off | |
1414 | + adm_cmd_wait_flag_mutex.lock(); | |
1415 | + adm_cmd_wait_flag = false; | |
1416 | + adm_cmd_wait_flag_cond.notify_one(); | |
1417 | + adm_cmd_wait_flag_mutex.unlock(); | |
1411 | 1418 | |
1412 | 1419 | err.setter(false, ""); |
1413 | 1420 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_VIRTUALSERVICE))) { |
@@ -1486,8 +1493,11 @@ void l7vs::virtualservice_tcp::del_realserver(const l7vs::virtualservice_element | ||
1486 | 1493 | } |
1487 | 1494 | } |
1488 | 1495 | |
1489 | - //pause active sessions | |
1490 | - active_sessions.do_all(boost::bind(&session_thread_control::session_pause_on, _1)); | |
1496 | + //lock adm_cmd_wait_flag on | |
1497 | + adm_cmd_wait_flag_mutex.lock(); | |
1498 | + adm_cmd_wait_flag = true; | |
1499 | + adm_cmd_wait_flag_cond.notify_one(); | |
1500 | + adm_cmd_wait_flag_mutex.unlock(); | |
1491 | 1501 | |
1492 | 1502 | //del realserver |
1493 | 1503 | for (std::vector<realserver_element>::iterator itr = in_element.realserver_vector.begin(); |
@@ -1503,8 +1513,11 @@ void l7vs::virtualservice_tcp::del_realserver(const l7vs::virtualservice_element | ||
1503 | 1513 | } |
1504 | 1514 | } |
1505 | 1515 | |
1506 | - //run active sessions | |
1507 | - active_sessions.do_all(boost::bind(&session_thread_control::session_pause_off, _1)); | |
1516 | + //lock adm_cmd_wait_flag off | |
1517 | + adm_cmd_wait_flag_mutex.lock(); | |
1518 | + adm_cmd_wait_flag = false; | |
1519 | + adm_cmd_wait_flag_cond.notify_one(); | |
1520 | + adm_cmd_wait_flag_mutex.unlock(); | |
1508 | 1521 | |
1509 | 1522 | if (unlikely(LOG_LV_DEBUG == Logger::getLogLevel(LOG_CAT_L7VSD_VIRTUALSERVICE))) { |
1510 | 1523 | boost::format formatter("out_function: void virtualservice_tcp::del_realserver( " |