-
Notifications
You must be signed in to change notification settings - Fork 624
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
Conversation
ankitaj224
commented
May 18, 2020
- Fixing delete API to access persisted FID using cross process safe locks.
- 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.
Binary Size ReportAffected SDKs
Test Logs
NotesHead commit (df669eaa) is created by Prow via merging commits: b1172c9 a5f6558. |
Coverage ReportAffected SDKs
Test Logs
NotesHTML coverage reports can be produced locally with 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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. */ |
There was a problem hiding this comment.
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. */
...ase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java
Outdated
Show resolved
Hide resolved
...ase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
* Cache FID to avoid multiple disk reads. * Addressing Rayo's comments.