-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize checkLocalConfig logic #11869
Open
PleaseGiveMeTheCoke
wants to merge
5
commits into
alibaba:develop
Choose a base branch
from
PleaseGiveMeTheCoke:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bf32067
优化checkLocalConfig逻辑
PleaseGiveMeTheCoke 46b5cc9
修改不规范的等号和分号
PleaseGiveMeTheCoke 90a9eaa
1. 多次校验文件是否存在
PleaseGiveMeTheCoke 8c109d8
format
PleaseGiveMeTheCoke dabda8a
Merge branch 'alibaba:develop' into develop
PleaseGiveMeTheCoke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -866,42 +866,36 @@ public void checkLocalConfig(CacheData cacheData) { | |
final String group = cacheData.group; | ||
final String tenant = cacheData.tenant; | ||
final String envName = cacheData.envName; | ||
|
||
// Check if a failover file exists for the specified dataId, group, and tenant. | ||
File file = LocalConfigInfoProcessor.getFailoverFile(envName, dataId, group, tenant); | ||
|
||
// If not using local config info and a failover file exists, load and use it. | ||
if (!cacheData.isUseLocalConfigInfo() && file.exists()) { | ||
|
||
// not using local config info, but a failover file exists | ||
boolean failOverFileCreated = !cacheData.isUseLocalConfigInfo() && file.exists(); | ||
|
||
// using local config info, but there is a change in local configuration | ||
boolean failOverFileChanged = cacheData.isUseLocalConfigInfo() && file.exists() && cacheData.getLocalConfigInfoVersion() != file.lastModified(); | ||
|
||
// using local config info, but the failover file is deleted | ||
boolean failOverFileDeleted = cacheData.isUseLocalConfigInfo() && !file.exists(); | ||
|
||
if (failOverFileCreated || failOverFileChanged) { | ||
// load and use the file content | ||
String content = LocalConfigInfoProcessor.getFailover(envName, dataId, group, tenant); | ||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); | ||
cacheData.setUseLocalConfigInfo(true); | ||
cacheData.setLocalConfigInfoVersion(file.lastModified()); | ||
cacheData.setContent(content); | ||
LOGGER.warn( | ||
"[{}] [failover-change] failover file created. dataId={}, group={}, tenant={}, md5={}, content={}", | ||
envName, dataId, group, tenant, md5, ContentUtils.truncateContent(content)); | ||
return; | ||
"[{}] [failover-change] failover file {}. dataId={}, group={}, tenant={}, md5={}, content={}", | ||
failOverFileCreated ? "created" : "changed", envName, dataId, group, tenant, md5, ContentUtils.truncateContent(content)); | ||
} | ||
// If use local config info, but the failover file is deleted, switch back to server config. | ||
if (cacheData.isUseLocalConfigInfo() && !file.exists()) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (failOverFileDeleted) { | ||
// switch back to server config. | ||
cacheData.setUseLocalConfigInfo(false); | ||
LOGGER.warn("[{}] [failover-change] failover file deleted. dataId={}, group={}, tenant={}", envName, | ||
dataId, group, tenant); | ||
return; | ||
} | ||
|
||
// When the failover file content changes, indicating a change in local configuration. | ||
if (cacheData.isUseLocalConfigInfo() && file.exists() | ||
&& cacheData.getLocalConfigInfoVersion() != file.lastModified()) { | ||
String content = LocalConfigInfoProcessor.getFailover(envName, dataId, group, tenant); | ||
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE); | ||
cacheData.setUseLocalConfigInfo(true); | ||
cacheData.setLocalConfigInfoVersion(file.lastModified()); | ||
cacheData.setContent(content); | ||
LOGGER.warn( | ||
"[{}] [failover-change] failover file changed. dataId={}, group={}, tenant={}, md5={}, content={}", | ||
envName, dataId, group, tenant, md5, ContentUtils.truncateContent(content)); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
麻烦使用nacos-code-style进行reformat, 不需要删除缩紧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done