Search in sources :

Example 1 with SlotInfo

use of com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo in project x-pipe by ctripcorp.

the class MoveSlotFromDeadOrEmpty method doExecute.

@Override
protected void doExecute() throws Exception {
    logger.info("[doExecute]{},{}->{}", slot, from, to);
    setSlotInfo(new SlotInfo(getTo().getServerId()));
    to.addSlot(slot);
    future().setSuccess(null);
}
Also used : SlotInfo(com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo)

Example 2 with SlotInfo

use of com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo in project x-pipe by ctripcorp.

the class MoveSlotFromLiving method setSuccess.

private void setSuccess() throws ShardingException {
    logger.info("[setSuccess]{},{},{}", getSlot(), getFrom(), getTo());
    setSlotInfo(new SlotInfo(to.getServerId()));
    getTo().addSlot(slot);
    getFrom().deleteSlot(slot);
    future().setSuccess(null);
}
Also used : SlotInfo(com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo)

Example 3 with SlotInfo

use of com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo 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();
}
Also used : ClusterServer(com.ctrip.xpipe.redis.meta.server.cluster.ClusterServer) SlotInfo(com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo)

Example 4 with SlotInfo

use of com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo in project x-pipe by ctripcorp.

the class DefaultSlotManager method allMoveingSlots.

@Override
public Map<Integer, SlotInfo> allMoveingSlots() {
    try {
        lock.readLock().lock();
        Map<Integer, SlotInfo> result = new HashMap<>();
        for (Entry<Integer, SlotInfo> entry : slotsMap.entrySet()) {
            Integer slot = entry.getKey();
            SlotInfo slotInfo = entry.getValue();
            if (slotInfo.getSlotState() == SLOT_STATE.MOVING) {
                result.put(slot, slotInfo.clone());
            }
        }
        return result;
    } catch (CloneNotSupportedException e) {
        throw new IllegalStateException(e);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : HashMap(java.util.HashMap) SlotInfo(com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo)

Example 5 with SlotInfo

use of com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo in project x-pipe by ctripcorp.

the class DefaultSlotManager method move.

@Override
public void move(int slotId, int fromServer, int toServer) {
    try {
        lock.writeLock().lock();
        if (serverMap.get(fromServer) == null) {
            logger.error("[fromServer not Found]" + fromServer);
            return;
        }
        slotsMap.put(slotId, new SlotInfo(toServer));
        serverMap.get(fromServer).remove(slotId);
        Set<Integer> toSlots = MapUtils.getOrCreate(serverMap, toServer, new ObjectFactory<Set<Integer>>() {

            @Override
            public Set<Integer> create() {
                return new HashSet<>();
            }
        });
        toSlots.add(slotId);
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SlotInfo(com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo)

Aggregations

SlotInfo (com.ctrip.xpipe.redis.meta.server.cluster.SlotInfo)13 HashSet (java.util.HashSet)3 ClusterException (com.ctrip.xpipe.redis.meta.server.cluster.ClusterException)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 META_SERVER_SERVICE (com.ctrip.xpipe.redis.core.metaserver.META_SERVER_SERVICE)1 MetaServer (com.ctrip.xpipe.redis.meta.server.MetaServer)1 ClusterServer (com.ctrip.xpipe.redis.meta.server.cluster.ClusterServer)1 MultiMetaServer (com.ctrip.xpipe.redis.meta.server.impl.MultiMetaServer)1 MovingTargetException (com.ctrip.xpipe.redis.meta.server.rest.exception.MovingTargetException)1 TimeoutException (java.util.concurrent.TimeoutException)1