[
https://issues.apache.org/jira/browse/SCB-802?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16579458#comment-16579458
]
ASF GitHub Bot commented on SCB-802:
------------------------------------
liubao68 closed pull request #857: [SCB-802]in rollback scenario, old versions
meta is used and invocation is fail
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/857
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalancerCreator.java
b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalancerCreator.java
index 78baad4ac..eedbb9ce3 100644
---
a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalancerCreator.java
+++
b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/LoadBalancerCreator.java
@@ -22,6 +22,8 @@
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
import com.netflix.loadbalancer.IRule;
@@ -43,6 +45,8 @@
* on the result of ServerListFilter, they should not contain operation level
state information in instance fields.
*/
public class LoadBalancerCreator {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(LoadBalancerCreator.class);
+
private List<Server> serverList = Collections.emptyList();
private IRule rule;
@@ -72,6 +76,9 @@ public void shutdown() {
// serverList almost not changed for different invocation
// so every invocation will call setServerList, this is no problem
public void setServerList(List<Server> serverList) {
+ if (serverList.isEmpty()) {
+ LOGGER.warn("Set empty server list.");
+ }
this.serverList = Collections.unmodifiableList(serverList);
}
@@ -86,6 +93,9 @@ public LoadBalancer createLoadBalancer(Invocation invocation)
{
for (ServerListFilterExt filter : this.filters) {
filter.setLoadBalancer(loadBalancer);
servers = filter.getFilteredListOfServers(servers, invocation);
+ if (servers.isEmpty()) {
+ LOGGER.warn("Filter {} get empty list.", filter.getClass().getName());
+ }
}
loadBalancer.setServerList(servers);
return loadBalancer;
diff --git
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
index 22060ae2b..cff2fae11 100644
---
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
+++
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
@@ -111,9 +112,18 @@ public void deleteMicroserviceVersion(MicroserviceVersion
microserviceVersion) {
}
protected void resetLatestVersion() {
+ Map<String, MicroserviceVersion> tempVersions = new HashMap<>();
+ instances.values().forEach(item -> {
+ MicroserviceVersion version = versions.get(item.getServiceId());
+ if (version != null) {
+ tempVersions.put(item.getServiceId(), version);
+ }
+ });
+
MicroserviceVersion lastLatestVersion = latestVersion;
- latestVersion = null;
- if (!versions.isEmpty()) {
+ if (!tempVersions.isEmpty()) {
+ latestVersion =
tempVersions.values().stream().max(Comparator.comparing(MicroserviceVersion::getVersion)).get();
+ } else if (!versions.isEmpty()) {
latestVersion =
versions.values().stream().max(Comparator.comparing(MicroserviceVersion::getVersion)).get();
}
@@ -172,5 +182,6 @@ public void setInstances(Collection<MicroserviceInstance>
newInstances) {
instances = Collections.unmodifiableMap(tmpInstances);
resetInstanceCache();
+ resetLatestVersion();
}
}
diff --git
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
index 8ac62a53e..659c8af26 100644
---
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
+++
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
@@ -78,7 +78,8 @@ public void deleteMicroserviceVersionMatchAndExist() {
microserviceVersionRule.addMicroserviceVersion(v2);
microserviceVersionRule.deleteMicroserviceVersion(v2);
- Assert.assertNull(microserviceVersionRule.getLatestMicroserviceVersion());
+ // keep a latest version always, event no versions.
+
Assert.assertEquals(microserviceVersionRule.getLatestMicroserviceVersion(), v2);
}
@Test
@@ -110,5 +111,12 @@ public void setInstances() {
microserviceVersionRule.getInstanceCache().getInstanceMap());
Assert.assertSame(microserviceVersionRule.getInstances(),
microserviceVersionRule.getVersionedCache().data());
+
Assert.assertEquals(microserviceVersionRule.getLatestMicroserviceVersion(), v2);
+ microserviceVersionRule.setInstances(Arrays.asList(instance2));
+
Assert.assertEquals(microserviceVersionRule.getLatestMicroserviceVersion(), v2);
+
+ MicroserviceVersion v3 =
MicroserviceVersionTestUtils.createMicroserviceVersion("3", "3.0.0");
+ microserviceVersionRule.addMicroserviceVersion(v3);
+
Assert.assertEquals(microserviceVersionRule.getLatestMicroserviceVersion(), v2);
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> in rollback scenario, old versions meta is used and invocation is fail
> ----------------------------------------------------------------------
>
> Key: SCB-802
> URL: https://issues.apache.org/jira/browse/SCB-802
> Project: Apache ServiceComb
> Issue Type: Bug
> Components: Java-Chassis
> Affects Versions: java-chassis-1.0.0
> Reporter: liubao
> Assignee: liubao
> Priority: Major
> Fix For: java-chassis-1.1.0
>
>
> Given version 1 & verson 2
> # version 1 have interface a, b, c, and consumer & provider are running
> good.
> # user upgrade to version 2, and mistaking to delete interface b. and
> consumer run error.
> # user degrade to version 1. consumer still run error and can not recover.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)