Commit 9b289bf
authored
Robj/deadlock fix (#644)
This patch fixes two deadlocks, also enabling threads to perform updates to splinterdb while also performing asynchronous queries.
The first deadlock was caused by trunk_merge_lookup acquiring two locks on the root. This deadlock prone because, if another thread begins to GC the root, it will set the writer bit on the root lock and then wait for the readers to clear out. But, if the query code has already acquired its first read lock on the root and attempts to acquire its second read lock after the writer bit is set, then it will deadlock with the GC thread.
The fix is to acquire a lock on the root only once.
The second deadlock could occur when a thread performing asynchronous queries performs an update which results in a GC. In this case, one of the thread's async queries may hold a read lock on a node-to-be-GCed, but the GC code will wait forever for that read lock to be released, causing the thread to deadlock with itself.
The fix in this case is to defer GC until there are no more readers. So there's now a queue of GC tasks in the trunk context. Any time GC reaches a node with a read lock, it stops and puts that node on the queue. Every trunk modification checks the queue and processes any GCs that are now available to perform.1 parent 7fecf01 commit 9b289bf
6 files changed
+258
-146
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
171 | | - | |
| 172 | + | |
| 173 | + | |
172 | 174 | | |
173 | 175 | | |
174 | 176 | | |
| |||
552 | 554 | | |
553 | 555 | | |
554 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
555 | 571 | | |
556 | 572 | | |
557 | 573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1480 | 1480 | | |
1481 | 1481 | | |
1482 | 1482 | | |
1483 | | - | |
| 1483 | + | |
1484 | 1484 | | |
1485 | 1485 | | |
1486 | 1486 | | |
| |||
1697 | 1697 | | |
1698 | 1698 | | |
1699 | 1699 | | |
1700 | | - | |
| 1700 | + | |
1701 | 1701 | | |
1702 | 1702 | | |
1703 | | - | |
| 1703 | + | |
1704 | 1704 | | |
1705 | 1705 | | |
1706 | 1706 | | |
| |||
1917 | 1917 | | |
1918 | 1918 | | |
1919 | 1919 | | |
1920 | | - | |
| 1920 | + | |
1921 | 1921 | | |
1922 | 1922 | | |
1923 | | - | |
| 1923 | + | |
1924 | 1924 | | |
1925 | 1925 | | |
1926 | 1926 | | |
| |||
2680 | 2680 | | |
2681 | 2681 | | |
2682 | 2682 | | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
2683 | 2698 | | |
2684 | 2699 | | |
2685 | 2700 | | |
| |||
2896 | 2911 | | |
2897 | 2912 | | |
2898 | 2913 | | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
2899 | 2921 | | |
2900 | 2922 | | |
2901 | 2923 | | |
| |||
3010 | 3032 | | |
3011 | 3033 | | |
3012 | 3034 | | |
| 3035 | + | |
3013 | 3036 | | |
3014 | 3037 | | |
3015 | 3038 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
| |||
169 | 172 | | |
170 | 173 | | |
171 | 174 | | |
| 175 | + | |
| 176 | + | |
172 | 177 | | |
173 | 178 | | |
174 | 179 | | |
| |||
1259 | 1264 | | |
1260 | 1265 | | |
1261 | 1266 | | |
1262 | | - | |
1263 | 1267 | | |
1264 | 1268 | | |
1265 | 1269 | | |
| |||
1339 | 1343 | | |
1340 | 1344 | | |
1341 | 1345 | | |
1342 | | - | |
1343 | | - | |
1344 | | - | |
1345 | 1346 | | |
| 1347 | + | |
1346 | 1348 | | |
1347 | 1349 | | |
1348 | 1350 | | |
| |||
0 commit comments