DB concurrency problem

Bug #579477 reported by Murphy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenSatNav
Fix Committed
Medium
Unassigned

Bug Description

OSN is using threads in order to simultaneously:
- download tiles (5 threads in [1]OpenStreetMapTileDownloader.getRemoteImageAsync() ),
- load map tiles (2 threads in [2]OpenStreetMapTileFilesystemProvider.loadMapTileToMemCacheAsync() ).

SQLite allows simultaneous SELECT in its database but not UPDATE.
That's why we have this kind of error sometimes:
<pre>
E/Database(24031): Failure 5 (database is locked) on 0xf1ee48 when executing 'UPDATE t_fscache SET countused = countused + 1 , used_timestamp = datetime('now') WHERE name_id = '/sdcard/org.opensatnav/tiles/tile.openstreetmap.org/18/xxxxxx/xxxxx.png.osn''
W/dalvikvm(24031): threadid=363: thread exiting with uncaught exception (group=0x4001b178)
I/global (24031): Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
E/AndroidRuntime(24031): Uncaught handler: thread pool-61-thread-1 exiting due to uncaught exception
E/AndroidRuntime(24031): android.database.sqlite.SQLiteException: database is locked: UPDATE t_fscache SET countused = countused + 1 , used_timestamp = datetime('now') WHERE name_id = '/sdcard/org.opensatnav/tiles/tile.openstreetmap.org/18/xxxxxx/xxxxx.png.osn'
E/AndroidRuntime(24031): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
E/AndroidRuntime(24031): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1610)
E/AndroidRuntime(24031): at org.andnav.osm.views.util.OpenStreetMapTileFilesystemProvider$OpenStreetMapTileFilesystemProviderDataBase.incrementUse(OpenStreetMapTileFilesystemProvider.java:403)
E/AndroidRuntime(24031): at org.andnav.osm.views.util.OpenStreetMapTileFilesystemProvider$1.run(OpenStreetMapTileFilesystemProvider.java:179)
E/AndroidRuntime(24031): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
E/AndroidRuntime(24031): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
E/AndroidRuntime(24031): at java.lang.Thread.run(Thread.java:1096)
</pre>

Both threads are calling OpenStreetMapTileFilesystemProvider.incrementUse() which executes an UPDATE.

How to keep the treads without perturbing SQLite?

Revision history for this message
Guillaume Rosaire (zerog) wrote :

Add a synchronized on the incrementUse() method ?

Changed in opensatnav:
milestone: none → 1.0
Revision history for this message
Kieran Fleming (kieran-fleming) wrote :

I've pushed a fix in rev 153 that checks if it's OK to write by calling isDbLockedByOtherThreads(). The problem occurs so rarely that it's probably easier just to wait and see if the crash reports go away.

Changed in opensatnav:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.