Skip to content

Conversation

@jpountz
Copy link
Contributor

@jpountz jpountz commented Apr 30, 2024

Because of concurrent merging (#13124), multiple threads may be updating (different) attributes concurrently, so we need to make reads and writes to attributes thread-safe.

Because of concurrent merging (apache#13124), multiple threads may be updating
(different) attributes concurrently, so we need to make reads and writes to
attributes thread-safe.
@jpountz jpountz added this to the 9.11.0 milestone Apr 30, 2024
@jpountz jpountz requested a review from benwtrent April 30, 2024 14:07
String oldValue = newMap.put(key, value);
// This needs to be thread-safe as multiple threads may be updating (different) attributes
// concurrently due to concurrent merging.
attributes = Collections.unmodifiableMap(newMap);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we are copying the map, why not use a ConcurrentHashMap?

Is this because we don't want this changing at all after something calls attributes()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Since SegmentInfo's attributes were already using this approach, I thought it made sense to follow the same approach instead of doing something different.

@jpountz jpountz merged commit c3b0e05 into apache:main May 2, 2024
@jpountz jpountz deleted the thread_safe_attributes branch May 2, 2024 16:31
jpountz added a commit that referenced this pull request May 6, 2024
Because of concurrent merging (#13124), multiple threads may be updating
(different) attributes concurrently, so we need to make reads and writes to
attributes thread-safe.
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