Skip to content

oracledb_cdc: upsert checkpoints with MERGE, fall back to the procedure - #4880

Open
Leward wants to merge 18 commits into
mainfrom
claude/wizardly-meninsky-acd5b6
Open

Leward wants to merge 18 commits into
mainfrom
claude/wizardly-meninsky-acd5b6

Conversation

@Leward

@Leward Leward commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The checkpoint cache wrote through a stored procedure, <schema>.CDC_CHECKPOINT_CACHE_UPDATE. One procedure exists per schema, and its body hard-codes the table of the first pipeline that started. A second pipeline with another checkpoint_cache_table_name in the same schema reuses that procedure. It writes its checkpoints to the first pipeline's table and reads them from its own. On restart it finds no checkpoint and starts from scratch.

This always happens in multitenant mode. Every pluggable database (PDB) gets its own table under C##RPCN, so two PDBs on one container database (CDB) share the procedure.

The fix writes with a MERGE on the pipeline's own table. The procedure runs with the rights of its owner, but a MERGE runs with the rights of the Connect user and needs INSERT and UPDATE on the table. A user that a DBA set up with only SELECT, UPDATE and EXECUTE would stop saving checkpoints after the upgrade, without an error (a failed write only fails the ack). So the cache probes the MERGE at start up and falls back to the procedure for those users:

 newCheckpointCache
   createCacheTable(<schema>.<table>)
-  createUpsertStoredProc
-  prepare "BEGIN <schema>.CDC_CHECKPOINT_CACHE_UPDATE(:1, :2); END;"
+  selectCheckpointWrite
+    mergeWrite                          # replication.ProbeStatement: MERGE, then ROLLBACK
+      ok                -> prepare "MERGE INTO <schema>.<table> ..."
+                           gauge oracledb_cdc_checkpoint_legacy_procedure = 0
+      missing privilege -> WARN with the GRANT to run, gauge = 1
+                           procedureWrite: createUpsertStoredProc,
+                           prepare "BEGIN ... END;"   # same as today
+      other error       -> fail Connect, so that it tries again

The fallback is the current code, unchanged. A pipeline on the fallback keeps today's behavior, the bug included. The warning tells it to grant INSERT, and the grant moves it to MERGE.

Upgrade step for the release note: grant SELECT, INSERT and UPDATE on the checkpoint table to the Connect user. A future version removes the fallback. Then a failed probe fails Connect with the GRANT text, so a missed warning gives a startup error, not lost checkpoints.

The Permissions docs list the SELECT, INSERT and UPDATE grants on the checkpoint table, the fallback, and the gauge.

replication.IsMissingPrivilege checks ORA-01031 and ORA-41900 (Oracle 23ai). The snapshot already checked both codes for FLASHBACK. Now the snapshot and the probe both use it. The probe itself is replication.ProbeStatement, next to it.

Evidence

TestIntegrationCheckpointCacheProcedureFallback (new) connects as a user with SELECT, UPDATE on the table and EXECUTE on the procedure, then writes a checkpoint:

before (MERGE only): Set fails with ORA-41900: missing INSERT privilege
after:               Set writes the row through the procedure

TestIntegrationCheckpointCacheTablesInSameSchema (new):

given two caches with tables A and B in one schema
when cache A writes pipeline_a and cache B writes pipeline_b
then table A has only pipeline_a, table B has only pipeline_b
  # procedure path (old behavior): pipeline_b lands in table A, table B is empty

TestIntegrationProbeStatement (new, replication package):

grants SELECT, UPDATE           -> IsMissingPrivilege(err) is true (ORA-41900 on Oracle Free 23ai)
grants SELECT, INSERT, UPDATE   -> no error
both cases                      -> table is still empty after the probe

TestIntegrationMigrateCheckpointCache, TestIntegrationCheckpointCacheNameIsAView, TestIntegrationCheckpointCacheConcurrentCreate and TestIntegrationSnapshotChunked still pass.

Merge Danger

