-
Notifications
You must be signed in to change notification settings - Fork 8.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: branch register resource only at RM server end #5399
Changes from 30 commits
8d2e41a
505f7c5
61aae61
968c8d0
bb1a55c
4c3875d
7cbf600
543eb5a
ddaaa91
26dc039
38361ba
5cca5c4
d98f3ab
daeaafc
002935e
e56a8b2
fa6e3bf
c42030e
22455a3
e6c90fe
80b175e
43f0bcc
b34ae57
f4030a5
3ec392b
c3ffb17
1da082e
bfa742a
93b32cf
8c23358
e5cfe2c
6719fe7
83e4dae
78c7121
378fc00
2df4c80
95c6903
057c581
3055c18
79288d6
076a8fc
a0fbe96
967bfd6
5af4071
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,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.integration.tx.api.interceptor.parser; | ||
|
||
public class IfNeedEnhanceBean { | ||
|
||
private boolean ifNeed; | ||
|
||
private NeedEnhanceEnum needEnhanceEnum; | ||
|
||
public boolean isIfNeed() { | ||
return ifNeed; | ||
} | ||
|
||
public void setIfNeed(boolean ifNeed) { | ||
this.ifNeed = ifNeed; | ||
} | ||
|
||
public NeedEnhanceEnum getNeedEnhanceEnum() { | ||
return needEnhanceEnum; | ||
} | ||
|
||
public void setNeedEnhanceEnum(NeedEnhanceEnum needEnhanceEnum) { | ||
this.needEnhanceEnum = needEnhanceEnum; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.integration.tx.api.interceptor.parser; | ||
|
||
/** | ||
* @author ruishansun | ||
*/ | ||
funky-eyes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public enum NeedEnhanceEnum { | ||
|
||
/** | ||
* global transactional bean type | ||
*/ | ||
GLOBAL_TRANSACTIONAL_BEAN, | ||
/** | ||
* service bean type | ||
*/ | ||
SERVICE_BEAN; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import java.util.concurrent.atomic.AtomicBoolean; | ||
import javax.annotation.Nullable; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import io.seata.common.util.CollectionUtils; | ||
import io.seata.common.util.StringUtils; | ||
import io.seata.config.ConfigurationCache; | ||
|
@@ -42,6 +43,8 @@ | |
import io.seata.integration.tx.api.interceptor.handler.GlobalTransactionalInterceptorHandler; | ||
import io.seata.integration.tx.api.interceptor.handler.ProxyInvocationHandler; | ||
import io.seata.integration.tx.api.interceptor.parser.DefaultInterfaceParser; | ||
import io.seata.integration.tx.api.interceptor.parser.IfNeedEnhanceBean; | ||
import io.seata.integration.tx.api.interceptor.parser.NeedEnhanceEnum; | ||
import io.seata.integration.tx.api.remoting.parser.DefaultRemotingParser; | ||
import io.seata.rm.RMClient; | ||
import io.seata.spring.annotation.scannercheckers.PackageScannerChecker; | ||
|
@@ -62,10 +65,13 @@ | |
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator; | ||
import org.springframework.aop.support.AopUtils; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.PropertyValue; | ||
import org.springframework.beans.factory.DisposableBean; | ||
import org.springframework.beans.factory.FactoryBean; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.beans.factory.config.RuntimeBeanReference; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
@@ -115,6 +121,8 @@ public class GlobalTransactionScanner extends AbstractAutoProxyCreator | |
|
||
private ApplicationContext applicationContext; | ||
|
||
private static final Set<String> NEED_ENHANCE_BEAN_NAME_SET = new HashSet<>(); | ||
|
||
|
||
/** | ||
* Instantiates a new Global transaction scanner. | ||
|
@@ -281,6 +289,9 @@ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) | |
if (PROXYED_SET.contains(beanName)) { | ||
return bean; | ||
} | ||
if (!NEED_ENHANCE_BEAN_NAME_SET.contains(beanName)) { | ||
return bean; | ||
} | ||
interceptor = null; | ||
ProxyInvocationHandler proxyInvocationHandler = DefaultInterfaceParser.get().parserInterfaceToProxy(bean, beanName); | ||
if (proxyInvocationHandler == null) { | ||
|
@@ -470,8 +481,68 @@ public void afterPropertiesSet() { | |
if (initialized.compareAndSet(false, true)) { | ||
initClient(); | ||
} | ||
|
||
this.findBusinessBeanNamesNeededEnhancement(); | ||
} | ||
|
||
private void findBusinessBeanNamesNeededEnhancement() { | ||
if (applicationContext instanceof ConfigurableApplicationContext) { | ||
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; | ||
ConfigurableListableBeanFactory configurableListableBeanFactory = configurableApplicationContext.getBeanFactory(); | ||
|
||
String[] beanNames = applicationContext.getBeanDefinitionNames(); | ||
for (String contextBeanName : beanNames) { | ||
BeanDefinition beanDefinition = configurableListableBeanFactory.getBeanDefinition(contextBeanName); | ||
if (IGNORE_ENHANCE_CHECK_SET.contains(beanDefinition.getBeanClassName())) { | ||
continue; | ||
} | ||
try { | ||
// get the class by bean definition class name | ||
Class<?> beanClass = Class.forName(beanDefinition.getBeanClassName()); | ||
// check if it needs enhancement by the class | ||
IfNeedEnhanceBean ifNeedEnhanceBean = DefaultInterfaceParser.get().parseIfNeedEnhancement(beanClass); | ||
if (!ifNeedEnhanceBean.isIfNeed()) { | ||
continue; | ||
} | ||
if (ifNeedEnhanceBean.getNeedEnhanceEnum().equals(NeedEnhanceEnum.SERVICE_BEAN)) { | ||
// the native bean which dubbo, sofa bean service bean referenced | ||
PropertyValue propertyValue = beanDefinition.getPropertyValues().getPropertyValue("ref"); | ||
funky-eyes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (propertyValue == null) { | ||
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. 这些逻辑看起来应该和parser强相关,是不是该挪到parser去?虽然这样做会带来一部分重复的代码 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. 如果引入到parser中,可能会给parser带来beanDefinition的spring依赖,原则上可能不想让parser层引入spring相关的依赖 |
||
// the native bean which HSF service bean referenced | ||
propertyValue = beanDefinition.getPropertyValues().getPropertyValue("target"); | ||
} | ||
if (propertyValue != null) { | ||
RuntimeBeanReference r = (RuntimeBeanReference) propertyValue.getValue(); | ||
if (r != null && StringUtils.isNotBlank(r.getBeanName())) { | ||
NEED_ENHANCE_BEAN_NAME_SET.add(r.getBeanName()); | ||
continue; | ||
} | ||
} | ||
// the native bean which local tcc service bean referenced | ||
NEED_ENHANCE_BEAN_NAME_SET.add(contextBeanName); | ||
} else if (ifNeedEnhanceBean.getNeedEnhanceEnum().equals(NeedEnhanceEnum.GLOBAL_TRANSACTIONAL_BEAN)) { | ||
// global transactional bean | ||
NEED_ENHANCE_BEAN_NAME_SET.add(contextBeanName); | ||
} | ||
} catch (ClassNotFoundException e) { | ||
LOGGER.warn("check if need enhance bean error, it can be ignore", e); | ||
} | ||
} | ||
LOGGER.info("The needed enhancement business beans are : {}", NEED_ENHANCE_BEAN_NAME_SET); | ||
} | ||
} | ||
|
||
private static final Set<String> IGNORE_ENHANCE_CHECK_SET = ImmutableSet.of( | ||
"io.seata.spring.annotation.GlobalTransactionScanner" | ||
, "io.seata.rm.fence.SpringFenceConfig" | ||
, "org.springframework.context.annotation.internalConfigurationAnnotationProcessor" | ||
, "org.springframework.context.annotation.internalAutowiredAnnotationProcessor" | ||
, "org.springframework.context.annotation.internalCommonAnnotationProcessor" | ||
, "org.springframework.context.event.internalEventListenerProcessor" | ||
, "org.springframework.context.event.internalEventListenerFactory" | ||
); | ||
|
||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.applicationContext = applicationContext; | ||
|
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.
Is need/isNeed() better than ifNeed/isIfNeed() ?