Skip to content

Commit ca3526d

Browse files
ChengbingLiuChengbing Liu
andauthored
HADOOP-18567. LogThrottlingHelper: properly trigger dependent recorders in cases of infrequent logging (#5215)
Signed-off-by: Erik Krogen <[email protected]> Co-authored-by: Chengbing Liu <[email protected]>
1 parent f7bdf6c commit ca3526d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogThrottlingHelper.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,15 @@ public LogAction record(String recorderName, long currentTimeMs,
262262
if (primaryRecorderName.equals(recorderName) &&
263263
currentTimeMs - minLogPeriodMs >= lastLogTimestampMs) {
264264
lastLogTimestampMs = currentTimeMs;
265-
for (LoggingAction log : currentLogs.values()) {
266-
log.setShouldLog();
267-
}
265+
currentLogs.replaceAll((key, log) -> {
266+
LoggingAction newLog = log;
267+
if (log.hasLogged()) {
268+
// create a fresh log since the old one has already been logged
269+
newLog = new LoggingAction(log.getValueCount());
270+
}
271+
newLog.setShouldLog();
272+
return newLog;
273+
});
268274
}
269275
if (currentLog.shouldLog()) {
270276
currentLog.setHasLogged();
@@ -357,6 +363,10 @@ private void setHasLogged() {
357363
hasLogged = true;
358364
}
359365

366+
private int getValueCount() {
367+
return stats.length;
368+
}
369+
360370
private void recordValues(double... values) {
361371
if (values.length != stats.length) {
362372
throw new IllegalArgumentException("received " + values.length +

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/log/TestLogThrottlingHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ public void testPrimaryAndDependentLoggers() {
142142
assertTrue(helper.record("bar", 0).shouldLog());
143143
}
144144

145+
@Test
146+
public void testInfrequentPrimaryAndDependentLoggers() {
147+
helper = new LogThrottlingHelper(LOG_PERIOD, "foo", timer);
148+
149+
assertTrue(helper.record("foo", 0).shouldLog());
150+
assertTrue(helper.record("bar", 0).shouldLog());
151+
152+
// Both should log once the period has elapsed
153+
assertTrue(helper.record("foo", LOG_PERIOD).shouldLog());
154+
assertTrue(helper.record("bar", LOG_PERIOD).shouldLog());
155+
}
156+
145157
@Test
146158
public void testMultipleLoggersWithValues() {
147159
helper = new LogThrottlingHelper(LOG_PERIOD, "foo", timer);

0 commit comments

Comments
 (0)