Fix partial cache invalidation for data changes

The partial cache was not be invalidated when data changed. As a result,
callers would receive stale results when data updated.

Fixes #589

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
Torin Sandall
2018-06-04 09:46:00 -07:00
parent 17e7eed776
commit c19e342fbe
2 changed files with 29 additions and 3 deletions
-3
View File
@@ -484,9 +484,6 @@ func (s *Server) reload(ctx context.Context, txn storage.Transaction, event stor
}
}
if !event.PolicyChanged() {
return
}
s.partials = map[string]rego.PartialResult{}
}
+29
View File
@@ -228,6 +228,23 @@ p = true { false }`
q[2] { input.y = 2 }
r[1] { input.z = 3 }`
testMod7Modified := `package testmod
default p = false
p { q[x]; not r[x] }
q[1] { input.x = 1 }
q[2] { input.y = 2 }
r[1] { input.z = 3 }
r[2] { input.z = 3 }`
testMod8 := `package testmod
p {
data.x = 1
}`
tests := []struct {
note string
reqs []tr
@@ -396,6 +413,18 @@ p = true { false }`
tr{http.MethodPost, "/data/testmod/p", `{"input": {"x": 1, "y": 2, "z": 9999}}`, 200, `{"result": true}`},
tr{http.MethodPost, "/data/testmod/p", `{"input": {"x": 1, "z": 3}}`, 200, `{"result": false}`},
}},
{"partial invalidate policy", []tr{
tr{http.MethodPut, "/policies/test", testMod7, 200, ""},
tr{http.MethodPost, "/data/testmod/p?partial", `{"input": {"x": 1, "y": 2, "z": 3}}`, 200, `{"result": true}`},
tr{http.MethodPut, "/policies/test", testMod7Modified, 200, ""},
tr{http.MethodPost, "/data/testmod/p?partial", `{"input": {"x": 1, "y": 2, "z": 3}}`, 200, `{"result": false}`},
}},
{"partial invalidate data", []tr{
tr{http.MethodPut, "/policies/test", testMod8, 200, ""},
tr{http.MethodPost, "/data/testmod/p?partial", "", 200, `{}`},
tr{http.MethodPut, "/data/x", `1`, 204, ""},
tr{http.MethodPost, "/data/testmod/p?partial", "", 200, `{"result": true}`},
}},
{"evaluation conflict", []tr{
tr{http.MethodPut, "/policies/test", testMod4, 200, ""},
tr{http.MethodPost, "/data/testmod/p", "", 500, `{