Door: two-way

A revert brings back the procedure for every pipeline. The MERGE path creates nothing new, so a rollback needs no DBA action.

Blast Radius: checkpoints

  • Checkpoints that a second pipeline wrote to the wrong table are not recovered. That pipeline never had a working checkpoint.
  • A user with the MERGE grants no longer needs CREATE PROCEDURE. An old procedure stays in the schema, unused. A DBA can drop it.
  • Each start runs one extra MERGE and rolls it back, with a 10 second timeout. Two pipelines that probe the same table at the same time wait for each other on the probe key until the first one rolls back. LogMiner skips rolled back transactions, and the checkpoint table is not in include.
  • A probe error that is not a missing privilege (for example the timeout) now fails Connect, which tries again. Before, start up did not depend on it.

@Leward Leward changed the title oracledb_cdc: use one checkpoint stored procedure per cache table oracledb_cdc: upsert checkpoints with MERGE instead of a stored procedure Sep 29, 2026
@Leward
Leward force-pushed the claude/wizardly-meninsky-acd5b6 branch from d21c443 to e93c8b2 Compare September 29, 2026 19:29
@Leward
Leward force-pushed the claude/wizardly-meninsky-acd5b6 branch from 8cd81f7 to 8089545 Compare September 29, 2026 19:53
@Leward
Leward force-pushed the claude/wizardly-meninsky-acd5b6 branch from 80f98ae to f387227 Compare October 1, 2026 15:45
@Leward
Leward force-pushed the claude/wizardly-meninsky-acd5b6 branch from f387227 to aaf6d12 Compare November 6, 2026 16:12
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Connect docs check

The docs build passed with this PR's generated docs.

Preview: https://connect-pr-4880--redpanda-connect.netlify.app/connect/home/

This PR changes 1 published page (2 generated files: 2 changed, 0 added, 0 removed). Review the rendered pages, not only the Go strings.

Page Preview
/connect/components/inputs/oracledb_cdc/ preview

Per-file diffs and the rendered-HTML findings are in the job summary. Checked at 6538445.

@vbotbuildovich
vbotbuildovich requested a review from a team November 6, 2026 16:22
@Leward Leward assigned Leward and unassigned Leward Nov 6, 2026
…dure

All cache tables in a schema shared one stored procedure whose body
contained the table name of the first pipeline. A second pipeline with
another table in the same schema wrote its checkpoints to the wrong
table. A MERGE statement from the connector removes the shared object.
@Leward
Leward force-pushed the claude/wizardly-meninsky-acd5b6 branch from abddbd1 to b9329a1 Compare November 17, 2026 05:11
== Permissions

When using the default Oracle based cache, the Connect user requires permission to create tables and stored procedures, and the ` + "`rpcn`" + ` schema must already exist. Refer to ` + "`" + ociFieldCheckpointCacheTableName + "`" + ` for more information.
When using the default Oracle based cache, the Connect user requires permission to create tables, and the ` + "`rpcn`" + ` schema must already exist. Refer to ` + "`" + ociFieldCheckpointCacheTableName + "`" + ` for more information.

This comment was marked as duplicate.

== Permissions

When using the default Oracle based cache, the Connect user requires permission to create tables and stored procedures, and the ` + "`rpcn`" + ` schema must already exist. Refer to ` + "`" + ociFieldCheckpointCacheTableName + "`" + ` for more information.
When using the default Oracle based cache, the Connect user requires permission to create tables, and the ` + "`rpcn`" + ` schema must already exist. Refer to ` + "`" + ociFieldCheckpointCacheTableName + "`" + ` for more information.

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.

The MERGE needs a privilege the old procedure call did not: INSERT on the checkpoint table for the connector user. The procedure ran with its owner's rights, so the connector user only needed EXECUTE on it, plus SELECT and UPDATE on the table for Get and migrateCacheTable.

