Skip to content

Commit

Permalink
make bootstrap return on successful notify
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Reyreaud <loic@weaviate.io>
  • Loading branch information
reyreaud-l committed May 8, 2024
1 parent a47564b commit 45216b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
24 changes: 21 additions & 3 deletions cluster/store/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
11 changes: 7 additions & 4 deletions cluster/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
}
Expand Down

0 comments on commit 45216b1

Please sign in to comment.