Flink: JdbcLockFactory concurrent lock-table creation can fail with "table already exists" and restart the job

Open Beginner friendly
#18,797 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend, databases

Research direction

Read JdbcLockFactory.initializeLockTables() and the CREATE_LOCK_TABLE_SQL definition, then check how TriggerManager and LockRemover call lockFactory.open(). Reproduce the concurrent table creation path and inspect the related Flink maintenance tests. Done means both operators can open the factory when the lock table is initially absent without failing the job.

Written by the indexing model from the issue text.

Description

bug
Apache Iceberg version

1.12.0 (latest release)

Query engine

Flink

Please describe the bug 🐞

With flink-maintenance.lock.jdbc.init-lock-table=true, two operators in the same job open the same JdbcLockFactory and each tries to create the lock table:

  • TriggerManager calls lockFactory.open() in initializeState.
  • LockRemover calls lockFactory.open() in open() (LockRemover.java:114).

JdbcLockFactory.initializeLockTables() runs CREATE_LOCK_TABLE_SQL only if the table is missing. That statement is a plain CREATE TABLE without IF NOT EXISTS, so the sequence is check-then-create. If both operators run the
check before either one has created the table, the second CREATE TABLE fails and the task goes to FAILED.

Encountered this bug when writing an E2E test in PR,
https://github.com/apache/iceberg/pull/18661#discussion_r4470462231

Willingness to contribute
  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time
Dominant language
Java
Stars
9.4k
Forks
3.6k
Avg merge
3d 16h
Merged PRs (30d)
138

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/iceberg

All issues in apache/iceberg

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.