From af22d35d6f5bd15d0a5a9f3cbfeed7c820566388 Mon Sep 17 00:00:00 2001 From: Pixy Yuan Date: Thu, 29 Sep 2022 09:42:03 +0800 Subject: [PATCH] =?UTF-8?q?[ISSUE=20#9230]=20Fix=20missing=20dependency=20?= =?UTF-8?q?between=20event=20publisher=20and=20subs=E2=80=A6=20(#9231)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ISSUE #9230] Fix missing dependency between event publisher and subscriber triggered on snapshot loading. * [ISSUE #9230] Fix codestyle. * [ISSUE #9230] Fix missing dependency between event publisher and subscriber triggered on persistent clients' snapshot loading. * [ISSUE #9230] Fix import. --- .../core/v2/client/manager/ClientManagerDelegate.java | 2 ++ .../client/manager/impl/EphemeralIpPortClientManager.java | 2 ++ .../nacos/naming/core/v2/pojo/InstancePublishInfo.java | 7 ++++++- .../core/v2/service/ClientOperationServiceProxy.java | 4 ++++ .../service/impl/PersistentClientOperationServiceImpl.java | 6 ++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/ClientManagerDelegate.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/ClientManagerDelegate.java index 4be778867..3525e37d6 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/ClientManagerDelegate.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/ClientManagerDelegate.java @@ -24,6 +24,7 @@ import com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient; import com.alibaba.nacos.naming.core.v2.client.manager.impl.ConnectionBasedClientManager; import com.alibaba.nacos.naming.core.v2.client.manager.impl.EphemeralIpPortClientManager; import com.alibaba.nacos.naming.core.v2.client.manager.impl.PersistentIpPortClientManager; +import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; import java.util.Collection; @@ -34,6 +35,7 @@ import java.util.HashSet; * * @author xiweng.yy */ +@DependsOn({"clientServiceIndexesManager", "namingMetadataManager"}) @Component("clientManager") public class ClientManagerDelegate implements ClientManager { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/impl/EphemeralIpPortClientManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/impl/EphemeralIpPortClientManager.java index 2f80dd5c0..64a750ec8 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/impl/EphemeralIpPortClientManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/client/manager/impl/EphemeralIpPortClientManager.java @@ -34,6 +34,7 @@ import com.alibaba.nacos.naming.misc.GlobalExecutor; import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.NamingExecuteTaskDispatcher; import com.alibaba.nacos.naming.misc.SwitchDomain; +import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; import java.util.Collection; @@ -46,6 +47,7 @@ import java.util.concurrent.TimeUnit; * * @author xiweng.yy */ +@DependsOn("clientServiceIndexesManager") @Component("ephemeralIpPortClientManager") public class EphemeralIpPortClientManager implements ClientManager { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/pojo/InstancePublishInfo.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/pojo/InstancePublishInfo.java index d6020c7b8..1632fa88e 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/pojo/InstancePublishInfo.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/pojo/InstancePublishInfo.java @@ -115,7 +115,12 @@ public class InstancePublishInfo implements Serializable { @Override public String toString() { - return "InstancePublishInfo{" + "ip='" + ip + '\'' + ", port=" + port + ", healthy=" + healthy + '}'; + return "InstancePublishInfo{" + + "ip='" + ip + '\'' + + ", port=" + port + + ", healthy=" + healthy + + ", cluster='" + cluster + '\'' + + '}'; } public static String genMetadataId(String ip, int port, String cluster) { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/ClientOperationServiceProxy.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/ClientOperationServiceProxy.java index 9b08b0d3c..2efa7c6dd 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/ClientOperationServiceProxy.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/ClientOperationServiceProxy.java @@ -24,6 +24,7 @@ import com.alibaba.nacos.naming.core.v2.service.impl.EphemeralClientOperationSer import com.alibaba.nacos.naming.core.v2.service.impl.PersistentClientOperationServiceImpl; import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.pojo.Subscriber; +import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; import java.util.List; @@ -31,8 +32,11 @@ import java.util.List; /** * Implementation of external exposure. * + *

Depends on {@link com.alibaba.nacos.naming.push.v2.NamingSubscriberServiceV2Impl namingSubscriberServiceV2Impl} + * having listen on related {@link com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent.ServiceChangedEvent events}. * @author liaochuntao */ +@DependsOn("namingSubscriberServiceV2Impl") @SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule") @Component public class ClientOperationServiceProxy implements ClientOperationService { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/impl/PersistentClientOperationServiceImpl.java b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/impl/PersistentClientOperationServiceImpl.java index 1db5608f0..abaa38742 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/impl/PersistentClientOperationServiceImpl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/v2/service/impl/PersistentClientOperationServiceImpl.java @@ -34,6 +34,7 @@ import com.alibaba.nacos.consistency.snapshot.Reader; import com.alibaba.nacos.consistency.snapshot.SnapshotOperation; import com.alibaba.nacos.consistency.snapshot.Writer; import com.alibaba.nacos.core.distributed.ProtocolManager; +import com.alibaba.nacos.core.utils.Loggers; import com.alibaba.nacos.naming.consistency.persistent.impl.AbstractSnapshotOperation; import com.alibaba.nacos.naming.constants.Constants; import com.alibaba.nacos.naming.core.v2.ServiceManager; @@ -113,6 +114,7 @@ public class PersistentClientOperationServiceImpl extends RequestProcessor4CP im try { protocol.write(writeRequest); + Loggers.RAFT.info("Client registered. service={}, clientId={}, instance={}", service, instance, clientId); } catch (Exception e) { throw new NacosRuntimeException(NacosException.SERVER_ERROR, e); } @@ -160,6 +162,7 @@ public class PersistentClientOperationServiceImpl extends RequestProcessor4CP im try { protocol.write(writeRequest); + Loggers.RAFT.info("Client unregistered. service={}, clientId={}, instance={}", service, instance, clientId); } catch (Exception e) { throw new NacosRuntimeException(NacosException.SERVER_ERROR, e); } @@ -313,6 +316,7 @@ public class PersistentClientOperationServiceImpl extends RequestProcessor4CP im @Override protected boolean readSnapshot(Reader reader) throws Exception { final String readerPath = reader.getPath(); + Loggers.RAFT.info("snapshot start to load from : {}", readerPath); final String sourceFile = Paths.get(readerPath, SNAPSHOT_ARCHIVE).toString(); final Checksum checksum = new CRC64(); byte[] snapshotBytes = DiskUtils.decompress(sourceFile, checksum); @@ -323,6 +327,7 @@ public class PersistentClientOperationServiceImpl extends RequestProcessor4CP im } } loadSnapshot(snapshotBytes); + Loggers.RAFT.info("snapshot success to load from : {}", readerPath); return true; } @@ -357,6 +362,7 @@ public class PersistentClientOperationServiceImpl extends RequestProcessor4CP im Service service = Service.newService(namespaces.get(i), groupNames.get(i), serviceNames.get(i), false); Service singleton = ServiceManager.getInstance().getSingleton(service); client.putServiceInstance(singleton, instances.get(i)); + Loggers.RAFT.info("[SNAPSHOT-LOAD] service={}, instance={}", service, instances.get(i)); NotifyCenter.publishEvent( new ClientOperationEvent.ClientRegisterServiceEvent(singleton, client.getClientId())); }