Skip to content

Make schemas back and forth compatible #1552

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

Merged
merged 7 commits into from
May 26, 2020
Merged

Make schemas back and forth compatible #1552

merged 7 commits into from
May 26, 2020

Conversation

ashwinraghav
Copy link
Contributor

@ashwinraghav ashwinraghav commented May 11, 2020

#1548 evidences issues that we have with our Schema Manager when customers go back and forth between versions (here on referred to as Version Fluidity) Thanks @rafikhan .

These are our options:

  1. We can either take Firestore's stand of being lossless when customers migrate back and forth between versions.
  2. We can take a systematic cleanup approach that deletes all state when clients are migrated to older versions.

We are leaning towards option 2

  1. Given Firestore' s approach to preserve state, the advice from the API council was to take a similar approach.
  2. Deleting old data might make in intractable to use Firelog for some use cases going foward.

Design considerations
We have modified migrations (history), which is typically a red flag. However since we have modeled db creation as running all migrations(replaying history), there's not a cleaner way forward.

Modifications to existing migrations involves one of two things

  1. Creating tables only if they don't exist.
  2. Altering columns if they exist. Since there's no sql construct, we catch exceptions around the operation.

Version compatibility

The migrations and tests are no longer representative of this compatibility since we essentially changing history.

Version Fluidity matrix

1 2 3 4
1 😐
2 😐
3 😐
4 😐

@googlebot googlebot added the cla: yes Override cla label May 11, 2020
@ashwinraghav ashwinraghav changed the base branch from master to schemaManagerTest May 11, 2020 23:18
@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 11, 2020

Coverage Report

Affected SDKs

  • transport-runtime

    SDK overall coverage changed from 58.53% (2f3447f) to 58.58% (fe8f6ea1) by +0.04%.

    Filename Base (2f3447f) Head (fe8f6ea1) Diff
    SQLiteEventStore.java 51.46% 51.09% -0.36%
    SchemaManager.java 98.08% 98.21% +0.14%

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (fe8f6ea1) is created by Prow via merging commits: 2f3447f 7c00efb.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 11, 2020

Binary Size Report

Affected SDKs

  • transport-api

    Type Base (2f3447f) Head (fe8f6ea1) Diff
    apk (aggressive) 11.0 kB 11.0 kB +2 B (+0.0%)
    apk (debug) 23.0 kB 23.0 kB +16 B (+0.1%)
  • transport-runtime

    Type Base (2f3447f) Head (fe8f6ea1) Diff
    aar 127 kB 127 kB +59 B (+0.0%)
    apk (aggressive) 35.6 kB 35.6 kB +17 B (+0.0%)
    apk (debug) 80.5 kB 80.6 kB +97 B (+0.1%)
    apk (release) 62.8 kB 62.9 kB +99 B (+0.2%)

Test Logs

Notes

Head commit (fe8f6ea1) is created by Prow via merging commits: 2f3447f 7c00efb.

@ashwinraghav ashwinraghav changed the base branch from schemaManagerTest to master May 15, 2020 17:23
@ashwinraghav ashwinraghav requested a review from vkryachko May 18, 2020 22:53
@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 18, 2020

@ashwinraghav: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
build-plugins-check 5edc500 link /test build-plugins-check

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@ashwinraghav ashwinraghav linked an issue May 18, 2020 that may be closed by this pull request
Copy link
Member

@vkryachko vkryachko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking "Request changes" to prevent accidental merge, let's discuss first, specifically the option to "drop if exists" when migrating to v4(it seems that it will resolve all issues)

@ashwinraghav
Copy link
Contributor Author

#1548 evidences issues that we have with our Schema Manager when customers go back and forth between versions (here on referred to as Version Fluidity) Thanks @rafikhan .

These are our options:

  1. We can either take Firestore's stand of being lossless when customers migrate back and forth between versions.
  2. We can take a systematic cleanup approach that deletes all state when clients are migrated to older versions.

