예제 #1
0
파일: session.c 프로젝트: bigshuai/MaxScale
/**
 * Close sessions that have been idle for too long.
 *
 * If the time since a session last sent data is greater than the set value in the
 * service, it is disconnected. The connection timeout is disabled by default.
 */
void process_idle_sessions()
{
    if (spinlock_acquire_nowait(&timeout_lock))
    {
        if (hkheartbeat >= next_timeout_check)
        {
            /** Because the resolution of the timeout is one second, we only need to
             * check for it once per second. One heartbeat is 100 milliseconds. */
            next_timeout_check = hkheartbeat + 10;
            spinlock_acquire(&session_spin);
            SESSION *all_session = get_all_sessions();

            while (all_session)
            {
                if (all_session->service && all_session->client_dcb && all_session->client_dcb->state == DCB_STATE_POLLING &&
                    hkheartbeat - all_session->client_dcb->last_read > all_session->service->conn_idle_timeout * 10)
                {
                    dcb_close(all_session->client_dcb);
                }

                all_session = all_session->next;
            }
            spinlock_release(&session_spin);
        }
        spinlock_release(&timeout_lock);
    }
}
예제 #2
0
int service_refresh_users(SERVICE *service) {
	int ret = 1;
	/* check for another running getUsers request */
	if (! spinlock_acquire_nowait(&service->users_table_spin)) {
		LOGIF(LD, (skygw_log_write_flush(
			LOGFILE_DEBUG,
			"%lu [service_refresh_users] failed to get get lock for loading new users' table: another thread is loading users",
			pthread_self())));

		return 1;
	}

	
	/* check if refresh rate limit has exceeded */
	if ( (time(NULL) < (service->rate_limit.last + USERS_REFRESH_TIME)) || (service->rate_limit.nloads > USERS_REFRESH_MAX_PER_TIME)) { 
		LOGIF(LE, (skygw_log_write_flush(
			LOGFILE_ERROR,
			"%lu [service_refresh_users] refresh rate limit exceeded loading new users' table",
			pthread_self())));

		spinlock_release(&service->users_table_spin);
 		return 1;
	}

	service->rate_limit.nloads++;	

	/* update time and counter */
	if (service->rate_limit.nloads > USERS_REFRESH_MAX_PER_TIME) {
		service->rate_limit.nloads = 1;
		service->rate_limit.last = time(NULL);
	}

	ret = replace_mysql_users(service);

	/* remove lock */
	spinlock_release(&service->users_table_spin);

	if (ret >= 0)
		return 0;
	else
		return 1;
}