Repository navigation
Commit fd91c62
authored
perf(knowledge): lock the knowledge base row FOR NO KEY UPDATE on document writes (#8909)
* perf(knowledge): lock the knowledge base row FOR NO KEY UPDATE on document writes
Document uploads, document hard deletes, connector creation, and knowledge
base restore locked the parent knowledge_base row FOR UPDATE. Every embedding
insert takes FOR KEY SHARE on that row through its foreign key and holds it
for the whole indexing transaction, and FOR UPDATE conflicts with KEY SHARE,
so these writes queued behind any indexing pass in the same knowledge base
(and vice versa). A hard delete could also deadlock against an indexing pass
on one of its own documents.
FOR NO KEY UPDATE still conflicts with itself, FOR SHARE (connector sync
saves and completion), FOR UPDATE (KB moves, tag mutations), and the
UPDATE/DELETE of the row, so every serialization these locks provided is
kept. No path under these locks writes knowledge_base.id, the only key
column (the other unique indexes are partial). This matches soft deletion
and connector cleanup, which already use FOR NO KEY UPDATE.
* test(knowledge): uploads and hard deletes commit while an embedding holds the KB key-share lock1 parent 5551eb6 commit fd91c62
4 files changed
Lines changed: 89 additions & 6 deletions
File tree
- apps/sim/lib/knowledge
- __integration__
- documents
- orchestration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
88 | 93 | | |
89 | 94 | | |
90 | 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 | + | |
91 | 132 | | |
92 | 133 | | |
93 | 134 | | |
| |||
229 | 270 | | |
230 | 271 | | |
231 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
232 | 300 | | |
233 | 301 | | |
234 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2546 | 2546 | | |
2547 | 2547 | | |
2548 | 2548 | | |
2549 | | - | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
2550 | 2558 | | |
2551 | 2559 | | |
2552 | 2560 | | |
| |||
3229 | 3237 | | |
3230 | 3238 | | |
3231 | 3239 | | |
3232 | | - | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
3233 | 3243 | | |
3234 | 3244 | | |
3235 | 3245 | | |
| |||
4332 | 4342 | | |
4333 | 4343 | | |
4334 | 4344 | | |
| 4345 | + | |
| 4346 | + | |
| 4347 | + | |
4335 | 4348 | | |
4336 | 4349 | | |
4337 | 4350 | | |
| |||
4351 | 4364 | | |
4352 | 4365 | | |
4353 | 4366 | | |
4354 | | - | |
| 4367 | + | |
4355 | 4368 | | |
4356 | 4369 | | |
4357 | 4370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
474 | | - | |
| 474 | + | |
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1136 | 1136 | | |
1137 | 1137 | | |
1138 | 1138 | | |
1139 | | - | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
1140 | 1142 | | |
1141 | 1143 | | |
1142 | 1144 | | |
| |||
0 commit comments