[
https://issues.apache.org/jira/browse/HADOOP-18567?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17646887#comment-17646887
]
ASF GitHub Bot commented on HADOOP-18567:
-----------------------------------------
xkrogen commented on code in PR #5215:
URL: https://github.com/apache/hadoop/pull/5215#discussion_r1047905288
##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogThrottlingHelper.java:
##########
@@ -262,8 +263,15 @@ public LogAction record(String recorderName, long
currentTimeMs,
if (primaryRecorderName.equals(recorderName) &&
currentTimeMs - minLogPeriodMs >= lastLogTimestampMs) {
lastLogTimestampMs = currentTimeMs;
- for (LoggingAction log : currentLogs.values()) {
- log.setShouldLog();
+ for (Iterator<LoggingAction> it = currentLogs.values().iterator(); it
+ .hasNext();) {
+ LoggingAction log = it.next();
+ if (log.hasLogged()) {
+ // Make sure the dependent recorders will be triggered the next time
+ it.remove();
+ } else {
+ log.setShouldLog();
+ }
}
Review Comment:
This does solve the issue but it feels a bit awkward/confusing to me. Having
no entry in `currentLogs` is supposed to indicate that this `recoderName` has
never been seen before.
What do you think about this instead:
```suggestion
currentLogs.replaceAll((k, log) -> {
LoggingAction newLog = log;
if (log.hasLogged()) {
// create a fresh log since the old one has already been logged
newLog = new LoggingAction(log.getValueCount());
}
newLog.setShouldLog();
return newLog;
});
```
I feel it's a bit more explicit/clear about what we're achieving. WDYT?
(note that this also requires creating a new method in `LoggingAction` to
expose the value count like `private int getValueCount() { return stats.length;
}`)
> LogThrottlingHelper: the dependent recorder is not triggered correctly
> ----------------------------------------------------------------------
>
> Key: HADOOP-18567
> URL: https://issues.apache.org/jira/browse/HADOOP-18567
> Project: Hadoop Common
> Issue Type: Bug
> Affects Versions: 3.3.4
> Reporter: Chengbing Liu
> Priority: Major
> Labels: pull-request-available
>
> The current implementation of {{LogThrottlingHelper}} works well most of the
> time, but it missed out one case, which appears quite common in the
> production codes:
> - if the dependent recorder was not suppressed before the primary one is
> triggered on the next period, then the next logging of the dependent recorder
> will be unexpectedly suppressed.
> {code:java}
> helper = new LogThrottlingHelper(LOG_PERIOD, "foo", timer);
> assertTrue(helper.record("foo", 0).shouldLog());
> assertTrue(helper.record("bar", 0).shouldLog());
> // Both should log once the period has elapsed
> // <pos1>
> assertTrue(helper.record("foo", LOG_PERIOD).shouldLog());
> assertTrue(helper.record("bar", LOG_PERIOD).shouldLog()); <--- This
> assertion will now fail
> {code}
> Note if we call {{helper.record("bar", LOG_PERIOD * 2)}} in <pos1>, as the
> existing test cases do, it will work as expected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]