Search in sources :

Example 1 with MovingTargetException

use of com.ctrip.xpipe.redis.meta.server.rest.exception.MovingTargetException in project x-pipe by ctripcorp.

the class AbstractDispatcherMetaServerController method getMetaServer.

private MetaServer getMetaServer(String clusterId, ForwardInfo forwardInfo, String uri) {
    int slotId = slotManager.getSlotIdByKey(clusterId);
    SlotInfo slotInfo = slotManager.getSlotInfo(slotId);
    if (forwardInfo != null && forwardInfo.getType() == ForwardType.MOVING) {
        if (!(slotInfo.getSlotState() == SLOT_STATE.MOVING && slotInfo.getToServerId() == currentMetaServer.getServerId())) {
            throw new MovingTargetException(forwardInfo, currentMetaServer.getServerId(), slotInfo, clusterId, slotId);
        }
        logger.info("[getMetaServer][use current server]");
        return currentMetaServer;
    }
    if (forwardInfo != null && forwardInfo.getType() == ForwardType.MULTICASTING) {
        logger.info("[multicast message][do now]");
        return currentMetaServer;
    }
    META_SERVER_SERVICE service = META_SERVER_SERVICE.fromPath(uri);
    Integer serverId = slotManager.getServerIdByKey(clusterId);
    if (serverId == null) {
        throw new IllegalStateException("clusterId:" + clusterId + ", unfound server");
    }
    if (service.getForwardType() == ForwardType.MULTICASTING) {
        logger.info("[getMetaServer][multi casting]{}, {}, {}", clusterId, forwardInfo, uri);
        Set<MetaServer> allServers = servers.allClusterServers();
        MetaServer current = servers.getClusterServer(serverId);
        allServers.remove(current);
        return MultiMetaServer.newProxy(current, new LinkedList<>(allServers));
    } else if (service.getForwardType() == ForwardType.FORWARD) {
        return servers.getClusterServer(serverId);
    } else {
        throw new IllegalStateException("service type can not be:" + service.getForwardType());
    }
}
Also used : MovingTargetException(com.ctrip.xpipe.redis.meta.server.rest.exception.MovingTargetException) MultiMetaServer(com.ctrip.xpipe.redis.meta.server.impl.MultiMetaServer) MetaServer(com.ctrip.xpipe.redis.meta.server.MetaServer) SlotInfo(com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo) META_SERVER_SERVICE(com.ctrip.xpipe.redis.core.metaserver.META_SERVER_SERVICE)

Aggregations

META_SERVER_SERVICE (com.ctrip.xpipe.redis.core.metaserver.META_SERVER_SERVICE)1 MetaServer (com.ctrip.xpipe.redis.meta.server.MetaServer)1 SlotInfo (com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo)1 MultiMetaServer (com.ctrip.xpipe.redis.meta.server.impl.MultiMetaServer)1 MovingTargetException (com.ctrip.xpipe.redis.meta.server.rest.exception.MovingTargetException)1