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

HDDS-11396. NPE due to empty Handler#clusterId #7145

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public Handler getHandler(ContainerProtos.ContainerType containerType) {

@Override
public void setClusterId(String clusterId) {
Preconditions.checkNotNull(clusterId, "clusterId Cannot be null");
Preconditions.checkNotNull(clusterId, "clusterId cannot be null");
Copy link
Contributor

Choose a reason for hiding this comment

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

@jianghuazhu, could you also revert this change if there is no specific reason? The general review guideline that I followed, is focus on the problem, and try not to touch irrelevant code as mush as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @ChenSammi .
I modified some code here. There are some main reasons:

  1. The errorMessage contained in Preconditions.checkNotNull() has a typo.
    Cannot should be changed to cannot.
  2. The old code added an if check, which means that clusterId can only be assigned once, which is too strict.
if (this.clusterId == null) {
  this.clusterId = clusterId;
  ...... 
}   

These are related to clusterId, so I updated them together.
This is my idea.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Let's keep the typo change.
It's expected that only one clusterId is valid during the DN lifetime, that clusterId is returned from SCM after DN registered to the SCM. So I will prefer keep the clusterId null check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @ChenSammi .
I have updated it.

if (this.clusterId == null) {
this.clusterId = clusterId;
for (Map.Entry<ContainerType, Handler> handlerMap : handlers.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ public void start(String clusterId) throws IOException {
replicationServer.start();
datanodeDetails.setPort(Name.REPLICATION, replicationServer.getPort());

writeChannel.start();
readChannel.start();
hddsDispatcher.init();
hddsDispatcher.setClusterId(clusterId);
writeChannel.start();
Copy link
Contributor

Choose a reason for hiding this comment

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

@jianghuazhu thanks for reporting the issue and find the root cause.
If I understand it correctly, this order change is the key to fix the problem, right? Any special reason that a ReentrantReadWriteLock is introduced in Handler.java?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @ChenSammi for the comment and review.
Yes, swapping the order here solves the problem.
Adding ReentrantReadWriteLock seems to be too strict, I will update it later.

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 have updated it.
@ChenSammi , can you review it again?
Thanks.

readChannel.start();
blockDeletingService.start();
recoveringContainerScrubbingService.start();

Expand Down