1
0
Fork 0

Small refactor of Stale Reads check

master
Philip O'Toole 8 months ago
parent be5eb8eb65
commit dbc4f2b63b

@ -2,6 +2,7 @@
### Implementation changes and bug fixes ### Implementation changes and bug fixes
- [PR #1670](https://github.com/rqlite/rqlite/pull/1670): Improve error message when query on remote node fails. - [PR #1670](https://github.com/rqlite/rqlite/pull/1670): Improve error message when query on remote node fails.
- [PR #1671](https://github.com/rqlite/rqlite/pull/1670): Minor optimizations to Unified Request processing. - [PR #1671](https://github.com/rqlite/rqlite/pull/1670): Minor optimizations to Unified Request processing.
- [PR #1674](https://github.com/rqlite/rqlite/pull/1674): Small refactor of _Stale Reads_ check.
## 8.19.0 (February 3rd 2024) ## 8.19.0 (February 3rd 2024)
This release allows you to set a maximum amount of a time a query will run. If the query does not complete within the set time, an error will be returned. This release allows you to set a maximum amount of a time a query will run. If the query does not complete within the set time, an error will be returned.

@ -1138,8 +1138,7 @@ func (s *Store) Query(qr *proto.QueryRequest) ([]*proto.QueryRows, error) {
return nil, ErrNotLeader return nil, ErrNotLeader
} }
if s.raft.State() != raft.Leader && qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE && if qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE && s.isStaleRead(qr.Freshness) {
qr.Freshness > 0 && time.Since(s.raft.LastContact()).Nanoseconds() > qr.Freshness {
return nil, ErrStaleRead return nil, ErrStaleRead
} }
@ -1179,11 +1178,8 @@ func (s *Store) Request(eqr *proto.ExecuteQueryRequest) ([]*proto.ExecuteQueryRe
} }
return resp return resp
} }
if eqr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE { if eqr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE && s.isStaleRead(eqr.Freshness) {
if !isLeader && eqr.Freshness > 0 && return nil, ErrStaleRead
time.Since(s.raft.LastContact()).Nanoseconds() > eqr.Freshness {
return nil, ErrStaleRead
}
} else if eqr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK { } else if eqr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK {
if !isLeader { if !isLeader {
return nil, ErrNotLeader return nil, ErrNotLeader
@ -1806,6 +1802,13 @@ func (s *Store) updateAppliedIndex() chan struct{} {
return done return done
} }
func (s *Store) isStaleRead(freshness int64) bool {
if freshness == 0 || s.raft.State() == raft.Leader {
return false
}
return time.Since(s.raft.LastContact()).Nanoseconds() > freshness
}
type fsmExecuteResponse struct { type fsmExecuteResponse struct {
results []*proto.ExecuteResult results []*proto.ExecuteResult
error error error error

Loading…
Cancel
Save