Skip to content

[CELEBORN-2577] Fix FsConfigServiceImpl#refreshCache publishing partially built dynamic config caches - #3984

Open
HanShuhang wants to merge 2 commits into
apache:mainfrom
HanShuhang:fix/hsh-fs-config-cache-publication
Open

HanShuhang wants to merge 2 commits into
apache:mainfrom
HanShuhang:fix/hsh-fs-config-cache-publication

Conversation

@HanShuhang

@HanShuhang HanShuhang commented Nov 19, 2026 •

Copy link
Copy Markdown

What changes were proposed in this pull request?

FsConfigServiceImpl#refreshCache was setting tenantConfigAtomicReference and tenantUserConfigAtomicReference inside the parsing loop. Those are the same HashMaps the loop is still filling, so another thread could read anempty or half-built tenant cache while the refresh was in progress. When that happened, DynamicConfig#getValue would fall through to the system-level config or the static CelebornConf default and return a different value thanwhat's in dynamicConfig.yaml.

Now the file is parsed and validated first, and the three caches are published once at the end. The three refs are still swapped separately and TenantConfig still resolves its parent through the live cache. That's pre-existing, so it's out of scope here.

Two things I had to fix along the way:

  • If a SYSTEM record doesn't have tags, the new SystemConfig used to end up with a null tag map. TagsManager.getTagStore passes that straight into JavaUtils.newConcurrentHashMap, so tag lookup would NPE. It now keeps theprevious tags, and getTags() never returns null.
  • A typo like level: SYSETM used to be silently skipped, but the new snapshot would then wipe the previous system config and tags. The file is now validated before anything is published, so an unknown level or a TENANT recordwithout tenantId fails the refresh and leaves the old caches alone. [] is still the explicit way to clear everything.

Why are the changes needed?

While dynamicConfig.yaml is being reloaded, a master/worker thread can read an empty or partially built tenant cache and fall back to the system-level or static config, so it may end up loading the wrong config value.

ConfigServiceSuiteJ#testFsConfig is flaky for the same reason.

Does this PR resolve a correctness bug?

  • Yes

Does this PR introduce any user-facing change?

  • Yes

How was this patch tested?

  • mvn -pl service test -Dtest=ConfigServiceSuiteJ
  • mvn spotless:check

@HanShuhang HanShuhang changed the title [MINOR] Fix flaky ConfigServiceSuiteJ by publishing dynamic config ca… [MINOR] Fix flaky ConfigServiceSuiteJ by publishing dynamic config caches after parsing Nov 19, 2026
@github-actions github-actions Bot added correctness Correctness bugfix and removed correctness Correctness bugfix labels Nov 19, 2026

@zaynt4606 zaynt4606 left a comment

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.

Thanks for fixing the publication of partially built tenant maps. I reproduced two regressions in the filesystem refresh path, noted inline.

Could you also narrow the snapshot guarantee in the PR description? Each tenant map is fully built before publication, but the three references are swapped separately and TenantConfig still resolves its parent through the current cache. A user config obtained before a refresh can therefore inherit a value from the next refresh. This behavior also exists on the base commit and can be tracked separately.

Since the fix affects the production refresh path, could you link a Bug-type CELEBORN JIRA and use its key in place of [MINOR]?

@Override
public synchronized void refreshCache() {
try (FileInputStream fileInputStream = new FileInputStream(getConfigFile(System.getenv()))) {
SystemConfig systemConfig = new SystemConfig(celebornConf);

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.

[P2] Preserve safe tag lookup after a refresh that omits SYSTEM.tags.

When a file that previously defined tags is replaced by a valid SYSTEM entry with config only, the old code keeps the current tags. The new SystemConfig leaves getTags() null. TagsManager.getTagStore passes that value straight to JavaUtils.newConcurrentHashMap, so a request with a nonempty tag expression can now fail with NullPointerException. I reproduced the map copy succeeding on the base commit and failing after the same refresh on this revision.

Could we preserve the existing behavior for omitted tags? If omission is intended to clear tags, please make the lookup use an empty map and cover refresh from populated tags to no tags.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I fixed it by keeping the previous tags when the SYSTEM record doesn't define tags, and by initializing the tag map in SystemConfig so getTags() can't return null. An explicit [] still clears tags to an empty map. Added a test thatrefreshes from a file with tags to one without and checks the tags are still there.

tenantUserConfigAtomicReference.set(tenantUserConfigs);
}
// Publish only after every record has been parsed; readers must not see maps being built.
systemConfigAtomicReference.set(systemConfig);

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.

[P2] Keep the previous system config when the input contains an unrecognized record.

A YAML record with a misspelled level: SYSETM and no tenantId parses successfully and is skipped by the loop. Publishing the new empty SystemConfig then discards the previous system settings and tags while the refresh reports success. On the base commit the system settings and tags survive the same input. The current failure test exercises a type error that throws, so it does not catch a record that is silently ignored.

Could we distinguish a deliberately empty list ([]) from an unrecognized record and reject the latter before publishing any of the new caches?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right, that was a behavior change I introduced. The file is now validated before anything is published: an unknown level, or a TENANT record without tenantId, makes refresh throw and leaves the previous caches untouched. []is still how you clear everything.

@HanShuhang HanShuhang changed the title [MINOR] Fix flaky ConfigServiceSuiteJ by publishing dynamic config caches after parsing [CELEBORN-2577] Fix FsConfigServiceImpl#refreshCache publishing partially built dynamic config caches Nov 20, 2026
@HanShuhang
HanShuhang force-pushed the fix/hsh-fs-config-cache-publication branch from a69b684 to 2e2112a Compare November 20, 2026 03:35
@github-actions github-actions Bot added the correctness Correctness bugfix label Nov 20, 2026
@HanShuhang

HanShuhang commented Nov 20, 2026 •

Copy link
Copy Markdown
Author

t

Thanks for the review. I reworded the description so it only claims that each map is complete before publication, not that the whole refresh is one atomic snapshot. I created CELEBORN-2577 (Bug) and retitled the PR. The two inline issues were real regressions. Both are fixed in the latest push. Details are in the threads.

@HanShuhang HanShuhang closed this Nov 20, 2026
@HanShuhang HanShuhang reopened this Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants