1
0
Fork 0

Merge pull request #1384 from rqlite/leader-id-addr

Use non-racy function for Leader ID and address
master
Philip O'Toole 1 year ago committed by GitHub
commit a3a8017fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,6 +30,7 @@ When officially released 8.0 will support (mostly) seamless upgrades from the 7.
- [PR #1377](https://github.com/rqlite/rqlite/pull/1377): Automatically upgrade 7.x snapshots.
- [PR #1380](https://github.com/rqlite/rqlite/pull/1380): Compress snapshots when transmitting over the network.
- [PR #1382](https://github.com/rqlite/rqlite/pull/1382), [PR #1383](https://github.com/rqlite/rqlite/pull/1383): Add basic stats for Snapshot store.
= [PR #1384](https://github.com/rqlite/rqlite/pull/1384): Use less-racy function to retrieve Leader Address and ID.
## 7.21.4 (July 8th 2023)
### Implementation changes and bug fixes

@ -686,22 +686,21 @@ func (s *Store) LeaderAddr() (string, error) {
// LeaderID returns the node ID of the Raft leader. Returns a
// blank string if there is no leader, or an error.
func (s *Store) LeaderID() (string, error) {
addr, err := s.LeaderAddr()
if err != nil {
if !s.open {
return "", nil
}
configFuture := s.raft.GetConfiguration()
if err := configFuture.Error(); err != nil {
s.logger.Printf("failed to get raft configuration: %v", err)
return "", err
}
_, id := s.raft.LeaderWithID()
return string(id), nil
}
for _, srv := range configFuture.Configuration().Servers {
if srv.Address == raft.ServerAddress(addr) {
return string(srv.ID), nil
}
// LeaderWithID is used to return the current leader address and ID of the cluster.
// It may return empty strings if there is no current leader or the leader is unknown.
func (s *Store) LeaderWithID() (string, string) {
if !s.open {
return "", ""
}
return "", nil
addr, id := s.raft.LeaderWithID()
return string(addr), string(id)
}
// Nodes returns the slice of nodes in the cluster, sorted by ID ascending.
@ -857,10 +856,7 @@ func (s *Store) Stats() (map[string]interface{}, error) {
if err != nil {
return nil, err
}
leaderID, err := s.LeaderID()
if err != nil {
return nil, err
}
leaderID, leaderAddr := s.LeaderWithID()
// Perform type-conversion to actual numbers where possible.
raftStats := make(map[string]interface{})
@ -891,10 +887,6 @@ func (s *Store) Stats() (map[string]interface{}, error) {
return nil, err
}
leaderAddr, err := s.LeaderAddr()
if err != nil {
return nil, err
}
lAppliedIdx, err := s.boltStore.GetAppliedIndex()
if err != nil {
return nil, err

Loading…
Cancel
Save