Skip to content

Commit

Permalink
[SCB-2773]Change mutil dicovery registry instance merge policy (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 authored Feb 21, 2023
1 parent fe9ca22 commit 69ac3f4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ public MicroserviceInstances findServiceInstances(String appId, String serviceNa
// default values not suitable for aggregate, reset.
result.setNeedRefresh(false);
result.setMicroserviceNotExist(true);
result.setRevision(revision);
discoveryList
.forEach(discovery -> {
MicroserviceInstances instances = discovery.findServiceInstances(appId, serviceName, versionRule, revision);
MicroserviceInstances instances = discovery.findServiceInstances(appId, serviceName, versionRule);
result.mergeMicroserviceInstances(instances);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ public interface Discovery extends SPIEnabled, SPIOrder, LifeCycle {
* @return all instances match the criteria.
*/
default MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule) {
return findServiceInstances(appId, serviceName, versionRule, null);
}

default MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule,
String revision) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,13 @@ public MicroserviceInstances setInstancesResponse(FindInstancesResponse instance
public void mergeMicroserviceInstances(MicroserviceInstances other) {
mergeNeedRefresh(other.needRefresh);
mergeMicroserviceNotExist(other.microserviceNotExist);
mergeRevision(other.revision);
mergeRevision(other);
mergeInstanceResponse(other.getInstancesResponse());
}

private void mergeRevision(String revision) {
if (revision == null) {
return;
}
if (this.revision == null || this.revision.compareTo(revision) < 0) {
this.revision = revision;
private void mergeRevision(MicroserviceInstances other) {
if (!other.isMicroserviceNotExist() && other.needRefresh) {
this.revision = other.getRevision();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public abstract class AbstractLightweightDiscovery implements Discovery, Initial

protected AppManager appManager;

protected String revision;

@Autowired
public AbstractLightweightDiscovery setEventBus(EventBus eventBus) {
this.eventBus = eventBus;
Expand Down Expand Up @@ -120,8 +122,11 @@ public MicroserviceInstance getMicroserviceInstance(String serviceId, String ins

// ignore versionRule, instances only filter by consumer logic
@Override
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String uselessVersionRule,
String revision) {
return store.findServiceInstances(appId, serviceName, revision);
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String uselessVersionRule) {
MicroserviceInstances microserviceInstances = store.findServiceInstances(appId, serviceName, this.revision);
if (!microserviceInstances.isMicroserviceNotExist() && microserviceInstances.isNeedRefresh()) {
this.revision = microserviceInstances.getRevision();
}
return microserviceInstances;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ public MicroserviceInstance getMicroserviceInstance(String serviceId, String ins
}

@Override
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule,
String revision) {
return localDiscoveryStore.findServiceInstances(appId, serviceName, versionRule, revision);
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule) {
return localDiscoveryStore.findServiceInstances(appId, serviceName, versionRule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ public MicroserviceInstance findMicroserviceInstance(String serviceId, String in
}

// local registry do not care about version and revision
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule,
String revision) {
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule) {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
List<MicroserviceInstance> instances = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public MicroserviceInstance getMicroserviceInstance(String serviceId, String ins
}

@Override
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule,
String revision) {
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule) {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
microserviceInstances.setMicroserviceNotExist(true);
return microserviceInstances;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public MicroserviceInstance getMicroserviceInstance(String serviceId, String ins
}

@Override
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule,
String revision) {
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule) {
return RegistryUtils.findServiceInstances(appId,
serviceName,
versionRule);
Expand Down

0 comments on commit 69ac3f4

Please sign in to comment.