Repository navigation
Use prepared statement for all record for Oracle Reverse Replication - #4628
dhwanilpatel wants to merge 6 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4628 +/- ##
============================================
+ Coverage 59.75% 66.09% +6.33%
+ Complexity 7926 4121 -3805
============================================
Files 1123 570 -553
Lines 72705 34905 -37800
Branches 8842 4003 -4839
============================================
- Hits 43447 23071 -20376
+ Misses 26362 10669 -15693
+ Partials 2896 1165 -1731
🚀 New features to boost your workflow:
|
e7186f7 to
bce3ea4
Compare
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request optimizes Oracle reverse replication by transitioning from raw DML string generation to parameterized statements. By utilizing bind variables, the system can now leverage Oracle's implicit statement cache, significantly reducing the overhead of SQL parsing and improving throughput. The changes include a new Oracle-specific DAO for robust type handling and improved connection configuration to manage statement cache sizes. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the Oracle DML generation and database access layers to use parameterized queries instead of inline literals. It introduces OracleJdbcDao to handle Oracle-specific JDBC bindings (such as typed NULLs, CLOB/NCLOB streaming, and fixed-width CHAR blank-padding) and adds a ColumnBinder helper in OracleDMLGenerator to manage query placeholders and parameters. Additionally, it enables implicit statement caching by default in OracleSpToSrcSourceConnector to improve performance. I have no feedback to provide as there are no review comments.
bharadwaj-aditya
left a comment
There was a problem hiding this comment.
The code looks a lot simpler but do we still need any type specific handling or the concept of rawValues ?
That should probably completely disappear right ?
| String legacySys = "'" + source + "_v1'"; | ||
| // With rawValues the value is bound as is (e.g. Oracle). Otherwise enclose it in single | ||
| // quotes since the DML generator injects custom responses directly as raw values. | ||
| String legacySys = rawValues ? source + "_v1" : "'" + source + "_v1'"; |
There was a problem hiding this comment.
i'm not sure why this variation in flow is required. Do we need the rawValues flag here ?
There was a problem hiding this comment.
CustomTransformation is shared across different source's IT (Mysql/PG/Oracle). In Oracle we are using prepared statement which will bind the value as it is from CustomTransformation, while other source's are using inline values, so they need sql literals for it.
Hence we have added this flag for passing rawValues for oracle and sql literals for other. Once other sources are also starts using prepared statement, we can remove this rawValues flag.
| } | ||
|
|
||
| /** Binds a prepared statement parameter. Sources can override this for type specific binding. */ | ||
| protected void bindParameter(java.sql.PreparedStatement pstmt, int paramIdx, Object param) |
There was a problem hiding this comment.
is there any value in the refactor on this method ?
There was a problem hiding this comment.
As discussed in [https://github.com//pull/4628#discussion_r4717510296], we might need specific bind handling to few types, respactive JDBCDAO per source will need this method for doing it.
Like for oracle this method will be overriden for bounding different types in this loop: setFixedCHAR for CHAR/NCHAR, setNString/setNClob for national types, streamed setClob for large CLOBs, and typed setNull.
This might require for other source as well if when we do prepared statement, hence I abstracted out this method.
| * </ul> | ||
| */ | ||
| private static Object toBindValueByType(String columnType, String colValue) { | ||
| if (NUMERIC_TYPES.contains(columnType)) { |
There was a problem hiding this comment.
prepared statements should handle the type behaviour out of the box. Is this required in oracle ?
There was a problem hiding this comment.
The SQL only carries type info for non-character types (TO_NUMBER(?), TO_DATE(?), TO_TIMESTAMP(?), TO_BINARY_*, TO_*INTERVAL). Character, LOB and binary columns use a plain ? in USING (SELECT ? AS col FROM DUAL), and Oracle's driver binds by the Java setter, not the target column. A SQL cast can't fix this, because the issues happen at bind time:
- CLOBs over 4000 bytes fail as VARCHAR2 binds (ORA-01461), so they must be streamed.
- National types need the national character set form, or characters are lost on non-Unicode databases. CHAR keys need blank-padded comparison (setFixedCHAR) for MERGE/DELETE to match.
- NUMBER is bound as BigDecimal to avoid dependence on the session decimal separator.
- NULLs are typed to match non-null rows, so cached statements stay shared.
| if (columnType == null) { | ||
| return ""; | ||
| } | ||
| return columnType.replaceAll("\\([^)]*\\)", "").trim().replaceAll("\\s+", " ").toLowerCase(); |
There was a problem hiding this comment.
this logic seems quite brittle, don't we get the type and the modifier as separate fields ?
There was a problem hiding this comment.
This is needed for few of the types where precision is in between types like (TIMESTAMP(6) WITH TIMEZONE, INTERVAL DAY(2) TO SECOND(6)). This is needed for removing those precision from type.
bharadwaj-aditya
left a comment
There was a problem hiding this comment.
Left a few comments around edge cases in typed NULL binding (for HEXTORAW(?) on CLOB/NCLOB, national-charset FORM_NCHAR handling in OracleJdbcDao, and BIND_MISMATCH on nullable numeric columns), implicitStatementCacheSize short-name handling in ojdbc8, and custom transformation edge cases (BINARY_FLOAT/BINARY_DOUBLE infinity and source-only DATE columns).
| toCustomTransformationBindValue( | ||
| normalizeSourceType(sourceType), customTransformationResponse.get(colName))); | ||
| return getColumnValueByType( | ||
| sourceType, sourceDbTimezoneOffset, getCustomTransformationSpannerType(colName)); |
There was a problem hiding this comment.
This applies the source-timezone conversion (AT TIME ZONE '') to custom transformation timestamps, so users with a non-UTC offset will see their returned values shifted.
Before this PR, custom values were used as-is. What is the decision here? We need to follow the same for MySQL. Can we skip the conversion for custom values here?
There was a problem hiding this comment.
We should write the custom transformation responses as is. If the response is invalid, the custom transformation function will need to change to handle that.
There was a problem hiding this comment.
Thanks for catching this. Fixed it for custom transformation where it will pass all the value as it is in plain ? with no TO_TIMESTAMP / AT TIME ZONE '<offset>', etc.
bharadwaj-aditya
left a comment
There was a problem hiding this comment.
Largely looks ok. But we need to be sure we don't edit the custom transformation response and write it as is.
Yes, the custom transformation response is no longer edited.
|
Use prepare statement for all records for oracle and enable prepareStatement caching. It provided 2x througput upto 10K events/s during load test.