mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Added retry blocks for failed (busy) sql queries & commits.
This commit is contained in:
@@ -18,10 +18,12 @@
|
|||||||
|
|
||||||
#include "database/TomahawkSqlQuery.h"
|
#include "database/TomahawkSqlQuery.h"
|
||||||
|
|
||||||
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <QThread>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#define QUERY_THRESHOLD 60
|
#define QUERY_THRESHOLD 60
|
||||||
@@ -35,6 +37,7 @@ TomahawkSqlQuery::TomahawkSqlQuery()
|
|||||||
|
|
||||||
TomahawkSqlQuery::TomahawkSqlQuery( const QSqlDatabase& db )
|
TomahawkSqlQuery::TomahawkSqlQuery( const QSqlDatabase& db )
|
||||||
: QSqlQuery( db )
|
: QSqlQuery( db )
|
||||||
|
, m_db( db )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,12 +56,20 @@ TomahawkSqlQuery::exec()
|
|||||||
QTime t;
|
QTime t;
|
||||||
t.start();
|
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 )
|
if ( !ret )
|
||||||
showError();
|
showError();
|
||||||
|
|
||||||
int e = t.elapsed();
|
int e = t.elapsed();
|
||||||
bool log = ( e >= QUERY_THRESHOLD );
|
bool log = ( e >= QUERY_THRESHOLD );
|
||||||
|
|
||||||
#ifdef TOMAHAWK_QUERY_ANALYZE
|
#ifdef TOMAHAWK_QUERY_ANALYZE
|
||||||
log = true;
|
log = true;
|
||||||
#endif
|
#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
|
void
|
||||||
TomahawkSqlQuery::showError()
|
TomahawkSqlQuery::showError()
|
||||||
{
|
{
|
||||||
|
@@ -35,8 +35,12 @@ public:
|
|||||||
bool exec( const QString& query );
|
bool exec( const QString& query );
|
||||||
bool exec();
|
bool exec();
|
||||||
|
|
||||||
|
bool commitTransaction();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showError();
|
void showError();
|
||||||
|
|
||||||
|
QSqlDatabase m_db;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOMAHAWKSQLQUERY_H
|
#endif // TOMAHAWKSQLQUERY_H
|
||||||
|
Reference in New Issue
Block a user