MXS-1623 Maintain count of current/total descriptors
This commit is contained in:
@ -172,6 +172,14 @@ public:
|
||||
return m_statistics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the count of descriptors.
|
||||
*
|
||||
* @param pnCurrent On output the current number of descriptors.
|
||||
* @param pnTotal On output the total number of descriptors.
|
||||
*/
|
||||
void get_descriptor_counts(uint32_t* pnCurrent, uint64_t* pnTotal);
|
||||
|
||||
/**
|
||||
* Add a file descriptor to the epoll instance of the worker.
|
||||
*
|
||||
@ -508,21 +516,23 @@ private:
|
||||
uint32_t handle_epoll_events(uint32_t events);
|
||||
|
||||
private:
|
||||
int m_id; /*< The id of the worker. */
|
||||
state_t m_state; /*< The state of the worker */
|
||||
int m_epoll_fd; /*< The epoll file descriptor. */
|
||||
STATISTICS m_statistics; /*< Worker statistics. */
|
||||
MessageQueue* m_pQueue; /*< The message queue of the worker. */
|
||||
THREAD m_thread; /*< The thread handle of the worker. */
|
||||
bool m_started; /*< Whether the thread has been started or not. */
|
||||
bool m_should_shutdown; /*< Whether shutdown should be performed. */
|
||||
bool m_shutdown_initiated; /*< Whether shutdown has been initated. */
|
||||
SessionsById m_sessions; /*< A mapping of session_id->MXS_SESSION. The map
|
||||
* should contain sessions exclusive to this
|
||||
* worker and not e.g. listener sessions. For now,
|
||||
* it's up to the protocol to decide whether a new
|
||||
* session is added to the map. */
|
||||
Zombies m_zombies; /*< DCBs to be deleted. */
|
||||
int m_id; /*< The id of the worker. */
|
||||
state_t m_state; /*< The state of the worker */
|
||||
int m_epoll_fd; /*< The epoll file descriptor. */
|
||||
STATISTICS m_statistics; /*< Worker statistics. */
|
||||
MessageQueue* m_pQueue; /*< The message queue of the worker. */
|
||||
THREAD m_thread; /*< The thread handle of the worker. */
|
||||
bool m_started; /*< Whether the thread has been started or not. */
|
||||
bool m_should_shutdown; /*< Whether shutdown should be performed. */
|
||||
bool m_shutdown_initiated; /*< Whether shutdown has been initated. */
|
||||
SessionsById m_sessions; /*< A mapping of session_id->MXS_SESSION. The map
|
||||
* should contain sessions exclusive to this
|
||||
* worker and not e.g. listener sessions. For now,
|
||||
* it's up to the protocol to decide whether a new
|
||||
* session is added to the map. */
|
||||
Zombies m_zombies; /*< DCBs to be deleted. */
|
||||
uint32_t m_nCurrent_descriptors; /*< Current number of descriptors. */
|
||||
uint64_t m_nTotal_descriptors; /*< Total number of descriptors. */
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -162,6 +162,8 @@ Worker::Worker(int id,
|
||||
, m_started(false)
|
||||
, m_should_shutdown(false)
|
||||
, m_shutdown_initiated(false)
|
||||
, m_nCurrent_descriptors(0)
|
||||
, m_nTotal_descriptors(0)
|
||||
{
|
||||
MXS_POLL_DATA::handler = &Worker::epoll_instance_handler;
|
||||
MXS_POLL_DATA::thread.id = id;
|
||||
@ -421,6 +423,12 @@ int64_t Worker::get_one_statistic(POLL_STAT what)
|
||||
return rv;
|
||||
}
|
||||
|
||||
void Worker::get_descriptor_counts(uint32_t* pnCurrent, uint64_t* pnTotal)
|
||||
{
|
||||
*pnCurrent = atomic_load_uint32(&m_nCurrent_descriptors);
|
||||
*pnTotal = atomic_load_uint64(&m_nTotal_descriptors);
|
||||
}
|
||||
|
||||
bool Worker::add_fd(int fd, uint32_t events, MXS_POLL_DATA* pData)
|
||||
{
|
||||
bool rv = true;
|
||||
@ -435,7 +443,12 @@ bool Worker::add_fd(int fd, uint32_t events, MXS_POLL_DATA* pData)
|
||||
|
||||
pData->thread.id = m_id;
|
||||
|
||||
if (epoll_ctl(m_epoll_fd, EPOLL_CTL_ADD, fd, &ev) != 0)
|
||||
if (epoll_ctl(m_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == 0)
|
||||
{
|
||||
atomic_add_uint32(&m_nCurrent_descriptors, 1);
|
||||
atomic_add_uint64(&m_nTotal_descriptors, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
poll_resolve_error(fd, errno, EPOLL_CTL_ADD);
|
||||
rv = false;
|
||||
@ -479,7 +492,11 @@ bool Worker::remove_fd(int fd)
|
||||
|
||||
struct epoll_event ev = {};
|
||||
|
||||
if (epoll_ctl(m_epoll_fd, EPOLL_CTL_DEL, fd, &ev) != 0)
|
||||
if (epoll_ctl(m_epoll_fd, EPOLL_CTL_DEL, fd, &ev) == 0)
|
||||
{
|
||||
atomic_add_uint32(&m_nCurrent_descriptors, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
poll_resolve_error(fd, errno, EPOLL_CTL_DEL);
|
||||
rv = false;
|
||||
|
||||
Reference in New Issue
Block a user