/* http://bugs.mysql.com/bug.php?id=68575 need protection from concurrent binlog rotate Start server with at least these options: --max-binlog-size=10M --sync-binlog=0 --innodb-flush-log-at-trx-commit=0 --innodb-support-xa=0 --innodb-checksums=0 --console --log-bin --binlog-format=statement Compile: gcc bug68575.c -Wall -g -o bug68575 `mysql_config --include` `mysql_config --libs_r` Run: ./bug68575 Monitor the binlog sizes after rotation */ #include #include #include #include #include #include #include #define TESTTIME (90000) #define NUMTHREADS (50) #define DATASIZE (16*1024*1024) char host[]="127.0.0.1"; int port=3306; char username[]="root"; char password[]=""; char database[]="test"; pthread_t pthreads[NUMTHREADS]; unsigned long client_version=0; unsigned long server_version=0; unsigned long num_queries=0; int threaddone=0; char *databucket=NULL; int db_query(MYSQL *dbc,char *sql,int showresults); char* alocmem(size_t num); int write_string(char *buf,const size_t minlen,const size_t maxlen); void *worker_thread(void *arg) { MYSQL *dbc=NULL; my_bool auto_reconnect=1; int cancelstate=0; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,&cancelstate); dbc = mysql_init(NULL); if(NULL == dbc) { printf("mysql_init failed\n"); goto threadexit; } else { if(0!=mysql_options(dbc,MYSQL_OPT_RECONNECT,(char*)&auto_reconnect)) { printf("mysql_options() failed to set MYSQL_OPT_RECONNECT"); } if (!mysql_real_connect(dbc,host,username,password,database,port, NULL, CLIENT_FOUND_ROWS|CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS)) { printf("mysql_real_connect failed: %s (%d) (%s)", mysql_error(dbc),mysql_errno(dbc),mysql_sqlstate(dbc)); mysql_close(dbc); dbc=NULL; } } char shortquery[1024]; memset(shortquery,0,1024); int g=0; char *c; c=NULL; while(0==threaddone && NULL!=dbc) { db_query(dbc,"start transaction",1); for(g=0;g 0) { myerrno=mysql_errno(dbc); printf("query failed '%s' : %d (%s) (%s)\n",sql,myerrno,mysql_error(dbc),mysql_sqlstate(dbc)); return 0; } num_queries++; do { r = mysql_use_result(dbc); if(r) { unsigned int numfields = mysql_num_fields(r); //unsigned int numrows=mysql_num_rows(r); while(0!=(field = mysql_fetch_field(r))) { //print metadata information about each field if(showresults > 1) { printf("%s ",field->name); } } if(showresults > 1) { printf("\n------------------------------------\n"); } while (0!=(w = mysql_fetch_row(r))) { for(i = 0; i < numfields; i++) { //print each field here if(showresults > 1) { printf("%s\t",w[i]); } } if(showresults > 1) { printf("\n"); } } if(showresults > 1) { printf("\n"); } mysql_free_result(r); } else //no rows returned. was it a select? { if(mysql_field_count(dbc) > 0 && showresults > 0) { printf("No results for '%s'. (%d) - %s (%s)\n",sql,mysql_errno(dbc),mysql_error(dbc),mysql_sqlstate(dbc)); return 0; } else //it could have been some insert/update/delete { //this is successful query } } moreresult=mysql_next_result(dbc); if(moreresult > 0 && showresults > 0) { printf("mysql_next_result returned %d, mysql error %s, (%d) (%s)\n",moreresult,mysql_error(dbc),mysql_errno(dbc),mysql_sqlstate(dbc)); return 0; } } while (0==moreresult); return 1; } char* alocmem(size_t num) { char *r=(char*)calloc(num,1); if(NULL == r) { printf("cannot calloc %lu bytes of memory\n",(unsigned long)num); exit(1); } return r; } int write_string(char *buf,const size_t minlen,const size_t maxlen) { if(!buf)return 0; if(maxlen==0 ){buf[0]=0;return 0;} size_t lengt=minlen + (maxlen<=minlen?0:lrand48() % (maxlen-minlen)); int start_lengt = lrand48()%(DATASIZE - lengt - 1); if(lengt<0) lengt=0; if(start_lengt<0) start_lengt=0; memcpy(buf,databucket+start_lengt,lengt); buf[lengt]=0; return lengt; }