Skip to content

Commit

Permalink
pkg: avoid make channel every time (#9009) (#9027)
Browse files Browse the repository at this point in the history
close #9004

Signed-off-by: ti-chi-bot <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: Ryan Leung <[email protected]>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 26, 2025
1 parent a63065b commit fd9f899
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,18 @@ type tsoRequest struct {
}

func (s *GrpcServer) dispatchTSORequest(ctx context.Context, request *tsoRequest, forwardedHost string, doneCh <-chan struct{}, errCh chan<- error) {
tsoRequestChInterface, loaded := s.tsoDispatcher.LoadOrStore(forwardedHost, make(chan *tsoRequest, maxMergeTSORequests))
val, loaded := s.tsoDispatcher.Load(forwardedHost)
if !loaded {
val = make(chan *tsoRequest, maxMergeTSORequests)
val, loaded = s.tsoDispatcher.LoadOrStore(forwardedHost, val)
}
reqCh := val.(chan *tsoRequest)
if !loaded {
tsDeadlineCh := make(chan deadline, 1)
go s.handleDispatcher(ctx, forwardedHost, tsoRequestChInterface.(chan *tsoRequest), tsDeadlineCh, doneCh, errCh)
go s.handleDispatcher(ctx, forwardedHost, reqCh, tsDeadlineCh, doneCh, errCh)
go watchTSDeadline(ctx, tsDeadlineCh)
}
tsoRequestChInterface.(chan *tsoRequest) <- request
reqCh <- request
}

func (s *GrpcServer) handleDispatcher(ctx context.Context, forwardedHost string, tsoRequestCh <-chan *tsoRequest, tsDeadlineCh chan<- deadline, doneCh <-chan struct{}, errCh chan<- error) {
Expand Down

0 comments on commit fd9f899

Please sign in to comment.