Skip to content

Migrations are not run correctly with NOMUTEX #28

@Nek-12

Description

@Nek-12

It seems that the migrations are not run correctly on 0.0.6, and I can't tell what exactly goes wrong.

internal class BundledDriverFactory(
    private val fileProvider: DatabaseFileProvider
) : DatabaseDriverFactory {

    private val driver = BundledSQLiteDriver()
    private val flags = SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE or SQLITE_OPEN_NOMUTEX

    override fun create() = AndroidxSqliteDriver(
        createConnection = { driver.open(it, flags) },
        databaseType = AndroidxSqliteDatabaseType.File(fileProvider(BuildFlags.DatabaseName)),
        schema = AppDatabase.Schema,
        isAccessMultithreaded = true,
        onConfigure = {
            enableWAL()
            enableForeignKeys()
        },
    )
}

When first installing the app, all seems fine since the DB is mostly empty. However, after adding new entries, something is broken. For example:

 android.database.SQLException: Error code: 1, message: view XXX is circularly defined

No it isn't. It works with native driver and I checked 3 times.

Or this:

1250, tid: 11338, name: AppDatabase  >>> com.app.debug <<<
                         #00 pc 00000000000c6fa4  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/base.apk (offset 0x244000)
                         #01 pc 00000000000d5e38  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/base.apk (offset 0x244000)
                         #02 pc 00000000000dd49c  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/base.apk (offset 0x244000)
                         #03 pc 00000000000ba3f0  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/base.apk (offset 0x244000) (sqlite3_step+364)
                         #04 pc 00000000000537ec  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/base.apk (offset 0x244000) (Java_androidx_sqlite_driver_bundled_BundledSQLiteStatementKt_nativeStep+36)
                         #12 pc 0000000002847648  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (androidx.sqlite.driver.bundled.BundledSQLiteStatementKt.access$nativeStep)
                         #18 pc 0000000002847822  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (androidx.sqlite.driver.bundled.BundledSQLiteStatement.step+10)
                         #24 pc 0000000002908300  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxCursor.next-mlR-ZEE+4)
                         #30 pc 00000000029081e0  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxCursor.next)
                         #36 pc 000000000289481e  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (app.cash.sqldelight.async.coroutines.QueryExtensionsKt$awaitAsList$2.invoke+10)
                         #42 pc 0000000002894932  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (app.cash.sqldelight.async.coroutines.QueryExtensionsKt$awaitAsList$2.invoke+6)
                         #48 pc 0000000002908726  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxQuery.executeQuery+110)
                         #54 pc 00000000029097fa  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDriver.executeQuery_0yMERmw$lambda$20+10)
                         #60 pc 00000000029096a4  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDriver.$r8$lambda$BXvRG9an3W6oyNxD8AgGHvRBZS8)
                         #66 pc 000000000290903c  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDriver$$ExternalSyntheticLambda3.invoke+8)
                         #72 pc 0000000002909712  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDriver.execute-zeHU3Mk+82)
                         #78 pc 00000000029097d6  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDriver.executeQuery-0yMERmw+42)
                         #84 pc 0000000002909540  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (com.eygraber.sqldelight.androidx.driver.AndroidxSqliteDriver.executeQuery)
                         #90 pc 00000000028934fc  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (app.cash.sqldelight.SimpleQuery.execute+36)
                         #96 pc 0000000002894d02  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (app.cash.sqldelight.async.coroutines.QueryExtensionsKt.awaitAsList+14)
                         #102 pc 0000000002895766  /data/app/com.app.debug-PrvLNGJ2sS6zii1849oz-Q==/oat/arm64/base.vdex (app.cash.sqldelight.coroutines.FlowQuery$mapToList$1$1.invokeSuspend+74)

I don't know what that is but I didn't do it.

Note: with SQLITE_OPEN_FULLMUTEX I don't observe these problems it seems, but I also don't observe any parallel access to the database at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions