-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
[Dubbo-7367]fix too many instance bean created #7438
[Dubbo-7367]fix too many instance bean created #7438
Conversation
1,修复相同parameters当产生多个Reference的问题。 2,如果相同服务以不同参数订阅多次,则启动时增加WARN日志
if ("parameters".equals(entry.getKey())) { | ||
// parameters spec is {key1,value1,key2,value2} | ||
ArrayList<String> kvList = new ArrayList<>(); | ||
for (int i = 0; i < entryValues.length / 2 * 2; i = i + 2) { |
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.
i < entryValues.length / 2 * 2
changed to i < entryValues.length
.
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.
This is to avoid mistake useage like {key1,value1,key2,value2,key3}
@Override | ||
public void onApplicationEvent(ApplicationEvent event) { | ||
if (event instanceof ContextRefreshedEvent) { | ||
referencedBeanNameIdx.entrySet().stream().filter(e -> e.getValue().size() > 1).forEach(e -> { |
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.
release referencedBeanNameIdx resource after app started.
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.
OK
release referencedBeanNameIdx after used.
Codecov Report
@@ Coverage Diff @@
## master #7438 +/- ##
============================================
- Coverage 59.39% 59.04% -0.35%
- Complexity 466 502 +36
============================================
Files 1043 1079 +36
Lines 42516 43368 +852
Branches 6226 6324 +98
============================================
+ Hits 25251 25606 +355
- Misses 14472 14920 +448
- Partials 2793 2842 +49 Continue to review full report at Codecov.
|
只处理String类型的array,对Method[]暂时不处理
支持处理methods属性和arguments属性
use lambda
调整ServiceInstancesChangedListener的事件通知。所有的directory都能通知到
private URL url; | ||
private Map<String, NotifyListener> listeners; | ||
private Map<String, List<NotifyListener>> listeners; |
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.
List改成Set
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.
OK~
listeners内部改为HashSet
generateReferenceBeanName改用3.0-preview逻辑
remote unused private method
//handle method array, generic array | ||
if (value != null && value.getClass().isArray()) { | ||
Object[] array = ObjectUtils.toObjectArray(value); | ||
value = Arrays.toString(array); |
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.
It seems that @Method
's @Argument
array is not handled properly.
@DubboReference(methods = @Method(name = "sayHello", timeout = 100, arguments = @Argument(index = 0, callback = true)))
Some code snippets:
for (String key : sortedAttrKeys) {
Object value = attributes.get(key);
value = convertAttribute(value);
beanNameBuilder.append(key)
.append('=')
.append(value)
.append(',');
}
private Object convertAttribute(Object obj) {
if (obj == null) {
return null;
}
if (obj instanceof Annotation) {
AnnotationAttributes attributes = AnnotationUtils.getAnnotationAttributes((Annotation) obj, true);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
entry.setValue(convertAttribute(entry.getValue()));
}
return attributes;
} else if (obj.getClass().isArray()) {
Object[] array = ObjectUtils.toObjectArray(obj);
Object[] newArray = new Object[array.length];
for (int i = 0; i < array.length; i++) {
newArray[i] = convertAttribute(array[i]);
}
return Arrays.toString(newArray);
} else {
return obj;
}
}
LGTM |
1,修复相同parameters当产生多个Reference的问题。 2,如果相同服务以不同参数订阅多次,则启动时增加WARN日志 * Update ReferenceAnnotationBeanPostProcessor.java 修改日志格式 * Update ReferenceAnnotationBeanPostProcessor.java release referencedBeanNameIdx after used. * Update ReferenceAnnotationBeanPostProcessorTest.java add UT * Update ReferenceAnnotationBeanPostProcessor.java 只处理String类型的array,对Method[]暂时不处理 * 优化generateReferenceBeanName 支持处理methods属性和arguments属性 * methods和arguments需要排序 * Update ReferenceAnnotationUtils.java use lambda * update ServiceInstancesChangedListener 调整ServiceInstancesChangedListener的事件通知。所有的directory都能通知到 * Update ServiceInstancesChangedListener.java listeners内部改为HashSet * update generateReferenceBeanName generateReferenceBeanName改用3.0-preview逻辑 * remote println * Update ReferenceAnnotationBeanPostProcessor.java remote unused private method * Update ReferenceAnnotationBeanPostProcessor.java * Update ReferenceAnnotationBeanPostProcessorTest.java update UT * update UT * revert to use ReferenceAnnotationUtils * 使用来自kylixs的convertAttribute方法 * organize imports & update UT * update UT * update ReferenceAnnotationBeanPostProcessor & UT (cherry picked from commit 2339729)
What is the purpose of the change
初步修复 #7367 的问题
当多处用注解订阅同一个服务,并使用parameters时,如
实际会产生多个Reference示例
Brief changelog
1,修复generateReferenceBeanName过程中未处理Array类型的entry问题
2,如果产生多个相同“INTERFACE:VERSION:GROUP”的Reference实例,则在启动日志中增加WARN信息,帮助用户分析
日志示例
Follow this checklist to help us incorporate your contribution quickly and easily:
[Dubbo-XXX] Fix UnknownException when host config not exist #XXX
. Each commit in the pull request should have a meaningful subject line and body.mvn clean install -DskipTests=false
&mvn clean test-compile failsafe:integration-test
to make sure unit-test and integration-test pass.