tikv / tikv/pd

server/cluster/cluster.go: could we remove the lock for get the address(pointer) which won't change once initted.

Open
#4,818 1 comment 0 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Go
Stars
1.2k
Forks
783
Avg merge
5d 21h
Merged PRs (30d)
36

Description

## Enhancement Task

The usage of `Lock` makes me confused, for example, let's see the following code:
[https://github.com/tikv/pd/blob/56a015c32925022cda9c803830c058916ca02d38/server/cluster/cluster.go#L422-L425](https://github.com/tikv/pd/blob/56a015c32925022cda9c803830c058916ca02d38/server/cluster/cluster.go#L422-L425)

It seems the `Lock` is try to protect the point `c.coordinator.opController`, which means we want to make sure the address of `opController` do not change in the lock. However, it seems the address won't change once it initted, so could we remove this lock?
Meanwhile, should we check if the `c.coordintator` is nil or not?

There are lots of similar function in this struct:
[https://github.com/tikv/pd/blob/56a015c32925022cda9c803830c058916ca02d38/server/cluster/cluster.go#L435-L461](https://github.com/tikv/pd/blob/56a015c32925022cda9c803830c058916ca02d38/server/cluster/cluster.go#L435-L461)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.