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

Fix potential race condition when registering remote storage info #481

Merged
merged 1 commit into from
Jan 16, 2023

Conversation

zuston
Copy link
Member

@zuston zuston commented Jan 13, 2023

What changes were proposed in this pull request?

  1. Use the concurrentHashmap's computeIfAbsent to keep thread safe

Why are the changes needed?

  1. To fix potential race condition when registering remote storage info

Does this PR introduce any user-facing change?

No

How was this patch tested?

Existing UTs

@jerqi
Copy link
Contributor

jerqi commented Jan 13, 2023

@smallzhongfeng Could you help me review this pr?

Copy link
Contributor

@advancedxy advancedxy left a comment

Choose a reason for hiding this comment

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

Is it possible to add a unit for data race case?

appIdToStorages.putIfAbsent(appId, pathToStorages.get(remoteStorage));
return hdfsStorage;
});
appIdToStorages.computeIfAbsent(appId, key -> pathToStorages.get(remoteStorage));
Copy link
Contributor

Choose a reason for hiding this comment

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

this line doesn't have race condition. putIfAbsent should be just fine?

Copy link
Member Author

Choose a reason for hiding this comment

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

If using putIfAbsent, the pathToStorages.get(remoteStorage) will be invoked everytime. Although it looks unrelated with this PR. Anyway, this is a performance improvement

Copy link
Member Author

Choose a reason for hiding this comment

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

Similar above problems exist in current codebase, maybe we could create some issues as good first issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, this is a performance improvement

Good to know. I was forgetting the performance difference. Although, putIfAbsent is more cleaner in most cases.

Similar above problems exist in current codebase, maybe we could create some issues as good first issue.

Yes, please create some new issues.

@zuston zuston merged commit 654d8c7 into apache:master Jan 16, 2023
@zuston
Copy link
Member Author

zuston commented Jan 16, 2023

Thanks for your review @advancedxy . Merged

@zuston zuston deleted the concurrentOp branch January 16, 2023 05:56
kaijchen pushed a commit that referenced this pull request Jan 17, 2023
### What changes were proposed in this pull request?

1. Use the concurrentHashMap's computeIfAbsent to keep thread safe

### Why are the changes needed?
1. To fix potential race condition when registering remote storage info

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Existing UTs
@smallzhongfeng
Copy link
Contributor

Late LGTM.

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.

None yet

4 participants