We are leaning towards option 2

  1. Given Firestore' s approach to preserve state, the advice from the API council was to take a similar approach.
  2. Deleting old data might make in intractable to use Firelog for some use cases going foward.

Design considerations
We have modified migrations (history), which is typically a red flag. However since we have modeled db creation as running all migrations(replaying history), there's not a cleaner way forward.

Modifications to existing migrations involves one of two things

  1. Creating tables only if they don't exist.
  2. Altering columns if they exist. Since there's no sql construct, we catch exceptions around the operation.

Version compatibility

The migrations and tests are no longer representative of this compatibility since we essentially changing history.

Version Fluidity matrix

1 2 3 4
1 😐 ✅ ✅ ❌
2 ✅ 😐 ✅ ❌
3 ✅ ✅ 😐 ❌
4 ❌ ❌ ❌ 😐

We've decided to minimize the scope of changes for now and roll forward with just dropping the table before creation

@ashwinraghav ashwinraghav requested a review from vkryachko May 26, 2020 22:25
@vkryachko vkryachko merged commit 376c25c into master May 26, 2020
@mkolodiiproexe
Copy link

@vkryachko could you please let me know, when these fixes will be released in production?
I'm currently having the issue happening with Analytics 17.4.3.

Fatal Exception: android.database.sqlite.SQLiteException: table event_payloads already exists (code 1 SQLITE_ERROR): , while compiling: CREATE TABLE event_payloads (sequence_num INTEGER NOT NULL, event_id INTEGER NOT NULL, bytes BLOB NOT NULL,FOREIGN KEY (event_id) REFERENCES events(_id) ON DELETE CASCADE,PRIMARY KEY (sequence_num, event_id))
       at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
       at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:986)
       at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:593)
       at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
       at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:61)
       at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:33)
       at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1805)
       at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1733)
       at com.google.android.datatransport.runtime.scheduling.persistence.SchemaManager.lambda$static$3(SchemaManager.java:109)
       at com.google.android.datatransport.runtime.scheduling.persistence.SchemaManager$$Lambda$4.upgrade(SchemaManager.java)
       at com.google.android.datatransport.runtime.scheduling.persistence.SchemaManager.upgrade(SchemaManager.java:182)
       at com.google.android.datatransport.runtime.scheduling.persistence.SchemaManager.onUpgrade(SchemaManager.java:152)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:417)
       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:317)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore$$Lambda$1.produce(SQLiteEventStore.java:2)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.retryIfDbLocked(SQLiteEventStore.java:517)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.getDb(SQLiteEventStore.java:82)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.runCriticalSection(SQLiteEventStore.java:549)
       at com.google.android.datatransport.runtime.scheduling.jobscheduling.WorkInitializer.lambda$ensureContextsScheduled$1(WorkInitializer.java:54)
       at com.google.android.datatransport.runtime.scheduling.jobscheduling.WorkInitializer$$Lambda$1.run(WorkInitializer.java:2)
       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:919)

@vkryachko
Copy link
Member

@mkolodiiproexe The fix is out as part of com.google.firebase:firebase-datatransport:17.0.6 and the latest crashlytics depend on it. Can you provide a list of your app deps to help figure out why you're seeing this?

@mirokolodii
Copy link

mirokolodii commented Jun 9, 2020

@vkryachko
Copy link
Member

sorry, the actual SDK that contained this bug was transport-runtime
I can see that you have the updated version of it 2.2.3 which has this fix, so it should not be happening.
@ashwinraghav any thoughts?

@ashwinraghav
Copy link
Contributor Author

@mkolodiiproexe these crashes are unrelated to analytics. If you meant crashlytics, they are already available in firebase-crashlytics:17.0.1

@mirokolodii
Copy link

@ashwinraghav ok, it may be crashlytics. It just started to happen when I added analytics lib. But anyway, how can it be fixed?

@firebase firebase locked and limited conversation to collaborators Jun 26, 2020
@kaibolay kaibolay deleted the schemaManagerFix branch September 14, 2022 17:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Override cla size/L
Projects
None yet
9 participants