Skip to content

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

Merged
merged 3 commits into from
Feb 10, 2023

Conversation

dave-fn
Copy link
Contributor

@dave-fn dave-fn commented Feb 9, 2023

Motivation and Context

The implementation of aggregate does not guarantee the profile files were submitted to ProfileFile.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, the values() 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@dave-fn dave-fn requested a review from a team as a code owner February 9, 2023 19:41
@dave-fn dave-fn force-pushed the feature/master/credentials-reload branch from 21d777b to 1854f93 Compare February 9, 2023 19:43
ProfileFile.Aggregator aggregator = ProfileFile.aggregator();
currentValuesBySupplier.values().forEach(aggregator::addFile);
Copy link
Contributor Author

@dave-fn dave-fn Feb 9, 2023

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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?

@dave-fn dave-fn force-pushed the feature/master/credentials-reload branch from 1854f93 to e45585b Compare February 9, 2023 19:48
@dave-fn dave-fn force-pushed the feature/master/credentials-reload branch from 8e532ae to 3e69637 Compare February 10, 2023 17:40
@@ -137,7 +138,7 @@ public ProfileFile get() {
return currentAggregateProfileFile.get();
}

private boolean didSuppliedValueChange(Supplier<ProfileFile> supplier) {
private synchronized boolean didSuppliedValueChange(Supplier<ProfileFile> supplier) {
Copy link
Contributor

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);
}

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 agree the easiest solution is just to wrap into Collections.synchronizedMap.

Yep, I missed the synchronized keyword on line 150.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 4 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

91.8% 91.8% Coverage
1.5% 1.5% Duplication

@dave-fn dave-fn merged commit fef74ab into master Feb 10, 2023
@dave-fn dave-fn deleted the feature/master/credentials-reload branch February 10, 2023 20:29
aws-sdk-java-automation added a commit that referenced this pull request Mar 19, 2025
…2d716c9fc

Pull request: release <- staging/1ea97dfa-f9ee-4bc0-95a8-e1a2d716c9fc
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.

2 participants