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

bugfix: fix the inconsistent configuration item names related to LoadBalance #5233

Merged
merged 9 commits into from Jan 12, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes/en-us/develop.md
Expand Up @@ -10,6 +10,8 @@ Add changes here for all PR submitted to the develop branch.
- [[#5021](https://github.com/seata/seata/pull/5201)] Fix JDK Reflection for Spring origin proxy failed in JDK17
- [[#5023](https://github.com/seata/seata/pull/5203)] Fix `seata-core` dependency transitive conflict in `seata-dubbo`
- [[#5224](https://github.com/seata/seata/pull/5224)] fix oracle initialize script index_name is duplicate
- [[#5233](https://github.com/seata/seata/pull/5233)] fix the inconsistent configuration item names related to LoadBalance



### optimize:
Expand All @@ -29,5 +31,6 @@ Thanks to these contributors for their code commits. Please report an unintended
- [albumenj](https://github.com/albumenj)
- [PeppaO](https://github.com/PeppaO)
- [yuruixin](https://github.com/yuruixin)
- [xingfudeshi](https://github.com/xingfudeshi)

Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
2 changes: 2 additions & 0 deletions changes/zh-cn/develop.md
Expand Up @@ -10,6 +10,7 @@
- [[#5021](https://github.com/seata/seata/pull/5201)] 修复 JDK17 下获取 Spring 原始代理对象失败的问题
- [[#5023](https://github.com/seata/seata/pull/5203)] 修复 `seata-core` 模块传递依赖冲突
- [[#5224](https://github.com/seata/seata/pull/5224)] 修复 oracle初始化脚本索引名重复的问题
- [[#5233](https://github.com/seata/seata/pull/5233)] 修复LoadBalance相关配置不一致的问题


### optimize:
Expand All @@ -29,5 +30,6 @@
- [albumenj](https://github.com/albumenj)
- [PeppaO](https://github.com/PeppaO)
- [yuruixin](https://github.com/yuruixin)
- [xingfudeshi](https://github.com/xingfudeshi)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
2 changes: 1 addition & 1 deletion common/src/main/java/io/seata/common/DefaultValues.java
Expand Up @@ -141,7 +141,7 @@ public interface DefaultValues {
* the constant TM_INTERCEPTOR_ORDER
*/
int TM_INTERCEPTOR_ORDER = Integer.MIN_VALUE + 1000;

/**
* the constant TCC_ACTION_INTERCEPTOR_ORDER
*/
Expand Down
Expand Up @@ -37,13 +37,13 @@
public class ConsistentHashLoadBalance implements LoadBalance {

/**
* The constant LOAD_BALANCE_CONSISTENT_HASH_VISUAL_NODES.
* The constant LOAD_BALANCE_CONSISTENT_HASH_VIRTUAL_NODES.
*/
public static final String LOAD_BALANCE_CONSISTENT_HASH_VISUAL_NODES = LOAD_BALANCE_PREFIX + "visualNodes";
public static final String LOAD_BALANCE_CONSISTENT_HASH_VIRTUAL_NODES = LOAD_BALANCE_PREFIX + "virtualNodes";
/**
* The constant VIRTUAL_NODES_NUM.
*/
private static final int VIRTUAL_NODES_NUM = ConfigurationFactory.getInstance().getInt(LOAD_BALANCE_CONSISTENT_HASH_VISUAL_NODES, VIRTUAL_NODES_DEFAULT);
private static final int VIRTUAL_NODES_NUM = ConfigurationFactory.getInstance().getInt(LOAD_BALANCE_CONSISTENT_HASH_VIRTUAL_NODES, VIRTUAL_NODES_DEFAULT);

@Override
public <T> T select(List<T> invokers, String xid) {
Expand Down
Expand Up @@ -37,9 +37,9 @@ void getInstance() {
void getLoadBalance() {
Configuration configuration = ConfigurationFactory.getInstance();
String loadBalanceType = configuration.getConfig(LoadBalanceFactory.LOAD_BALANCE_TYPE);
int visualNode = configuration.getInt(ConsistentHashLoadBalance.LOAD_BALANCE_CONSISTENT_HASH_VISUAL_NODES);
Assertions.assertEquals("RandomLoadBalance", loadBalanceType);
Assertions.assertEquals(10,visualNode);
int virtualNode = configuration.getInt(ConsistentHashLoadBalance.LOAD_BALANCE_CONSISTENT_HASH_VIRTUAL_NODES);
Assertions.assertEquals("XID", loadBalanceType);
Assertions.assertEquals(10,virtualNode);
}

}
}
6 changes: 3 additions & 3 deletions discovery/seata-discovery-core/src/test/resources/file.conf
Expand Up @@ -17,7 +17,7 @@
#loadBalance config
client {
loadBalance {
type = "RandomLoadBalance"
visualNodes = 10
type = "XID"
virtualNodes = 10
}
}
}
4 changes: 2 additions & 2 deletions script/client/conf/file.conf
Expand Up @@ -106,7 +106,7 @@ client {
}
}
loadBalance {
type = "RandomLoadBalance"
type = "XID"
virtualNodes = 10
}
}
Expand All @@ -120,4 +120,4 @@ tcc {
# tcc fence log clean period
cleanPeriod = 1h
}
}
}
2 changes: 1 addition & 1 deletion script/client/spring/application.properties
Expand Up @@ -54,7 +54,7 @@ seata.client.undo.log-table=undo_log
seata.client.undo.compress.enable=true
seata.client.undo.compress.type=zip
seata.client.undo.compress.threshold=64k
seata.client.load-balance.type=RandomLoadBalance
seata.client.load-balance.type=XID
seata.client.load-balance.virtual-nodes=10
seata.log.exception-rate=100
seata.service.vgroup-mapping.default_tx_group=default
Expand Down
2 changes: 1 addition & 1 deletion script/client/spring/application.yml
Expand Up @@ -44,7 +44,7 @@ seata:
type: zip
threshold: 64k
load-balance:
type: RandomLoadBalance
type: XID
virtual-nodes: 10
service:
vgroup-mapping:
Expand Down
Expand Up @@ -214,7 +214,7 @@
"name": "seata.client.load-balance.type",
"type": "java.lang.String",
"sourceType": "io.seata.spring.boot.autoconfigure.properties.client.LoadBalanceProperties",
"defaultValue": "RandomLoadBalance"
"defaultValue": "XID"
},
{
"name": "seata.client.load-balance.virtual-nodes",
Expand Down Expand Up @@ -348,7 +348,7 @@
"name": "seata.client.load-balance.type",
"values": [
{
"value": "RandomLoadBalance",
"value": "XID",
xingfudeshi marked this conversation as resolved.
Show resolved Hide resolved
"description": "the default load balance."
},
{
Expand All @@ -359,6 +359,9 @@
},
{
"value": "LeastActiveLoadBalance"
},
{
"value": "RandomLoadBalance"
}
]
},
Expand Down Expand Up @@ -442,4 +445,4 @@
]
}
]
}
}
@@ -0,0 +1,70 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* 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 io.seata.spring.boot.autoconfigure.properties.client;

import io.seata.common.loader.EnhancedServiceLoader;
import io.seata.config.Configuration;
import io.seata.config.ExtConfigurationProvider;
import io.seata.config.FileConfiguration;
import io.seata.config.springcloud.SpringApplicationContextProvider;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

import static io.seata.spring.boot.autoconfigure.StarterConstants.LOAD_BALANCE_PREFIX;
import static io.seata.spring.boot.autoconfigure.StarterConstants.PROPERTY_BEAN_MAP;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

/**
* @author xingfudeshi@gmail.com
**/
@Import(SpringApplicationContextProvider.class)
@org.springframework.context.annotation.Configuration
public class LoadBalancePropertiesTest {
private static AnnotationConfigApplicationContext applicationContext;

@BeforeAll
public static void initContext() {
applicationContext = new AnnotationConfigApplicationContext(LoadBalancePropertiesTest.class);
}

@Bean
LoadBalanceProperties loadBalanceProperties() {
LoadBalanceProperties loadBalanceProperties = new LoadBalanceProperties();
PROPERTY_BEAN_MAP.put(LOAD_BALANCE_PREFIX, LoadBalanceProperties.class);
return loadBalanceProperties;
}

@Test
public void testLoadBalanceProperties() {
FileConfiguration configuration = mock(FileConfiguration.class);
Configuration currentConfiguration =
EnhancedServiceLoader.load(ExtConfigurationProvider.class).provide(configuration);
System.setProperty("seata.client.loadBalance.virtualNodes", "30");
assertEquals(30, currentConfiguration.getInt("client.loadBalance.virtualNodes"));
System.setProperty("seata.client.loadBalance.type", "test");
assertEquals("test", currentConfiguration.getConfig("client.loadBalance.type"));
}

@AfterAll
public static void closeContext() {
applicationContext.close();
}
}
4 changes: 2 additions & 2 deletions test/src/test/resources/file.conf
Expand Up @@ -63,7 +63,7 @@ client {
sagaCompensatePersistModeUpdate = false
}
loadBalance {
type = "RandomLoadBalance"
type = "XID"
virtualNodes = 10
}
}
}