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

Don't need to double synchronize on simple map operations #14435

Merged
merged 2 commits into from
Jun 18, 2023

Conversation

georgew5656
Copy link
Contributor

@georgew5656 georgew5656 commented Jun 15, 2023

Description

We are using a lock around a concurrentHashMap for simple one line get/insert operations into the map

The concurrentHashMap guarantees that computeIfAbsent will only call the operation once if multiple threads attempt to call it concurrently, so this shouldn't be necessary.

We don't need the lock inside doTask either because doTask is called as a part of the operation in computeIfAbsent from either joinAsync or run for a single taskId. Because the map is concurrent, there will be one thread running doTask per taskId.

Release note

  • remove unnecessary synchronization in K8s task runner.

This PR has:

  • [X ] been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • [ X] been tested in a test Druid cluster.

Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

After these changes, would there be any operation in this class that is still synchronized on tasks?

@georgew5656
Copy link
Contributor Author

Makes sense to me.

After these changes, would there be any operation in this class that is still synchronized on tasks?

no, i don't believe so

@suneet-s suneet-s merged commit bd07c3d into apache:master Jun 18, 2023
@abhishekagarwal87 abhishekagarwal87 added this to the 27.0 milestone Jul 19, 2023
kfaraz pushed a commit that referenced this pull request Jul 27, 2023
…map (#14643)

Changes:
- Fix race condition in KubernetesTaskRunner introduced by #14435 
- Perform addition and removal from map inside a synchronized block
- Update tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants