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());
}
}
Aggregations