Commutativity specifications for HTTP, S3 and the Kubernetes API #
World.lean proves psync's schedule correct against any server, relative to a commutativity
specification that is Sound for that server. This file gives three servers as explicit models and
proves a specification sound for each, together with the places where a plausible rule fails.
- HTTP (RFC 9110). Resources on a tree of paths.
GET,HEADand listing a collection are safe (§9.2.1: they do not change the resource state);PUTandDELETEchange their target only. The spec: two safe requests commute, and so do two requests whose targets are apart (neither is a prefix of the other, psync's rule for paths). Idempotent is not commutative: two identicalPUTs leave the same state, but the first answers201 Createdand the second200 OK, so they do not commute (http_put_twice_not_commute). - S3 (without versioning; strongly consistent, as S3 is since 2020). The same, and since an
object's ETag depends only on its body and
DeleteObjectanswers204whether or not the key existed, two identicalPUTs commute, and so do two identicalDELETEs. - Kubernetes. Every write gets the next value of one global counter, the
resourceVersion, and returns it. So two writes to different objects do not commute: their resourceVersions depend on the order (kube_writes_not_commute). They commute for a client that does not use resourceVersion values (kube_commutes_up_to_rv): the server with resourceVersions erased is a simulation of the real one, and the spec is sound for it.
The models are the stated assumptions: one copy of the state, applied request by request
(linearizable), no versioning, lifecycle rules or admission webhooks, and POST with an effect the
model does not fix (HReq.post), which no spec lets commute with anything.
Notation used in the theorem statements #
- $\mathrm{Commutes}(T, a, b)$: in every state, $a;b$ and $b;a$ end in the same server state and
give each request the response it gets when run first (
World.lean). - $\mathrm{Sound}(T, \mathit{spec})$: every pair the spec allows commutes.
- $p \sqsubseteq q$: path $p$ is a prefix of $q$; $p \mathrel{\#} q$ (
apart): neither is a prefix of the other. - $\mathrm{erase}$: a Kubernetes state or response with every resourceVersion removed.
Paths #
A path: interned segments (/a/b is [a, b]).
Equations
Instances For
Neither path is a prefix of the other, so no request on one can see or change the other.
Equations
- PsyncSpecs.apart p q = (PsyncFootprint.lpre p q = false ∧ PsyncFootprint.lpre q p = false)
Instances For
$$p \mathrel{\#} q \implies p \neq q$$
$$p \mathrel{\#} q \implies q \mathrel{\#} p$$
Set k to v.
Instances For
$$p \neq q \implies f[p \mapsto a][q \mapsto b] = f[q \mapsto b][p \mapsto a]$$
$$q \neq p \implies f[p \mapsto a](q) = f(q)$$
$$f[p \mapsto a][p \mapsto b] = f[p \mapsto b]$$
HTTP #
The server's state: a body per path.
Equations
Instances For
An HTTP server, given what POST does. Everything else is RFC 9110's meaning.
Equations
- PsyncSpecs.http post (PsyncSpecs.HReq.get p) x✝ = (x✝, PsyncSpecs.HRsp.body (x✝ p))
- PsyncSpecs.http post (PsyncSpecs.HReq.head p) x✝ = (x✝, PsyncSpecs.HRsp.exists_ (x✝ p).isSome)
- PsyncSpecs.http post (PsyncSpecs.HReq.list p) x✝ = (x✝, PsyncSpecs.HRsp.listing (PsyncSpecs.below x✝ p))
- PsyncSpecs.http post (PsyncSpecs.HReq.put p b) x✝ = (PsyncSpecs.upd x✝ p (some b), PsyncSpecs.HRsp.exists_ (x✝ p).isSome)
- PsyncSpecs.http post (PsyncSpecs.HReq.delete p) x✝ = (PsyncSpecs.upd x✝ p none, PsyncSpecs.HRsp.exists_ (x✝ p).isSome)
- PsyncSpecs.http post (PsyncSpecs.HReq.post p) x✝ = ((post p x✝).fst, PsyncSpecs.HRsp.other (post p x✝).snd)
Instances For
Safe methods (RFC 9110 §9.2.1).
Equations
- (PsyncSpecs.HReq.get p).safe = True
- (PsyncSpecs.HReq.head p).safe = True
- (PsyncSpecs.HReq.list p).safe = True
- x✝.safe = False
Instances For
The path a request is about.
Equations
- (PsyncSpecs.HReq.get p).tgt = p
- (PsyncSpecs.HReq.head p).tgt = p
- (PsyncSpecs.HReq.list p).tgt = p
- (PsyncSpecs.HReq.put p body).tgt = p
- (PsyncSpecs.HReq.delete p).tgt = p
- (PsyncSpecs.HReq.post p).tgt = p
Instances For
$$\forall\, \mathit{post},\ \mathrm{Sound}(\mathrm{http}(\mathit{post}), \mathrm{httpSpec})$$
The HTTP spec is sound, whatever POST does.
$$\neg\,\mathrm{Commutes}(\mathrm{http}(\mathit{post}), \mathrm{PUT}\,p\,b, \mathrm{PUT}\,p\,b)$$
Idempotent is not commutative. Two identical PUTs end in the same state, but the second
answers "existed" (200) where the first, run alone on an empty server, answers 201.
S3 #
Equations
- PsyncSpecs.s3 (PsyncSpecs.S3Req.get k) x✝ = (x✝, PsyncSpecs.S3Rsp.body (x✝ k))
- PsyncSpecs.s3 (PsyncSpecs.S3Req.head k) x✝ = (x✝, PsyncSpecs.S3Rsp.found (x✝ k).isSome)
- PsyncSpecs.s3 (PsyncSpecs.S3Req.list p) x✝ = (x✝, PsyncSpecs.S3Rsp.listing (PsyncSpecs.below x✝ p))
- PsyncSpecs.s3 (PsyncSpecs.S3Req.put k b) x✝ = (PsyncSpecs.upd x✝ k (some b), PsyncSpecs.S3Rsp.etag b)
- PsyncSpecs.s3 (PsyncSpecs.S3Req.delete k) x✝ = (PsyncSpecs.upd x✝ k none, PsyncSpecs.S3Rsp.noContent)
Instances For
Equations
- (PsyncSpecs.S3Req.get k).safe = True
- (PsyncSpecs.S3Req.head k).safe = True
- (PsyncSpecs.S3Req.list p).safe = True
- x✝.safe = False
Instances For
Equations
- (PsyncSpecs.S3Req.get k).tgt = k
- (PsyncSpecs.S3Req.head k).tgt = k
- (PsyncSpecs.S3Req.list k).tgt = k
- (PsyncSpecs.S3Req.put k body).tgt = k
- (PsyncSpecs.S3Req.delete k).tgt = k
Instances For
$$\mathrm{Sound}(\mathrm{s3}, \mathrm{s3Spec})$$
The S3 spec is sound, including identical PUTs and identical DELETEs.
$$b \neq b' \implies \neg\,\mathrm{Commutes}(\mathrm{s3}, \mathrm{PUT}\,k\,b, \mathrm{PUT}\,k\,b')$$
Two PUTs of different bodies to one key do not commute: the last one wins.
Kubernetes #
An object: namespace and name.
Equations
- PsyncSpecs.KKey = (Nat × Nat)
Instances For
Every write takes the next resourceVersion.
Equations
- PsyncSpecs.kube (PsyncSpecs.KReq.get k) x✝ = (x✝, PsyncSpecs.KRsp.obj (x✝.objs k))
- PsyncSpecs.kube (PsyncSpecs.KReq.list ns) x✝ = (x✝, PsyncSpecs.KRsp.objs (PsyncSpecs.inNs x✝.objs ns) x✝.rev)
- PsyncSpecs.kube (PsyncSpecs.KReq.apply k v) x✝ = ({ objs := PsyncSpecs.upd x✝.objs k (some (v, x✝.rev + 1)), rev := x✝.rev + 1 }, PsyncSpecs.KRsp.rv (x✝.rev + 1))
- PsyncSpecs.kube (PsyncSpecs.KReq.delete k) x✝ = ({ objs := PsyncSpecs.upd x✝.objs k none, rev := x✝.rev + 1 }, PsyncSpecs.KRsp.rv (x✝.rev + 1))
Instances For
Instances For
$$\mathrm{Sound}(\mathrm{kube}, \mathrm{both\ reads})$$
Two reads commute, exactly.
$$\neg\,\mathrm{Commutes}(\mathrm{kube}, \mathrm{apply}\,(0,0)\,1, \mathrm{apply}\,(0,1)\,1)$$
Writes to different objects do not commute: whichever runs first gets the lower resourceVersion. psync's built-in rule (different targets commute) is therefore unsound for a client that reads resourceVersions.
Without resourceVersions #
Equations
- PsyncSpecs.erase s k = Option.map Prod.fst (s.objs k)
Instances For
Equations
Instances For
The API server without resourceVersions: a key-value store with namespaces.
Equations
- PsyncSpecs.kubeObs (PsyncSpecs.KReq.get k) x✝ = (x✝, PsyncSpecs.ORsp.obj (x✝ k))
- PsyncSpecs.kubeObs (PsyncSpecs.KReq.list ns) x✝ = (x✝, PsyncSpecs.ORsp.objs (PsyncSpecs.inNs x✝ ns))
- PsyncSpecs.kubeObs (PsyncSpecs.KReq.apply k v) x✝ = (PsyncSpecs.upd x✝ k (some v), PsyncSpecs.ORsp.done)
- PsyncSpecs.kubeObs (PsyncSpecs.KReq.delete k) x✝ = (PsyncSpecs.upd x✝ k none, PsyncSpecs.ORsp.done)
Instances For
$$\mathrm{erase}(\mathrm{kube}(l, s)) = \mathrm{kubeObs}(l, \mathrm{erase}(s))$$
Simulation. Erasing resourceVersions commutes with every request, in the state and in the response.
Equations
- (PsyncSpecs.KReq.apply k v).key = some k
- (PsyncSpecs.KReq.delete k).key = some k
- (PsyncSpecs.KReq.get k).key = some k
- (PsyncSpecs.KReq.list ns).key = none
Instances For
Equations
- (PsyncSpecs.KReq.apply k v).ns = k.fst
- (PsyncSpecs.KReq.delete k).ns = k.fst
- (PsyncSpecs.KReq.get k).ns = k.fst
- (PsyncSpecs.KReq.list ns).ns = ns
Instances For
The spec for clients that ignore resourceVersions: two reads, or two requests that cannot see each other: different objects, and a listing never in the namespace of a write.
Equations
- One or more equations did not get rendered due to their size.
Instances For
$$\mathrm{Sound}(\mathrm{kubeObs}, \mathrm{kubeSpec})$$
$$\mathrm{kubeSpec}(a, b) \implies \forall s,\ \mathrm{erase}(s \cdot a \cdot b) = \mathrm{erase}(s \cdot b \cdot a) \,\wedge\, \text{responses agree after erasing}$$
Kubernetes requests the spec allows commute up to resourceVersions: in either order, the objects end the same, and every response is the same as when the request runs first, once resourceVersions are erased.