Skip to content

Commit 9999b2f

Browse files
committed
passing MDC context from Cinder
1 parent 1c4f393 commit 9999b2f

File tree

13 files changed

+210
-34
lines changed

13 files changed

+210
-34
lines changed

hollow-diff-ui/dependencies.lock

+18
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
"com.netflix.hollow:hollow-ui-tools"
6969
],
7070
"locked": "2.3"
71+
},
72+
"org.slf4j:jul-to-slf4j": {
73+
"firstLevelTransitive": [
74+
"com.netflix.hollow:hollow"
75+
],
76+
"locked": "2.0.9"
7177
}
7278
},
7379
"testCompileClasspath": {
@@ -145,6 +151,12 @@
145151
"com.netflix.hollow:hollow-ui-tools"
146152
],
147153
"locked": "2.3"
154+
},
155+
"org.slf4j:jul-to-slf4j": {
156+
"firstLevelTransitive": [
157+
"com.netflix.hollow:hollow"
158+
],
159+
"locked": "2.0.9"
148160
}
149161
},
150162
"toolsCompileClasspath": {
@@ -222,6 +234,12 @@
222234
"com.netflix.hollow:hollow-ui-tools"
223235
],
224236
"locked": "2.3"
237+
},
238+
"org.slf4j:jul-to-slf4j": {
239+
"firstLevelTransitive": [
240+
"com.netflix.hollow:hollow"
241+
],
242+
"locked": "2.0.9"
225243
}
226244
}
227245
}

hollow-explorer-ui/dependencies.lock

+18
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858
"com.netflix.hollow:hollow-ui-tools"
5959
],
6060
"locked": "2.3"
61+
},
62+
"org.slf4j:jul-to-slf4j": {
63+
"firstLevelTransitive": [
64+
"com.netflix.hollow:hollow"
65+
],
66+
"locked": "2.0.9"
6167
}
6268
},
6369
"testCompileClasspath": {
@@ -125,6 +131,12 @@
125131
"com.netflix.hollow:hollow-ui-tools"
126132
],
127133
"locked": "2.3"
134+
},
135+
"org.slf4j:jul-to-slf4j": {
136+
"firstLevelTransitive": [
137+
"com.netflix.hollow:hollow"
138+
],
139+
"locked": "2.0.9"
128140
}
129141
},
130142
"toolsCompileClasspath": {
@@ -192,6 +204,12 @@
192204
"com.netflix.hollow:hollow-ui-tools"
193205
],
194206
"locked": "2.3"
207+
},
208+
"org.slf4j:jul-to-slf4j": {
209+
"firstLevelTransitive": [
210+
"com.netflix.hollow:hollow"
211+
],
212+
"locked": "2.0.9"
195213
}
196214
}
197215
}

hollow-jsonadapter/dependencies.lock

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
},
3232
"commons-lang:commons-lang": {
3333
"locked": "2.6"
34+
},
35+
"org.slf4j:jul-to-slf4j": {
36+
"firstLevelTransitive": [
37+
"com.netflix.hollow:hollow"
38+
],
39+
"locked": "2.0.9"
3440
}
3541
},
3642
"testCompileClasspath": {
@@ -71,6 +77,12 @@
7177
},
7278
"junit:junit": {
7379
"locked": "4.11"
80+
},
81+
"org.slf4j:jul-to-slf4j": {
82+
"firstLevelTransitive": [
83+
"com.netflix.hollow:hollow"
84+
],
85+
"locked": "2.0.9"
7486
}
7587
}
7688
}

hollow-perf/dependencies.lock

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
},
4242
"org.openjdk.jmh:jmh-generator-bytecode": {
4343
"locked": "1.25"
44+
},
45+
"org.slf4j:jul-to-slf4j": {
46+
"firstLevelTransitive": [
47+
"com.netflix.hollow:hollow"
48+
],
49+
"locked": "2.0.9"
4450
}
4551
},
4652
"runtimeClasspath": {
@@ -49,6 +55,12 @@
4955
},
5056
"org.openjdk.jmh:jmh-core": {
5157
"locked": "1.21"
58+
},
59+
"org.slf4j:jul-to-slf4j": {
60+
"firstLevelTransitive": [
61+
"com.netflix.hollow:hollow"
62+
],
63+
"locked": "2.0.9"
5264
}
5365
},
5466
"testCompileClasspath": {
@@ -65,6 +77,12 @@
6577
},
6678
"org.openjdk.jmh:jmh-core": {
6779
"locked": "1.21"
80+
},
81+
"org.slf4j:jul-to-slf4j": {
82+
"firstLevelTransitive": [
83+
"com.netflix.hollow:hollow"
84+
],
85+
"locked": "2.0.9"
6886
}
6987
}
7088
}

