Search in sources :

Example 1 with IsolationServerEvent

use of org.apache.servicecomb.loadbalance.event.IsolationServerEvent in project java-chassis by ServiceComb.

the class IsolationDiscoveryFilter method allowVisit.

private boolean allowVisit(Invocation invocation, MicroserviceInstance instance) {
    ServiceCombServer server = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(instance);
    if (server == null) {
        // first time accessed.
        return true;
    }
    ServiceCombServerStats serverStats = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server);
    Settings settings = createSettings(invocation);
    if (!checkThresholdAllowed(settings, serverStats)) {
        if (serverStats.isIsolated() && (System.currentTimeMillis() - serverStats.getLastVisitTime()) > settings.singleTestTime) {
            return ServiceCombServerStats.applyForTryingChance(invocation);
        }
        if (!serverStats.isIsolated()) {
            // checkThresholdAllowed is not concurrent control, may print several logs/events in current access.
            serverStats.markIsolated(true);
            eventBus.post(new IsolationServerEvent(invocation, instance, serverStats, settings, Type.OPEN, server.getEndpoint()));
            LOGGER.warn("Isolate service {}'s instance {}.", invocation.getMicroserviceName(), instance.getInstanceId());
        }
        return false;
    }
    if (serverStats.isIsolated()) {
        // high volume of concurrent requests with a percentage of error(e.g. 50%) scenario with no isolation
        if ((System.currentTimeMillis() - serverStats.getIsolatedTime()) <= settings.minIsolationTime) {
            return false;
        }
        serverStats.markIsolated(false);
        eventBus.post(new IsolationServerEvent(invocation, instance, serverStats, settings, Type.CLOSE, server.getEndpoint()));
        LOGGER.warn("Recover service {}'s instance {} from isolation.", invocation.getMicroserviceName(), instance.getInstanceId());
    }
    return true;
}
Also used : ServiceCombServer(org.apache.servicecomb.loadbalance.ServiceCombServer) IsolationServerEvent(org.apache.servicecomb.loadbalance.event.IsolationServerEvent) ServiceCombServerStats(org.apache.servicecomb.loadbalance.ServiceCombServerStats)

Aggregations

ServiceCombServer (org.apache.servicecomb.loadbalance.ServiceCombServer)1 ServiceCombServerStats (org.apache.servicecomb.loadbalance.ServiceCombServerStats)1 IsolationServerEvent (org.apache.servicecomb.loadbalance.event.IsolationServerEvent)1