func (d *discoverdSimulator) SetClusterState(s *state.DiscoverdState) { d.Lock() defer d.Unlock() if d.state.Index != s.Index { panic(fmt.Sprintf("incorrect state index, have %d, want %d", s.Index, d.state.Index)) } d.state.Index++ d.state.State = s.State.Clone() s.Index = d.state.Index for _, c := range d.clients { go c.notifyStateChanged() } }
func (d *Discoverd) SetState(state *state.DiscoverdState) error { data, err := json.Marshal(state.State) if err != nil { return err } meta := &discoverd.ServiceMeta{Index: state.Index, Data: data} if err := d.service.SetMeta(meta); err != nil { return err } state.Index = meta.Index if state.State.Primary != nil { if err := d.service.SetLeader(state.State.Primary.ID); err != nil { d.log.Error("error setting discoverd leader", "id", state.State.Primary.ID, "err", err) // TODO(titanous): can we do anything about this? } } return nil }