Commit 08021c9
Fix background database account refresh stopping in multi-writer accounts (#48758)
* Fix background database account refresh stopping in multi-writer accounts
In multi-writer accounts, refreshLocationPrivateAsync() stops the background
refresh timer when shouldRefreshEndpoints() returns false. This means topology
changes (e.g., multi-write to single-write transitions) go undetected until
the next explicit refresh trigger.
The .NET SDK (azure-cosmos-dotnet-v3) correctly continues the background
refresh loop unconditionally - the loop only stops when canRefreshInBackground
is explicitly false, not when shouldRefreshEndpoints returns false.
This fix adds startRefreshLocationTimerAsync() to the else-branch of
refreshLocationPrivateAsync(), ensuring the background timer always reschedules
itself regardless of whether endpoints currently need refreshing.
Without this fix, after a multi-write -> single-write -> multi-write transition,
reads remain stuck on the primary region because the SDK never re-reads account
metadata to learn about the restored multi-write topology.
Unit tests updated:
- backgroundRefreshForMultiMaster: assertTrue (timer must keep running)
- backgroundRefreshDetectsTopologyChangeForMultiMaster: new test proving
MW->SW transition detection via mock
Related: PR #6139 (point #4 in description acknowledged this bug)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add DR drill test results (4 scenarios: MW offline, MW transitions, SW switch, SW offline)
Kusto-backed evidence with charts for PR #48758 validation.
Accounts: bgrefresh-mw-test-440 (multi-writer), bgrefresh-sw-test-440 (single-writer)
Branch: fix/background-refresh-multi-writer @ 2048abe
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Revert "Add DR drill test results (4 scenarios: MW offline, MW transitions, SW switch, SW offline)"
This reverts commit c9fc5c4.
* Restart background timer on force-refresh path (403/3 driven)
The forceRefresh=true path in refreshLocationAsync() updates the
LocationCache but never restarts the background timer. After a
MW→SW transition triggered by 403/3, the timer stays dead and the
SDK never detects MW re-enablement — traffic stays pinned to the
SW write region permanently.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add jitter (0-15s) to background refresh interval to prevent thundering herd
Configurable via COSMOS.BACKGROUND_REFRESH_LOCATION_JITTER_MAX_IN_SECONDS
(default 15). Spreads refresh calls from many CosmosClient instances to
avoid overwhelming the compute gateway.
Jitter is skipped during initialization (zero delay for first refresh).
Tests set jitter to 0 for deterministic behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Disable background refresh jitter in GatewayServiceConfigurationReaderTest
The background refresh jitter (0-15s) added to prevent thundering herd
causes the refresh interval to exceed the 2-second sleep windows used
by this test. Disable jitter so the background refresh fires predictably.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent b4c5d57 commit 08021c9
5 files changed
Lines changed: 95 additions & 6 deletions
File tree
- sdk/cosmos
- azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/directconnectivity
- azure-cosmos/src/main/java/com/azure/cosmos/implementation
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
Lines changed: 59 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
239 | 242 | | |
240 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
241 | 291 | | |
242 | 292 | | |
243 | 293 | | |
| |||
254 | 304 | | |
255 | 305 | | |
256 | 306 | | |
| 307 | + | |
257 | 308 | | |
258 | 309 | | |
259 | 310 | | |
260 | 311 | | |
261 | 312 | | |
262 | 313 | | |
263 | 314 | | |
264 | | - | |
265 | 315 | | |
266 | 316 | | |
267 | 317 | | |
| |||
341 | 391 | | |
342 | 392 | | |
343 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
344 | 400 | | |
345 | 401 | | |
346 | 402 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
188 | 192 | | |
189 | 193 | | |
190 | 194 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| 121 | + | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
| |||
567 | 569 | | |
568 | 570 | | |
569 | 571 | | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
570 | 576 | | |
571 | 577 | | |
572 | 578 | | |
| |||
Lines changed: 23 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
302 | 304 | | |
303 | 305 | | |
304 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
305 | 318 | | |
306 | 319 | | |
307 | 320 | | |
| |||
320 | 333 | | |
321 | 334 | | |
322 | 335 | | |
323 | | - | |
324 | 336 | | |
325 | 337 | | |
326 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
327 | 344 | | |
328 | 345 | | |
329 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
330 | 350 | | |
331 | 351 | | |
332 | 352 | | |
| |||
0 commit comments