Merge pull request #860 from rqlite/query-strong-check

Perform leader check first for STRONG query
This commit is contained in:
Philip O'Toole
2021-08-17 09:21:24 -04:00
committed by GitHub

View File

@@ -627,6 +627,10 @@ func (s *Store) execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, e
// Query executes queries that return rows, and do not modify the database. // Query executes queries that return rows, and do not modify the database.
func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) { func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG { if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
if s.raft.State() != raft.Leader {
return nil, ErrNotLeader
}
b, compressed, err := s.reqMarshaller.Marshal(qr) b, compressed, err := s.reqMarshaller.Marshal(qr)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -672,8 +676,7 @@ func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
return nil, ErrStaleRead return nil, ErrStaleRead
} }
rows, err := s.db.Query(qr.Request, qr.Timings) return s.db.Query(qr.Request, qr.Timings)
return rows, err
} }
// Backup writes a snapshot of the underlying database to dst // Backup writes a snapshot of the underlying database to dst