Skip to content
Permalink
Browse files
oracle provider: skip retrying unavailable connections for 30s
(cherry picked from commit b0126d0)
  • Loading branch information
jef-n committed May 18, 2017
1 parent 38ed0e5 commit 4e47ce032ea10749fd74132b02e249513dfd1edd
Showing with 30 additions and 8 deletions.
  1. +28 −8 src/providers/oracle/qgsoracleconn.cpp
  2. +2 −0 src/providers/oracle/qgsoracleconn.h
@@ -25,11 +25,11 @@
#include "qgssettings.h"

#include <QSqlError>
#include <QDateTime>

QMap<QString, QgsOracleConn *> QgsOracleConn::sConnections;
int QgsOracleConn::snConnections = 0;
const int QgsOracleConn::sGeomTypeSelectLimit = 100;
QMap<QString, QDateTime> QgsOracleConn::sBrokenConnections;

QgsOracleConn *QgsOracleConn::connectDb( const QgsDataSourceUri &uri )
{
@@ -72,24 +72,44 @@ QgsOracleConn::QgsOracleConn( QgsDataSourceUri uri )
mDatabase.setUserName( uri.username() );
mDatabase.setPassword( uri.password() );

QgsDebugMsg( QString( "Connecting with options: " ) + options );
QString username = uri.username();
QString password = uri.password();

if ( !mDatabase.open() )
QString realm( database );
if ( !username.isEmpty() )
realm.prepend( username + "@" );

if ( sBrokenConnections.contains( realm ) )
{
QString username = uri.username();
QString password = uri.password();
QDateTime now( QDateTime::currentDateTime() );
QDateTime since( sBrokenConnections[ realm ] );
QgsDebugMsg( QString( "Broken since %1 [%2s ago]" ).arg( since.toString( Qt::ISODate ) ).arg( since.secsTo( now ) ) );

QString realm( database );
if ( !username.isEmpty() )
realm.prepend( username + "@" );
if ( since.secsTo( now ) < 30 )
{
QgsMessageLog::logMessage( tr( "Connection failed %1s ago - skipping retry" ).arg( since.secsTo( now ) ), tr( "Oracle" ) );
mRef = 0;
return;
}
}

QgsDebugMsg( QString( "Connecting with options: " ) + options );
if ( !mDatabase.open() )
{
QgsCredentials::instance()->lock();

while ( !mDatabase.open() )
{
bool ok = QgsCredentials::instance()->get( realm, username, password, mDatabase.lastError().text() );
if ( !ok )
{
QDateTime now( QDateTime::currentDateTime() );
QgsDebugMsg( QString( "get failed: %1 <= %2" ).arg( realm ).arg( now.toString( Qt::ISODate ) ) );
sBrokenConnections.insert( realm, now );
break;
}

sBrokenConnections.remove( realm );

if ( !username.isEmpty() )
{
@@ -25,6 +25,7 @@
#include <QSet>
#include <QThread>
#include <QVariant>
#include <QDateTime>

#include "qgis.h"
#include "qgsdatasourceuri.h"
@@ -191,6 +192,7 @@ class QgsOracleConn : public QObject

static QMap<QString, QgsOracleConn *> sConnections;
static int snConnections;
static QMap<QString, QDateTime> sBrokenConnections;
};

#endif

0 comments on commit 4e47ce0

Please sign in to comment.