From 45216b1cccc951851517277662aaa327cbfecee4 Mon Sep 17 00:00:00 2001 From: Loic Reyreaud Date: Wed, 8 May 2024 09:07:28 +0200 Subject: [PATCH] make bootstrap return on successful notify Signed-off-by: Loic Reyreaud --- cluster/store/bootstrap.go | 24 +++++++++++++++++++++--- cluster/store/store.go | 11 +++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/cluster/store/bootstrap.go b/cluster/store/bootstrap.go index 52943d1dfcb..87b2f6768cc 100644 --- a/cluster/store/bootstrap.go +++ b/cluster/store/bootstrap.go @@ -66,15 +66,33 @@ func (b *Bootstrapper) Do(ctx context.Context, serverPortMap map[string]int, lg return ctx.Err() case <-ticker.C: // try to join an existing cluster - if leader, err := b.join(ctx, servers, voter); err == nil { - lg.WithField("leader", leader).Info("successfully joined cluster") + if leader, err := b.join(ctx, servers, voter); err != nil { + lg.WithFields(logrus.Fields{ + "servers": servers, + "action": "bootstrap", + "voter": voter, + }).WithError(err).Warning("failed to join cluster, will notify next if voter") + } else { + lg.WithFields(logrus.Fields{ + "action": "bootstrap", + "leader": leader, + }).Info("successfully joined cluster") return nil } if voter { // notify other servers about readiness of this node to be joined if err := b.notify(ctx, servers); err != nil { - lg.WithField("servers", servers).WithError(err).Error("notify all peers") + lg.WithFields(logrus.Fields{ + "action": "bootstrap", + "servers": servers, + }).WithError(err).Error("notify all peers") + } else { + lg.WithFields(logrus.Fields{ + "action": "bootstrap", + "servers": servers, + }).Info("notified peers this node is ready to join as voter") + return nil } } diff --git a/cluster/store/store.go b/cluster/store/store.go index 2d3dae3496c..18bee976399 100644 --- a/cluster/store/store.go +++ b/cluster/store/store.go @@ -767,7 +767,6 @@ func (st *Store) Remove(id string) error { // Notify signals this Store that a node is ready for bootstrapping at the specified address. // Bootstrapping will be initiated once the number of known nodes reaches the expected level, // which includes this node. - func (st *Store) Notify(id, addr string) (err error) { if !st.open.Load() { return ErrNotOpen @@ -783,9 +782,10 @@ func (st *Store) Notify(id, addr string) (err error) { st.candidates[id] = addr if len(st.candidates) < st.bootstrapExpect { st.log.WithFields(logrus.Fields{ + "action": "bootstrap", "expect": st.bootstrapExpect, "got": st.candidates, - }).Debug("number of candidates") + }).Debug("number of candidates lower than bootstrap expect param, stopping notify") return nil } candidates := make([]raft.Server, 0, len(st.candidates)) @@ -800,11 +800,14 @@ func (st *Store) Notify(id, addr string) (err error) { i++ } - st.log.WithField("candidates", candidates).Info("starting cluster bootstrapping") + st.log.WithFields(logrus.Fields{ + "action": "bootstrap", + "candidates": candidates, + }).Info("starting cluster bootstrapping") fut := st.raft.BootstrapCluster(raft.Configuration{Servers: candidates}) if err := fut.Error(); err != nil { - st.log.WithError(err).Error("bootstrapping cluster") + st.log.WithField("action", "bootstrap").WithError(err).Error("could not bootstrapping cluster") if !errors.Is(err, raft.ErrCantBootstrap) { return err }