hollow-test/dependencies.lock

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"runtimeClasspath": {
88
"com.netflix.hollow:hollow": {
99
"project": true
10+
},
11+
"org.slf4j:jul-to-slf4j": {
12+
"firstLevelTransitive": [
13+
"com.netflix.hollow:hollow"
14+
],
15+
"locked": "2.0.9"
1016
}
1117
},
1218
"testCompileClasspath": {
@@ -23,6 +29,12 @@
2329
},
2430
"junit:junit": {
2531
"locked": "4.11"
32+
},
33+
"org.slf4j:jul-to-slf4j": {
34+
"firstLevelTransitive": [
35+
"com.netflix.hollow:hollow"
36+
],
37+
"locked": "2.0.9"
2638
}
2739
}
2840
}

hollow-ui-tools/dependencies.lock

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
},
3838
"org.apache.velocity:velocity-engine-core": {
3939
"locked": "2.3"
40+
},
41+
"org.slf4j:jul-to-slf4j": {
42+
"firstLevelTransitive": [
43+
"com.netflix.hollow:hollow"
44+
],
45+
"locked": "2.0.9"
4046
}
4147
},
4248
"testCompileClasspath": {
@@ -83,6 +89,12 @@
8389
},
8490
"org.apache.velocity:velocity-engine-core": {
8591
"locked": "2.3"
92+
},
93+
"org.slf4j:jul-to-slf4j": {
94+
"firstLevelTransitive": [
95+
"com.netflix.hollow:hollow"
96+
],
97+
"locked": "2.0.9"
8698
}
8799
},
88100
"toolsCompileClasspath": {
@@ -129,6 +141,12 @@
129141
},
130142
"org.apache.velocity:velocity-engine-core": {
131143
"locked": "2.3"
144+
},
145+
"org.slf4j:jul-to-slf4j": {
146+
"firstLevelTransitive": [
147+
"com.netflix.hollow:hollow"
148+
],
149+
"locked": "2.0.9"
132150
}
133151
}
134152
}

hollow-zenoadapter/dependencies.lock

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
},
1414
"com.netflix.zeno:netflix-zeno": {
1515
"locked": "2.22.3"
16+
},
17+
"org.slf4j:jul-to-slf4j": {
18+
"firstLevelTransitive": [
19+
"com.netflix.hollow:hollow"
20+
],
21+
"locked": "2.0.9"
1622
}
1723
},
1824
"testCompileClasspath": {
@@ -35,6 +41,12 @@
3541
},
3642
"junit:junit": {
3743
"locked": "4.11"
44+
},
45+
"org.slf4j:jul-to-slf4j": {
46+
"firstLevelTransitive": [
47+
"com.netflix.hollow:hollow"
48+
],
49+
"locked": "2.0.9"
3850
}
3951
}
4052
}

hollow/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dependencies {
66
testImplementation 'org.mockito:mockito-core:2.15.0'
77
testImplementation 'com.github.spotbugs:spotbugs:4.2.1'
88
testImplementation 'org.assertj:assertj-core:3.15.0'
9+
implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: '2.0.9'
910
}
1011

1112
tasks.withType(JavaCompile).configureEach {

hollow/dependencies.lock

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2+
"compileClasspath": {
3+
"org.slf4j:jul-to-slf4j": {
4+
"locked": "2.0.9"
5+
}
6+
},
7+
"runtimeClasspath": {
8+
"org.slf4j:jul-to-slf4j": {
9+
"locked": "2.0.9"
10+
}
11+
},
212
"testCompileClasspath": {
313
"com.github.spotbugs:spotbugs": {
414
"locked": "4.2.1"
@@ -14,6 +24,9 @@
1424
},
1525
"org.mockito:mockito-core": {
1626
"locked": "2.15.0"
27+
},
28+
"org.slf4j:jul-to-slf4j": {
29+
"locked": "2.0.9"
1730
}
1831
},
1932
"testRuntimeClasspath": {
@@ -37,6 +50,12 @@
3750
},
3851
"org.mockito:mockito-core": {
3952
"locked": "2.15.0"
53+
},
54+
"org.slf4j:jul-to-slf4j": {
55+
"firstLevelTransitive": [
56+
"com.netflix.hollow:hollow"
57+
],
58+
"locked": "2.0.9"
4059
}
4160
}
4261
}

