Skip to content

fix(admin): add PostgreSQL and Oracle reservation SQL for AppAuth requests - #8185

Merged
Aias00 merged 2 commits into
apache:masterfrom
markjoin123:cursor/appauth-reservation-sql-8133-3715
Oct 30, 2026
Merged

Aias00 merged 2 commits into
apache:masterfrom
markjoin123:cursor/appauth-reservation-sql-8133-3715

Conversation

@markjoin123

Copy link
Copy Markdown
Contributor

Fixes #8133

What changed

AppAuthRequestMapper.reserveIfAbsent only had MySQL INSERT ... ON DUPLICATE KEY UPDATE, so AppAuth apply/revoke failed when Admin's databaseId was PostgreSQL or Oracle.

  • PostgreSQL and OpenGauss: INSERT ... ON CONFLICT DO NOTHING.
  • Oracle: MERGE that inserts only when (caller_key, namespace_id, request_id) is absent.
  • MySQL, H2 (MODE=MySQL), and OceanBase keep the existing statement. Nullable hash and auth id are bound as VARCHAR.

The service still treats a locked row whose id differs from the candidate as a replay, so hash, state, and auth id are not overwritten.

Tests

AppAuthRequestReservationDialectTest runs the mapped statement for databaseIds mysql, h2, oceanbase, postgresql, opengauss, and oracle on H2 compatibility modes. A second reserve leaves the original id, hash, and CREATED state, and a null-hash REVOKED tombstone can be inserted. Checkstyle: 0 violations. RAT: Unapproved 0.

H2 modes are not real PostgreSQL or Oracle. Two concurrent Oracle inserts of the same new key can still raise a unique-constraint error; MySQL ON DUPLICATE KEY and PostgreSQL ON CONFLICT absorb that race.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: the new dialect branches do not yet provide working production lifecycle behavior. The main issues are state literals changed by the configured SQL interceptors, openGauss syntax/dialect selection, and the remaining Oracle concurrent-reservation failure.

Validation at head 99565ddd346aee3337bbda5911e51ac7ca29d0f8:

  • Targeted ./mvnw -pl shenyu-admin -am test completed successfully: Maven reported 19 tests, 0 failures/errors, 2 skipped. The newly added test exercises six databaseIds through H2 modes; real-MySQL lifecycle suites requiring explicit JDBC properties were not enabled.
  • Additional probes used the actual mapper, production prepare interceptors, transaction-service body, driver metadata selection and facade. Sequential reservations preserve original id/hash/state/authId and their update-count differences are correctly ignored by the service.
  • No native PostgreSQL, Oracle or openGauss service was available. H2-mode probes are not presented as native dialect certification; openGauss syntax was checked against the pinned engine's primary parser source, and Oracle concurrency against Oracle's published reproduction.

(#{id,jdbcType=VARCHAR}, #{callerKey,jdbcType=VARCHAR}, #{namespaceId,jdbcType=VARCHAR},
#{requestId,jdbcType=VARCHAR}, #{requestHash,jdbcType=VARCHAR}, #{authId,jdbcType=VARCHAR},
#{state,jdbcType=VARCHAR})
ON CONFLICT DO NOTHING

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Use openGauss-supported conflict syntax and verify actual databaseId selection

ON CONFLICT DO NOTHING is PostgreSQL syntax, not a supported insert branch in the openGauss 5.0.1 engine pinned by this repository's native SQL matrix. Its versioned parser grammar accepts ON DUPLICATE KEY UPDATE (including NOTHING) and has no ON CONFLICT production; the official versioned INSERT reference matches that contract. The new H2 PostgreSQL-mode case cannot validate openGauss syntax.

There is also a selection issue: executing PgDatabaseMetaData.getDatabaseProductName() from the project's actual opengauss-jdbc:5.0.0-og dependency returns PostgreSQL. Passing that metadata through the real DataBaseConfiguration.databaseIdProvider() selects postgresql, so a normal openGauss deployment takes the other new branch, which contains the same unsupported clause; setting shenyu.database.dialect=opengauss only chooses the interceptor configuration. Please fix both the supported reservation statement and dialect selection, then verify the mapped operation on the claimed native openGauss version. Updating this explicit block alone will not fix the default driver path. I verified grammar/driver selection locally; no native openGauss server was available.

@markjoin123

Copy link
Copy Markdown
Contributor Author

@Aias00 Thanks for the detailed review. All three points are addressed in 0131a89.

[P1] State literals and the prepare interceptors. The prepare interceptors still lowercase the SQL text. completeCreated and markRevoked now bind the state as a parameter instead of using 'CREATED' and 'REVOKED' literals. So a reservation stored as CREATED still matches the CAS, and revoke persists REVOKED. AppAuthRequestReservationDialectTest now runs reserve, backfill and revoke through PostgreSQLPrepareInterceptor and OracleSQLPrepareInterceptor.

[P1] openGauss syntax and databaseId selection. openGauss now uses ON DUPLICATE KEY UPDATE NOTHING. The MyBatis database id now comes from shenyu.database.dialect, so an openGauss driver that reports its product name as PostgreSQL no longer picks the ON CONFLICT statement. DataBaseConfigurationTest checks that OpenGauss maps to opengauss without reading the JDBC product name. The mapper test checks that the mapped statement is the NOTHING form.

[P2] Oracle concurrent reservation. Oracle MERGE can still raise a unique-key error when two transactions insert the same key. AppAuthTransactionService now catches DuplicateKeyException from reserveIfAbsent and falls through to selectByKeyForUpdate. The hash-conflict, revoked-row and missing-row checks are unchanged, and any other integrity error still propagates. AppAuthReservationConflictTest covers same-key apply/apply (same hash returns the winning auth, a different hash is rejected) and revoke/revoke (the second call is idempotent).

Testing. I don't have native PostgreSQL, Oracle or openGauss here, so the executable checks used H2 compatibility modes. H2 rejects ON DUPLICATE KEY UPDATE NOTHING, so that openGauss insert was checked as mapped SQL rather than executed. The overlap tests simulate the exception Oracle would throw. Running ./mvnw -pl shenyu-admin -am test on the targeted tests gave 17 tests with 0 failures, and checkstyle reported 0 violations.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 0131a89.

The prior dialect findings are addressed in source: lifecycle state values are bound parameters, configured openGauss selection is distinct from PostgreSQL vendor reporting and uses its own reservation syntax, and an Oracle duplicate-key reservation continues through the locked-row replay/conflict checks. Unrelated database failures still propagate.

Validation is limited to the mapped H2 compatibility and service/configuration regressions; one database-dependent case is skipped. H2 modes and mocked duplicate-key exceptions are not native PostgreSQL/Oracle/openGauss certification. The applicable native-sql-matrix jobs remain the merge gate.

Targeted test report: 10 cases, 0 failures, 0 errors, 1 skipped.

Validation used ./mvnw, Amazon Corretto 21 and project target Java 17. Targeted Checkstyle, separately executed Apache RAT and git diff --check pass. No full-repository or Docker E2E pass is claimed; required CI must succeed before merge.

@Aias00
Aias00 merged commit f230b52 into apache:master Oct 30, 2026
56 checks passed
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] AppAuth lifecycle reservation SQL has no PostgreSQL or Oracle dialect implementation

2 participants