retry join instead of failing

this make it easier to bootstrap a cluster and also makes the cluster
more resilient to full-cluster failures or restarts

fixes #6
This commit is contained in:
Leo Antunes
2019-08-06 21:53:38 +02:00
parent 3a401a7942
commit 5427aa5e84
4 changed files with 29 additions and 3 deletions

11
main.go
View File

@ -5,6 +5,9 @@ import (
"os"
"os/signal"
"syscall"
"time"
"github.com/cenkalti/backoff"
"github.com/sirupsen/logrus"
@ -39,7 +42,13 @@ func main() {
}
nodec, errc := cluster.members() // avoid deadlocks by starting before join
if err := cluster.join(config.Join); err != nil {
if err := backoff.RetryNotify(
func() error { return cluster.join(config.Join) },
backoff.NewExponentialBackOff(),
func(err error, dur time.Duration) {
logrus.Errorf("could not join cluster, retrying in %s: %s", dur, err)
},
); err != nil {
logrus.Fatalf("could not join cluster: %s", err)
}