Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2078 from manisandro/connpoolfixes
Connection pool fixes
  • Loading branch information
mhugent committed May 26, 2015
2 parents e2edc54 + a6bf6e9 commit 930ad68
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
17 changes: 15 additions & 2 deletions src/core/qgsconnectionpool.h
Expand Up @@ -123,9 +123,8 @@ class QgsConnectionPoolGroup

void release( T conn )
{
acquiredConns.removeAll( conn );

connMutex.lock();
acquiredConns.removeAll( conn );
Item i;
i.c = conn;
i.lastUsedTime = QTime::currentTime();
Expand Down Expand Up @@ -255,6 +254,20 @@ class QgsConnectionPool
group->release( conn );
}

//! Invalidates all connections to the specified resource.
//! The internal state of certain handles (for instance OGR) are altered
//! when a dataset is modified. Consquently, all open handles need to be
//! invalidated when such datasets are changed to ensure the handles are
//! refreshed. See the OGR provider for an example where this is needed.
void invalidateConnections( const QString& connInfo )
{
mMutex.lock();
if ( mGroups.contains( connInfo ) )
mGroups[connInfo]->invalidateConnections();
mMutex.unlock();
}


protected:
T_Groups mGroups;
QMutex mMutex;
Expand Down
8 changes: 0 additions & 8 deletions src/providers/ogr/qgsogrconnpool.cpp
Expand Up @@ -31,11 +31,3 @@ QgsOgrConnPool::~QgsOgrConnPool()
{
QgsDebugCall;
}

void QgsOgrConnPool::invalidateHandles( const QString& connInfo )
{
mMutex.lock();
if ( mGroups.contains( connInfo ) )
mGroups[connInfo]->invalidateConnections();
mMutex.unlock();
}
2 changes: 0 additions & 2 deletions src/providers/ogr/qgsogrconnpool.h
Expand Up @@ -79,8 +79,6 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup
public:
static QgsOgrConnPool* instance();

void invalidateHandles( const QString& connInfo );

protected:
Q_DISABLE_COPY( QgsOgrConnPool )

Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -741,7 +741,7 @@ OGRwkbGeometryType QgsOgrProvider::getOgrGeomType( OGRLayerH ogrLayer )

void QgsOgrProvider::loadFields()
{
QgsOgrConnPool::instance()->invalidateHandles( filePath() );
QgsOgrConnPool::instance()->invalidateConnections( filePath() );
//the attribute fields need to be read again when the encoding changes
mAttributeFields.clear();

Expand Down Expand Up @@ -2524,7 +2524,7 @@ void QgsOgrProvider::recalculateFeatureCount()
OGR_L_SetSpatialFilter( ogrLayer, filter );
}

QgsOgrConnPool::instance()->invalidateHandles( filePath() );
QgsOgrConnPool::instance()->invalidateConnections( filePath() );
}

OGRwkbGeometryType QgsOgrProvider::ogrWkbSingleFlatten( OGRwkbGeometryType type )
Expand Down

0 comments on commit 930ad68

Please sign in to comment.