DRILL-1697. C++ Client. Use the object io_service::work to prevent io_service running out of work.
- Deleting the `work` object to permit the io_service to exit. - Also reset `io_service` before submitting query. Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/6676f2d7 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/6676f2d7 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/6676f2d7 Branch: refs/heads/master Commit: 6676f2d7688a3de1118006752f1ad1c2cca103b0 Parents: 7f5ce32 Author: Xiao Meng <xiaom...@gmail.com> Authored: Tue Nov 4 13:16:51 2014 -0800 Committer: Parth Chandra <pchan...@maprtech.com> Committed: Fri Feb 13 21:50:49 2015 -0800 ---------------------------------------------------------------------- contrib/native/client/src/clientlib/drillClientImpl.cpp | 6 ++++-- contrib/native/client/src/clientlib/drillClientImpl.hpp | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/6676f2d7/contrib/native/client/src/clientlib/drillClientImpl.cpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/src/clientlib/drillClientImpl.cpp b/contrib/native/client/src/clientlib/drillClientImpl.cpp index ebeeee2..40bd81e 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.cpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.cpp @@ -347,8 +347,8 @@ DrillClientQueryResult* DrillClientImpl::SubmitQuery(::exec::shared::QueryType t //run this in a new thread { if(this->m_pListenerThread==NULL){ - // reset io_service before running - m_io_service.reset(); + // Stopping the io_service from running out-of-work + this->m_pWork = new boost::asio::io_service::work(m_io_service); this->m_pListenerThread = new boost::thread(boost::bind(&boost::asio::io_service::run, &this->m_io_service)); DRILL_LOG(LOG_DEBUG) << "DrillClientImpl::SubmitQuery: Starting listener thread: " @@ -397,6 +397,8 @@ void DrillClientImpl::getNextResult(){ } void DrillClientImpl::waitForResults(){ + // do nothing. No we do not need to explicity wait for the listener thread to finish + delete this->m_pWork; this->m_pWork = NULL; // inform io_service that io_service is permited to exit this->m_pListenerThread->join(); DRILL_LOG(LOG_DEBUG) << "DrillClientImpl::waitForResults: Listener thread " << this->m_pListenerThread << " exited." << std::endl; http://git-wip-us.apache.org/repos/asf/drill/blob/6676f2d7/contrib/native/client/src/clientlib/drillClientImpl.hpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/src/clientlib/drillClientImpl.hpp b/contrib/native/client/src/clientlib/drillClientImpl.hpp index fdcf178..bd33317 100644 --- a/contrib/native/client/src/clientlib/drillClientImpl.hpp +++ b/contrib/native/client/src/clientlib/drillClientImpl.hpp @@ -193,6 +193,7 @@ class DrillClientImpl{ m_pError(NULL), m_pListenerThread(NULL), m_socket(m_io_service), + m_pWork(NULL), m_deadlineTimer(m_io_service), m_rbuf(NULL), m_wbuf(MAX_SOCK_RD_BUFSIZE) @@ -206,6 +207,10 @@ class DrillClientImpl{ //Free any record batches or buffers remaining //Cancel any pending requests //Clear and destroy DrillClientQueryResults vector? + if(this->m_pWork!=NULL){ + delete this->m_pWork; + this->m_pWork = NULL; + } clearCancelledEntries(); m_deadlineTimer.cancel(); @@ -224,6 +229,7 @@ class DrillClientImpl{ this->m_pListenerThread->interrupt(); this->m_pListenerThread->join(); delete this->m_pListenerThread; + this->m_pListenerThread = NULL; } }; @@ -310,6 +316,8 @@ class DrillClientImpl{ // for boost asio boost::thread * m_pListenerThread; boost::asio::io_service m_io_service; + // the work object prevent io_service running out of work + boost::asio::io_service::work * m_pWork; boost::asio::ip::tcp::socket m_socket; boost::asio::deadline_timer m_deadlineTimer; // to timeout async queries that never return