apache / apache/iceberg

TableMetadata is not thread-safe

Open
#17,585 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
9.2k
Forks
3.5k
Avg merge
2d 11h
Merged PRs (30d)
132

Description

### Apache Iceberg version

1.11.0 (latest release)

### Query engine

Trino

### Please describe the bug 🐞

`RESTSessionCatalog`'s `RESTTableCache` caches `TableMetadata` and shares it across threads. `TableMetadata` itself handles this correctly - its lazy fields use `synchronized` + `volatile`. However, `BaseSnapshot` and `Schema`, reachable from `TableMetadata`, have lazily-initialized fields with no synchronization:

https://github.com/apache/iceberg/blob/7aa4f97fae8f6393950d925ca67e8331a780a20a/core/src/main/java/org/apache/iceberg/BaseSnapshot.java#L51-L57

https://github.com/apache/iceberg/blob/7aa4f97fae8f6393950d925ca67e8331a780a20a/api/src/main/java/org/apache/iceberg/Schema.java#L77-L83

`PartitionSpec` follows the same lazy pattern but correctly uses `synchronized` + `volatile`.

### 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

Contributor guide

Open the contributing guide

Research direction

Start with the lazy fields at the referenced lines in core/src/main/java/org/apache/iceberg/BaseSnapshot.java and api/src/main/java/org/apache/iceberg/Schema.java, then compare their initialization pattern with PartitionSpec. Trace how RESTTableCache shares TableMetadata across threads and verify that concurrent access to these fields is safe without changing the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.