hollow/src/main/java/com/netflix/hollow/api/client/HollowAnnouncementWatcher.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import com.netflix.hollow.api.consumer.HollowConsumer;
2222
import com.netflix.hollow.core.HollowConstants;
23+
import org.slf4j.MDC;
24+
25+
import java.util.Map;
2326
import java.util.Random;
2427
import java.util.concurrent.ExecutorService;
2528
import java.util.concurrent.Executors;
@@ -129,16 +132,23 @@ public void triggerAsyncRefreshWithRandomDelay(int maxDelayMillis) {
129132
public void triggerAsyncRefreshWithDelay(int delayMillis) {
130133
final HollowClient client = this.client;
131134
final long targetBeginTime = System.currentTimeMillis() + delayMillis;
132-
135+
// Capture MDC context on the original thread
136+
final Map<String, String> mdcContext = MDC.getCopyOfContextMap();
133137
refreshExecutor.execute(new Runnable() {
134138
public void run() {
139+
// Set MDC context on the new thread
140+
if (mdcContext != null) {
141+
MDC.setContextMap(mdcContext);
142+
}
135143
try {
136144
long delay = targetBeginTime - System.currentTimeMillis();
137145
if(delay > 0)
138146
Thread.sleep(delay);
139147
client.triggerRefresh();
140148
} catch(Throwable th) {
141149
log.log(Level.SEVERE, "Async refresh failed", th);
150+
} finally {
151+
MDC.clear();
142152
}
143153
}
144154
});

hollow/src/main/java/com/netflix/hollow/api/consumer/HollowConsumer.java

+28-15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import com.netflix.hollow.core.util.DefaultHashCodeFinder;
4040
import com.netflix.hollow.core.util.HollowObjectHashCodeFinder;
4141
import com.netflix.hollow.tools.history.HollowHistory;
42+
import org.slf4j.MDC;
43+
4244
import java.io.File;
4345
import java.io.IOException;
4446
import java.io.InputStream;
@@ -258,25 +260,36 @@ public void triggerAsyncRefresh() {
258260
*/
259261
public void triggerAsyncRefreshWithDelay(int delayMillis) {
260262
final long targetBeginTime = System.currentTimeMillis() + delayMillis;
263+
// Capture MDC context on the original thread
264+
final Map<String, String> mdcContext = MDC.getCopyOfContextMap();
261265

262266
refreshExecutor.execute(() -> {
263-
try {
264-
long delay = targetBeginTime - System.currentTimeMillis();
265-
if (delay > 0)
266-
Thread.sleep(delay);
267-
} catch (InterruptedException e) {
268-
// Interrupting, such as shutting down the executor pool,
269-
// cancels the trigger
270-
LOG.log(Level.INFO, "Async refresh interrupted before trigger, refresh cancelled", e);
271-
return;
267+
// Set MDC context on the new thread
268+
if (mdcContext != null) {
269+
MDC.setContextMap(mdcContext);
272270
}
273-
274271
try {
275-
triggerRefresh();
276-
} catch (Error | RuntimeException e) {
277-
// Ensure exceptions are propagated to the executor
278-
LOG.log(Level.SEVERE, "Async refresh failed", e);
279-
throw e;
272+
try {
273+
long delay = targetBeginTime - System.currentTimeMillis();
274+
if (delay > 0)
275+
Thread.sleep(delay);
276+
} catch (InterruptedException e) {
277+
// Interrupting, such as shutting down the executor pool,
278+
// cancels the trigger
279+
LOG.log(Level.INFO, "Async refresh interrupted before trigger, refresh cancelled", e);
280+
return;
281+
}
282+
283+
try {
284+
triggerRefresh();
285+
} catch (Error | RuntimeException e) {
286+
// Ensure exceptions are propagated to the executor
287+
LOG.log(Level.SEVERE, "Async refresh failed", e);
288+
throw e;
289+
}
290+
} finally {
291+
// clear MDC context when entire task is done
292+
MDC.clear();
280293
}
281294
});
282295
}

0 commit comments

Comments
 (0)