Skip to content

Commit

Permalink
GPKG: add debug traces and testing for issue of qgis/QGIS#51188
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault authored and github-actions[bot] committed Dec 13, 2022
1 parent 32d9462 commit aa069fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions autotest/ogr/ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7244,10 +7244,15 @@ def test_ogr_gpkg_background_rtree_build(filename):
ds = gdaltest.gpkg_dr.CreateDataSource(filename)
with gdaltest.config_option("OGR_GPKG_THREADED_RTREE_AT_FIRST_FEATURE", "YES"):
lyr = ds.CreateLayer("foo")
assert lyr.StartTransaction() == ogr.OGRERR_NONE
for i in range(1000):
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometryDirectly(ogr.CreateGeometryFromWkt("POINT(%d %d)" % (i, i)))
assert lyr.CreateFeature(f) == ogr.OGRERR_NONE
if i == 500:
assert lyr.CommitTransaction() == ogr.OGRERR_NONE
assert lyr.StartTransaction() == ogr.OGRERR_NONE
assert lyr.CommitTransaction() == ogr.OGRERR_NONE
ds = None
assert gdal.VSIStatL(filename + ".tmp_rtree_foo.db") is None

Expand Down
18 changes: 17 additions & 1 deletion ogr/ogrsf_frmts/gpkg/ogrgeopackagetablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,10 @@ OGRErr OGRGeoPackageTableLayer::CreateOrUpsertFeature( OGRFeature *poFeature, bo
else if( !bUpsert && m_bAllowedRTreeThread && !m_bErrorDuringRTreeThread )
{
GPKGRTreeEntry sEntry;
#ifdef DEBUG_VERBOSE
if( m_aoRTreeEntries.empty() )
CPLDebug("GPKG", "Starting to fill m_aoRTreeEntries at FID " CPL_FRMT_GIB, nFID);
#endif
sEntry.nId = nFID;
sEntry.fMinX = rtreeValueDown(oEnv.MinX);
sEntry.fMaxX = rtreeValueUp(oEnv.MaxX);
Expand Down Expand Up @@ -2226,7 +2230,7 @@ void OGRGeoPackageTableLayer::SetDeferredSpatialIndexCreation( bool bFlag )
// For unit tests
if( CPLTestBool(CPLGetConfigOption("OGR_GPKG_THREADED_RTREE_AT_FIRST_FEATURE", "NO")) )
{
m_nRTreeBatchSize = 1;
m_nRTreeBatchSize = 10;
m_nRTreeBatchesBeforeStart = 1;
}
}
Expand Down Expand Up @@ -2363,11 +2367,21 @@ void OGRGeoPackageTableLayer::AsyncRTreeThreadFunction()
}

SQLCommand(m_hAsyncDBHandle, "BEGIN");
GIntBig nCount = 0;
while( true )
{
const auto aoEntries = m_oQueueRTreeEntries.get_and_pop_front();
if( aoEntries.empty() )
break;
#ifdef DEBUG_VERBOSE
CPLDebug("GPKG", "AsyncRTreeThreadFunction(): "
"Processing batch of %d features, "
"starting at FID " CPL_FRMT_GIB " and ending "
"at FID " CPL_FRMT_GIB,
static_cast<int>(aoEntries.size()),
aoEntries.front().nId,
aoEntries.back().nId);
#endif
for( const auto& entry: aoEntries )
{
if( (entry.nId % 500000) == 0 )
Expand All @@ -2382,6 +2396,7 @@ void OGRGeoPackageTableLayer::AsyncRTreeThreadFunction()
}
sqlite3_reset(hStmt);

nCount ++;
sqlite3_bind_int64(hStmt,1,entry.nId);
sqlite3_bind_double(hStmt,2,entry.fMinX);
sqlite3_bind_double(hStmt,3,entry.fMaxX);
Expand All @@ -2408,6 +2423,7 @@ void OGRGeoPackageTableLayer::AsyncRTreeThreadFunction()
}

sqlite3_finalize(hStmt);
CPLDebug("GPKG", "AsyncRTreeThreadFunction(): " CPL_FRMT_GIB " rows inserted into RTree", nCount);

if( m_bErrorDuringRTreeThread )
{
Expand Down

0 comments on commit aa069fc

Please sign in to comment.