MXS-1220: Simplify admin request handling

The admin requests are now processed in blocking mode. The timing out of
connecttions is handled by a specific timeout thread that checks the state
of each admin request.

The simplification will help with the JSON parsing with PUT/POST
commands. If non-blocking IO is used, the network reading code and JSON
parsing needs a lot more work to handle partial reads.

If the administrative interface requires higher performance and
concurrency, a multi-threaded solution could be created.
This commit is contained in:
Markus Mäkelä
2017-04-15 06:26:10 +03:00
committed by Markus Mäkelä
parent 439d67d129
commit e34b65658e
4 changed files with 125 additions and 52 deletions

View File

@ -15,13 +15,17 @@
#include <maxscale/cppdefs.hh>
#include <string>
#include <deque>
#include <maxscale/thread.h>
#include "adminclient.hh"
using std::deque;
using std::string;
typedef deque<SAdminClient> ClientList;
/** The admin interface configuration */
struct AdminConfig
{
@ -50,13 +54,20 @@ public:
*/
void stop();
/**
* Close timed out connections
*/
void check_timeouts();
private:
void handle_clients();
void handle_timeouts();
AdminClient* accept_client();
int m_socket; /**< The network socket we listen on */
int m_active; /**< Positive value if the admin is active */
int m_timeout; /**< Network timeout in seconds */
int m_socket; /**< The network socket we listen on */
int m_active; /**< Positive value if the admin is active */
int m_timeout; /**< Network timeout in seconds */
ClientList m_clients;
};
/**

View File

@ -17,6 +17,12 @@
#include <map>
#include <sys/socket.h>
#include <tr1/memory>
#include <maxscale/atomic.h>
#include <maxscale/spinlock.hh>
using mxs::SpinLock;
class AdminClient
{
@ -33,12 +39,30 @@ public:
~AdminClient();
/**
* Process one request
* @brief Process one request
*/
void process();
/**
* @brief Close the connection
*/
void close_connection();
/**
* @brief Get last activity timestamp
*
* @return The hkheartbeat of the last activity
*/
int64_t last_activity()
{
return atomic_read_int64(&m_last_activity);
}
private:
int m_fd; /**< The client socket */
int m_timeout; /**< Network timeout for reads and writes */
int64_t m_last_activity;
struct sockaddr_storage m_addr; /**< Network info for the client */
SpinLock m_lock;
};
typedef std::shared_ptr<AdminClient> SAdminClient;