Suzzt / dao-cloud

自研的微服务提供一站式轻量级框架(基于tcp自定义`dao`通信协议)。
Apache License 2.0
14 stars 3 forks source link

新加入的节点在同步数据的时候不能能够提供服务的能力,应处于CP模式 #9

Closed yomea closed 5 months ago

yomea commented 1 year ago

代码位置: com.junmo.center.bootstarp.DaoCloudCenterConfiguration#onApplicationEvent public void onApplicationEvent(ApplicationEvent applicationEvent) { if (applicationEvent instanceof ContextRefreshedEvent) { // init center cluster attribute persistence CenterClusterManager.setPersistence(persistence); ThreadPoolFactory.GLOBAL_THREAD_POOL.execute(() -> { NioEventLoopGroup boss = new NioEventLoopGroup(); NioEventLoopGroup worker = new NioEventLoopGroup(4); try { ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.channel(NioServerSocketChannel.class); serverBootstrap.group(boss, worker); serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ch.pipeline().addLast(new ProtocolFrameDecoder()); ch.pipeline().addLast(new DaoMessageCoder()); ch.pipeline().addLast(new IdleStateHandler(0, 10, 0, TimeUnit.SECONDS)); ch.pipeline().addLast(new InquireClusterCenterRequestHandler()); ch.pipeline().addLast(new ClusterRequestHandler()); ch.pipeline().addLast(new SubscribeConfigHandler(configCenterManager)); ch.pipeline().addLast(new PullServerHandler()); ch.pipeline().addLast(new PullConfigRequestHandler(configCenterManager)); ch.pipeline().addLast(new SyncClusterInformationRequestHandler(configCenterManager)); ch.pipeline().addLast(new ServerRegisterHandler()); } }); Channel channel = serverBootstrap.bind(DaoCloudConstant.CENTER_IP).sync().channel(); if (StringUtils.hasLength(DaoCloudClusterCenterProperties.ip)) { // join cluster CenterClusterManager.inquireIpAddress = DaoCloudClusterCenterProperties.ip; CenterClusterManager.start(); } configCenterManager.init(); log.info(">>>>>>>>>>>> dao-cloud-center port:{} start success <<<<<<<<<<<", DaoCloudConstant.CENTER_IP); channel.closeFuture().sync(); } catch (Exception e) { log.error("dao-cloud center start error", e); } finally { boss.shutdownGracefully(); worker.shutdownGracefully(); System.exit(1); } }); } else if (applicationEvent instanceof WebServerInitializedEvent) { WebServerInitializedEvent event = (WebServerInitializedEvent) applicationEvent; if (contextPath == null) { log.info("======================================== open web dao-cloud page address: http://{}:{}/dao-cloud/index.html ========================================", NetUtil.getLocalIp(), event.getWebServer().getPort()); } else { log.info("======================================== open web dao-cloud page address: http://{}:{}{}/dao-cloud/index.html ========================================", NetUtil.getLocalIp(), event.getWebServer().getPort(), contextPath); } } }

此处先启动了集群端口,然后开始同步节点数据 预期:新加入的节点在全量同步节点数据时不应提供服务,否则很容易读取不到数据