Skip to content

Commit

Permalink
Fix service discovery metadata update failed (#11298)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ authored Jan 14, 2023
1 parent a1356d9 commit f9b27ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,22 @@ public List<URL> lookup(URL url) {
throw new UnsupportedOperationException("Service discovery implementation does not support lookup of url list.");
}

protected void doUpdate(ServiceInstance oldServiceInstance, ServiceInstance newServiceInstance) throws RuntimeException {
/**
* Update Service Instance. Unregister and then register by default.
* Can be override if registry support update instance directly.
* <br/>
* NOTICE: Remind to update {@link AbstractServiceDiscovery#serviceInstance}'s reference if updated
* and report metadata by {@link AbstractServiceDiscovery#reportMetadata(MetadataInfo)}
*
* @param oldServiceInstance origin service instance
* @param newServiceInstance new service instance
*/
protected void doUpdate(ServiceInstance oldServiceInstance, ServiceInstance newServiceInstance) {
this.doUnregister(oldServiceInstance);

if (!EMPTY_REVISION.equals(getExportedServicesRevision(serviceInstance))) {
reportMetadata(serviceInstance.getServiceMetadata());
this.serviceInstance = newServiceInstance;
reportMetadata(newServiceInstance.getServiceMetadata());
this.doRegister(newServiceInstance);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ protected void doUpdate(ServiceInstance oldServiceInstance, ServiceInstance newS
if (!Objects.equals(oldServiceInstance.getServiceName(), newServiceInstance.getServiceName()) ||
!Objects.equals(oldServiceInstance.getAddress(), newServiceInstance.getAddress()) ||
!Objects.equals(oldServiceInstance.getPort(), newServiceInstance.getPort())) {
// ignore if host-ip changed
// Ignore if host-ip changed. Should unregister first.
super.doUpdate(oldServiceInstance, newServiceInstance);
return;
}

try {
this.serviceInstance = newServiceInstance;
reportMetadata(newServiceInstance.getServiceMetadata());

// override without unregister
this.doRegister(newServiceInstance);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected void doUpdate(ServiceInstance oldServiceInstance, ServiceInstance newS
org.apache.curator.x.discovery.ServiceInstance<ZookeeperInstance> newInstance = build(newServiceInstance);
if (!Objects.equals(newInstance.getName(), oldInstance.getName()) ||
!Objects.equals(newInstance.getId(), oldInstance.getId())) {
// ignore if id changed
// Ignore if id changed. Should unregister first.
super.doUpdate(oldServiceInstance, newServiceInstance);
return;
}
Expand Down

0 comments on commit f9b27ed

Please sign in to comment.