Search in sources :

Example 1 with MetricMeta

use of com.alibaba.jstorm.common.metric.MetricMeta in project jstorm by alibaba.

the class RefreshEvent method syncMetaFromRemote.

private void syncMetaFromRemote(String topologyId, TopologyMetricContext tmContext) {
    try {
        int memSize = tmContext.getMemMeta().size();
        //Integer zkSize = (Integer) context.getStormClusterState().get_topology_metric(topologyId);
        Set<String> added = new HashSet<>();
        List<Pair<MetricMeta, Long>> pairsToCheck = new ArrayList<>();
        ConcurrentMap<String, Long> memMeta = tmContext.getMemMeta();
        for (MetaType metaType : MetaType.values()) {
            List<MetricMeta> metaList = context.getMetricQueryClient().getMetricMeta(context.getClusterName(), topologyId, metaType);
            if (metaList != null) {
                LOG.debug("get remote metric meta, topology:{}, metaType:{}, local mem:{}, remote:{}", topologyId, metaType, memSize, metaList.size());
                for (MetricMeta meta : metaList) {
                    String fqn = meta.getFQN();
                    if (added.contains(fqn)) {
                        Long existingId = memMeta.get(fqn);
                        if (existingId != null && existingId != meta.getId()) {
                            LOG.warn("duplicate remote metric meta:{}, will double-check...", fqn);
                            pairsToCheck.add(new Pair<>(meta, existingId));
                        }
                    } else {
                        // force remote to overwrite local meta
                        LOG.debug("overwrite local from remote:{}", fqn);
                        added.add(fqn);
                        memMeta.put(fqn, meta.getId());
                    }
                }
            }
        }
        context.getMetricCache().putMeta(topologyId, memMeta);
        if (pairsToCheck.size() > 0) {
            CheckMetricEvent.pushEvent(topologyId, tmContext, pairsToCheck);
        }
    } catch (Exception ex) {
        LOG.error("failed to sync remote meta", ex);
    }
}
Also used : ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Pair(com.alibaba.jstorm.utils.Pair) MetaType(com.alibaba.jstorm.metric.MetaType) MetricMeta(com.alibaba.jstorm.common.metric.MetricMeta)

Example 2 with MetricMeta

use of com.alibaba.jstorm.common.metric.MetricMeta in project jstorm by alibaba.

the class ClusterMetricsContext method deleteMetric.

public void deleteMetric(String topologyId, int metaType, List<String> idList) {
    final TopologyMetricContext context = topologyMetricContexts.get(topologyId);
    if (context != null) {
        for (String id : idList) {
            MetricMeta meta = metricQueryClient.getMetricMeta(clusterName, topologyId, MetaType.parse(metaType), Long.valueOf(id));
            if (meta != null) {
                LOG.warn("deleting metric meta:{}", meta);
                metricQueryClient.deleteMeta(meta);
                context.getMemMeta().remove(meta.getFQN());
                metricCache.put(topologyId, context.getMemMeta());
            } else {
                LOG.warn("Failed to delete metric meta, topology:{}, metaType:{}, id:{}, meta not found", topologyId, metaType, id);
            }
        }
    } else {
        LOG.warn("Failed to delete metric meta, topology:{} doesn't exist!", topologyId);
    }
}
Also used : TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext) MetricMeta(com.alibaba.jstorm.common.metric.MetricMeta)

Example 3 with MetricMeta

use of com.alibaba.jstorm.common.metric.MetricMeta in project jstorm by alibaba.

the class CheckMetricEvent method run.

@Override
public void run() {
    try {
        MetricQueryClient metricQueryClient = context.getMetricQueryClient();
        int batch = 30;
        long start = System.currentTimeMillis() - batch * AsmWindow.M1_WINDOW * TimeUtils.MS_PER_SEC;
        long end = System.currentTimeMillis();
        List<MetricMeta> toDelete = new ArrayList<>();
        for (Pair<MetricMeta, Long> pair : pairs) {
            MetricMeta meta = pair.getFirst();
            MetricType metricType = MetricType.parse(meta.getMetricType());
            Long id1 = meta.getId();
            Long id2 = pair.getSecond();
            List<Object> data1 = metricQueryClient.getMetricData(id1, metricType, AsmWindow.M1_WINDOW, start, end, batch);
            List<Object> data2 = metricQueryClient.getMetricData(id2, metricType, AsmWindow.M1_WINDOW, start, end, batch);
            int size1 = data1 != null ? data1.size() : 0;
            int size2 = data2 != null ? data2.size() : 0;
            LOG.info("check duplicate metric meta for {}, id1:{}, size:{}, id2:{}, size:{}", meta.getMetricName(), id1, size1, id2, size2);
            if (size1 > size2) {
                // delete id2
                meta.setId(id2);
                toDelete.add(meta);
                tmContext.getMemMeta().put(meta.getFQN(), id1);
            } else {
                // delete id1
                toDelete.add(meta);
                tmContext.getMemMeta().put(meta.getFQN(), id2);
            }
        }
        if (toDelete.size() > 0) {
            LOG.warn("will delete the following duplicate metric meta\n----------------------------\n");
            for (MetricMeta meta : toDelete) {
                LOG.warn("metric:{}, id:{}", meta.getFQN(), meta.getId());
            }
            LOG.info("\n");
            metricQueryClient.deleteMeta(toDelete);
        }
    //context.getMetricCache().putMeta(topologyId, tmContext.getMemMeta());
    //context.getStormClusterState().set_topology_metric(topologyId, zkSize - dupMetaList.size());
    } catch (Exception ex) {
        LOG.error("Error", ex);
    }
}
Also used : MetricQueryClient(com.alibaba.jstorm.metric.MetricQueryClient) MetricType(com.alibaba.jstorm.metric.MetricType) ArrayList(java.util.ArrayList) MetricMeta(com.alibaba.jstorm.common.metric.MetricMeta)

Aggregations

MetricMeta (com.alibaba.jstorm.common.metric.MetricMeta)3 ArrayList (java.util.ArrayList)2 MetaType (com.alibaba.jstorm.metric.MetaType)1 MetricQueryClient (com.alibaba.jstorm.metric.MetricQueryClient)1 MetricType (com.alibaba.jstorm.metric.MetricType)1 TopologyMetricContext (com.alibaba.jstorm.metric.TopologyMetricContext)1 Pair (com.alibaba.jstorm.utils.Pair)1 HashSet (java.util.HashSet)1