Skip to content

Commit

Permalink
Merge pull request #2272 from greenbone/add-deadlock-retry
Browse files Browse the repository at this point in the history
Change: Retry on deadlocks in sql_x
  • Loading branch information
a-h-abdelsalam authored Aug 21, 2024
2 parents 57728f5 + 9ac8946 commit 6d01a9f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ sql_insert (const char *string)
*
* @return 0 success, 1 gave up (even when retry given),
* 2 reserved (lock unavailable), 3 unique constraint violation,
* -1 error.
* 4 deadlock, -1 error.
*/
int
sqlv (int retry, char* sql, va_list args)
Expand Down Expand Up @@ -274,13 +274,14 @@ sql (char* sql, ...)
continue;
else if (ret == 4)
{
if (deadlock_amount++ > DEADLOCK_THRESHOLD)
{
g_warning("%s: %d deadlocks detected, waiting and retrying %s", __func__, deadlock_amount, sql);
}
gvm_usleep (DEADLOCK_SLEEP);
continue;
}
if (deadlock_amount++ > DEADLOCK_THRESHOLD)
{
g_warning("%s: %d deadlocks detected, waiting and retrying %s",
__func__, deadlock_amount, sql);
}
gvm_usleep (DEADLOCK_SLEEP);
continue;
}
else if (ret)
abort();
break;
Expand Down Expand Up @@ -355,6 +356,7 @@ int
sql_x (char* sql, va_list args, sql_stmt_t** stmt_return)
{
int ret;
unsigned int deadlock_amount = 0;

assert (stmt_return);

Expand Down Expand Up @@ -392,6 +394,16 @@ sql_x (char* sql, va_list args, sql_stmt_t** stmt_return)
sql_finalize (*stmt_return);
continue;
}
if (ret == -5)
{
if (deadlock_amount++ > DEADLOCK_THRESHOLD)
{
g_warning("%s: %d deadlocks detected, waiting and retrying %s",
__func__, deadlock_amount, sql);
}
gvm_usleep (DEADLOCK_SLEEP);
continue;
}
break;
}
assert (ret == 1);
Expand Down

0 comments on commit 6d01a9f

Please sign in to comment.