Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] LCP data base schema issue. #604

Open
veeraglass opened this issue Jan 8, 2025 · 6 comments
Open

[Bug] LCP data base schema issue. #604

veeraglass opened this issue Jan 8, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@veeraglass
Copy link

Describe the bug

We have released a new application to our client with upgrading readium from 2.0.0 to 2.4.0
While upgrading the client application, the LCP data base throwing issue by mentioning schema is incorrect.

Please find issue details below

Exception java.lang.IllegalStateException: Pre-packaged database has an invalid schema: passphrases(org.readium.r2.lcp.persistence.Passphrase).
Expected:
TableInfo{name='passphrases', columns={passphrase=Column{name='passphrase', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='undefined'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=1, defaultValue='undefined'}, provider=Column{name='provider', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='undefined'}, user_id=Column{name='user_id', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='undefined'}, license_id=Column{name='license_id', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='undefined'}}, foreignKeys=[], indices=[]}
Found:
TableInfo{name='passphrases', columns={}, foreignKeys=[], indices=[]}
at androidx.room.RoomOpenHelper.checkIdentity (RoomOpenHelper.kt:158)
at androidx.room.RoomOpenHelper.onOpen (RoomOpenHelper.kt:127)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen (FrameworkSQLiteOpenHelper.kt:287)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked (SQLiteOpenHelper.java:447)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase (SQLiteOpenHelper.java:332)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableOrReadableDatabase (FrameworkSQLiteOpenHelper.kt:232)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.innerGetDatabase (FrameworkSQLiteOpenHelper.kt:190)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getSupportDatabase (FrameworkSQLiteOpenHelper.kt:151)
at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase (FrameworkSQLiteOpenHelper.kt:104)
at androidx.room.RoomDatabase.inTransaction (RoomDatabase.kt:632)
at androidx.room.RoomDatabase.assertNotSuspendingTransaction (RoomDatabase.kt:451)
at androidx.room.RoomDatabase.query (RoomDatabase.kt:480)
at androidx.room.util.DBUtil.query (DBUtil.kt:75)
at org.readium.r2.lcp.persistence.LcpDao_Impl$12.call (LcpDao_Impl.java:379)
at org.readium.r2.lcp.persistence.LcpDao_Impl$12.call (LcpDao_Impl.java:375)
at androidx.room.CoroutinesRoom$Companion$execute$4$job$1.invokeSuspend (CoroutinesRoom.kt:87)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at java.lang.Thread.run (Thread.java:929)

How to reproduce?

  1. Open a book after upgrading the client application which has readium version 2.4.0.

Readium version

2.4.0

Android API version

34

Additional context

No response

@veeraglass veeraglass added bug Something isn't working triage Triage needed by maintainers labels Jan 8, 2025
@mickael-menu
Copy link
Member

Unfortunately 2.0 is too old and can't even be tested on this monorepo (which starts from 2.1).

We did have a migration from Anko to Room with a SQL schema change in 2.1, but there is an explicit SQL transaction and we didn't get any bug report about issues with it: readium/r2-lcp-kotlin#116

Apart from that, your error is very strange:

  • There's an empty passphrases table, but in the previous schema it was called Transactions.
  • It's mentioning a "Pre-packaged database" but we don't have any in Readium.

Does that ring a bell?

Is the crash happening in production for all the users, or only some of them? Can you reproduce the issue yourself?

@mickael-menu
Copy link
Member

You could also try upgrading to 2.1 and see if that helps, before upgrading to the newer versions.

@mickael-menu mickael-menu removed the triage Triage needed by maintainers label Jan 8, 2025
@veeraglass
Copy link
Author

Currently we are using 2.4.0 in Production and 2.4.3 in development, are you use suggesting to downgrade to 2.1. because it may lead to lot of code changes right.

@mickael-menu
Copy link
Member

I'm brainstorming ideas as I can't reproduce the issue.

If it's acceptable to loose the license' passphrases (the users will be required to enter the passphrase again when opening the book), you could try removing the LCP database file if creating the LcpService fails.

You should be able to find the file using context.getDatabasePath("lcpdatabase") (I didn't test it, you should verify).

If you need to keep the user passphrase, try replicating the upgrade from your old app version on a development device and take a look at the SQLite database file to see what happened to the schema.

To catch this kind of issues early you should always test an upgrade of your app from an older version before releasing to production.

@stevenzeck
Copy link
Contributor

It looks like it didn't go through the migration for some reason. In the Room, it looks like it does a lookup for a Room master table, and if that doesn't exist and the schema isn't valid, it throws that error. I remember testing that whole migration process thoroughly.

I tried to create a project using 2.0.0, but it's too old at this point with stuff going to jcenter and jitpack.

@qnga
Copy link
Member

qnga commented Jan 9, 2025

A Room upgrade can have broken the migration path. I guess you could try to force a lower Room version in 2.4, not sure if we use new features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants