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 push schedule commands. #669

Merged
merged 12 commits into from
Jul 5, 2017
Merged

server push schedule commands. #669

merged 12 commits into from
Jul 5, 2017

Conversation

disksing
Copy link
Contributor

Another approach of #661.
Now dispatch() does not return responses, all responses transfers through heartbeatStream.

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

the rest LGTM! this approach is more clear than I do.

@@ -290,27 +295,13 @@ func (s *Server) RegionHeartbeat(server pdpb.PD_RegionHeartbeatServer) error {
continue
}

var resp *pdpb.RegionHeartbeatResponse
resp, err = cluster.handleRegionHeartbeat(region)
err = cluster.handleRegionHeartbeat(region)
if err != nil {
msg := errors.Trace(err).Error()
err = sendErrorRegionHeartbeatResponse(server, s.clusterID, pdpb.ErrorType_UNKNOWN, msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

should send error by hbstreams in 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.

It's ok, server can be accessed by both here and there.

Copy link
Contributor

Choose a reason for hiding this comment

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

function name is too long.

Btw, do we need to close the stream in the heartbeat loop?

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 think no need to drop the stream. The stream itself is in good condition, only some requests are not able to respond.

for {
select {
case update := <-s.streamCh:
s.streams[update.storeID] = update.stream
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to close old one if have?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to. ServerStream does not have Close function, it will close automatically after eof.

delete(s.streams, storeID)
}
} else {
log.Debugf("heartbeat stream not found for store %v, skip send message", storeID)
Copy link
Contributor

Choose a reason for hiding this comment

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

should add a metric for it.

} else {
log.Debugf("heartbeat stream not found for store %v, skip send message", storeID)
}
case <-s.ctx.Done():
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should use a sub context to avoid using the same context in different goroutines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay.

@siddontang
Copy link
Contributor

PTAL @overvenus


if region := c.cluster.getRegion(op.GetRegionID()); region != nil {
if msg, _ := op.Do(region); msg != nil {
c.hbStreams.sendMsg(region, msg)
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to put sendMsg in dispatch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a scheduler calls addOperator, I want the operator be sent to tikv ASAP.

@siddontang
Copy link
Contributor

PTAL @huachaohuang

# Conflicts:
#	server/cluster_worker_test.go
return errors.Trace(err)
}
storeID := request.GetLeader().GetStoreId()
cluster.coordinator.hbStreams.bindStream(storeID, server)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it safe to send with server concurrently?
Seems server will still be used in this function.

@disksing
Copy link
Contributor Author

disksing commented Jul 4, 2017

PTAL @huachaohuang

// RegionHeartbeat implements gRPC PDServer.
func (s *Server) RegionHeartbeat(server pdpb.PD_RegionHeartbeatServer) error {
syncServer := &syncHeartbeatServer{server: server}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the server reused?
If it is, it will be protected by different locks on each call.

Copy link
Contributor

@nolouch nolouch Jul 4, 2017

Choose a reason for hiding this comment

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

I think send the error message with hbstreams same as a normal response better than use lock.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

delete(s.streams, storeID)
regionHeartbeatCounter.WithLabelValues("down", "err")
} else {
regionHeartbeatCounter.WithLabelValues("down", "ok")
Copy link
Contributor

Choose a reason for hiding this comment

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

why down here?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe push?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, "up" and "down" seem strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

push for server -> client, and what for client -> server? @huachaohuang @siddontang

Copy link
Contributor

Choose a reason for hiding this comment

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

server push operator to client, and client pull operator from server, make senses?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think not pull 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.

"report" and "schedule"?

Copy link
Contributor

Choose a reason for hiding this comment

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

report may be better
/cc @huachaohuang

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with "push" and "report".

@siddontang
Copy link
Contributor

Rest LGTM

PTAL @huachaohuang @nolouch

cluster := s.GetRaftCluster()
if cluster == nil {
resp := &pdpb.RegionHeartbeatResponse{
Header: &pdpb.ResponseHeader{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the same as s.notBootstrappedHeader?

storeID := request.GetLeader().GetStoreId()
cluster.coordinator.hbStreams.bindStream(storeID, syncServer)
hbStreams.bindStream(storeID, server)
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 bind stream before the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. We don't know the storeID yet.

delete(s.streams, storeID)
regionHeartbeatCounter.WithLabelValues("down", "err")
} else {
regionHeartbeatCounter.WithLabelValues("down", "ok")
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with "push" and "report".

cluster := s.GetRaftCluster()
if cluster == nil {
resp := &pdpb.RegionHeartbeatResponse{
Header: &pdpb.ResponseHeader{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the same as s.notBootstrappedHeader()?


if isNew {
storeID := request.GetLeader().GetStoreId()
hbStreams.bindStream(storeID, server)
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 bind stream before the loop?

Copy link
Contributor

@huachaohuang huachaohuang 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
Copy link
Contributor

nolouch commented Jul 5, 2017

LGTM

@disksing disksing merged commit 0e4b711 into master Jul 5, 2017
@disksing disksing deleted the disksing/stream branch July 5, 2017 06:10
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

5 participants