Skip to content

Fix stale server status in lifecycle statistics by using getDirectly() instead of get() - #2529

Open
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:master
Open

Fix stale server status in lifecycle statistics by using getDirectly() instead of get()#2529
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:master

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #2528

Problem

JobStatisticsAPIImpl.isAllDisabled(), JobStatisticsAPIImpl.getJobStatusByJobNameAndIp(), and ServerStatisticsAPIImpl.getAllServersBriefInfo() read server status via regCenter.get(), which returns data from CuratorCache. After JobOperateAPI.disable() or JobOperateAPI.enable() writes the new value to ZooKeeper, the cache refresh is asynchronous — there is a window where the cached value is still the old one.

For example, after a server node changes from ENABLED to DISABLED:

  • JobStatisticsAPI.getJobsBriefInfo(ip) can still return OK
  • JobStatisticsAPI.getJobBriefInfo(jobName) can fail to report that all servers are disabled
  • ServerStatisticsAPI.getAllServersBriefInfo() can undercount disabledJobsNum

Fix

Use regCenter.getDirectly() instead of regCenter.get() for server status reads in the three methods above. getDirectly() always reads the authoritative value from ZooKeeper, bypassing the local cache.

Scope

Only server status values under /<jobName>/servers/<serverIp>. Sharding assignment consistency and instance traversal races are not affected.

Testing

Updated existing unit tests to mock getDirectly() instead of get() for server status paths — the tests verify the same behavior (DISABLED → DISABLED, mixed → OK, per-IP → DISABLED) against the authoritative read path.

…) instead of get()

Switched from regCenter.get() to regCenter.getDirectly() for server status
reads in JobStatisticsAPIImpl and ServerStatisticsAPIImpl. The get() method
returns data from CuratorCache, which can return stale values during the
async cache propagation window after ZooKeeper writes. getDirectly() always
reads the authoritative value from ZooKeeper.

Affected methods:
- JobStatisticsAPIImpl.isAllDisabled()
- JobStatisticsAPIImpl.getJobStatusByJobNameAndIp()
- ServerStatisticsAPIImpl.getAllServersBriefInfo()

Fixes apache#2528

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You obviously need to resolve the merge conflict.

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.

Lifecycle statistics may return stale server status from CuratorCache

2 participants