use of com.ctrip.xpipe.redis.meta.server.MetaServer in project x-pipe by ctripcorp.
the class DispatchMoving method exportServer.
protected MetaServer exportServer(Object key) {
SlotInfo slotInfo = slotManager.getSlotInfoByKey(key);
if (slotInfo.getSlotState() == SLOT_STATE.MOVING) {
MetaServer clusterServer = clusterServers.getClusterServer(slotInfo.getToServerId());
logger.info("[exportServer]{}, {}", key, clusterServer);
return clusterServer;
}
return null;
}
use of com.ctrip.xpipe.redis.meta.server.MetaServer in project x-pipe by ctripcorp.
the class MultiMetaServer method invoke.
@Override
public Object invoke(Object proxy, final Method method, final Object[] rawArgs) throws Throwable {
for (final MetaServer metaServer : otherServers) {
final Object[] args = copy(rawArgs);
executors.execute(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
method.invoke(metaServer, args);
}
});
}
final Object[] args = copy(rawArgs);
return method.invoke(dstServer, args);
}
use of com.ctrip.xpipe.redis.meta.server.MetaServer in project x-pipe by ctripcorp.
the class MultiMetaServerTest method testMultiProxy.
@Test
public void testMultiProxy() {
int serversCount = 10;
List<MetaServer> servers = new LinkedList<>();
for (int i = 0; i < serversCount - 1; i++) {
servers.add(mock(MetaServer.class));
}
MetaServer metaServer = MultiMetaServer.newProxy(mock(MetaServer.class), servers);
final ForwardInfo forwardInfo = new ForwardInfo();
metaServer.clusterDeleted(getClusterId(), forwardInfo);
for (MetaServer mockServer : servers) {
verify(mockServer).clusterDeleted(eq(getClusterId()), argThat(new BaseMatcher<ForwardInfo>() {
@Override
public boolean matches(Object item) {
// should be cloned
if (item == forwardInfo) {
return false;
}
return true;
}
@Override
public void describeTo(Description description) {
}
}));
}
}
use of com.ctrip.xpipe.redis.meta.server.MetaServer in project x-pipe by ctripcorp.
the class DispatchMoving method tryMovingDispatch.
@Around("pointcutMovingMethod() && args(clusterId,..,forwardInfo)")
public Object tryMovingDispatch(ProceedingJoinPoint joinpoint, String clusterId, ForwardInfo forwardInfo) throws Throwable {
String targetMethodName = joinpoint.getSignature().getName();
logger.info("[tryMovingDispatch]{}, {}", targetMethodName, clusterId);
if (forwardInfo != null && forwardInfo.getType() == ForwardType.MOVING) {
logger.info("[tryMovingDispatch][isMoving][self process]{}, {}", targetMethodName, clusterId);
return joinpoint.proceed();
}
MetaServer exportServer = exportServer(clusterId);
if (exportServer == currentClusterServer) {
throw new IllegalStateException("export server should not be current " + exportServer);
}
if (exportServer != null) {
Object[] args = joinpoint.getArgs();
if (forwardInfo == null) {
forwardInfo = new ForwardInfo();
replace(args, forwardInfo);
}
forwardInfo.setType(ForwardType.MOVING);
Method method = ObjectUtils.getMethod(targetMethodName, MetaServer.class);
if (method == null) {
// impossible to happen
throw new IllegalStateException("can not find method " + targetMethodName);
}
return method.invoke(exportServer, args);
}
return joinpoint.proceed();
}
use of com.ctrip.xpipe.redis.meta.server.MetaServer 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