Status Update
Comments
ap...@google.com <ap...@google.com> #2
Branch: androidx-main
commit 81a5bc96ea042f39b8d3f1784713c8b7ee1eba17
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Aug 16 18:06:04 2021
Multi-process lock for opening DB (and migrations too)
Adds a lock at the FrameworkSQLite* level, to protect multi-process 1st time database creation and migrations. To avoid a performance regression, process-lock is only done when the database instance is not known to be opened, such that consecutive getDatabase() calls are quick and do not have to use a FileLock. Note that in-memory databases (null name) also don't use a FileLock.
Bug: 193182592
Test: n/a
Relnote: Added API for multi-process lock and usage at the FrameworkSQLite* level, to protect multi-process 1st time database creation and migrations.
Change-Id: Ied267cd32e3248cec5ebb772778d2e94fd450270
M sqlite/sqlite-framework/api/current.txt
M sqlite/sqlite-framework/src/main/java/androidx/sqlite/util/ProcessLock.java
M room/room-runtime/api/restricted_current.txt
M sqlite/sqlite-framework/api/public_plus_experimental_current.txt
M room/room-runtime/src/main/java/androidx/room/SQLiteCopyOpenHelper.java
M jetifier/jetifier/core/src/main/resources/default.generated.config
M jetifier/jetifier/migration.config
M sqlite/sqlite-framework/build.gradle
M sqlite/sqlite-framework/src/main/java/androidx/sqlite/db/framework/FrameworkSQLiteOpenHelper.java
M jetifier/jetifier/core/src/main/resources/default.config
A room/room-runtime/api/restricted_current.ignore
M sqlite/sqlite-framework/api/restricted_current.txt
da...@google.com <da...@google.com>
ra...@gmail.com <ra...@gmail.com> #3
Issue still exists in new room stable version: 2.4.3
androidx.sqlite.util.ProcessLock.lock (ProcessLock.java:90) androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase (FrameworkSQLiteOpenHelper.java:181) androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase (FrameworkSQLiteOpenHelper.java:133) androidx.room.RoomDatabase.inTransaction (RoomDatabase.java:706) androidx.room.RoomDatabase.assertNotSuspendingTransaction (RoomDatabase.java:483) androidx.room.RoomDatabase.query (RoomDatabase.java:526) androidx.room.util.DBUtil.query (DBUtil.java:86) com.bimagyanplus.Bimagyanplus.DAO.FollowUpDao_Impl.getFollowUpData (FollowUpDao_Impl.java:99) com.bimagyanplus.Bimagyanplus.Service.MyPeriodicWork.getAllData (MyPeriodicWork.kt:335) com.bimagyanplus.Bimagyanplus.Service.MyPeriodicWork.startWork (MyPeriodicWork.kt:172) androidx.work.impl.WorkerWrapper$1.run (WorkerWrapper.java:301)
Description
To fix https://b.corp.google.com/issues/193182278 we can try to add our own file locking layer to FrameworkSQLiteOpenHelper such that Room and other database libraries that use
androidx.sqlite
are protected from multi-processes racing to create or upgrade the same database file at the same time.