Retry until a leader is selected. (#4318)

Fixes regression introduced in
https://github.com/seaweedfs/seaweedfs/pull/4313

Related to #4307
This commit is contained in:
Stewart Miles 2023-03-16 20:50:38 -07:00 committed by GitHub
parent d695119073
commit 264be0d2d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -101,7 +101,20 @@ func (t *Topology) Leader() (l pb.ServerAddress, err error) {
exponentialBackoff := backoff.NewExponentialBackOff()
exponentialBackoff.InitialInterval = 100 * time.Millisecond
exponentialBackoff.MaxElapsedTime = 20 * time.Second
return backoff.RetryWithData(t.MaybeLeader, exponentialBackoff)
leaderNotSelected := errors.New("leader not selected yet")
l, err = backoff.RetryWithData(
func() (l pb.ServerAddress, err error) {
l, err = t.MaybeLeader()
if err == nil && l == "" {
err = leaderNotSelected
}
return l, err
},
exponentialBackoff)
if err == leaderNotSelected {
l = ""
}
return l, err
}
func (t *Topology) MaybeLeader() (l pb.ServerAddress, err error) {