Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[DISCUSSION] Workload splitting through Hazelcast

未关闭
#5,743 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃

调研方向

Start by reviewing the proposed HazelcastPartitionFilter and the adaptations to CloudDiscoveryService, the triggers, InstanceRegistry, and InstanceDiscoveryListener in the issue. Check how these components currently handle discovery and events, then assess whether the proposal covers all relevant code paths and preserves expected behavior across nodes. Done means reaching agreement on an approach before any large implementation PR.

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

描述

Hello guys.

Recently I've been thinking to ways to make the current (half) clustering work fully so that jobs (e.g. StatusUpdateTrigger, InfoUpdateTrigger, NotificationTrigger and so on) are executed only on one one node while the whole state is anyway kept in sync with Hazelcast-specific collections.

I've therefore been working a bit with AI on this and this was a suggestion I got from it which, when I see it, code quality aside, it kind of makes sense to me:

    @Component
    public static class HazelcastPartitionFilter {
        private final HazelcastInstance hazelcastInstance;

        public HazelcastPartitionFilter(HazelcastInstance hazelcastInstance) {
            this.hazelcastInstance = hazelcastInstance;
        }

        public boolean isMyPartition(InstanceId instanceId) {
            if (instanceId == null || instanceId.getValue() == null) {
                return false;
            }
            var partitionService = hazelcastInstance.getPartitionService();
            Partition partition = partitionService.getPartition(instanceId.getValue());
            return partition.getOwner() != null && partition.getOwner().localMember();
        }
    }

    public static class HazelcastShardedDiscoveryService extends CloudDiscoveryService {
        private final DiscoveryClient discoveryClient;
        private final HazelcastPartitionFilter partitionFilter;

        public HazelcastShardedDiscoveryService(DiscoveryClient discoveryClient, 
                                                HazelcastPartitionFilter partitionFilter) {
            super(discoveryClient);
            this.discoveryClient = discoveryClient;
            this.partitionFilter = partitionFilter;
        }

        @Override
        public Flux<Registration> convertToRegistrations(String serviceId) {
            return Flux.fromIterable(discoveryClient.getInstances(serviceId))
                    .map(instance -> this.convertToRegistration(serviceId, instance))
                    .filter(reg -> partitionFilter.isMyPartition(reg.getInstanceId()));
        }
    }

    @Bean
    @Primary
    public CloudDiscoveryService cloudDiscoveryService(DiscoveryClient discoveryClient, 
                                                       HazelcastPartitionFilter partitionFilter) {
        return new HazelcastShardedDiscoveryService(discoveryClient, partitionFilter);
    }

    @Bean
    @Primary
    public StatusUpdateTrigger statusUpdateTrigger(StatusUpdater statusUpdater, HazelcastPartitionFilter partitionFilter) {
        return new StatusUpdateTrigger(statusUpdater) {
            @Override
            protected Publisher<Void> handle(InstanceEvent event) {
                if (partitionFilter.isMyPartition(event.getInstance())) {
                    return super.handle(event);
                }
                return Mono.empty();
            }
        };
    }

    @Bean
    @Primary
    public InfoUpdateTrigger infoUpdateTrigger(InfoUpdater infoUpdater, HazelcastPartitionFilter partitionFilter) {
        return new InfoUpdateTrigger(infoUpdater) {
            @Override
            protected Publisher<Void> handle(InstanceEvent event) {
                if (partitionFilter.isMyPartition(event.getInstance())) {
                    return super.handle(event);
                }
                return Mono.empty();
            }
        };
    }

    @Bean
    @Primary
    public EndpointDetectionTrigger endpointDetectionTrigger(EndpointDetector endpointDetector, HazelcastPartitionFilter partitionFilter) {
        return new EndpointDetectionTrigger(endpointDetector) {
            @Override
            protected Publisher<Void> handle(InstanceEvent event) {
                if (partitionFilter.isMyPartition(event.getInstance())) {
                    return super.handle(event);
                }
                return Mono.empty();
            }
        };
    }

    @Bean
    @Primary
    public NotificationTrigger notificationTrigger(Notifier notifier, 
                                                   InstanceRepository repository, 
                                                   HazelcastPartitionFilter partitionFilter) {
        return new NotificationTrigger(notifier, repository) {
            @Override
            protected Publisher<Void> handle(InstanceEvent event) {
                if (partitionFilter.isMyPartition(event.getInstance())) {
                    return super.handle(event);
                }
                return Mono.empty();
            }
        };
    }

    @Bean
    @Primary
    public InstanceRegistry instanceRegistry(InstanceRepository repository,
                                             InstanceIdGenerator idGenerator,
                                             HazelcastPartitionFilter partitionFilter) {
        return new InstanceRegistry(repository, idGenerator) {
            @Override
            public Mono<InstanceId> register(Registration registration) {
                if (partitionFilter.isMyPartition(idGenerator.generateId(registration))) {
                    return super.register(registration);
                }
                return Mono.empty();
            }
        };
    }

    @Bean
    @Primary
    public InstanceDiscoveryListener instanceDiscoveryListener(CloudDiscoveryService discoveryService,
                                                               InstanceRegistry registry,
                                                               InstanceRepository repository) {
        return new InstanceDiscoveryListener(discoveryService, registry, repository) {
            @Override
            public void discover() {
                // Force the sync
                super.discover();
            }
        };
    }

I wanted to open this ticket to discuss with you the solution above and, in particular:

  • if there any other code paths which I'm not aware of and that would require a similar adaptation
  • if you think the solution above makes sense and it could actually work
  • if you're willing to accept a PR with a polished version of the above (I can already anticipate it will be big)
主要语言
Java
星标
12.9k
派生
3.2k
平均合并
13 小时 56 分钟
30 天内合并 PR
84

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

codecentric/spring-boot-admin 的其他 Issue

查看 codecentric/spring-boot-admin 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

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