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

server: remove extra region clone when handle region heartbeat #1195

Merged
merged 13 commits into from
Sep 6, 2018

Conversation

nolouch
Copy link
Contributor

@nolouch nolouch commented Aug 14, 2018

What have you changed? (required)

the region variable already is a new object from the request. we only read it in one goroutine now, so the clone is useless, remove it.

What are the type of the changes (required)?

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested (required)?

manual tests
unit tests

Copy link
Contributor

@siddontang siddontang left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -446,7 +446,6 @@ func (c *clusterInfo) updateStoreStatusLocked(id uint64) {

// handleRegionHeartbeat updates the region information.
func (c *clusterInfo) handleRegionHeartbeat(region *core.RegionInfo) error {
region = region.Clone()
Copy link
Contributor

Choose a reason for hiding this comment

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

The region is used after calling this function. Are you sure that it is safe to not clone? See: https://github.com/pingcap/pd/blob/9b0763fb0474c657c1abbef8238871f3d1284817/server/cluster_worker.go#L28-L41

Copy link
Contributor Author

@nolouch nolouch Aug 16, 2018

Choose a reason for hiding this comment

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

Actually, all function only read it. More reassuring, I clone the region which has operator now.

Copy link
Contributor

Choose a reason for hiding this comment

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

It does not make sense to clone the region. Cloning the region reads the region too.

I'm not so sure that the region is inmutable. I think you can propose another PR to change all fields of core.RegionInfo to unexported fields and add read only methods to access them. After that we can be sure that the RegionInfo is inmutable and discard the Clone method of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it.

@nolouch
Copy link
Contributor Author

nolouch commented Aug 16, 2018

/run-all-tests

Copy link
Contributor

@liukun4515 liukun4515 left a comment

Choose a reason for hiding this comment

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

LGTM

@nolouch nolouch removed the DNM label Sep 3, 2018
@nolouch
Copy link
Contributor Author

nolouch commented Sep 3, 2018

PTAL @disksing @rleungx

@@ -71,7 +71,7 @@ func (s *testAdminSuite) TestDropRegion(c *C) {
c.Assert(err, IsNil)
c.Assert(res.StatusCode, Equals, http.StatusOK)
res.Body.Close()
err = cluster.HandleRegionHeartbeat(region)
err = cluster.HandleRegionHeartbeat(region.Clone())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the Clone method?

@@ -378,20 +378,12 @@ func (s *testClusterInfoSuite) TestRegionHeartbeat(c *C) {
checkRegionsKV(c, cluster.kv, regions[:i+1])

// region is updated.
Copy link
Member

Choose a reason for hiding this comment

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

This comment should be removed.

Copy link
Member

Choose a reason for hiding this comment

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

BTW, why do you remove this?

)
regions[i] = region
c.Assert(cluster.handleRegionHeartbeat(region), IsNil)
checkRegions(c, cluster.core.Regions, regions[:i+1])
checkRegionsKV(c, cluster.kv, regions[:i+1])
Copy link
Member

Choose a reason for hiding this comment

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

duplicated?

Copy link
Member

@rleungx rleungx left a comment

Choose a reason for hiding this comment

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

LGTM.

@nolouch nolouch merged commit 5d1bac0 into tikv:master Sep 6, 2018
@nolouch nolouch deleted the remove-clone branch September 6, 2018 04:07
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.

5 participants