// non blocking API void MySQL_Connection::connect_start() { PROXY_TRACE(); mysql=mysql_init(NULL); assert(mysql); mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); unsigned int timeout= 1; mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&timeout); const CHARSET_INFO * c = proxysql_find_charset_nr(mysql_thread___default_charset); if (!c) { proxy_error("Not existing charset number %u\n", mysql_thread___default_charset); assert(0); } mysql_options(mysql, MYSQL_SET_CHARSET_NAME, c->csname); unsigned long client_flags = 0; if (mysql_thread___client_found_rows) client_flags += CLIENT_FOUND_ROWS; if (parent->compression) client_flags += CLIENT_COMPRESS; if (parent->port) { async_exit_status=mysql_real_connect_start(&ret_mysql, mysql, parent->address, userinfo->username, userinfo->password, userinfo->schemaname, parent->port, NULL, client_flags); } else { async_exit_status=mysql_real_connect_start(&ret_mysql, mysql, "localhost", userinfo->username, userinfo->password, userinfo->schemaname, parent->port, parent->address, client_flags); } fd=mysql_get_socket(mysql); }
void MySQL_Connection::set_names_start() { PROXY_TRACE(); const CHARSET_INFO * c = proxysql_find_charset_nr(options.charset); if (!c) { proxy_error("Not existing charset number %u\n", options.charset); assert(0); } async_exit_status = mysql_set_character_set_start(&interr,mysql, c->csname); }
void start_background_threads(pthread_attr_t *attra, void **stackspts) { pthread_attr_t attr; int r; r=pthread_attr_init(&attr); assert(r==0); void *sp; #ifdef DEBUG r=posix_memalign(&sp, sysconf(_SC_PAGESIZE), glovars.stack_size); assert(r==0); stackspts[glovars.mysql_threads+2+0]=sp; r=pthread_attr_setstack(&attr, sp, glovars.stack_size); assert(r==0); r=pthread_create(&thread_dbg_logger, &attr, debug_logger , NULL); assert(r==0); #endif if (glovars.mysql_query_cache_enabled==TRUE) { PROXY_TRACE(); fdb_hashes_new(&QC,glovars.mysql_query_cache_partitions, glovars.mysql_query_cache_default_timeout, glovars.mysql_query_cache_size); // pthread_t qct; r=posix_memalign(&sp, sysconf(_SC_PAGESIZE), glovars.stack_size); assert(r==0); stackspts[glovars.mysql_threads+2+1]=sp; r=pthread_attr_setstack(&attr, sp, glovars.stack_size); assert(r==0); r=pthread_create(&thread_qct, &attr, purgeHash_thread, &QC); assert(r==0); } // Added by chan //printf("=> create new qr_hash\n"); qr_hashes_new(&QR_HASH_T); //printf("=> end\n"); r=posix_memalign(&sp, sysconf(_SC_PAGESIZE), glovars.stack_size); assert(r==0); stackspts[glovars.mysql_threads+2+2]=sp; r=pthread_attr_setstack(&attr, sp, glovars.stack_size); assert(r==0); r=pthread_create(&thread_qr, &attr, qr_report_thread, &QR_HASH_T); assert(r==0); // Added by chan end. // pthread_t cppt; r=posix_memalign(&sp, sysconf(_SC_PAGESIZE), glovars.stack_size); assert(r==0); stackspts[glovars.mysql_threads+2+3]=sp; r=pthread_attr_setstack(&attr, sp, glovars.stack_size); assert(r==0); r=pthread_create(&thread_cppt, &attr, mysql_connpool_purge_thread , NULL); assert(r==0); }
void init_proxyipc() { int i; PROXY_TRACE(); proxyipc.fdIn=g_malloc0_n(glovars.mysql_threads,sizeof(int)); proxyipc.fdOut=g_malloc0_n(glovars.mysql_threads,sizeof(int)); proxyipc.queue=g_malloc0_n(glovars.mysql_threads+1,sizeof(GAsyncQueue *)); // create pipes for (i=0; i<glovars.mysql_threads; i++) { int fds[2]; int rc; rc=pipe(fds); assert(rc==0); // if (rc==-1) { // perror("pipe"); // assert(rc==0); // } proxyipc.fdIn[i]=fds[0]; proxyipc.fdOut[i]=fds[1]; } // initialize the async queue for (i=0; i<glovars.mysql_threads+1; i++) { proxyipc.queue[i]=g_async_queue_new(); } }
void MySQL_Connection::store_result_start() { PROXY_TRACE(); async_exit_status = mysql_store_result_start(&mysql_result, mysql); }
void MySQL_Connection::real_query_start() { PROXY_TRACE(); async_exit_status = mysql_real_query_start(&interr , mysql, query.ptr, query.length); }
void MySQL_Connection::set_autocommit_start() { PROXY_TRACE(); async_exit_status = mysql_autocommit_start(&ret_bool, mysql, options.autocommit); }
void MySQL_Connection::initdb_start() { PROXY_TRACE(); MySQL_Connection_userinfo *client_ui=myds->sess->client_myds->myconn->userinfo; async_exit_status = mysql_select_db_start(&interr,mysql,client_ui->schemaname); }
void MySQL_Connection::ping_start() { PROXY_TRACE(); //fprintf(stderr,"ping_start FD %d\n", fd); async_exit_status = mysql_ping_start(&interr,mysql); }
void MySQL_Connection::change_user_start() { PROXY_TRACE(); //fprintf(stderr,"change_user_start FD %d\n", fd); MySQL_Connection_userinfo *_ui=myds->sess->client_myds->myconn->userinfo; async_exit_status = mysql_change_user_start(&ret_bool,mysql,_ui->username, _ui->password, _ui->schemaname); }