mirror of
https://github.com/rqlite/rqlite.git
synced 2022-10-30 02:37:32 +03:00
Merge pull request #860 from rqlite/query-strong-check
Perform leader check first for STRONG query
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user