HIVE-29583: Profile the underlying JDBC execution in Metastore#6464
Open
dengzhhu653 wants to merge 4 commits intoapache:masterfrom
Open
HIVE-29583: Profile the underlying JDBC execution in Metastore#6464dengzhhu653 wants to merge 4 commits intoapache:masterfrom
dengzhhu653 wants to merge 4 commits intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces JDBC execution profiling for the Standalone Metastore by wrapping JDBC Connections/Statements to emit per-call timing metrics and slow-query counters, and by wiring Thrift call context into the handler so JDBC activity can be attributed to a specific API call.
Changes:
- Add a JDBC
Driver/Connection/Statementwrapper layer (MetastoreDriver,MetastoreConnection,MetastoreStatement) to time statement execution and log/count slow queries. - Track the current Thrift call in
HMSHandlerContextand set/clear it inRetryingHMSHandlerto correlate JDBC activity with Thrift APIs. - Add new metastore configuration knobs and unit tests to validate metrics/slow-query behavior across pool implementations.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/datasource/TestMetastoreConnection.java | Adds unit tests validating JDBC profiling metrics/slow-query counting with HikariCP and DBCP. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/RetryingHMSHandler.java | Sets a per-call context identifier to correlate JDBC profiling with the current Thrift API. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metrics/MetricsConstants.java | Adds metric name constants for slow JDBC queries and JDBC execution timers. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HMSHandlerContext.java | Adds storage/accessors for the current Thrift call identifier. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/datasource/MetastoreStatement.java | Adds a Statement proxy to time executions, emit metrics, and log/count slow queries. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/datasource/MetastoreDriver.java | Adds a JDBC driver wrapper intended to return MetastoreConnection instances for profiling. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/datasource/MetastoreConnection.java | Adds a Connection wrapper that returns proxied Statements/PreparedStatements for profiling. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/datasource/HikariCPDataSourceProvider.java | Refactors pool initialization to use a shared helper for init SQL and DS properties. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/datasource/DbCPDataSourceProvider.java | Refactors pool initialization to use a shared helper for init SQL and DS properties. |
| standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/datasource/DataSourceProvider.java | Routes JDBC URL through MetastoreDriver when profiling is enabled; adds shared pool-prep helper. |
| standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java | Adds new configuration flags for JDBC profiling and slow-query thresholds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+96
to
+108
| if (!local) { | ||
| Optional<Pair<String, Long>> previousCall = HMSHandlerContext.getCallId(); | ||
| if (previousCall.isEmpty()) { | ||
| Pair<String, Long> currentCall = Pair.of(method.getName(), System.currentTimeMillis()); | ||
| HMSHandlerContext.setCallId(currentCall); | ||
| clearLocal = true; | ||
| } | ||
| } | ||
| object = method.invoke(baseHandler, args); | ||
| } finally { | ||
| if (clearLocal) { | ||
| HMSHandlerContext.setCallId(null); | ||
| } |
Comment on lines
+121
to
+133
| long start = System.currentTimeMillis(); | ||
| hook.preRun(method, args); | ||
| Object result = method.invoke(delegate, args); | ||
| hook.postRun(method, args, result); | ||
| long timeSpent = System.currentTimeMillis() - start; | ||
| if (shouldMonitor) { | ||
| String statement = rawSql != null ? rawSql : (args != null && args.length > 0 ? (String) args[0] : "no sql found"); | ||
| LOG.debug("SQL query: {} completed in {} ms", statement, timeSpent); | ||
| } | ||
| logSlowExecution(timeSpent, configuration, rawSql, method, args); | ||
| if (adder != null) { | ||
| adder.add(timeSpent); | ||
| } |
| METASTORE_JDBC_SLOW_QUERIES("metastore.jdbc.execution.logSlowQueriesThreshold", "metastore.jdbc.execution.logSlowQueriesThreshold", | ||
| 3000, "Log the slow jdbc query that Metastore has been waiting for the result beyond the threshold(ms), " + | ||
| "should enable the metastore.profile.jdbc.execution first"), | ||
| METASTORE_PROFILE_JDBC_EXECUTION("metastore.profile.jdbc.execution", "metastore.profile.jdbc.execution", true, |
Comment on lines
+124
to
+128
| long start = System.currentTimeMillis(); | ||
| hook.preRun(method, args); | ||
| Object result = method.invoke(delegate, args); | ||
| hook.postRun(method, args, result); | ||
| long timeSpent = System.currentTimeMillis() - start; |
Comment on lines
+138
to
+140
| } catch (InvocationTargetException | UndeclaredThrowableException e) { | ||
| throw e.getCause(); | ||
| } finally { |
| } else { | ||
| CALL_CTX.remove(); | ||
| } | ||
| } |
Comment on lines
+652
to
+655
| 3000, "Log the slow jdbc query that Metastore has been waiting for the result beyond the threshold(ms), " + | ||
| "should enable the metastore.profile.jdbc.execution first"), | ||
| METASTORE_PROFILE_JDBC_EXECUTION("metastore.profile.jdbc.execution", "metastore.profile.jdbc.execution", true, | ||
| "Profile the jdbc executions, will give the histogram about the jdbc read and write if check the metrics"), |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changes were proposed in this pull request?
Why are the changes needed?
Does this PR introduce any user-facing change?
How was this patch tested?