-
Notifications
You must be signed in to change notification settings - Fork 910
ProfileFileSupplier aggregate files in order #3754
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
21d777b
to
1854f93
Compare
ProfileFile.Aggregator aggregator = ProfileFile.aggregator(); | ||
currentValuesBySupplier.values().forEach(aggregator::addFile); |
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.
values
won't necessarily return the values in order since it's backed by a Map.
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.
Could we switch it to a linked hash map?
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.
Yes. The thing is we lose the Concurrency
from the current map, but we can synchronize manually. Would that be a preferred solution?
1854f93
to
e45585b
Compare
8e532ae
to
3e69637
Compare
@@ -137,7 +138,7 @@ public ProfileFile get() { | |||
return currentAggregateProfileFile.get(); | |||
} | |||
|
|||
private boolean didSuppliedValueChange(Supplier<ProfileFile> supplier) { | |||
private synchronized boolean didSuppliedValueChange(Supplier<ProfileFile> supplier) { |
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.
Should we just wrap currentValuesBySupplier in a Collections.synchronizedMap instead of synchronizing ourselves?
If there's some problem with that:
Can we synchronize just around the writes to the currentValuesBySupplier so that we don't hold the lock while calling the supplier?
ProfileFile current;
synchronized (currentValuesBySupplier) {
current = currentValuesBySupplier.put(supplier, next);
}
I think we also need to synchronize our iterating over the values on line 150, since modification of the collection during iteration is undefined.
synchronized (currentValuesBySupplier) {
currentValuesBySupplier.values().forEach(aggregator::addFile);
}
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 agree the easiest solution is just to wrap into Collections.synchronizedMap.
Yep, I missed the synchronized keyword on line 150.
SonarCloud Quality Gate failed. |
…2d716c9fc Pull request: release <- staging/1ea97dfa-f9ee-4bc0-95a8-e1a2d716c9fc
Motivation and Context
The implementation of
aggregate
does not guarantee the profile files were submitted toProfileFile.Aggregator.addFile()
in the order given by the suppliers.The current implementation uses a
Map
to keep track of whether a supplier returns a different object. Unfortunately, thevalues()
method does not guarantee an ordering.Modifications
In order to preserve ordering and thread-safety, a
LinkedHashMap
will be used to feed the aggregator.Testing
Added two unit tests.
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License