Commit 4931e83
committed
feat(persistence): implement optimistic concurrency control with CAS
Adds Compare-And-Swap (CAS) based optimistic concurrency control to
prevent lost updates in concurrent modification scenarios. This
implements client-driven CAS for update operations and proper atomic
create protection.
Database Changes:
- Add resource_version field to ObjectMeta proto message
- Add resource_version column to objects table (migration 005)
- Implement update_message_cas for single-attempt versioned updates
- Add WriteCondition::MatchResourceVersion for CAS enforcement
- Add PersistenceError::Conflict for version mismatch detection
Protected Operations:
- AttachSandboxProvider: uses client-driven CAS with
expected_resource_version parameter
- DetachSandboxProvider: uses client-driven CAS with
expected_resource_version parameter
- UpdateProvider: extracts resource_version from Provider.metadata,
validates against current version
- UpdateConfig: uses client-driven CAS for policy backfill path
- CreateProvider: uses WriteCondition::MustCreate for atomic creation
- SSH session operations: proper CAS protection
CAS Modes:
- Client-driven (expected_version > 0): Client fetches resource,
uses its version for update. Conflict returns ABORTED status.
- Server-driven (expected_version = 0): Server uses current DB
version. Used for internal operations.
CLI Changes:
- Update attach/detach operations to fetch sandbox first and use
its resource_version for CAS protection
- Add clear error messages for ABORTED status on CAS conflicts
- Add expected_resource_version: 0 to all UpdateConfig requests
Testing:
- 12 integration tests for concurrent modification scenarios
- Tests verify ABORTED status on version conflicts
- Coverage for all protected operations
Documentation:
- Update architecture/gateway.md with CAS design and semantics
- Document expected_version parameter modes
- List all client-driven CAS operations
Signed-off-by: Derek Carr <decarr@redhat.com>1 parent 52c7757 commit 4931e83
29 files changed
Lines changed: 3750 additions & 286 deletions
File tree
- architecture
- crates
- openshell-cli
- src
- tests
- openshell-core/src
- openshell-sandbox/src
- openshell-server
- migrations
- postgres
- sqlite
- src
- compute
- grpc
- persistence
- openshell-tui/src
- proto
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
116 | 168 | | |
117 | 169 | | |
118 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2279 | 2279 | | |
2280 | 2280 | | |
2281 | 2281 | | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
2282 | 2287 | | |
2283 | 2288 | | |
2284 | 2289 | | |
| |||
2888 | 2893 | | |
2889 | 2894 | | |
2890 | 2895 | | |
2891 | | - | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
2892 | 2911 | | |
2893 | 2912 | | |
2894 | 2913 | | |
| 2914 | + | |
2895 | 2915 | | |
2896 | 2916 | | |
2897 | | - | |
2898 | | - | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
2899 | 2928 | | |
2900 | 2929 | | |
2901 | 2930 | | |
| |||
2917 | 2946 | | |
2918 | 2947 | | |
2919 | 2948 | | |
2920 | | - | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
2921 | 2964 | | |
2922 | 2965 | | |
2923 | 2966 | | |
| 2967 | + | |
2924 | 2968 | | |
2925 | 2969 | | |
2926 | | - | |
2927 | | - | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
2928 | 2981 | | |
2929 | 2982 | | |
2930 | 2983 | | |
| |||
3259 | 3312 | | |
3260 | 3313 | | |
3261 | 3314 | | |
| 3315 | + | |
3262 | 3316 | | |
3263 | 3317 | | |
3264 | 3318 | | |
| |||
3299 | 3353 | | |
3300 | 3354 | | |
3301 | 3355 | | |
| 3356 | + | |
3302 | 3357 | | |
3303 | 3358 | | |
3304 | 3359 | | |
| |||
3711 | 3766 | | |
3712 | 3767 | | |
3713 | 3768 | | |
| 3769 | + | |
3714 | 3770 | | |
3715 | 3771 | | |
3716 | 3772 | | |
| |||
3755 | 3811 | | |
3756 | 3812 | | |
3757 | 3813 | | |
| 3814 | + | |
| 3815 | + | |
| 3816 | + | |
| 3817 | + | |
| 3818 | + | |
3758 | 3819 | | |
3759 | 3820 | | |
3760 | 3821 | | |
| |||
4211 | 4272 | | |
4212 | 4273 | | |
4213 | 4274 | | |
| 4275 | + | |
4214 | 4276 | | |
4215 | 4277 | | |
4216 | 4278 | | |
| |||
4765 | 4827 | | |
4766 | 4828 | | |
4767 | 4829 | | |
| 4830 | + | |
4768 | 4831 | | |
4769 | 4832 | | |
4770 | 4833 | | |
| |||
4963 | 5026 | | |
4964 | 5027 | | |
4965 | 5028 | | |
| 5029 | + | |
4966 | 5030 | | |
4967 | 5031 | | |
4968 | 5032 | | |
| |||
4997 | 5061 | | |
4998 | 5062 | | |
4999 | 5063 | | |
| 5064 | + | |
5000 | 5065 | | |
5001 | 5066 | | |
5002 | 5067 | | |
| |||
5031 | 5096 | | |
5032 | 5097 | | |
5033 | 5098 | | |
| 5099 | + | |
5034 | 5100 | | |
5035 | 5101 | | |
5036 | 5102 | | |
| |||
5065 | 5131 | | |
5066 | 5132 | | |
5067 | 5133 | | |
| 5134 | + | |
5068 | 5135 | | |
5069 | 5136 | | |
5070 | 5137 | | |
| |||
5123 | 5190 | | |
5124 | 5191 | | |
5125 | 5192 | | |
| 5193 | + | |
5126 | 5194 | | |
5127 | 5195 | | |
5128 | 5196 | | |
| |||
5297 | 5365 | | |
5298 | 5366 | | |
5299 | 5367 | | |
| 5368 | + | |
5300 | 5369 | | |
5301 | 5370 | | |
5302 | 5371 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
| 381 | + | |
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
| |||
Lines changed: 22 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
117 | 133 | | |
118 | 134 | | |
119 | 135 | | |
| |||
183 | 199 | | |
184 | 200 | | |
185 | 201 | | |
186 | | - | |
| 202 | + | |
187 | 203 | | |
188 | 204 | | |
189 | 205 | | |
| |||
220 | 236 | | |
221 | 237 | | |
222 | 238 | | |
223 | | - | |
| 239 | + | |
224 | 240 | | |
225 | 241 | | |
226 | 242 | | |
| |||
475 | 491 | | |
476 | 492 | | |
477 | 493 | | |
| 494 | + | |
478 | 495 | | |
479 | 496 | | |
480 | 497 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| 144 | + | |
143 | 145 | | |
144 | 146 | | |
145 | 147 | | |
| |||
354 | 356 | | |
355 | 357 | | |
356 | 358 | | |
| 359 | + | |
357 | 360 | | |
358 | 361 | | |
359 | 362 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
0 commit comments