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

Add extension component fail insulator config, default to no #763

Merged
merged 2 commits into from
Nov 12, 2020
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 @@ -39,7 +39,8 @@
@TestPropertySource(properties = { "com.alipay.sofa.boot.disableJvmFirst=true",
"com.alipay.sofa.boot.skipJvmReferenceHealthCheck=true",
"com.alipay.sofa.boot.skipJvmSerialize=true",
"com.alipay.sofa.boot.skipExtensionHealthCheck=true" })
"com.alipay.sofa.boot.skipExtensionHealthCheck=true",
"com.alipay.sofa.boot.extensionFailureInsulating=true" })
public class SofaRuntimePropertiesTest {

@Autowired
Expand Down Expand Up @@ -82,9 +83,18 @@ public void testSkipExtensionHealthCheckProperty() {
Assert.assertTrue(configurationProperties.isSkipExtensionHealthCheck());
}

@Test
public void testExtensionFailureInsulating() {
SofaRuntimeConfigurationProperties configurationProperties = ctx
.getBean(SofaRuntimeConfigurationProperties.class);

Assert.assertTrue(SofaRuntimeProperties.isSkipExtensionHealthCheck(ctx.getClassLoader()));
Assert.assertTrue(configurationProperties.isExtensionFailureInsulating());
}

@Configuration
@EnableAutoConfiguration
static class SofaRuntimePropertiesTestConfiguration {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
*/
public class SofaRuntimeProperties {

private static ConcurrentHashMap<ClassLoader, Boolean> skipJvmReferenceHealthCheckMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<ClassLoader, Boolean> skipExtensionHealthCheckMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<ClassLoader, Boolean> disableJvmFirstMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<ClassLoader, Boolean> skipJvmSerializeMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipJvmReferenceHealthCheckMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipExtensionHealthCheckMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> disableJvmFirstMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipJvmSerializeMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> extensionFailureInsulatingMap = new ConcurrentHashMap<>();

private static boolean jvmFilterEnable = false;
private static boolean jvmFilterEnable = false;

public static boolean isJvmFilterEnable() {
return jvmFilterEnable;
Expand All @@ -55,6 +56,16 @@ public static void setSkipJvmReferenceHealthCheck(ClassLoader classLoader,
skipJvmReferenceHealthCheckMap.putIfAbsent(classLoader, skipJvmReferenceHealthCheck);
}

public static boolean isExtensionFailureInsulating(ClassLoader classLoader) {
return extensionFailureInsulatingMap.get(classLoader) != null
&& extensionFailureInsulatingMap.get(classLoader);
}

public static void setExtensionFailureInsulating(ClassLoader classLoader,
boolean extensionFailureInsulating) {
extensionFailureInsulatingMap.putIfAbsent(classLoader, extensionFailureInsulating);
}

public static boolean isSkipExtensionHealthCheck(SofaRuntimeContext sofaRuntimeContext) {
return isSkipExtensionHealthCheck(sofaRuntimeContext.getAppClassLoader());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public boolean isSkipJvmReferenceHealthCheck() {
.isSkipJvmReferenceHealthCheck(this.getClass().getClassLoader());
}

public void setExtensionFailureInsulating(boolean extensionFailureInsulating) {
SofaRuntimeProperties.setExtensionFailureInsulating(this.getClass().getClassLoader(),
extensionFailureInsulating);
}

public boolean isExtensionFailureInsulating() {
return SofaRuntimeProperties.isExtensionFailureInsulating(this.getClass().getClassLoader());
}

public boolean isDisableJvmFirst() {
return SofaRuntimeProperties.isDisableJvmFirst(this.getClass().getClassLoader());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ private void loadContributions(ExtensionPoint extensionPoint, Extension extensio
.loadContributions((ExtensionInternal) extension);
((ExtensionInternal) extension).setContributions(contribs);
} catch (Exception e) {
if (SofaRuntimeProperties.isExtensionFailureInsulating(sofaRuntimeContext
.getAppClassLoader())) {
this.e = e;
}
SofaLogger.error("Failed to create contribution objects", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void before() {
properties.setProperty("com.alipay.sofa.boot.skipJvmReferenceHealthCheck", "true");
properties.setProperty("com.alipay.sofa.boot.skipExtensionHealthCheck", "true");
properties.setProperty("com.alipay.sofa.boot.skipJvmSerialize", "true");
properties.setProperty("com.alipay.sofa.boot.extensionFailureInsulating", "true");
properties.setProperty("spring.application.name", "tSofaEventHandlerTest");
SofaFramework.getRuntimeSet().forEach(value -> SofaFramework.unRegisterSofaRuntimeManager(value));
SpringApplication springApplication = new SpringApplication(
Expand Down Expand Up @@ -104,6 +105,8 @@ public void testUninstallEvent() {
Assert
.assertFalse(SofaRuntimeProperties.isSkipJvmReferenceHealthCheck(ctx.getClassLoader()));
Assert.assertFalse(SofaRuntimeProperties.isSkipExtensionHealthCheck(ctx.getClassLoader()));
Assert
.assertFalse(SofaRuntimeProperties.isExtensionFailureInsulating(ctx.getClassLoader()));
Assert.assertFalse(SofaRuntimeProperties.isSkipJvmSerialize(ctx.getClassLoader()));
Assert.assertTrue(SofaFramework.getRuntimeSet().isEmpty());
Assert.assertFalse(ctx.isActive());
Expand Down