Commit 5ba0c59
committed
Implement dynamic token stale period based on token TTL.
Replace the fixed 5-minute stale window with a per-token formula: stale_period = min(TTL / 2, 20 minutes). This ensures that short-lived tokens (e.g. FastPath tokens with a 10-minute TTL) enter the stale window early enough to trigger a proactive async refresh, while long-lived tokens are capped at 20 minutes to maintain a meaningful refresh buffer under a 99.99% uptime SLA.
The stale duration is computed at token fetch time using the remaining TTL as a proxy, since the SDK does not track token issuance timestamps. It is updated after every successful refresh (both synchronous and asynchronous) via computeStaleDuration(), and stored in a volatile field so that the unsynchronized fast-path read in getTokenAsync() sees a consistent value.
Due to the exposed CachedTokenSource builder function setStalePeriod backwards compatibility is maintained through the useDynamicStalePeriod flag. Using the setStalePeriod function disables this flag, reverting the behaviour of the token cache to the legacy one.1 parent a5a437c commit 5ba0c59
File tree
2 files changed
+79
-13
lines changed- databricks-sdk-java/src
- main/java/com/databricks/sdk/core/oauth
- test/java/com/databricks/sdk/core/oauth
2 files changed
+79
-13
lines changedLines changed: 42 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
38 | 43 | | |
| |||
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
45 | | - | |
| 50 | + | |
46 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| |||
60 | 69 | | |
61 | 70 | | |
62 | 71 | | |
| 72 | + | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
66 | 82 | | |
67 | 83 | | |
68 | 84 | | |
| |||
75 | 91 | | |
76 | 92 | | |
77 | 93 | | |
| 94 | + | |
78 | 95 | | |
79 | 96 | | |
80 | 97 | | |
| |||
130 | 147 | | |
131 | 148 | | |
132 | 149 | | |
| 150 | + | |
133 | 151 | | |
134 | 152 | | |
135 | 153 | | |
| |||
188 | 206 | | |
189 | 207 | | |
190 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
191 | 220 | | |
192 | 221 | | |
193 | 222 | | |
| |||
201 | 230 | | |
202 | 231 | | |
203 | 232 | | |
204 | | - | |
| 233 | + | |
| 234 | + | |
205 | 235 | | |
206 | 236 | | |
207 | 237 | | |
| |||
235 | 265 | | |
236 | 266 | | |
237 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
238 | 273 | | |
239 | 274 | | |
240 | 275 | | |
| |||
281 | 316 | | |
282 | 317 | | |
283 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
284 | 324 | | |
285 | 325 | | |
286 | 326 | | |
| |||
Lines changed: 37 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
22 | 37 | | |
23 | 38 | | |
24 | 39 | | |
25 | 40 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
32 | 48 | | |
33 | 49 | | |
34 | 50 | | |
35 | 51 | | |
36 | 52 | | |
37 | 53 | | |
38 | 54 | | |
| 55 | + | |
39 | 56 | | |
40 | 57 | | |
41 | 58 | | |
42 | 59 | | |
43 | 60 | | |
| 61 | + | |
| 62 | + | |
44 | 63 | | |
45 | 64 | | |
46 | 65 | | |
47 | 66 | | |
48 | 67 | | |
49 | | - | |
| 68 | + | |
50 | 69 | | |
51 | | - | |
| 70 | + | |
52 | 71 | | |
53 | 72 | | |
54 | 73 | | |
| |||
69 | 88 | | |
70 | 89 | | |
71 | 90 | | |
| 91 | + | |
72 | 92 | | |
73 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
74 | 97 | | |
75 | 98 | | |
76 | 99 | | |
| |||
90 | 113 | | |
91 | 114 | | |
92 | 115 | | |
93 | | - | |
| 116 | + | |
94 | 117 | | |
95 | 118 | | |
96 | 119 | | |
97 | 120 | | |
98 | 121 | | |
99 | | - | |
| 122 | + | |
100 | 123 | | |
101 | 124 | | |
102 | 125 | | |
| |||
132 | 155 | | |
133 | 156 | | |
134 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
135 | 161 | | |
136 | 162 | | |
137 | 163 | | |
| |||
0 commit comments