Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Jan 23, 2025
1 parent 3f64d88 commit 995d25c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions pkg/syncer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ type RegionSyncer struct {
clientCtx context.Context
clientCancel context.CancelFunc
}
broadcastDone chan struct{}
server Server
wg sync.WaitGroup
history *historyBuffer
limit *ratelimit.RateLimiter
tlsConfig *grpcutil.TLSConfig
server Server
wg sync.WaitGroup
history *historyBuffer
limit *ratelimit.RateLimiter
tlsConfig *grpcutil.TLSConfig
// status when as client
streamingRunning atomic.Bool
}
Expand All @@ -98,11 +97,10 @@ func NewRegionSyncer(s Server) *RegionSyncer {
return nil
}
syncer := &RegionSyncer{
server: s,
history: newHistoryBuffer(defaultHistoryBufferSize, regionStorage.(kv.Base)),
limit: ratelimit.NewRateLimiter(defaultBucketRate, defaultBucketCapacity),
tlsConfig: s.GetTLSConfig(),
broadcastDone: make(chan struct{}, 1),
server: s,
history: newHistoryBuffer(defaultHistoryBufferSize, regionStorage.(kv.Base)),
limit: ratelimit.NewRateLimiter(defaultBucketRate, defaultBucketCapacity),
tlsConfig: s.GetTLSConfig(),
}
syncer.mu.streams = make(map[string]ServerStream)
return syncer
Expand Down Expand Up @@ -348,6 +346,7 @@ func (s *RegionSyncer) bindStream(name string, stream ServerStream) {
}

func (s *RegionSyncer) broadcast(ctx context.Context, regions *pdpb.SyncRegionResponse) {
broadcastDone := make(chan struct{}, 1)
go func() {
defer logutil.LogPanic()
var failed []string
Expand All @@ -368,10 +367,10 @@ func (s *RegionSyncer) broadcast(ctx context.Context, regions *pdpb.SyncRegionRe
}
s.mu.Unlock()
}
s.broadcastDone <- struct{}{}
close(broadcastDone)
}()
select {
case <-s.broadcastDone:
case <-broadcastDone:
case <-ctx.Done():
}
}

0 comments on commit 995d25c

Please sign in to comment.