Skip to content
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

fix:fix config recreate NPE. #565

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ public void addConfigFile(RemoteConfigFileRepo remoteConfigFileRepo) {
}
}

public void removeConfigFile(RemoteConfigFileRepo remoteConfigFileRepo) {
ConfigFileMetadata configFileMetadata = remoteConfigFileRepo.getConfigFileMetadata();
long version = remoteConfigFileRepo.getConfigFileVersion();
LOGGER.info("[Config] remove long polling config file. file = {}, version = {}", configFileMetadata, version);
configFilePool.remove(configFileMetadata);
//长轮询起始的配置文件版本号应该以第一次同步拉取为准
notifiedVersion.remove(configFileMetadata);
}

private void startLongPollingTask() {
if (!started.compareAndSet(false, true)) {
return;
Expand Down Expand Up @@ -157,7 +148,7 @@ private void doLongPolling() {
changedConfigFile.getFileGroup(),
changedConfigFile.getFileName());
long newNotifiedVersion = changedConfigFile.getVersion();
long oldNotifiedVersion = notifiedVersion.get(metadata);
long oldNotifiedVersion = notifiedVersion.getOrDefault(metadata, -1L);

long maxVersion = newNotifiedVersion;
if (connector.isNotifiedVersionIncreaseStrictly()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,6 @@ public ConfigKVFile getConfigKVFile(ConfigFileMetadata configFileMetadata, Confi
return configFile;
}

public ConfigKVFile removeConfigKVFile(ConfigFileMetadata configFileMetadata) {
ConfigKVFile configFile = null;
synchronized (this) {
configFile = configPropertiesFileCache.get(configFileMetadata);
if (configFile != null) {
configFile = configPropertiesFileCache.remove(configFileMetadata);
}
}
return configFile;
}

public ConfigFileResponse createConfigFile(CreateConfigFileRequest request) {
com.tencent.polaris.api.plugin.configuration.ConfigFile configFile =
new com.tencent.polaris.api.plugin.configuration.ConfigFile(request.getNamespace(),
Expand Down Expand Up @@ -172,7 +161,7 @@ public ConfigFileResponse upsertAndPublish(ConfigPublishRequest request) {
public ConfigFile createConfigFile(ConfigFileMetadata configFileMetadata) {

ConfigFileRepo configFileRepo = new RemoteConfigFileRepo(context, longPullService, configFileFilterChain,
connector, configFileMetadata, persistentHandler, this);
connector, configFileMetadata, persistentHandler);

return new DefaultConfigFile(configFileMetadata.getNamespace(), configFileMetadata.getFileGroup(),
configFileMetadata.getFileName(), configFileRepo,
Expand All @@ -181,7 +170,7 @@ public ConfigFile createConfigFile(ConfigFileMetadata configFileMetadata) {

public ConfigKVFile createConfigKVFile(ConfigFileMetadata configFileMetadata, ConfigFileFormat format) {
ConfigFileRepo configFileRepo = new RemoteConfigFileRepo(context, longPullService, configFileFilterChain,
connector, configFileMetadata, persistentHandler, this);
connector, configFileMetadata, persistentHandler);
switch (format) {
case Properties: {
return new ConfigPropertiesFile(configFileMetadata.getNamespace(), configFileMetadata.getFileGroup(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.client.util.NamedThreadFactory;
import com.tencent.polaris.configuration.api.core.ConfigFileMetadata;
import com.tencent.polaris.configuration.api.core.ConfigKVFile;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -56,8 +55,6 @@ public class RemoteConfigFileRepo extends AbstractConfigFileRepo {
private final RetryPolicy retryPolicy;
private ConfigFilePersistentHandler configFilePersistHandler;
private final boolean fallbackToLocalCache;
private final ConfigFileManager configFileManager;
private final ConfigFileLongPullService pullService;

private String token;

Expand All @@ -70,7 +67,7 @@ public RemoteConfigFileRepo(SDKContext sdkContext,
ConfigFileFilterChain configFileFilterChain,
ConfigFileConnector connector,
ConfigFileMetadata configFileMetadata,
ConfigFilePersistentHandler handler, ConfigFileManager configFileManager) {
ConfigFilePersistentHandler handler) {
super(sdkContext, configFileMetadata);
//保证线程池正常初始化
createPullExecutorService();
Expand All @@ -80,8 +77,6 @@ public RemoteConfigFileRepo(SDKContext sdkContext,
this.retryPolicy = new ExponentialRetryPolicy(1, 120);
this.configFilePersistHandler = handler;
this.configFileFilterChain = configFileFilterChain;
this.configFileManager = configFileManager;
this.pullService = pullService;
//获取远程调用插件实现类
this.configFileConnector = connector;
this.fallbackToLocalCache = sdkContext.getConfig().getConfigFile().getServerConnector().getFallbackToLocalCache();
Expand Down Expand Up @@ -193,8 +188,6 @@ protected void doPull() {
//删除配置文件
if (remoteConfigFile.get() != null) {
remoteConfigFile.set(null);
ConfigKVFile configKVFile = configFileManager.removeConfigKVFile(configFileMetadata);
pullService.removeConfigFile(this);
//删除配置文件也需要触发通知
fireChangeEvent(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testPullSuccess() {

RemoteConfigFileRepo remoteConfigFileRepo =
new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileFilterChain, configFileConnector,
configFileMetadata, configFilePersistHandler, new ConfigFileManager());
configFileMetadata, configFilePersistHandler);

verify(configFileFilterChain).execute(any(), any());
verify(configFileLongPollingService).addConfigFile(remoteConfigFileRepo);
Expand All @@ -108,7 +108,7 @@ public void testPullNotFoundConfigFile() {

RemoteConfigFileRepo remoteConfigFileRepo =
new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileFilterChain, configFileConnector,
configFileMetadata, configFilePersistHandler, new ConfigFileManager());
configFileMetadata, configFilePersistHandler);

verify(configFileFilterChain).execute(any(), any());
verify(configFileLongPollingService).addConfigFile(remoteConfigFileRepo);
Expand All @@ -127,7 +127,7 @@ public void testPullWithUnexpectedResponseCode() {

RemoteConfigFileRepo remoteConfigFileRepo =
new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileFilterChain, configFileConnector,
configFileMetadata, configFilePersistHandler, new ConfigFileManager());
configFileMetadata, configFilePersistHandler);

//重试三次
verify(configFileFilterChain, times(3)).execute(any(), any());
Expand All @@ -145,7 +145,7 @@ public void testPullWithRetryException() {

RemoteConfigFileRepo remoteConfigFileRepo =
new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileFilterChain, configFileConnector,
configFileMetadata, configFilePersistHandler, new ConfigFileManager());
configFileMetadata, configFilePersistHandler);

//重试三次
verify(configFileFilterChain, times(3)).execute(any(), any());
Expand All @@ -171,7 +171,7 @@ public void testNotifyAndPullSecondTime() throws InterruptedException {

RemoteConfigFileRepo remoteConfigFileRepo =
new RemoteConfigFileRepo(sdkContext, configFileLongPollingService, configFileFilterChain, configFileConnector,
configFileMetadata, configFilePersistHandler, new ConfigFileManager());
configFileMetadata, configFilePersistHandler);

AtomicInteger cbCnt = new AtomicInteger();
//增加两个listener
Expand Down
Loading