mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
* Added retry blocks for failed (busy) sql queries & commits.
This commit is contained in:
parent
872d8a3da5
commit
d8c3006cb4
@ -18,10 +18,12 @@
|
||||
|
||||
#include "database/TomahawkSqlQuery.h"
|
||||
|
||||
#include "utils/TomahawkUtils.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QSqlError>
|
||||
#include <QTime>
|
||||
#include <QThread>
|
||||
#include <QVariant>
|
||||
|
||||
#define QUERY_THRESHOLD 60
|
||||
@ -35,6 +37,7 @@ TomahawkSqlQuery::TomahawkSqlQuery()
|
||||
|
||||
TomahawkSqlQuery::TomahawkSqlQuery( const QSqlDatabase& db )
|
||||
: QSqlQuery( db )
|
||||
, m_db( db )
|
||||
{
|
||||
}
|
||||
|
||||
@ -53,12 +56,20 @@ TomahawkSqlQuery::exec()
|
||||
QTime t;
|
||||
t.start();
|
||||
|
||||
bool ret = QSqlQuery::exec();
|
||||
unsigned int retries = 0;
|
||||
while ( !QSqlQuery::exec() && ++retries < 10 )
|
||||
{
|
||||
tDebug() << "INFO: Retrying failed query:" << this->lastQuery() << this->lastError().text();
|
||||
TomahawkUtils::msleep( 25 );
|
||||
}
|
||||
|
||||
bool ret = ( retries < 10 );
|
||||
if ( !ret )
|
||||
showError();
|
||||
|
||||
int e = t.elapsed();
|
||||
bool log = ( e >= QUERY_THRESHOLD );
|
||||
|
||||
#ifdef TOMAHAWK_QUERY_ANALYZE
|
||||
log = true;
|
||||
#endif
|
||||
@ -70,6 +81,20 @@ TomahawkSqlQuery::exec()
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TomahawkSqlQuery::commitTransaction()
|
||||
{
|
||||
unsigned int retries = 0;
|
||||
while ( !m_db.commit() && ++retries < 10 )
|
||||
{
|
||||
tDebug() << "INFO: Retrying failed commit:" << this->lastQuery() << this->lastError().text();
|
||||
TomahawkUtils::msleep( 25 );
|
||||
}
|
||||
|
||||
return ( retries < 10 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSqlQuery::showError()
|
||||
{
|
||||
|
@ -34,9 +34,13 @@ public:
|
||||
|
||||
bool exec( const QString& query );
|
||||
bool exec();
|
||||
|
||||
bool commitTransaction();
|
||||
|
||||
private:
|
||||
void showError();
|
||||
|
||||
QSqlDatabase m_db;
|
||||
};
|
||||
|
||||
#endif // TOMAHAWKSQLQUERY_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user