I tried it on Oracle Free with a user that has only SELECT, UPDATE and EXECUTE. The old BEGIN ...CDC_CHECKPOINT_CACHE_UPDATE(:1, :2); END; call works. The new MERGE fails with ORA-41900: missing INSERT privilege, even when the row already exists. Since Set errors are only logged, such a pipeline keeps running after the upgrade and stops saving checkpoints.

Two things would cover it:

  • Say here that the user needs SELECT, INSERT and UPDATE on the checkpoint table, and mention it in the release note as an upgrade step.
  • Add the start up write probe you describe in the PR body (a MERGE in a rolled back transaction), so a missing grant fails Connect instead of being logged at the first checkpoint. Fine as a follow-up if you want to keep this PR small.

@Leward Leward Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in this PR. At start up, the cache runs the MERGE in a transaction and rolls it back. Without INSERT or UPDATE, it logs a warning with the GRANT to run, sets oracledb_cdc_checkpoint_legacy_procedure to 1, and writes with the stored procedure as before. The docs list SELECT, INSERT and UPDATE on the checkpoint table, and the commit message has the upgrade step. A future version removes the fallback, and then a failed probe fails Connect. TestIntegrationCheckpointCacheProcedureFallback reproduces your ORA-41900 case.

…sky-acd5b6

# Conflicts:
#	internal/impl/oracledb/checkpoint_cache.go
Oracle 23ai returns ORA-41900 for a missing object privilege, and older
versions return ORA-01031. The snapshot checked both codes for the FLASHBACK
grant. The checkpoint cache needs the same check, so it moves to
replication.IsMissingPrivilege.
…SERT

The stored procedure runs with the rights of its owner, so a user with only
SELECT and UPDATE on the checkpoint table and EXECUTE on the procedure could
write checkpoints. The MERGE fails for that user with ORA-41900 (or ORA-01031).

At start up, the cache now runs the MERGE in a transaction and rolls it back.
If a privilege is missing, it logs a warning with the GRANT to run, sets the
gauge oracledb_cdc_checkpoint_legacy_procedure to 1, and writes with the
stored procedure as before. Another probe error fails Connect, so that it
tries again.

Upgrade step: grant SELECT, INSERT and UPDATE on the checkpoint table to the
Connect user. A future version removes the stored procedure fallback.
Leward added a commit that referenced this pull request Nov 24, 2026
#4880 now probes the MERGE at start up and falls back to the stored procedure
when a privilege is missing. This PR keeps only the checkpoint write error
counter, which is useful for any checkpoint cache.
… helper

TestIntegrationCheckpointCacheTablesInSameSchema now writes through two
caches instead of two pipelines. It still fails with the old per-schema
procedure, and runs in 0.5 s instead of 13 s.

The fallback test creates the procedure with the production
createUpsertStoredProc instead of a copy of its SQL.

TestDB.CreateUserWithGrants replaces two copies of the same helper, in the
checkpoint cache and the flashback snapshot tests.

IsMissingPrivilege links the Oracle docs of ORA-01031 and ORA-41900.
@Leward Leward changed the title oracledb_cdc: upsert checkpoints with MERGE instead of a stored procedure oracledb_cdc: upsert checkpoints with MERGE, fall back to the procedure Nov 24, 2026
…exports

selectCheckpointWrite now picks between mergeWrite and procedureWrite. The
rolled back probe moves to replication.ProbeStatement, next to
IsMissingPrivilege, and TestIntegrationProbeStatement checks both against a
real Oracle error.

The checkpoint cache tests move to the internal test package, so
export_test.go is no longer needed. The Permissions docs are shorter.
mergeWrite returns the raw probe error. selectCheckpointWrite handles
success, other errors and a missing privilege one after the other, so the
warning starts with its own sentence and not with a wrapped error.
…claude/wizardly-meninsky-acd5b6

# Conflicts:
#	internal/impl/oracledb/input_oracledb_cdc.go
…ntence

CreateUserWithGrants takes t, so a failed grant is reported on the subtest
that uses the user, and the user is dropped when that subtest ends.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants