use of com.ctrip.xpipe.redis.meta.server.cluster.ClusterServer in project x-pipe by ctripcorp.
the class AbstractDirectMoveSharding method doShardingTask.
@Override
protected void doShardingTask() throws ShardingException {
List<Integer> slots = getSlotsToArrange();
List<ClusterServer> aliveServers = allAliveServers();
logger.info("[doExecute][aliveServers]{}", aliveServers);
if (aliveServers.size() == 0) {
logger.info("[doExecute][no aliveServers]{}");
future().setSuccess(null);
return;
}
int aliveTotal = getAliveTotal(aliveServers);
int average = (aliveTotal + slots.size()) / aliveServers.size();
int slotIndex = 0;
for (ClusterServer alive : aliveServers) {
int currentServerSlotsSize = slotManager.getSlotsSizeByServerId(alive.getServerId());
for (int i = 0; i < average - currentServerSlotsSize; i++) {
executeTask(new MoveSlotFromDeadOrEmpty(slots.get(slotIndex), getDeadServer(), alive, zkClient));
slotIndex++;
}
}
int aliveServerIndex = 0;
for (; slotIndex < slots.size(); slotIndex++) {
executeTask(new MoveSlotFromDeadOrEmpty(slots.get(slotIndex), getDeadServer(), aliveServers.get(aliveServerIndex++ % aliveServers.size()), zkClient));
}
}
use of com.ctrip.xpipe.redis.meta.server.cluster.ClusterServer in project x-pipe by ctripcorp.
the class RollbackMovingTask method doExecute.
@Override
protected void doExecute() throws Exception {
setSlotInfo(new SlotInfo(from.getServerId()));
ClusterServer from = getFrom();
ClusterServer to = getTo();
if (from != null) {
from.addSlot(slot);
}
if (to != null) {
to.deleteSlot(slot);
}
future().setSuccess();
}
use of com.ctrip.xpipe.redis.meta.server.cluster.ClusterServer in project x-pipe by ctripcorp.
the class ServerBalanceResharding method doShardingTask.
@Override
protected void doShardingTask() throws ShardingException {
Set<? extends ClusterServer> aliveServers = servers.allClusterServers();
if (aliveServers.size() == 0) {
logger.info("[doExecute][no aliveServers]{}", aliveServers);
future().setSuccess(null);
return;
}
int totalSlots = getAliveTotal(aliveServers);
int average = totalSlots / aliveServers.size();
ClusterServer easyServer = null;
for (ClusterServer clusterServer : aliveServers) {
int currentSlots = slotManager.getSlotsSizeByServerId(clusterServer.getServerId());
logger.info("[doExecute]{}, {}", clusterServer, currentSlots);
if (currentSlots < average / 2) {
easyServer = clusterServer;
break;
}
}
if (easyServer == null) {
logger.info("[doExecute][no easy server][exit]{}", servers.allClusterServers());
future().setSuccess(null);
return;
}
logger.info("[doExecute][easy server]{}", easyServer);
int maxMove = average - slotManager.getSlotsSizeByServerId(easyServer.getServerId());
int totalMove = 0;
for (ClusterServer clusterServer : aliveServers) {
if (clusterServer.equals(easyServer)) {
continue;
}
int currentSlotsSize = slotManager.getSlotsSizeByServerId(clusterServer.getServerId());
int toMove = Math.min(currentSlotsSize - average, maxMove - totalMove);
if (toMove > 0) {
logger.info("[doExecute][move from server to dst]{}->{} {}", clusterServer, easyServer, toMove);
move(clusterServer, easyServer, toMove);
}
totalMove += toMove;
if (totalMove >= maxMove) {
logger.info("[doExecute][totalMove > maxMove]{} > {}", totalMove, maxMove);
break;
}
}
}
Aggregations