Skip to content

Commit 4e47ce0

Browse files
committedMay 18, 2017
oracle provider: skip retrying unavailable connections for 30s
(cherry picked from commit b0126d0)
1 parent 38ed0e5 commit 4e47ce0

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed
 

‎src/providers/oracle/qgsoracleconn.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
#include "qgssettings.h"
2626

2727
#include <QSqlError>
28-
#include <QDateTime>
2928

3029
QMap<QString, QgsOracleConn *> QgsOracleConn::sConnections;
3130
int QgsOracleConn::snConnections = 0;
3231
const int QgsOracleConn::sGeomTypeSelectLimit = 100;
32+
QMap<QString, QDateTime> QgsOracleConn::sBrokenConnections;
3333

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

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

77-
if ( !mDatabase.open() )
78+
QString realm( database );
79+
if ( !username.isEmpty() )
80+
realm.prepend( username + "@" );
81+
82+
if ( sBrokenConnections.contains( realm ) )
7883
{
79-
QString username = uri.username();
80-
QString password = uri.password();
84+
QDateTime now( QDateTime::currentDateTime() );
85+
QDateTime since( sBrokenConnections[ realm ] );
86+
QgsDebugMsg( QString( "Broken since %1 [%2s ago]" ).arg( since.toString( Qt::ISODate ) ).arg( since.secsTo( now ) ) );
8187

82-
QString realm( database );
83-
if ( !username.isEmpty() )
84-
realm.prepend( username + "@" );
88+
if ( since.secsTo( now ) < 30 )
89+
{
90+
QgsMessageLog::logMessage( tr( "Connection failed %1s ago - skipping retry" ).arg( since.secsTo( now ) ), tr( "Oracle" ) );
91+
mRef = 0;
92+
return;
93+
}
94+
}
8595

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

88101
while ( !mDatabase.open() )
89102
{
90103
bool ok = QgsCredentials::instance()->get( realm, username, password, mDatabase.lastError().text() );
91104
if ( !ok )
105+
{
106+
QDateTime now( QDateTime::currentDateTime() );
107+
QgsDebugMsg( QString( "get failed: %1 <= %2" ).arg( realm ).arg( now.toString( Qt::ISODate ) ) );
108+
sBrokenConnections.insert( realm, now );
92109
break;
110+
}
111+
112+
sBrokenConnections.remove( realm );
93113

94114
if ( !username.isEmpty() )
95115
{

‎src/providers/oracle/qgsoracleconn.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QSet>
2626
#include <QThread>
2727
#include <QVariant>
28+
#include <QDateTime>
2829

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

192193
static QMap<QString, QgsOracleConn *> sConnections;
193194
static int snConnections;
195+
static QMap<QString, QDateTime> sBrokenConnections;
194196
};
195197

196198
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.