kfaraz commented on code in PR #18844:
URL: https://github.com/apache/druid/pull/18844#discussion_r2680837382


##########
server/src/main/java/org/apache/druid/segment/metadata/SqlCompactionStateStorage.java:
##########
@@ -398,4 +313,40 @@ private static void bindValuesToInClause(
       query.bind(parameterPrefix + i, values.get(i));
     }
   }
+
+  /**
+   * Checks if an exception is a unique constraint violation.
+   * This is expected when multiple threads try to insert the same fingerprint 
concurrently.
+   * Since operations are idempotent, these violations can be safely ignored.
+   */
+  private boolean isUniqueConstraintViolation(Exception e)
+  {
+    // Look for SQLException in the cause chain
+    Throwable cause = e;
+    while (cause != null) {
+      if (cause instanceof SQLException) {
+        SQLException sqlException = (SQLException) cause;
+        String sqlState = sqlException.getSQLState();
+
+        // SQL standard unique constraint violation codes
+        // 23505 = unique_violation (PostgreSQL, Derby)
+        // 23000 = integrity_constraint_violation (MySQL and others)
+        if ("23505".equals(sqlState) || "23000".equals(sqlState)) {

Review Comment:
   It would be cleaner to add the method `isUniqueConstraintViolation` to 
`SQLMetadataConnector` so that each concrete DB may provide its own 
implementation, rather than handle all possible cases here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to