Skip to content

oracledb_cdc: tolerate a checkpoint table created by another pipeline - #4887

Merged
Leward merged 5 commits into
mainfrom
pj/oracledb-cache-table-race
Nov 17, 2026
Merged

Leward merged 5 commits into
mainfrom
pj/oracledb-cache-table-race

Conversation

@Leward

@Leward Leward commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CREATE TABLE for the checkpoint cache is check-then-create. When two pipelines start at the same time on one table, both see no table. The second CREATE TABLE fails with ORA-00955, and that pipeline does not start.

 createCacheTable
   if cacheTableExists
     migrate
     return
   CREATE TABLE
-  on error: fail
+  on ORA-00955:
+    if cacheTableExists          # another pipeline created it
+      return (not created)       # its table has the current layout, no migration
+    fail with ORA-00955          # name is a view or another user's table
+  on other error: fail

The second check matters. all_tables only lists tables that the connected user can see. A naive "continue on ORA-00955" would start the pipeline, and it would then fail at the first checkpoint write with a confusing error.

Evidence

  • TestIntegrationCheckpointCacheConcurrentCreate (new): five concurrent createCacheTable calls on one fresh table. All must succeed, and exactly one must report that it created the table.
    Before: on main, three or four of the five calls fail with ORA-00955 in every run.
    After: passes.
  • TestIntegrationCheckpointCacheNameIsAView (new): names a view as the cache table and expects a start up error.
    Before: passes on main. Fails on a naive "continue on ORA-00955".
    After: passes.
  • TestIntegrationMigrateCheckpointCache still passes.

Merge Danger

Door: two-way

The change only adds a recovery path after ORA-00955. It does not change the table layout or stored data. A revert brings back the old start up failure and nothing else.

Blast Radius: small

Only oracledb_cdc start up when it creates the checkpoint cache table. The stored procedure has the same check-then-create race, and this PR does not fix it. #4880 removes the procedure, so the start up path is race free once both PRs are merged. The concurrent test calls createCacheTable directly, so this PR does not depend on #4880.

var oraErr *goora.OracleError
if errors.As(err, &oraErr) && oraErr.ErrCode == errCodeNameAlreadyUsed {
if exists, checkErr := cacheTableExists(ctx, db, tbl); checkErr == nil && exists {
return false, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: the concurrent-start fix only covers half the race (§3.1.4)

This handles the case where two pipelines race on CREATE TABLE. But both of them then call createUpsertStoredProc (checkpoint_cache.go#L258-L297), which does the same check-then-create for CDC_CHECKPOINT_CACHE_UPDATE. It uses a COUNT(*) on ALL_PROCEDURES and then a plain CREATE PROCEDURE. So when two pipelines start at the same time on a fresh schema, both see no procedure, and the second CREATE PROCEDURE fails with ORA-00955. The pipeline start the commit message describes still fails, just one step later.

Suggested fix: make the procedure creation idempotent too. CREATE OR REPLACE PROCEDURE is the simplest option, since the body is always the same. Or apply the same ORA-00955 tolerance there: re-check ALL_PROCEDURES and continue if the procedure now exists.

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.

Correct, this PR only covers CREATE TABLE. The procedure is removed in #4880, which replaces it with a MERGE from the connector.

The race is fully closed once both are merged. I will not touch createUpsertStoredProc here, because #4880 deletes it and the two PRs would conflict.

Comment on lines +246 to +249
var oraErr *goora.OracleError
if errors.As(err, &oraErr) && oraErr.ErrCode == errCodeNameAlreadyUsed {
if exists, checkErr := cacheTableExists(ctx, db, tbl); checkErr == nil && exists {
return false, nil

This comment was marked as duplicate.

// TestIntegrationCheckpointCacheNameIsAView makes sure that the cache fails at start up when the configured table name
// belongs to an object that is not a table. CREATE TABLE fails with ORA-00955, the same error as when another pipeline
// created the table first, so the cache must not mistake the view for that table.
func TestIntegrationCheckpointCacheNameIsAView(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test coverage: this test only covers the negative branch, where the name belongs to a view and the error is kept. No test covers the behaviour this PR adds: if another pipeline created the table between the check and CREATE TABLE, createCacheTable should return false, nil and newCheckpointCache should succeed. The tester guidelines say to flag changed code that lacks tests.

Suggested test: start several newCheckpointCache calls on the same table name at the same time (for example with an errgroup) and assert that all of them succeed. That test would also catch the remaining stored-procedure race described in the other comment.

Comment on lines +244 to +250
// Another pipeline can create the table after our check. Its table has the current layout, so no
// migration is necessary. Re-check because the name can also belong to a view or to another user's table.
var oraErr *goora.OracleError
if errors.As(err, &oraErr) && oraErr.ErrCode == errCodeNameAlreadyUsed {
if exists, checkErr := cacheTableExists(ctx, db, tbl); checkErr == nil && exists {
return false, nil
}

This comment was marked as duplicate.

CREATE TABLE for the checkpoint cache was check-then-create. Two
pipelines that start at the same time on one table both see no table,
and the second CREATE TABLE fails the pipeline start with ORA-00955.
Continue when the table is visible after that error. Keep the error
when the name belongs to a view or to a table of another user.
@Leward
Leward force-pushed the pj/oracledb-cache-table-race branch from 092ae7e to f538428 Compare November 17, 2026 05:09
// migration is necessary. Re-check because the name can also belong to a view or to another user's table.
var oraErr *goora.OracleError
if errors.As(err, &oraErr) && oraErr.ErrCode == errCodeNameAlreadyUsed {
if exists, checkErr := cacheTableExists(ctx, db, tbl); checkErr == nil && exists {

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.

nit: checkErr is dropped here. If the second cacheTableExists call fails (a cancelled context or a lost connection, for example), the user only sees ORA-00955 and nothing says the re-check failed. Also, when the name is a view or another user's table, the error is a bare creating table: ORA-00955. A short hint would make both cases easier to debug:

exists, checkErr := cacheTableExists(ctx, db, tbl)
if checkErr != nil {
	return false, fmt.Errorf("creating table: %w (re-check failed: %v)", err, checkErr)
}
if exists {
	return false, nil
}
return false, fmt.Errorf("creating table: name is used by an object that is not a table visible to this user: %w", err)

Optional, fine to leave as is.

…t find the table

Show the re-check error when the re-check fails. Add a hint when the name
belongs to an object that is not a table visible to the connected user.
@Leward
Leward merged commit 94246e3 into main Nov 17, 2026
15 checks passed
@Leward
Leward deleted the pj/oracledb-cache-table-race branch November 17, 2026 15:10
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