forked from sofastack/sofa-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic fault tolerance module change to extension mode. (sofastac…
- Loading branch information
Showing
16 changed files
with
94 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
core/api/src/test/java/com/alipay/sofa/rpc/ext/WrongProtocol.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">liangen</a> | ||
*/ | ||
@Extensible | ||
@Extensible(singleton = false) | ||
public interface DegradeStrategy { | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
* @author <a href="mailto:[email protected]">liangen</a> | ||
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
@Extensible | ||
@Extensible(singleton = false) | ||
public interface MeasureStrategy { | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">liangen</a> | ||
*/ | ||
@Extensible | ||
@Extensible(singleton = false) | ||
public interface RecoverStrategy { | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">liangen</a> | ||
*/ | ||
@Extensible | ||
@Extensible(singleton = false) | ||
public interface RegulationStrategy { | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,14 @@ | |
*/ | ||
package com.alipay.sofa.rpc.client.aft; | ||
|
||
import com.alipay.sofa.rpc.ext.Extensible; | ||
|
||
/** | ||
* Regulator of adaptive fault tolerance | ||
* | ||
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
@Extensible(singleton = false) | ||
public interface Regulator { | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,13 @@ | |
import com.alipay.sofa.rpc.client.aft.RecoverStrategy; | ||
import com.alipay.sofa.rpc.client.aft.RegulationStrategy; | ||
import com.alipay.sofa.rpc.client.aft.Regulator; | ||
import com.alipay.sofa.rpc.common.RpcConfigs; | ||
import com.alipay.sofa.rpc.common.RpcOptions; | ||
import com.alipay.sofa.rpc.common.struct.NamedThreadFactory; | ||
import com.alipay.sofa.rpc.common.struct.ScheduledService; | ||
import com.alipay.sofa.rpc.common.utils.ThreadPoolUtils; | ||
import com.alipay.sofa.rpc.ext.Extension; | ||
import com.alipay.sofa.rpc.ext.ExtensionLoaderFactory; | ||
import com.alipay.sofa.rpc.log.LogCodes; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
|
@@ -51,6 +55,7 @@ | |
* @author <a href="mailto:[email protected]">liangen</a> | ||
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
@Extension("timeWindow") | ||
public class TimeWindowRegulator implements Regulator { | ||
|
||
/** Logger for this class */ | ||
|
@@ -96,15 +101,12 @@ public class TimeWindowRegulator implements Regulator { | |
private RegulationStrategy regulationStrategy; | ||
|
||
/** | ||
* 降级策略: 调整权重 | ||
* 降级策略: 例如调整权重 | ||
*/ | ||
private DegradeStrategy weightDegradeStrategy; | ||
/** | ||
* 降级策略: 只打印日志 | ||
*/ | ||
private DegradeStrategy logDegradeStrategy; | ||
private DegradeStrategy degradeStrategy; | ||
|
||
/** | ||
* 恢复策略:调整权重 | ||
* 恢复策略:例如调整权重 | ||
*/ | ||
private RecoverStrategy recoverStrategy; | ||
|
||
|
@@ -115,11 +117,21 @@ public class TimeWindowRegulator implements Regulator { | |
|
||
@Override | ||
public void init() { | ||
measureStrategy = new ServiceHorizontalMeasureStrategy(); | ||
regulationStrategy = new ServiceHorizontalRegulationStrategy(); | ||
weightDegradeStrategy = new WeightDegradeStrategy(); | ||
logDegradeStrategy = new LogPrintDegradeStrategy(); | ||
recoverStrategy = new WeightRecoverStrategy(); | ||
String measureStrategyAlias = RpcConfigs | ||
.getOrDefaultValue(RpcOptions.AFT_MEASURE_STRATEGY, "serviceHorizontal"); | ||
String regulationStrategyAlias = RpcConfigs.getOrDefaultValue(RpcOptions.AFT_REGULATION_STRATEGY, | ||
"serviceHorizontal"); | ||
String degradeStrategyAlias = RpcConfigs.getOrDefaultValue(RpcOptions.AFT_DEGRADE_STRATEGY, "weight"); | ||
String recoverStrategyAlias = RpcConfigs.getOrDefaultValue(RpcOptions.AFT_RECOVER_STRATEGY, "weight"); | ||
|
||
measureStrategy = ExtensionLoaderFactory.getExtensionLoader(MeasureStrategy.class).getExtension( | ||
measureStrategyAlias); | ||
regulationStrategy = ExtensionLoaderFactory.getExtensionLoader(RegulationStrategy.class).getExtension( | ||
regulationStrategyAlias); | ||
degradeStrategy = ExtensionLoaderFactory.getExtensionLoader(DegradeStrategy.class).getExtension( | ||
degradeStrategyAlias); | ||
recoverStrategy = ExtensionLoaderFactory.getExtensionLoader(RecoverStrategy.class).getExtension( | ||
recoverStrategyAlias); | ||
|
||
InvocationStatFactory.addListener(listener); | ||
} | ||
|
@@ -151,8 +163,7 @@ public void destroy() { | |
// release strategy | ||
measureStrategy = null; | ||
regulationStrategy = null; | ||
weightDegradeStrategy = null; | ||
logDegradeStrategy = null; | ||
degradeStrategy = null; | ||
recoverStrategy = null; | ||
} | ||
|
||
|
@@ -222,10 +233,11 @@ void doRegulate(MeasureResultDetail measureResultDetail) { | |
|
||
boolean isDegradeEffective = regulationStrategy.isDegradeEffective(measureResultDetail); | ||
if (isDegradeEffective) { | ||
measureResultDetail.setLogOnly(false); | ||
if (measureState.equals(MeasureState.ABNORMAL)) { | ||
boolean isReachMaxDegradeIpCount = regulationStrategy.isReachMaxDegradeIpCount(measureResultDetail); | ||
if (!isReachMaxDegradeIpCount) { | ||
weightDegradeStrategy.degrade(measureResultDetail); | ||
degradeStrategy.degrade(measureResultDetail); | ||
} else { | ||
String appName = measureResult.getMeasureModel().getAppName(); | ||
if (LOGGER.isInfoEnabled(appName)) { | ||
|
@@ -243,8 +255,9 @@ void doRegulate(MeasureResultDetail measureResultDetail) { | |
//没有被降级过,因此不需要被恢复。 | ||
} | ||
} else { | ||
measureResultDetail.setLogOnly(true); | ||
if (measureState.equals(MeasureState.ABNORMAL)) { | ||
logDegradeStrategy.degrade(measureResultDetail); | ||
degradeStrategy.degrade(measureResultDetail); | ||
String appName = measureResult.getMeasureModel().getAppName(); | ||
if (LOGGER.isInfoEnabled(appName)) { | ||
LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGULATION_ABNORMAL_NOT_DEGRADE, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
.../main/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.client.aft.DegradeStrategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
log=com.alipay.sofa.rpc.client.aft.impl.LogPrintDegradeStrategy | ||
weight=com.alipay.sofa.rpc.client.aft.impl.WeightDegradeStrategy |
1 change: 1 addition & 0 deletions
1
.../main/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.client.aft.MeasureStrategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
serviceHorizontal=com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalMeasureStrategy |
1 change: 1 addition & 0 deletions
1
.../main/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.client.aft.RecoverStrategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
weight=com.alipay.sofa.rpc.client.aft.impl.WeightRecoverStrategy |
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.client.aft.RegulationStrategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
serviceHorizontal=com.alipay.sofa.rpc.client.aft.impl.ServiceHorizontalRegulationStrategy |
1 change: 1 addition & 0 deletions
1
...ce/src/main/resources/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.client.aft.Regulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
timeWindow=com.alipay.sofa.rpc.client.aft.impl.TimeWindowRegulator |