From 8985c5ad1944400ae011d68fa209fe5bed0bf729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B5=A9=E6=96=8C?= Date: Mon, 24 Jul 2017 12:49:19 +0800 Subject: [PATCH] independent core of mysql --- trunk/core/judged/judged.cc | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/trunk/core/judged/judged.cc b/trunk/core/judged/judged.cc index 319edb8b023..b054f9d91d2 100644 --- a/trunk/core/judged/judged.cc +++ b/trunk/core/judged/judged.cc @@ -81,11 +81,13 @@ static char oj_redisqname[BUFFER_SIZE]; static bool STOP = false; static int DEBUG = 0; static int ONCE = 0; +#ifdef _mysql_h static MYSQL *conn; static MYSQL_RES *res; static MYSQL_ROW row; //static FILE *fp_log; static char query[BUFFER_SIZE]; +#endif void call_for_exit(int s) { STOP = true; @@ -190,9 +192,11 @@ void init_mysql_conf() { } +#ifdef _mysql_h sprintf(query, "SELECT solution_id FROM solution WHERE language in (%s) and result<2 and MOD(solution_id,%d)=%d ORDER BY result ASC,solution_id ASC limit %d", oj_lang_set, oj_tot, oj_mod, max_running * 2); +#endif sleep_tmp = sleep_time; // fclose(fp); } @@ -233,6 +237,7 @@ void run_client(int runid, int clientid) { //exit(0); } +#ifdef _mysql_h int executesql(const char * sql) { if (mysql_real_query(conn, sql, strlen(sql))) { @@ -244,7 +249,9 @@ int executesql(const char * sql) { } else return 0; } +#endif +#ifdef _mysql_h int init_mysql() { if (conn == NULL) { conn = mysql_init(NULL); // init the database connection @@ -265,6 +272,7 @@ int init_mysql() { return executesql("set names utf8"); } } +#endif FILE * read_cmd_output(const char * fmt, ...) { char cmd[BUFFER_SIZE]; @@ -326,6 +334,7 @@ int _get_jobs_http(int * jobs) { jobs[i++] = 0; return ret; } +#ifdef _mysql_h int _get_jobs_mysql(int * jobs) { if (mysql_real_query(conn, query, strlen(query))) { if (DEBUG) @@ -350,7 +359,7 @@ int _get_jobs_mysql(int * jobs) { jobs[i++] = 0; return ret; } - +#endif int _get_jobs_redis(int * jobs){ int ret=0; const char * cmd="redis-cli -h %s -p %d -a %s --raw rpop %s"; @@ -379,11 +388,16 @@ int get_jobs(int * jobs) { if(oj_redis){ return _get_jobs_redis(jobs); }else{ +#ifdef _mysql_h return _get_jobs_mysql(jobs); +#else + return 0; +#endif } } } +#ifdef _mysql_h bool _check_out_mysql(int solution_id, int result) { char sql[BUFFER_SIZE]; sprintf(sql, @@ -400,6 +414,7 @@ bool _check_out_mysql(int solution_id, int result) { } } +#endif bool _check_out_http(int solution_id, int result) { login(); @@ -416,8 +431,13 @@ bool check_out(int solution_id, int result) { if(oj_redis) return true; if (http_judge) { return _check_out_http(solution_id, result); - } else + } else{ +#ifdef _mysql_h return _check_out_mysql(solution_id, result); +#else + return 0; +#endif + } } int work() { @@ -491,11 +511,13 @@ int work() { printf("tmp_pid = %d\n", tmp_pid); } if (!http_judge) { +#ifdef _mysql_h if(res!=NULL) { mysql_free_result(res); // free the memory res=NULL; } executesql("commit"); +#endif } if (DEBUG && retcnt) write_log("<<%ddone!>>", retcnt); @@ -594,13 +616,19 @@ int main(int argc, char** argv) { // struct timespec final_sleep; // final_sleep.tv_sec=0; // final_sleep.tv_nsec=500000000; +#ifdef _mysql_h init_mysql_conf(); // set the database info +#endif signal(SIGQUIT, call_for_exit); signal(SIGKILL, call_for_exit); signal(SIGTERM, call_for_exit); int j = 1; while (1) { // start to run - while (j && (http_judge || !init_mysql())) { + while (j && (http_judge +#ifdef _mysql_h + || !init_mysql() +#endif + )) { j = work();