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

[Data sync] Rewrite data and photo sync workers to be more robust and readable #2867

Merged
merged 66 commits into from
Dec 2, 2024

Conversation

gino-m
Copy link
Collaborator

@gino-m gino-m commented Nov 22, 2024

  1. Try to process entire queue each time worker is run rather than just mutation for a specific enqueued LOI. This makes the sync worker more robust in the case that a worker failed for a particular LOI before it could request a retry() or update the mutation status.
  2. Introduces the UploadQueueEntry wrapper / grouping for mutations to be used by the workers and UI.

Towards #2840

Copy link

codecov bot commented Nov 22, 2024

Codecov Report

Attention: Patch coverage is 84.26966% with 14 lines in your changes missing coverage. Please review.

Project coverage is 61.68%. Comparing base (c982a50) to head (a3cd4bf).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...droid/ground/persistence/sync/MediaUploadWorker.kt 73.68% 1 Missing and 4 partials ⚠️
...ogle/android/ground/ui/home/HomeScreenViewModel.kt 0.00% 2 Missing and 2 partials ⚠️
...le/android/ground/repository/MutationRepository.kt 93.02% 0 Missing and 3 partials ⚠️
.../android/ground/repository/SubmissionRepository.kt 0.00% 1 Missing ⚠️
.../main/java/com/google/android/ground/util/Debug.kt 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2867      +/-   ##
============================================
+ Coverage     61.19%   61.68%   +0.48%     
+ Complexity     1183     1173      -10     
============================================
  Files           267      268       +1     
  Lines          6396     6344      -52     
  Branches        914      876      -38     
============================================
- Hits           3914     3913       -1     
+ Misses         1943     1890      -53     
- Partials        539      541       +2     
Files with missing lines Coverage Δ
.../src/main/java/com/google/android/ground/Config.kt 100.00% <ø> (ø)
...ndroid/ground/model/mutation/SubmissionMutation.kt 89.47% <ø> (+3.11%) ⬆️
...ndroid/ground/model/submission/UploadQueueEntry.kt 100.00% <100.00%> (ø)
...ground/persistence/sync/LocalMutationSyncWorker.kt 96.00% <100.00%> (+2.97%) ⬆️
.../ground/repository/LocationOfInterestRepository.kt 52.72% <100.00%> (ø)
.../android/ground/repository/SubmissionRepository.kt 18.60% <0.00%> (ø)
.../main/java/com/google/android/ground/util/Debug.kt 71.42% <0.00%> (-5.50%) ⬇️
...le/android/ground/repository/MutationRepository.kt 87.50% <93.02%> (+2.88%) ⬆️
...ogle/android/ground/ui/home/HomeScreenViewModel.kt 79.24% <0.00%> (-1.46%) ⬇️
...droid/ground/persistence/sync/MediaUploadWorker.kt 84.84% <73.68%> (+9.40%) ⬆️

... and 11 files with indirect coverage changes

@gino-m gino-m force-pushed the gino-m/2840/improve-upload-queue-1 branch from 3a0d9d4 to 375a906 Compare November 25, 2024 17:16
@gino-m gino-m changed the title [Data sync] Try to process entire queue each time worker is run [Data sync] Major rewrite of data sync workers Nov 26, 2024
@gino-m gino-m marked this pull request as ready for review November 27, 2024 20:25
@gino-m gino-m requested review from shobhitagarwal1612 and anandwana001 and removed request for scolsen and sufyanAbbasi November 27, 2024 20:25
@gino-m
Copy link
Collaborator Author

gino-m commented Nov 27, 2024

@shobhitagarwal1612 @anandwana001 PTAL?

Copy link
Member

@shobhitagarwal1612 shobhitagarwal1612 left a comment

Choose a reason for hiding this comment

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

I took a first pass and left some comments. Will take another pass soon.

@@ -40,3 +42,5 @@ object Debug {
null
}
}

fun Throwable.priority() = if (this is FirebaseNetworkException) Log.DEBUG else Log.ERROR
Copy link
Member

Choose a reason for hiding this comment

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

How about adding a check here and log to console?

Then we can continue to use Timber.e normally in all classes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those events shouldn't be shown as errors in local logs either, and I'm not sure we want to have the priority change magically without any indication in the code doing the logging.

} catch (t: Throwable) {
Timber.e(t, "Failed to upload photo")
kotlin.Result.failure(t)
Timber.log(t.priority(), t, "Photo upload failed")
Copy link
Member

Choose a reason for hiding this comment

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

Please see the other comment regarding reverting this change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See response in other comment. Perhaps an extension function would be more elegant here? Timber.log override with no "priority", for example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forked this discussion into a suggestion in #2891.

Copy link
Collaborator Author

@gino-m gino-m left a comment

Choose a reason for hiding this comment

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

@shobhitagarwal1612 PTAL at my comments/questions

@@ -40,3 +42,5 @@ object Debug {
null
}
}

fun Throwable.priority() = if (this is FirebaseNetworkException) Log.DEBUG else Log.ERROR
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those events shouldn't be shown as errors in local logs either, and I'm not sure we want to have the priority change magically without any indication in the code doing the logging.

} catch (t: Throwable) {
Timber.e(t, "Failed to upload photo")
kotlin.Result.failure(t)
Timber.log(t.priority(), t, "Photo upload failed")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See response in other comment. Perhaps an extension function would be more elegant here? Timber.log override with no "priority", for example?

@gino-m gino-m merged commit 9ab91bc into master Dec 2, 2024
4 checks passed
@gino-m gino-m deleted the gino-m/2840/improve-upload-queue-1 branch December 2, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants