does the cluster sort here actually reorder anything? its compare never says one cluster comes first, so the order looks random and which cluster gets split depends on that

未关闭 适合新手
#14,625 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

找到 pull request 14000 讨论中展示的 sortByClusterSize 方法,并追踪其返回的 map 在哪里决定拆分哪个集群。检查比较器如何处理集群大小,以及最终顺序是否具有确定性;当顺序反映预期的集群优先级,且受影响的行为得到测试覆盖时,即为完成。

由索引模型根据 Issue 内容生成。

描述

does the cluster sort here actually reorder anything? its compare never says one cluster comes first, so the order looks random and which cluster gets split depends on that

Originally posted by @Damans227 in https://github.com/apache/cloudstack/pull/14000#discussion_r4184044883

    public static LinkedHashMap<Long, List<HostVO>> sortByClusterSize(final Map<Long, List<HostVO>> hostToClusterMap) {
        List<Long> keys = new ArrayList<Long>();
        keys.addAll(hostToClusterMap.keySet());
        Collections.sort(keys, new Comparator<Long>() {
            @Override
            public int compare(Long o1, Long o2) {
                List<HostVO> v1 = hostToClusterMap.get(o1);
                List<HostVO> v2 = hostToClusterMap.get(o2);
                if (v1 == null) {
                    return (v2 == null) ? 0 : 1;
                }

                if (v1.size() < v2.size()) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });

        LinkedHashMap<Long, List<HostVO>> sortedMap = new LinkedHashMap<Long, List<HostVO>>();
        for (Long key : keys) {
            sortedMap.put(key, hostToClusterMap.get(key));
        }
        return sortedMap;
    }
主要语言
Java
星标
3.1k
派生
1.4k
平均合并
6 天 20 小时
30 天内合并 PR
17

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/cloudstack 的其他 Issue

查看 apache/cloudstack 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。