Documentation

Specs

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.

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 #

Paths #

@[reducible, inline]

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
    Instances For
      theorem PsyncSpecs.apart_ne {p q : Path} (h : apart p q) :
      p ≠ q

      $$p \mathrel{\#} q \implies p \neq q$$

      theorem PsyncSpecs.apart_symm {p q : Path} (h : apart p q) :
      apart q p

      $$p \mathrel{\#} q \implies q \mathrel{\#} p$$

      def PsyncSpecs.upd {α β : Type} [DecidableEq α] (f : α → β) (k : α) (v : β) :
      α → β

      Set k to v.

      Equations
      Instances For
        theorem PsyncSpecs.upd_comm {α β : Type} [DecidableEq α] {f : α → β} {p q : α} (h : p ≠ q) (a b : β) :
        upd (upd f p a) q b = upd (upd f q b) p a

        $$p \neq q \implies f[p \mapsto a][q \mapsto b] = f[q \mapsto b][p \mapsto a]$$

        theorem PsyncSpecs.upd_ne {α β : Type} [DecidableEq α] {f : α → β} {p q : α} (h : q ≠ p) (a : β) :
        upd f p a q = f q

        $$q \neq p \implies f[p \mapsto a](q) = f(q)$$

        theorem PsyncSpecs.upd_upd {α β : Type} [DecidableEq α] (f : α → β) (p : α) (a b : β) :
        upd (upd f p a) p b = upd f p b

        $$f[p \mapsto a][p \mapsto b] = f[p \mapsto b]$$

        def PsyncSpecs.below {β : Type} (f : Path → Option β) (p : Path) :
        Path → Option β

        The entries at or below p: what listing the collection p returns.

        Equations
        Instances For
          theorem PsyncSpecs.below_upd {β : Type} {f : Path → Option β} {p q : Path} (h : PsyncFootprint.lpre p q = false) (v : Option β) :
          below (upd f q v) p = below f p

          $$p \not\sqsubseteq q \implies \mathrm{below}(f[q \mapsto v], p) = \mathrm{below}(f, p)$$

          HTTP #

          An HTTP request. post p has an effect the server decides (HServer.post).

          Instances For

            A response: a body or its absence (404), a listing, or whether the target existed before (200/204 against 201/404).

            Instances For
              @[reducible, inline]

              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
                Instances For

                  Safe methods (RFC 9110 §9.2.1).

                  Equations
                  Instances For

                    The spec: two safe requests commute; so do two requests other than POST on paths apart.

                    Equations
                    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 #

                      An S3 request on keys (paths). list p is ListObjectsV2 with prefix p.

                      Instances For

                        A response. PutObject returns the ETag, a hash of the body (here the body itself); DeleteObject returns 204 whether the key existed or not.

                        Instances For

                          The spec: two reads; two requests on keys apart; or the same PUT or DELETE twice.

                          Equations
                          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 #

                            @[reducible, inline]

                            An object: namespace and name.

                            Equations
                            Instances For

                              The API server's state: each object's spec and resourceVersion, and the global counter.

                              Instances For
                                Instances For

                                  Responses carry resourceVersions: the object's, the list's, or the write's.

                                  Instances For
                                    def PsyncSpecs.inNs {β : Type} (f : KKey → Option β) (ns : Nat) :
                                    KKey → Option β
                                    Equations
                                    Instances For

                                      Every write takes the next resourceVersion.

                                      Equations
                                      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 #

                                        What a client sees that ignores resourceVersions.

                                        Instances For
                                          Equations
                                          Instances For
                                            theorem PsyncSpecs.kube_simulation (l : KReq) (s : KState) :
                                            erase (kube l s).fst = (kubeObs l (erase s)).fst ∧ eraseR (kube l s).snd = (kubeObs l (erase s)).snd

                                            $$\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.

                                            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
                                              theorem PsyncSpecs.inNs_upd {β : Type} {f : KKey → Option β} {ns : Nat} {k : KKey} (h : ns ≠ k.fst) (v : Option β) :
                                              inNs (upd f k v) ns = inNs f ns

                                              $$\mathrm{Sound}(\mathrm{kubeObs}, \mathrm{kubeSpec})$$

                                              theorem PsyncSpecs.kube_commutes_up_to_rv {a b : KReq} (h : kubeSpec a b) (s : KState) :
                                              erase (kube b (kube a s).fst).fst = erase (kube a (kube b s).fst).fst ∧ eraseR (kube a (kube b s).fst).snd = eraseR (kube a s).snd ∧ eraseR (kube b (kube a s).fst).snd = eraseR (kube b s).snd

                                              $$\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.