Skip to content
Permalink
Browse files
fix offlineApp does not work as expected, because of empty revision c…
…heck stops the de-registration. (#10009)

fixes #9986
  • Loading branch information
chickenlj committed May 7, 2022
1 parent 0661816 commit 435a2e23cd2cecf56946d319d407b255429ee8ab
Showing 2 changed files with 8 additions and 10 deletions.
@@ -171,10 +171,9 @@ public String getRevision() {
}

/**
* Calculation of this instance's status and modification of the instance must be synchronized among different threads.
* Calculation of this instance's status like revision and modification of the same instance must be synchronized among different threads.
* <p>
* Usage of this method is strictly restricted at certain point of registration, always try using {@link this#getRevision()}
* instead of this method.
* Usage of this method is strictly restricted to certain points such as when during registration. Always try to use {@link this#getRevision()} instead.
*/
public synchronized String calAndGetRevision() {
if (revision != null && !updated) {
@@ -40,6 +40,7 @@
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.EXPORTED_SERVICES_REVISION_PROPERTY_NAME;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getExportedServicesRevision;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.isValidInstance;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.setMetadataStorageType;

@@ -235,11 +236,12 @@ public List<URL> lookup(URL url) {
}

protected void doUpdate(ServiceInstance serviceInstance) throws RuntimeException {

this.unregister();

reportMetadata(serviceInstance.getServiceMetadata());
this.doRegister(serviceInstance);
if (!EMPTY_REVISION.equals(getExportedServicesRevision(serviceInstance))) {
reportMetadata(serviceInstance.getServiceMetadata());
this.doRegister(serviceInstance);
}
}

@Override
@@ -262,13 +264,10 @@ protected ServiceInstance createServiceInstance(MetadataInfo metadataInfo) {
}

protected boolean calOrUpdateInstanceRevision(ServiceInstance instance) {
String existingInstanceRevision = instance.getMetadata().get(EXPORTED_SERVICES_REVISION_PROPERTY_NAME);
String existingInstanceRevision = getExportedServicesRevision(instance);
MetadataInfo metadataInfo = instance.getServiceMetadata();
String newRevision = metadataInfo.calAndGetRevision();
if (!newRevision.equals(existingInstanceRevision)) {
if (EMPTY_REVISION.equals(newRevision)) {
return false;
}
instance.getMetadata().put(EXPORTED_SERVICES_REVISION_PROPERTY_NAME, metadataInfo.getRevision());
return true;
}

0 comments on commit 435a2e2

Please sign in to comment.