Add client-side DataSource registration and connection pool + SQL metrics collection #7782
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.
Ⅰ. Describe what this PR did
1.Connection pool registration
1)Modifications
rm-datasource/src/main/java/org/apache/seata/rm/datasource/DataSourceProxy.javaAfter
init(DataSource, String)finishes the original initialization, the enhancer is invoked to register the data source into connection pool monitoring:In
close()a destroy hook is added to unregister monitoring and clear caches:-Effect: the lifecycle of
DataSourceProxyis bound to the connection pool monitoring lifecycle. Initialization triggers registration, and close triggers unregistration, ensuring that metrics are only collected from valid data source instances.2)Additions
rm-datasource/src/main/java/org/apache/seata/rm/datasource/DataSourceProxyEnhancer.javaConnection-pool monitoring integration enhancer. It automatically registers/unregisters data sources when DataSourceProxy is initialized/destroyed, and also provides public methods for manual registration/unregistration.
Key methods and code snippet:
Effect: acts as the bridge between
rm-datasourceand thecoremodule’sDataSourceConnectionPoolCollectorhiding concrete pool implementations (HikariCP / Druid) from(HikariCP/Druid)。2.SQL collection
1)Modifications
rm-datasource/src/main/java/org/apache/seata/rm/datasource/exec/ExecuteTemplate.javaIn the common SQL execution entry for AT mode, SQL execution and slow SQL are collected in the 'finally' block:
作用:Effect: provides unified collection of SQL execution time and slow SQL information in AT mode so that the client can periodically report it to the server.
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/StatementProxyXA.javaIn the XA-mode
Statementproxy, collection is added for theexecute / executeQuery / executeUpdatemethods:Effect: collects SQL execution time and slow SQL in XA mode as well, keeping the metrics consistent with AT mode.
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/PreparedStatementProxyXA.javaIn the XA-mode
PreparedStatementproxy, collection is added for theexecuteQuery / executeUpdate / executemethods:Effect: collects metrics for prepared statement executions, ensuring that SQL records are complete.
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/AbstractConnectionProxyXA.javaPreparedStatementProxyXA,constructor that carries the SQL text.2)Additions
core/src/main/java/org/apache/seata/core/rpc/netty/SqlCollector.javaSQL models:
core/src/main/java/org/apache/seata/core/protocol/SqlExecutionEntry.javacore/src/main/java/org/apache/seata/core/protocol/SlowSqlEntry.java3.Connection pool metrics collection
1)Additions
core/src/main/java/org/apache/seata/core/rpc/netty/DataSourceConnectionPoolCollector.javaDataSource(invoked byDataSourceProxyEnhancer)and caches them on the client.,Collects HikariCP/Druid runtime metrics.。updateConfig(poolName, request),safely invoking connection-pool setter methods via reflection.SqlCollector.Example snippet:
Metrics models:
core/src/main/java/org/apache/seata/core/protocol/HikariConnectionPoolMetrics.javacore/src/main/java/org/apache/seata/core/protocol/DruidConnectionPoolMetrics.javacore/src/main/java/org/apache/seata/core/model/PoolConfigUpdateRequest.java4.Class relationship diagram
Ⅴ. Special notes for reviews