Skip to content

Commit

Permalink
IMPALA-11406: Fix incorrect duration log for authorization
Browse files Browse the repository at this point in the history
IMPALA-8443 extends EventSequence.markEvent() to return the duration
between the last and the current event. However, the duration is
calculated using the start time, not the last time it's invoked, which
causes misleading time in logs of "Authorization check took n ms".

This fixes the bug and also adds a log for the analysis duration.

Change-Id: I8b665f1b4ac86577711598ce9d845cf82fedbcd7
Reviewed-on: http://gerrit.cloudera.org:8080/18682
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
  • Loading branch information
stiga-huang authored and Impala Public Jenkins committed Jul 18, 2022
1 parent d029ae5 commit 733c950
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ public AnalysisResult analyzeAndAuthorize(StatementBase stmt,
} finally {
authzChecker.postAnalyze(authzCtx);
}
timeline_.markEvent("Analysis finished");
long durationMs = timeline_.markEvent("Analysis finished") / 1000000;
LOG.info("Analysis took {} ms", durationMs);

// Authorize statement and record exception. Authorization relies on information
// collected during analysis.
Expand Down
8 changes: 6 additions & 2 deletions fe/src/main/java/org/apache/impala/util/EventSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public class EventSequence {

private final long startTime_;
private final String name_;
private long lastTime_;

public EventSequence(String name) {
name_ = name;
startTime_ = System.nanoTime();
lastTime_ = startTime_;
}

/**
Expand All @@ -45,8 +47,10 @@ public EventSequence(String name) {
*/
public long markEvent(String label) {
// Timestamps should be in ns resolution
long durationNs = System.nanoTime() - startTime_;
timestamps_.add(durationNs);
long currentTime = System.nanoTime();
long durationNs = currentTime - lastTime_;
lastTime_ = currentTime;
timestamps_.add(currentTime - startTime_);
labels_.add(label);
return durationNs;
}
Expand Down

0 comments on commit 733c950

Please sign in to comment.