Skip to content

Commit

Permalink
Use Fail-Fast in Method `com.alibaba.nacos.naming.core.ServiceManager… (
Browse files Browse the repository at this point in the history
#8731)

* Use Fail-Fast in Method `com.alibaba.nacos.naming.core.ServiceManager#createServiceIfAbsent`

* Modify Comments
  • Loading branch information
ZhangShenao authored Jul 14, 2022
1 parent 667a34d commit 8cc92c5
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,26 +446,28 @@ public void createEmptyService(String namespaceId, String serviceName, boolean l
public void createServiceIfAbsent(String namespaceId, String serviceName, boolean local, Cluster cluster)
throws NacosException {
Service service = getService(namespaceId, serviceName);
if (service == null) {

Loggers.SRV_LOG.info("creating empty service {}:{}", namespaceId, serviceName);
service = new Service();
service.setName(serviceName);
service.setNamespaceId(namespaceId);
service.setGroupName(NamingUtils.getGroupName(serviceName));
// now validate the service. if failed, exception will be thrown
service.setLastModifiedMillis(System.currentTimeMillis());
service.recalculateChecksum();
if (cluster != null) {
cluster.setService(service);
service.getClusterMap().put(cluster.getName(), cluster);
}
service.validate();

putServiceAndInit(service);
if (!local) {
addOrReplaceService(service);
}
//return if service already exists
if (service != null) {
return;
}

Loggers.SRV_LOG.info("creating empty service {}:{}", namespaceId, serviceName);
service = new Service();
service.setName(serviceName);
service.setNamespaceId(namespaceId);
service.setGroupName(NamingUtils.getGroupName(serviceName));
// now validate the service. if failed, exception will be thrown
service.setLastModifiedMillis(System.currentTimeMillis());
service.recalculateChecksum();
if (cluster != null) {
cluster.setService(service);
service.getClusterMap().put(cluster.getName(), cluster);
}
service.validate();

putServiceAndInit(service);
if (!local) {
addOrReplaceService(service);
}
}

Expand Down

0 comments on commit 8cc92c5

Please sign in to comment.