Repository navigation
oracledb_cdc: tolerate a checkpoint table created by another pipeline - #4887
Conversation
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
| 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.
This comment was marked as duplicate.
Sorry, something went wrong.
| // 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) { |
There was a problem hiding this comment.
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.
| // 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.
This comment was marked as duplicate.
Sorry, something went wrong.
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.
092ae7e to
f538428
Compare
| // 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 { |
There was a problem hiding this comment.
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.
Summary
CREATE TABLEfor the checkpoint cache is check-then-create. When two pipelines start at the same time on one table, both see no table. The secondCREATE TABLEfails 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: failThe second check matters.
all_tablesonly 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 concurrentcreateCacheTablecalls 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.
TestIntegrationMigrateCheckpointCachestill 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_cdcstart 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 callscreateCacheTabledirectly, so this PR does not depend on #4880.