Skip to content

Commit

Permalink
Connection pool fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed May 26, 2015
1 parent 72c9830 commit a6bf6e9
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 a6bf6e9

Please sign in to comment.