Search in sources :

Example 1 with DcMetaComparator

use of com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator in project x-pipe by ctripcorp.

the class DefaultDcMetaCache method clusterDeleted.

@Override
public void clusterDeleted(String clusterId) {
    EventMonitor.DEFAULT.logEvent(META_CHANGE_TYPE, String.format("del:%s", clusterId));
    ClusterMeta clusterMeta = dcMetaManager.get().removeCluster(clusterId);
    logger.info("[clusterDeleted]{}", clusterMeta);
    DcMetaComparator dcMetaComparator = DcMetaComparator.buildClusterRemoved(clusterMeta);
    notifyObservers(dcMetaComparator);
}
Also used : DcMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)

Example 2 with DcMetaComparator

use of com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator in project x-pipe by ctripcorp.

the class DefaultDcMetaCache method clusterModified.

@Override
public void clusterModified(ClusterMeta clusterMeta) {
    EventMonitor.DEFAULT.logEvent(META_CHANGE_TYPE, String.format("mod:%s", clusterMeta.getId()));
    ClusterMeta current = dcMetaManager.get().getClusterMeta(clusterMeta.getId());
    dcMetaManager.get().update(clusterMeta);
    logger.info("[clusterModified]{}, {}", current, clusterMeta);
    DcMetaComparator dcMetaComparator = DcMetaComparator.buildClusterChanged(current, clusterMeta);
    notifyObservers(dcMetaComparator);
}
Also used : DcMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)

Example 3 with DcMetaComparator

use of com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator in project x-pipe by ctripcorp.

the class DefaultDcMetaCache method changeDcMeta.

@VisibleForTesting
protected void changeDcMeta(DcMeta current, DcMeta future) {
    DcMetaComparator dcMetaComparator = new DcMetaComparator(current, future);
    dcMetaComparator.compare();
    if (dcMetaComparator.totalChangedCount() > META_MODIFY_PROTECT_COUNT) {
        logger.error("[run][modify count size too big]{}, {}, {}", META_MODIFY_PROTECT_COUNT, dcMetaComparator.totalChangedCount(), dcMetaComparator);
        EventMonitor.DEFAULT.logAlertEvent("remove too many:" + dcMetaComparator.totalChangedCount());
        return;
    }
    logger.info("[run][change dc meta]");
    dcMetaManager.set(DefaultDcMetaManager.buildFromDcMeta(future));
    if (dcMetaComparator.totalChangedCount() > 0) {
        logger.info("[run][change]{}", dcMetaComparator);
        EventMonitor.DEFAULT.logEvent(META_CHANGE_TYPE, String.format("[add:%s, del:%s, mod:%s]", StringUtil.join(",", (clusterMeta) -> clusterMeta.getId(), dcMetaComparator.getAdded()), StringUtil.join(",", (clusterMeta) -> clusterMeta.getId(), dcMetaComparator.getRemoved()), StringUtil.join(",", (comparator) -> comparator.idDesc(), dcMetaComparator.getMofified())));
        notifyObservers(dcMetaComparator);
    }
}
Also used : DcMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 4 with DcMetaComparator

use of com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator in project x-pipe by ctripcorp.

the class DefaultCurrentMetaManager method dcMetaChange.

private void dcMetaChange(DcMetaComparator comparator) {
    for (ClusterMeta clusterMeta : comparator.getAdded()) {
        if (currentClusterServer.hasKey(clusterMeta.getId())) {
            addCluster(clusterMeta.getId());
        } else {
            logger.info("[dcMetaChange][add][not interested]{}", clusterMeta.getId());
        }
    }
    for (ClusterMeta clusterMeta : comparator.getRemoved()) {
        if (currentClusterServer.hasKey(clusterMeta.getId())) {
            destroyCluster(clusterMeta);
        } else {
            logger.info("[dcMetaChange][destroy][not interested]{}", clusterMeta.getId());
        }
    }
    for (@SuppressWarnings("rawtypes") MetaComparator changedComparator : comparator.getMofified()) {
        ClusterMetaComparator clusterMetaComparator = (ClusterMetaComparator) changedComparator;
        String clusterId = clusterMetaComparator.getCurrent().getId();
        if (currentClusterServer.hasKey(clusterId)) {
            handleClusterChanged(clusterMetaComparator);
        } else {
            logger.info("[dcMetaChange][change][not interested]{}", clusterId);
        }
    }
}
Also used : ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) MetaComparator(com.ctrip.xpipe.redis.core.meta.MetaComparator) DcMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)

Aggregations

DcMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)4 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 MetaComparator (com.ctrip.xpipe.redis.core.meta.MetaComparator)1 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1