Changes between Version 5 and Version 6 of rfc16_ogr_reentrancy


Ignore:
Timestamp:
Sep 19, 2007, 6:51:48 PM (17 years ago)
Author:
warmerdam
Comment:

Substantial update, added GetLayerClone().

Legend:

Unmodified
Added
Removed
Modified
  • rfc16_ogr_reentrancy

    v5 v6  
    1 
    21= RFC 16: OGR Thread Safety =
    32
     
    2524
    2625{{{
    27 #define OLCReentrant "Reentrant"
    28 #define ODsReentrant "Reentrant"
    29 #define ODsThreadSafe "Threadsafe"
     26#define OLCReentrant    "Reentrant"
     27#define ODsCLayerClones "LayerClones"
     28#define ODsCReentrant   "Reentrant"
     29#define ODsCThreadSafe  "Threadsafe"
    3030}}}
    3131
    32 Note that layers cannot be threadsafe as long as layer feature reading status is implicit in the layer object.  The default return value for all test values is FALSE, as is normal for the !TestCapability() method, but specific drivers can return TRUE after determining that the driver datasources or layers are in fact reentrant and/or threadsafe.
     32Meaning:
     33 * OLCReentrant: The layer class is reentrant.  Multiple threads can operate on distinct instances of this class - including different layers on a single datasource.
     34 * ODsCReentrant: The datasource class is reentrant.  Multiple threads can operate on distinct instances of this class.
     35 * ODsCThreadSafe: The datasource class is thread-safe.  Multiple threads can operate on a single instance of this class.
     36 * ODsCLayerClones: The OGRDataSource::!GetLayerClone() method is supported, and returns a layer instance with distinct state from the default layer returned by !GetLayer().
     37
     38Note that a single layer instance cannot be threadsafe as long as layer feature reading status is implicit in the layer object.  The default return value for all test values is FALSE, as is normal for the !TestCapability() method, but specific drivers can return TRUE after determining that the driver datasources or layers are in fact reentrant and/or threadsafe.
    3339
    3440== OGRSFDriverRegistrar ==
     
    4450This class has been modified to include an m_hMutex class data member which is a mutex used to ensure thread safe access to internal datastructures such as the layer list.  Classes derived from OGRDataSource that wish to implement threadsafe operation should use this mutex when exclusivity is required.
    4551
     52A new method is added to this class:
     53
     54{{{
     55  OGRLayer *GetLayerClone( int i );
     56}}}
     57
     58The default implementation of this method returns NULL.  If the ODsCLayerClones capability is true for the datasource, this method must return duplicates of the requested layer that have distinct feature reading state.  That is they can have their own spatial and attribute filter settings, and the internal feature iterator (for !GetNextFeature() and !ResetReading()) is distinct from other OGRLayer instances referencing the same underlying datasource layer.
     59
     60The intention of this method in the multi-threaded context is that different threads can have clones of a layer with distinct read state.  A sort of poor-mans threadsafety, even though in fact it is just reentrancy.
     61
     62Layers return by !GetLayerClone() should be released with the OGRDataSource::!ReleaseResultSet() method, much like layers returned by ExecuteSQL().
     63
    4664== ExecuteSQL() ==
    4765
    48 The default OGR implementation of OGRDataSource::ExecuteSQL() internally uses and modifies the layer state (feature iterators and filters) and as such is not appropriate to use on a datasource that is attempting to be threadsafe even though it is understood that individual layers are not threadsafe.  The proposed solution is to offer an OGRTS "dialect" (OGR Thread Safe) which actually opens a duplicate (readonly) datasource so that there will be distinct instances of the layers for the use of the resulset from ExecuteSQL().  This is very expensive in terms of file access and file handles consumed so it is not the default. The default dialect (NULL, "" or "OGR") will continue to use the layers from the current datasource despite the various side effects implied.
     66The default OGR implementation of OGRDataSource::ExecuteSQL() internally uses and modifies the layer state (feature iterators and filters) and as such is not appropriate to use on a datasource that is attempting to be threadsafe even though it is understood that individual layers are not threadsafe. 
     67
     68The proposed solution is that this code will be modified to use !GetLayerClone() if the datasource supports !GetLayerClone().
     69
     70== Testing ==
     71
     72A multi-threaded C++ test harnass will be implemented for read-only stress testing of datasources claiming to support reentrancy and threadsafety.
     73
     74No testing of reentrancy and threadsafety will be incorporated into the regression test suite (gdalautotest) as it does not appear to be practical.
     75
     76Twenty hours is allocated for stress testing the updated drivers.
     77
     78== Implementation ==
     79
     80Frank Warmerdam will implement all the core features of this RFC for the  GDAL/OGR 1.5.0 release.  As well the Shapefile, Personal Geodatabase, ODBC and Oracle drivers will implement OLCReentrant, ODsCLayerClones, ODsCReentrant and ODsThreadSafe. 
    4981
    5082
    51