Commit be795b5
authored
chore(spanner): optimize lock contention and skipped tablet reporting (#12719)
## Summary
- **Replace `synchronized` with `ReadWriteLock` in `KeyRangeCache`** to
reduce lock contention on the hot path. Read operations (`findServer`,
`getActiveAddresses`, `size`, `debugString`) now take a read lock,
allowing concurrent lookups. Group updates are performed outside the
write lock to minimize critical section duration.
- **Move cache updates to an async executor** in `ChannelFinder` via
`updateAsync()`, using a sequential executor backed by a shared daemon
thread pool. This prevents `CacheUpdate` processing from blocking the
gRPC response listener thread.
- **Report skipped tablets for recently evicted TRANSIENT_FAILURE
endpoints.** Previously, when an endpoint was evicted after repeated
TRANSIENT_FAILURE probes and not yet recreated, its tablets were
silently skipped — the server never learned the client considered them
unhealthy. Now `EndpointLifecycleManager` tracks addresses evicted for
TRANSIENT_FAILURE and `KeyRangeCache` includes their tablet UIDs in
`skipped_tablets`, giving the server better routing visibility.
- **Deduplicate skipped tablet UIDs** to avoid reporting the same tablet
multiple times when it appears across replicas.
- **Report known TRANSIENT_FAILURE replicas** even when an earlier
healthy replica was already selected, so the server gets a complete
picture of unhealthy tablets for the group.
- Mark `CachedRange.lastAccess` as `volatile` for safe cross-thread
reads.1 parent 57baaea commit be795b5
File tree
7 files changed
+503
-42
lines changed- java-spanner/google-cloud-spanner/src
- main/java/com/google/cloud/spanner/spi/v1
- test/java/com/google/cloud/spanner/spi/v1
7 files changed
+503
-42
lines changedjava-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/ChannelFinder.java
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
50 | 60 | | |
51 | 61 | | |
52 | 62 | | |
53 | 63 | | |
54 | 64 | | |
| 65 | + | |
| 66 | + | |
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
| |||
77 | 89 | | |
78 | 90 | | |
79 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
80 | 108 | | |
81 | 109 | | |
82 | 110 | | |
| |||
112 | 140 | | |
113 | 141 | | |
114 | 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 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
115 | 186 | | |
116 | 187 | | |
117 | 188 | | |
| |||
Lines changed: 49 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| |||
95 | 102 | | |
96 | 103 | | |
97 | 104 | | |
| 105 | + | |
98 | 106 | | |
99 | 107 | | |
100 | 108 | | |
| |||
103 | 111 | | |
104 | 112 | | |
105 | 113 | | |
106 | | - | |
107 | | - | |
| 114 | + | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
187 | 195 | | |
188 | 196 | | |
189 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
190 | 216 | | |
191 | 217 | | |
192 | 218 | | |
| |||
235 | 261 | | |
236 | 262 | | |
237 | 263 | | |
| 264 | + | |
238 | 265 | | |
239 | 266 | | |
240 | 267 | | |
| |||
276 | 303 | | |
277 | 304 | | |
278 | 305 | | |
| 306 | + | |
279 | 307 | | |
280 | 308 | | |
281 | 309 | | |
| |||
412 | 440 | | |
413 | 441 | | |
414 | 442 | | |
| 443 | + | |
415 | 444 | | |
416 | 445 | | |
417 | 446 | | |
| |||
439 | 468 | | |
440 | 469 | | |
441 | 470 | | |
442 | | - | |
| 471 | + | |
443 | 472 | | |
444 | 473 | | |
445 | 474 | | |
446 | 475 | | |
447 | 476 | | |
448 | | - | |
| 477 | + | |
449 | 478 | | |
450 | 479 | | |
451 | 480 | | |
| |||
482 | 511 | | |
483 | 512 | | |
484 | 513 | | |
485 | | - | |
| 514 | + | |
486 | 515 | | |
487 | 516 | | |
488 | 517 | | |
489 | 518 | | |
490 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
491 | 525 | | |
492 | 526 | | |
493 | 527 | | |
494 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
495 | 534 | | |
496 | 535 | | |
497 | 536 | | |
| |||
526 | 565 | | |
527 | 566 | | |
528 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
529 | 572 | | |
530 | 573 | | |
531 | 574 | | |
| |||
558 | 601 | | |
559 | 602 | | |
560 | 603 | | |
| 604 | + | |
561 | 605 | | |
562 | 606 | | |
563 | 607 | | |
| |||
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
187 | 197 | | |
188 | 198 | | |
189 | 199 | | |
| |||
798 | 808 | | |
799 | 809 | | |
800 | 810 | | |
801 | | - | |
| 811 | + | |
802 | 812 | | |
803 | 813 | | |
804 | 814 | | |
805 | 815 | | |
806 | 816 | | |
807 | | - | |
| 817 | + | |
808 | 818 | | |
809 | 819 | | |
810 | 820 | | |
811 | 821 | | |
812 | 822 | | |
813 | | - | |
| 823 | + | |
814 | 824 | | |
815 | 825 | | |
816 | 826 | | |
817 | 827 | | |
818 | 828 | | |
819 | | - | |
| 829 | + | |
820 | 830 | | |
821 | 831 | | |
822 | 832 | | |
| |||
0 commit comments