Skip to content

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

Merged
suneet-s merged 2 commits intoapache:masterfrom
georgew5656:removeLocks
Jun 18, 2023
Merged

Don't need to double synchronize on simple map operations#14435
suneet-s merged 2 commits intoapache:masterfrom
georgew5656:removeLocks

Conversation

@georgew5656
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
FrankChen021 pushed a commit that referenced this pull request Feb 3, 2025
…map (#14643)

Changes:
- Fix race condition in KubernetesTaskRunner introduced by #14435 
- Perform addition and removal from map inside a synchronized block
- Update tests
GabrielCWT pushed a commit to GabrielCWT/druid that referenced this pull request Sep 9, 2025
…map (apache#14643)

Changes:
- Fix race condition in KubernetesTaskRunner introduced by apache#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