Skip to content

Completing getId call with the disk reads on the caller thread. #1570

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 32 commits into from
May 20, 2020

Conversation

ankitaj224
Copy link
Contributor

  1. Fixing delete API to access persisted FID using cross process safe locks.
  2. Minor code cleanup

Access the data shared by multiple threads only after acquiring cross-process and multi-thread safe locks.
Also, fixing delete API to access persisted FID using cross process
safe locks.
@googlebot googlebot added cla: yes Override cla labels May 18, 2020
@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 18, 2020

Binary Size Report

Affected SDKs

  • firebase-common

    Type Base (b1172c9) Head (df669eaa) Diff
    apk (aggressive) 82.5 kB 82.5 kB -3 B (-0.0%)
    apk (debug) 770 kB 770 kB -2 B (-0.0%)
  • firebase-components

    Type Base (b1172c9) Head (df669eaa) Diff
    apk (aggressive) 10.9 kB 11.0 kB +15 B (+0.1%)
    apk (debug) 35.9 kB 35.9 kB +4 B (+0.0%)
  • firebase-installations

    Type Base (b1172c9) Head (df669eaa) Diff
    aar 58.5 kB 57.6 kB -859 B (-1.5%)
    apk (debug) 794 kB 794 kB +69 B (+0.0%)
    apk (release) 657 kB 657 kB +116 B (+0.0%)
  • firebase-installations-interop

    Type Base (b1172c9) Head (df669eaa) Diff
    apk (aggressive) 61.7 kB 61.7 kB -13 B (-0.0%)
    apk (debug) 744 kB 744 kB -51 B (-0.0%)

Test Logs

Notes

Head commit (df669eaa) is created by Prow via merging commits: b1172c9 a5f6558.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 18, 2020

Coverage Report

Affected SDKs

  • firebase-installations

    SDK overall coverage changed from 58.00% (b1172c9) to 58.06% (df669eaa) by +0.06%.

    Filename Base (b1172c9) Head (df669eaa) Diff
    FirebaseInstallations.java 97.79% 97.84% +0.05%

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 (df669eaa) is created by Prow via merging commits: b1172c9 a5f6558.

@@ -520,7 +509,7 @@ private PersistedInstallationEntry fetchAuthTokenFromServer(
* storage.
*/
private Void deleteFirebaseInstallationId() throws FirebaseInstallationsException, IOException {
PersistedInstallationEntry entry = persistedInstallation.readPersistedInstallationEntryValue();
PersistedInstallationEntry entry = getPrefsWithGeneratedIdMultiProcessSafe();
Copy link
Contributor

Choose a reason for hiding this comment

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

This will create a new fid and delete it. I think it is better the way it was.

Copy link
Contributor Author

@ankitaj224 ankitaj224 May 18, 2020

Choose a reason for hiding this comment

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

Reason for this: If there is one thread that is triggering getId or getToken and another triggering delete. If the delete read is not multi-process safe, and tries to read the same data locked by other thread acquiring CrossProcessLock - could lead to OverLappingFileLockException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed offline: created and used cross-process safe read prefs method.

Task<String> task = addGetIdListener();
backgroundExecutor.execute(this::doGetId);
return task;
synchronized (lockGetFid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you want to emulate the old behavior of this being serialized on a sinle thread, but I don't know of adding an additional synchronization block is the right way to go.

For one thing, it isn't multi-process safe.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, everything doGetId() does it already thread and process safe, so this doesn't need its own protection, does it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that local variables are thread safe. PTAL

@ankitaj224 ankitaj224 requested a review from fredquintana May 18, 2020 21:41
Copy link
Contributor

@andirayo andirayo left a comment

Choose a reason for hiding this comment

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

I fear I don't have enough knowledge about what is going on with the locks, the syncs, and our SDK in general. Happy to dive in deeper and wrap my head around it, though. plmk

@@ -73,6 +73,10 @@

/* used for thread-level synchronization of generating and persisting fids */
private static final Object lockGenerateFid = new Object();

/* used for thread-level synchronization of getting a fid. */
Copy link
Contributor

Choose a reason for hiding this comment

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

How about this comment:
/** Thread level synchronization for reading FID from disk. */

Copy link
Contributor

@fredquintana fredquintana left a comment

Choose a reason for hiding this comment

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

looks good

@ankitaj224 ankitaj224 merged commit 1a36dd7 into master May 20, 2020
@firebase firebase locked and limited conversation to collaborators Jun 20, 2020
@kaibolay kaibolay deleted the blockID 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
Development

Successfully merging this pull request may close these issues.

5 participants