-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Refactor ConfigCache and related pathways ,uniformly use UTF-8 encoding for md5 fields #12876
Changes from 3 commits
2a4da2a
cec625c
fc7a15a
9644edc
07da6e3
0ea6fe0
392ef61
b8dea6a
042db53
2a0dafa
3042bf2
4f67995
52c661b
0de3352
5c4bdb4
7651eb3
66705e3
4961191
28548c1
fce80e3
1d73500
135bf61
4616dd4
16b6a80
a5c2855
e6389f9
9831fa7
fae642f
12699ee
96d2c73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 1999-2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.config.server.model; | ||
|
||
/** | ||
* The interface Config cache factory. | ||
* | ||
* @author Sunrisea | ||
*/ | ||
public interface ConfigCacheFactory { | ||
|
||
/** | ||
* Create config cache config cache. | ||
* | ||
* @return the config cache | ||
*/ | ||
public ConfigCache createConfigCache(); | ||
|
||
/** | ||
* Create config cache config cache. | ||
* | ||
* @param md5 the md 5 | ||
* @param lastModifiedTs the last modified ts | ||
* @return the config cache | ||
*/ | ||
public ConfigCache createConfigCache(String md5, long lastModifiedTs); | ||
|
||
/** | ||
* Create config cache gray config cache gray. | ||
* | ||
* @param grayName the gray name | ||
* @return the config cache gray | ||
*/ | ||
public ConfigCacheGray createConfigCacheGray(String grayName); | ||
|
||
/** | ||
* Create config cache gray config cache gray. | ||
* | ||
* @param md5 the md 5 | ||
* @param lastModifiedTs the last modified ts | ||
* @param grayRule the gray rule | ||
* @return the config cache gray | ||
*/ | ||
public ConfigCacheGray createConfigCacheGray(String md5, long lastModifiedTs, String grayRule); | ||
|
||
/** | ||
* Gets config cache factroy name. | ||
* | ||
* @return the config cache factory name | ||
*/ | ||
public String getConfigCacheFactoryName(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 1999-2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.config.server.model; | ||
|
||
import com.alibaba.nacos.common.spi.NacosServiceLoader; | ||
import com.alibaba.nacos.common.utils.StringUtils; | ||
import com.alibaba.nacos.sys.env.EnvUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* The type Config cache factory delegate. | ||
* | ||
* @author Sunrisea | ||
*/ | ||
public class ConfigCacheFactoryDelegate { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCacheFactoryDelegate.class); | ||
|
||
private static final ConfigCacheFactoryDelegate INSTANCE = new ConfigCacheFactoryDelegate(); | ||
|
||
private String configCacheFactoryType = EnvUtil.getProperty("nacos.config.cache.type", "nacos"); | ||
|
||
private ConfigCacheFactory configCacheFactory = null; | ||
|
||
private ConfigCacheFactoryDelegate() { | ||
Collection<ConfigCacheFactory> configCacheFactories = NacosServiceLoader.load(ConfigCacheFactory.class); | ||
for (ConfigCacheFactory each : configCacheFactories) { | ||
if (StringUtils.isEmpty(each.getConfigCacheFactoryName())) { | ||
LOGGER.warn("[ConfigCacheFactory] Load ConfigCacheFactory({}) ConfigFactroyName (null/empty) fail. " | ||
+ "Please add ConfigFactoryName to resolve", | ||
each.getClass()); | ||
continue; | ||
} | ||
LOGGER.info("[ConfigCacheFactory] Load ConfigCacheFactory({}) ConfigCacheFactoryName({}) successfully. ", | ||
each.getClass(), each.getConfigCacheFactoryName()); | ||
if (StringUtils.equals(configCacheFactoryType, each.getConfigCacheFactoryName())) { | ||
this.configCacheFactory = each; | ||
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. add log , load specific config cache factory successfully with name {name} |
||
} | ||
} | ||
if (this.configCacheFactory == null) { | ||
this.configCacheFactory = new NacosConfigCacheFactory(); | ||
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. add log , load default config cache factory successfully |
||
} | ||
} | ||
|
||
public static ConfigCacheFactoryDelegate getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
public ConfigCache createConfigCache() { | ||
return configCacheFactory.createConfigCache(); | ||
} | ||
|
||
public ConfigCache createConfigCache(String md5, long lastModifiedTs) { | ||
return configCacheFactory.createConfigCache(md5, lastModifiedTs); | ||
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. 改为 |
||
} | ||
|
||
public ConfigCacheGray createConfigCacheGray(String grayName) { | ||
return configCacheFactory.createConfigCacheGray(grayName); | ||
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. 改为 |
||
} | ||
|
||
public ConfigCacheGray createConfigCacheGray(String md5, long lastModifiedTs, String grayRule) { | ||
return configCacheFactory.createConfigCacheGray(md5, lastModifiedTs, grayRule); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 1999-2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.config.server.model; | ||
|
||
/** | ||
* The interface Config cache md5 post processor. | ||
* | ||
* @author Sunrisea | ||
*/ | ||
public interface ConfigCacheMd5PostProcessor { | ||
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. 类名上可以不要透出md5,不要在开源侧过多展示md5相关的语义 |
||
|
||
/** | ||
* Gets post processor name. | ||
* | ||
* @return the post processor name | ||
*/ | ||
public String getPostProcessorName(); | ||
|
||
/** | ||
* Post process. | ||
* | ||
* @param configCache the config cache | ||
* @param content the content | ||
*/ | ||
public void postProcess(ConfigCache configCache, String content); | ||
} |
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.
interface中减少方法数量,仅透出createConfigCache(),createConfigCacheGray() ,
比如
可在次基础上在ConfigCacheFactoryDelegate中重载提供四个方法,内部调用ConfigCacheFactory中的原子方法进行二次封装