6198: Log more errors in sql code r=def- a=Zwelf

Log whether deleting ranks from _backup tables fails due to locking issues in sqlite.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Zwelf <zwelf@strct.cc>
This commit is contained in:
bors[bot] 2022-12-26 16:50:21 +00:00 committed by GitHub
commit 9631468a32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
#include "scoreworker.h"
#include "base/system.h"
#include <base/log.h>
#include <base/system.h>
#include <engine/server/databases/connection.h>
#include <engine/server/databases/connection_pool.h>
#include <engine/server/sql_string_helpers.h>
@ -415,16 +416,19 @@ bool CScoreWorker::SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameDat
pSqlServer->BindString(3, pData->m_aTimestamp);
pSqlServer->Print();
int NumDeleted;
pSqlServer->ExecuteUpdate(&NumDeleted, pError, ErrorSize);
if(pSqlServer->ExecuteUpdate(&NumDeleted, pError, ErrorSize))
{
return true;
}
if(NumDeleted == 0)
{
dbg_msg("sql", "Warning: Rank got moved out of backup database, will show up as duplicate rank in MySQL");
log_warn("sql", "Rank got moved out of backup database, will show up as duplicate rank in MySQL");
}
return false;
}
if(w == Write::NORMAL_FAILED)
{
int NumInserted;
int NumUpdated;
// move to non-tmp table succeded. delete from backup again
str_format(aBuf, sizeof(aBuf),
"INSERT INTO %s_race SELECT * FROM %s_race_backup WHERE GameId=? AND Name=? AND Timestamp=%s",
@ -437,7 +441,10 @@ bool CScoreWorker::SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameDat
pSqlServer->BindString(2, pData->m_aName);
pSqlServer->BindString(3, pData->m_aTimestamp);
pSqlServer->Print();
pSqlServer->ExecuteUpdate(&NumInserted, pError, ErrorSize);
if(pSqlServer->ExecuteUpdate(&NumUpdated, pError, ErrorSize))
{
return true;
}
// move to non-tmp table succeded. delete from backup again
str_format(aBuf, sizeof(aBuf),
@ -451,7 +458,14 @@ bool CScoreWorker::SaveScore(IDbConnection *pSqlServer, const ISqlData *pGameDat
pSqlServer->BindString(2, pData->m_aName);
pSqlServer->BindString(3, pData->m_aTimestamp);
pSqlServer->Print();
pSqlServer->ExecuteUpdate(&NumInserted, pError, ErrorSize);
if(pSqlServer->ExecuteUpdate(&NumUpdated, pError, ErrorSize))
{
return true;
}
if(NumUpdated == 0)
{
log_warn("sql", "Rank got moved out of backup database, will show up as duplicate rank in MySQL");
}
return false;
}
@ -566,7 +580,7 @@ bool CScoreWorker::SaveTeamScore(IDbConnection *pSqlServer, const ISqlData *pGam
}
if(NumDeleted == 0)
{
dbg_msg("sql", "Warning: Teamrank got moved out of backup database, will show up as duplicate teamrank in MySQL");
log_warn("sql", "Teamrank got moved out of backup database, will show up as duplicate teamrank in MySQL");
}
return false;
}