mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-28 08:05:56 -05:00
Handle SQLITE_SCHEMA error in db_exec()
This happens under database load with many concurrent threads doing updates; queries failing with SQLITE_SCHEMA at step time need to retried from scratch until they succeeded or hit a best-effort limit of 5 retries.
This commit is contained in:
parent
4594cc3d63
commit
4f3635e354
13
src/db.c
13
src/db.c
@ -535,10 +535,13 @@ static int
|
|||||||
db_exec(const char *query, char **errmsg)
|
db_exec(const char *query, char **errmsg)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
int try;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
*errmsg = NULL;
|
*errmsg = NULL;
|
||||||
|
|
||||||
|
for (try = 0; try < 5; try++)
|
||||||
|
{
|
||||||
ret = db_blocking_prepare_v2(query, -1, &stmt, NULL);
|
ret = db_blocking_prepare_v2(query, -1, &stmt, NULL);
|
||||||
if (ret != SQLITE_OK)
|
if (ret != SQLITE_OK)
|
||||||
{
|
{
|
||||||
@ -549,16 +552,18 @@ db_exec(const char *query, char **errmsg)
|
|||||||
while ((ret = db_blocking_step(stmt)) == SQLITE_ROW)
|
while ((ret = db_blocking_step(stmt)) == SQLITE_ROW)
|
||||||
; /* EMPTY */
|
; /* EMPTY */
|
||||||
|
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
|
||||||
|
if (ret != SQLITE_SCHEMA)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret != SQLITE_DONE)
|
if (ret != SQLITE_DONE)
|
||||||
{
|
{
|
||||||
*errmsg = sqlite3_mprintf("step failed: %s", sqlite3_errmsg(hdl));
|
*errmsg = sqlite3_mprintf("step failed: %s", sqlite3_errmsg(hdl));
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_finalize(stmt);
|
|
||||||
|
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user