Search in sources :

Example 11 with InvocationStatDimension

use of com.alipay.sofa.rpc.client.aft.InvocationStatDimension in project sofa-rpc by sofastack.

the class WeightRecoverStrategy method recover.

@Override
public void recover(MeasureResultDetail measureResultDetail) {
    InvocationStatDimension statDimension = measureResultDetail.getInvocationStatDimension();
    ProviderInfo providerInfo = statDimension.getProviderInfo();
    // if provider is removed or provider is warming up
    if (providerInfo == null || providerInfo.getStatus() == ProviderStatus.WARMING_UP) {
        return;
    }
    Integer currentWeight = ProviderInfoWeightManager.getWeight(providerInfo);
    if (currentWeight == -1) {
        return;
    }
    String appName = statDimension.getAppName();
    double weightRecoverRate = FaultToleranceConfigManager.getWeightRecoverRate(appName);
    int recoverWeight = CalculateUtils.multiply(currentWeight, weightRecoverRate);
    int originWeight = statDimension.getOriginWeight();
    // recover weight of this provider info
    if (recoverWeight >= originWeight) {
        measureResultDetail.setRecoveredOriginWeight(true);
        ProviderInfoWeightManager.recoverOriginWeight(providerInfo, originWeight);
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, "the weight was recovered to origin value. serviceUniqueName:[" + statDimension.getService() + "],ip:[" + statDimension.getIp() + "],origin weight:[" + currentWeight + "],recover weight:[" + originWeight + "].");
        }
    } else {
        measureResultDetail.setRecoveredOriginWeight(false);
        boolean success = ProviderInfoWeightManager.recoverWeight(providerInfo, recoverWeight);
        if (success && LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, "the weight was recovered. serviceUniqueName:[" + statDimension.getService() + "],ip:[" + statDimension.getIp() + "],origin weight:[" + currentWeight + "],recover weight:[" + recoverWeight + "].");
        }
    }
}
Also used : ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) InvocationStatDimension(com.alipay.sofa.rpc.client.aft.InvocationStatDimension)

Aggregations

InvocationStatDimension (com.alipay.sofa.rpc.client.aft.InvocationStatDimension)11 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)2 InvocationStat (com.alipay.sofa.rpc.client.aft.InvocationStat)2 MeasureModel (com.alipay.sofa.rpc.client.aft.MeasureModel)2 MeasureResult (com.alipay.sofa.rpc.client.aft.MeasureResult)1 MeasureResultDetail (com.alipay.sofa.rpc.client.aft.MeasureResultDetail)1 ArrayList (java.util.ArrayList)1