1
0
Fork 0

Merge pull request #1649 from rqlite/otoolep-request-leader-check-none

Add Leader check to /db/request when using NONE
master
Philip O'Toole 8 months ago committed by GitHub
commit fabd16703f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,6 +2,7 @@
### Implementation changes and bug fixes
- [PR #1646](https://github.com/rqlite/rqlite/pull/1646): Expose BUSY TIMEOUT on /status.
- [PR #1647](https://github.com/rqlite/rqlite/pull/1647): More CHECKPOINT test coverage.
- [PR #1649](https://github.com/rqlite/rqlite/pull/1649): Check Leader when handling `/db/request` with _None_ read consistency. Fixes issue [#1648](https://github.com/rqlite/rqlite/issues/1648).
## 8.18.4 (January 30th 2024)
### Implementation changes and bug fixes

@ -1177,7 +1177,8 @@ func (s *Store) Request(eqr *proto.ExecuteQueryRequest) ([]*proto.ExecuteQueryRe
}
if eqr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE {
if eqr.Freshness > 0 && time.Since(s.raft.LastContact()).Nanoseconds() > eqr.Freshness {
if s.raft.State() != raft.Leader && eqr.Freshness > 0 &&
time.Since(s.raft.LastContact()).Nanoseconds() > eqr.Freshness {
return nil, ErrStaleRead
}
qr, err := s.db.Query(eqr.Request, eqr.Timings)

@ -1128,6 +1128,7 @@ func Test_SingleNodeExecuteQueryFreshness(t *testing.T) {
if err != nil {
t.Fatalf("failed to wait for fsmIndex: %s", err.Error())
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Freshness = mustParseDuration("1ns").Nanoseconds()
@ -1141,6 +1142,17 @@ func Test_SingleNodeExecuteQueryFreshness(t *testing.T) {
if exp, got := `[[1,"fiona"]]`, asJSON(r[0].Values); exp != got {
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
}
rr := executeQueryRequestFromString("SELECT * FROM foo", proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
false, false)
rr.Freshness = mustParseDuration("1ns").Nanoseconds()
eqr, err := s0.Request(rr)
if err != nil {
t.Fatalf("failed to query leader node: %s", err.Error())
}
if exp, got := `[{"columns":["id","name"],"types":["integer","text"],"values":[[1,"fiona"]]}]`, asJSON(eqr); exp != got {
t.Fatalf("unexpected results for request\nexp: %s\ngot: %s", exp, got)
}
}
// Test_SingleNodeBackup tests that a Store correctly backs up its data

Loading…
Cancel
Save