Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2069 from manisandro/ogrpool
Add connection pool for OGR provider
- Loading branch information
Showing
9 changed files
with
191 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*************************************************************************** | ||
qgsogrconnpool.cpp | ||
--------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Sandro Mani | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsogrconnpool.h" | ||
|
||
|
||
QgsOgrConnPool* QgsOgrConnPool::instance() | ||
{ | ||
static QgsOgrConnPool sInstance; | ||
return &sInstance; | ||
} | ||
|
||
QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup>() | ||
{ | ||
QgsDebugCall; | ||
} | ||
|
||
QgsOgrConnPool::~QgsOgrConnPool() | ||
{ | ||
QgsDebugCall; | ||
} | ||
|
||
void QgsOgrConnPool::invalidateHandles( const QString& connInfo ) | ||
{ | ||
mMutex.lock(); | ||
if ( mGroups.contains( connInfo ) ) | ||
mGroups[connInfo]->invalidateConnections(); | ||
mMutex.unlock(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*************************************************************************** | ||
qgsogrconnpool.h | ||
--------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Sandro Mani | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSOGRCONNPOOL_H | ||
#define QGSOGRCONNPOOL_H | ||
|
||
#include "qgsconnectionpool.h" | ||
#include <ogr_api.h> | ||
|
||
|
||
struct QgsOgrConn | ||
{ | ||
QString path; | ||
OGRDataSourceH ds; | ||
bool valid; | ||
}; | ||
|
||
inline QString qgsConnectionPool_ConnectionToName( QgsOgrConn* c ) | ||
{ | ||
return c->path; | ||
} | ||
|
||
inline void qgsConnectionPool_ConnectionCreate( QString connInfo, QgsOgrConn*& c ) | ||
{ | ||
c = new QgsOgrConn; | ||
c->ds = OGROpen( connInfo.toUtf8().constData(), false, NULL ); | ||
c->path = connInfo; | ||
c->valid = true; | ||
} | ||
|
||
inline void qgsConnectionPool_ConnectionDestroy( QgsOgrConn* c ) | ||
{ | ||
OGR_DS_Destroy( c->ds ); | ||
delete c; | ||
} | ||
|
||
inline void qgsConnectionPool_InvalidateConnection( QgsOgrConn* c ) | ||
{ | ||
c->valid = false; | ||
} | ||
|
||
inline bool qgsConnectionPool_ConnectionIsValid( QgsOgrConn* c ) | ||
{ | ||
return c->valid; | ||
} | ||
|
||
class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgrConn*> | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsOgrConnPoolGroup( QString name ) : QgsConnectionPoolGroup<QgsOgrConn*>( name ) { initTimer( this ); } | ||
|
||
protected slots: | ||
void handleConnectionExpired() { onConnectionExpired(); } | ||
void startExpirationTimer() { expirationTimer->start(); } | ||
void stopExpirationTimer() { expirationTimer->stop(); } | ||
|
||
protected: | ||
Q_DISABLE_COPY( QgsOgrConnPoolGroup ) | ||
|
||
}; | ||
|
||
/** Ogr connection pool - singleton */ | ||
class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup> | ||
{ | ||
public: | ||
static QgsOgrConnPool* instance(); | ||
|
||
void invalidateHandles( const QString& connInfo ); | ||
|
||
protected: | ||
Q_DISABLE_COPY( QgsOgrConnPool ) | ||
|
||
private: | ||
QgsOgrConnPool(); | ||
~QgsOgrConnPool(); | ||
}; | ||
|
||
|
||
#endif // QGSOGRCONNPOOL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manisandro I've been trying to track down a regression on OSX which is causing attribute changes made via QgsOgrProvider::changeAttributeValues to get lost. It's only visible on OSX, and I've bisected it back to this commit. You can see the failure in the results of the zonalstatistics test, eg http://dash.orfeo-toolbox.org/testDetails.php?test=30531850&build=184378 (that's the first failure following the ogr pool commit).
I'll keep digging - but do you have any ideas what could be causing this?
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyalldawson Oh, damn. Just to make sure, is this master? In particular, is 100de72 included?
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manisandro it's still present in master, even with that fix
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this cause to have the edited attributes "lost" on save (they load if you reload the layer or the project)? If yes I have seen all day on QGIS 2.10 on Windows from OSGeo4W.
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyalldawson Could you try adding
at the end of
QgsOgrProvider::changeAttributeValues
, before thereturn true
? If that solves the issue, it appears that the internal state of the ogr connection handle also depends on the actual attribute values...@gioman Yes that sounds like the same issue...
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manisandro yep, adding that line fixes it
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyalldawson Ok... Can you commit that change?
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manisandro will do- what about the other methods, like QgsOgrProvider::changeGeometryValues? Will they also need the fix?
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyalldawson At this point I'd say yes, anything which changes the dataset. Situation should be:
add/deleteFeatures
are taken care of viarecalculateFeatureCount
add/deleteAttributes
are taken care of vialoadFields
changeAttributeValues
andchangeGeometryValues
need the fixI think that should cover it?
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manisandro this ok? nyalldawson@ca16703
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyalldawson Yes, thanks a lot.
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manisandro Do you think http://hub.qgis.org/issues/13082 could be related to this work?
72c9830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyalldawson Fear so, yes. Pull request with suggested fix: #2197.