Skip to content

Commit

Permalink
fix: mysql reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
M1saka10010 committed Jan 24, 2024
1 parent 2284159 commit df0af25
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 23 deletions.
42 changes: 30 additions & 12 deletions judge/src/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,19 @@ FILE *read_cmd_output(const char *fmt, ...)

int _get_jobs_mysql(int *jobs)
{
if (mysql_real_query(conn, query, strlen(query)))
// if (mysql_real_query(conn, query, strlen(query)))
// {
// if (DEBUG)
// write_log("%s", mysql_error(conn));
// sleep(20);
// return 0;
// }
while (mysql_real_query(conn, query, strlen(query)))
{
if (DEBUG)
write_log("%s", mysql_error(conn));
sleep(20);
return 0;
init_mysql();
sleep(10);
}
res = mysql_store_result(conn);
int i = 0;
Expand Down Expand Up @@ -309,18 +316,29 @@ bool check_out(int solution_id, int result)
"UPDATE solution SET result=%d,time=0,memory=0,judgetime=NOW() "
"WHERE id=%d and result<2 LIMIT 1",
result, solution_id);
if (mysql_real_query(conn, sql, strlen(sql)))
// if (mysql_real_query(conn, sql, strlen(sql)))
// {
// syslog(LOG_ERR | LOG_DAEMON, "%s", mysql_error(conn));
// return false;
// }
// else
// {
// if (conn != NULL && mysql_affected_rows(conn) > 0ul)
// return true;
// else
// return false;
// }
while (mysql_real_query(conn, sql, strlen(sql)))
{
syslog(LOG_ERR | LOG_DAEMON, "%s", mysql_error(conn));
return false;
if (DEBUG)
write_log("%s", mysql_error(conn));
sleep(10);
init_mysql();
}
if (conn != NULL && mysql_affected_rows(conn) > 0ul)
return true;
else
{
if (conn != NULL && mysql_affected_rows(conn) > 0ul)
return true;
else
return false;
}
return false;
}

int work()
Expand Down
39 changes: 28 additions & 11 deletions polygon/src/polygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,19 @@ FILE *read_cmd_output(const char *fmt, ...)

int _get_jobs_mysql(int *jobs)
{
if (mysql_real_query(conn, query, strlen(query)))
// if (mysql_real_query(conn, query, strlen(query)))
// {
// if (DEBUG)
// write_log("%s", mysql_error(conn));
// sleep(20);
// return 0;
// }
while (mysql_real_query(conn, query, strlen(query)))
{
if (DEBUG)
write_log("%s", mysql_error(conn));
sleep(20);
return 0;
sleep(10);
init_mysql();
}
res = mysql_store_result(conn);
int i = 0;
Expand Down Expand Up @@ -352,18 +359,28 @@ bool check_out(int problem_id, int result)
"UPDATE polygon_status SET result=%d,time=0,memory=0 "
"WHERE id=%d and result<2 LIMIT 1",
result, problem_id);
if (mysql_real_query(conn, sql, strlen(sql)))
// if (mysql_real_query(conn, sql, strlen(sql)))
// {
// syslog(LOG_ERR | LOG_DAEMON, "%s", mysql_error(conn));
// return false;
// }
// else
// {
// if (conn != NULL && mysql_affected_rows(conn) > 0ul)
// return true;
// else
// return false;
// }
while (mysql_real_query(conn, sql, strlen(sql)))
{
syslog(LOG_ERR | LOG_DAEMON, "%s", mysql_error(conn));
return false;
sleep(10);
init_mysql();
}
if (conn != NULL && mysql_affected_rows(conn) > 0ul)
return true;
else
{
if (conn != NULL && mysql_affected_rows(conn) > 0ul)
return true;
else
return false;
}
return false;
}

int work()
Expand Down

0 comments on commit df0af25

Please sign in to comment.