Commit 6316aa6
committed
fixes lack of idempotency in WriteToSpiceDB
I started all of this because of flakes that were trivially
to reproduce, and the underlying issue was WriteToSpiceDB was not idempotent.
It was used by both the optimistic and pesimistic locking workflows, and
the lack of idempotency meant the workflows couldn't recover
by themselves from transient errors. When the tests failed
for the wrong reasons, they flaked.
We introduced `failpoints` as a mechanism to simulate panics
similar to hardware or network failures. However, some recent
changes meant the failpoints were no longer unique and
were causing failures _in the wrong places_.
- when the pessimistic wrote an exclusive lock, retrying it due to
failure wouldn't work, because the precondition prevented it
(_make sure no one has a lock on this resource_!)
- when the optimistic wrote with CREATE semantics, a
subsequent retry after a successful write due to failure
response failure would fail because the tuples already exist.
This commit proposes making WriteToSpiceDB truly idempotent by
introducing idempotency keys in the SpiceDB schema. All writes
will include a relationships that identify the workflow and the hash
of the payload as the idempotency key.
The flow is as follows:
- perform write
- if failure happens, check if idempotency key was written in previous request
- if exists, assume operation was successful
- if it does not, bubble up the error
The cost of the extra ReadRelationships is only paid in the even of a retry
due to a failure.
The tests were written with the assumption that the system would bubble up
errors after recovery. This goes against the expectations of a durable
workflow engine, which embraces idempotency and is expected to retry
on errors, rather than have the client retry, unless those are unrecoverable.
This was all by design: the workflow wouldn't be responsible to retry things, but rather
execute compensatory operations after an operation failed. This meant
the client had to retry those errors, and it turns out troubleshooting
what happened on a transient error is not that trivial for folks
building on top of the spicedb-kubeapi-proxy.1 parent 6b04cf9 commit 6316aa6
File tree
4 files changed
+129
-46
lines changed- e2e
- pkg
- authz/distributedtx
- spicedb
4 files changed
+129
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
796 | | - | |
| 796 | + | |
797 | 797 | | |
798 | 798 | | |
799 | 799 | | |
800 | | - | |
801 | | - | |
| 800 | + | |
| 801 | + | |
802 | 802 | | |
803 | | - | |
804 | | - | |
805 | | - | |
| 803 | + | |
806 | 804 | | |
807 | | - | |
808 | | - | |
| 805 | + | |
| 806 | + | |
809 | 807 | | |
810 | | - | |
811 | | - | |
812 | | - | |
| 808 | + | |
| 809 | + | |
813 | 810 | | |
814 | 811 | | |
815 | 812 | | |
816 | 813 | | |
817 | 814 | | |
818 | 815 | | |
819 | 816 | | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
| 817 | + | |
824 | 818 | | |
825 | 819 | | |
826 | | - | |
| 820 | + | |
827 | 821 | | |
828 | 822 | | |
829 | 823 | | |
830 | 824 | | |
831 | 825 | | |
832 | 826 | | |
833 | | - | |
834 | | - | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
835 | 830 | | |
836 | 831 | | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
846 | 835 | | |
847 | 836 | | |
848 | 837 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | | - | |
| 43 | + | |
42 | 44 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
46 | 134 | | |
47 | 135 | | |
48 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| 313 | + | |
313 | 314 | | |
314 | | - | |
| 315 | + | |
315 | 316 | | |
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
319 | | - | |
| 320 | + | |
320 | 321 | | |
321 | | - | |
| 322 | + | |
322 | 323 | | |
323 | 324 | | |
324 | 325 | | |
| |||
342 | 343 | | |
343 | 344 | | |
344 | 345 | | |
345 | | - | |
| 346 | + | |
346 | 347 | | |
347 | 348 | | |
348 | 349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
0 commit comments