Skip to content

core,api: Make BaseSnapshot and Schema lazy fields thread-safe [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #17586

Open
waterWang wants to merge 2 commits into
apache:mainfrom
waterWang:fix/threadsafe-lazy-init-17585
Open

core,api: Make BaseSnapshot and Schema lazy fields thread-safe [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT]#17586
waterWang wants to merge 2 commits into
apache:mainfrom
waterWang:fix/threadsafe-lazy-init-17585

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #17585

RESTTableCache caches TableMetadata and shares it across threads. TableMetadata lazily-initializes fields in BaseSnapshot and Schema without synchronization, while PartitionSpec correctly uses synchronized + volatile (double-checked locking).

This PR applies the same thread-safe lazy-initialization pattern:

  • BaseSnapshot: mark 7 lazy fields volatile and guard allManifests/dataManifests/deleteManifests/addedDataFiles/removedDataFiles/addedDeleteFiles/removedDeleteFiles getters with double-checked locking (synchronized (this) + inner null check).
  • Schema: mark 7 lazy fields volatile and guard the 6 lazy*() initializers (lazyIdToField, lazyNameToId, lazyIdToName, lazyLowerCaseNameToId, lazyIdToAccessor, lazyIdentifierFieldIdSet) with double-checked locking.

This eliminates the data race on lazily-initialized fields when TableMetadata is shared across threads (e.g. via RESTSessionCatalog's RESTTableCache), matching the existing PartitionSpec pattern.

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.

TableMetadata is not thread-safe

1 participant