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 committed Dec 13, 2022
1 parent 3f5f622 commit 8be83d7
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
Expand Up @@ -7853,10 +7853,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
Expand Up @@ -2205,6 +2205,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 @@ -2258,7 +2262,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 @@ -2395,11 +2399,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 @@ -2414,6 +2428,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 @@ -2440,6 +2455,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 8be83d7

Please sign in to comment.