Skip to content

Commit d594925

Browse files
authored
merge migration rule support from 3.0 (#6773)
1 parent 27571a0 commit d594925

File tree

126 files changed

+4742
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+4742
-747
lines changed

dubbo-all/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,13 @@
544544
<scope>compile</scope>
545545
<optional>true</optional>
546546
</dependency>
547+
<dependency>
548+
<groupId>org.apache.dubbo</groupId>
549+
<artifactId>dubbo-metadata-report-failover</artifactId>
550+
<version>${project.version}</version>
551+
<scope>compile</scope>
552+
<optional>true</optional>
553+
</dependency>
547554

548555
<!-- Transitive dependencies -->
549556
<dependency>
@@ -684,6 +691,7 @@
684691
<include>org.apache.dubbo:dubbo-metadata-report-consul</include>
685692
<include>org.apache.dubbo:dubbo-metadata-report-etcd</include>
686693
<include>org.apache.dubbo:dubbo-metadata-report-nacos</include>
694+
<include>org.apache.dubbo:dubbo-metadata-report-failover</include>
687695
<include>org.apache.dubbo:dubbo-serialization-native-hession</include>
688696
</includes>
689697
</artifactSet>
@@ -859,6 +867,12 @@
859867
META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory
860868
</resource>
861869
</transformer>
870+
<transformer
871+
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
872+
<resource>
873+
META-INF/dubbo/internal/org.apache.dubbo.metadata.store.failover.FailoverCondition
874+
</resource>
875+
</transformer>
862876
<!-- @since 2.7.5 -->
863877
<transformer
864878
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">

dubbo-bom/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@
248248
<artifactId>dubbo-registry-multicast</artifactId>
249249
<version>${project.version}</version>
250250
</dependency>
251+
<dependency>
252+
<groupId>org.apache.dubbo</groupId>
253+
<artifactId>dubbo-registry-multiple</artifactId>
254+
<version>${project.version}</version>
255+
</dependency>
251256
<dependency>
252257
<groupId>org.apache.dubbo</groupId>
253258
<artifactId>dubbo-registry-zookeeper</artifactId>
@@ -399,6 +404,11 @@
399404
<artifactId>dubbo-metadata-report-nacos</artifactId>
400405
<version>${project.version}</version>
401406
</dependency>
407+
<dependency>
408+
<groupId>org.apache.dubbo</groupId>
409+
<artifactId>dubbo-metadata-report-failover</artifactId>
410+
<version>${project.version}</version>
411+
</dependency>
402412

403413
<!-- config-center -->
404414
<dependency>

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Directory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ public interface Directory<T> extends Node {
5353

5454
boolean isDestroyed();
5555

56+
void discordAddresses();
57+
5658
}

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ public void destroy() {
123123
destroyed = true;
124124
}
125125

126+
@Override
127+
public void discordAddresses() {
128+
// do nothing by default
129+
}
130+
126131
protected abstract List<Invoker<T>> doList(Invocation invocation) throws RpcException;
127132

128133
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.rpc.cluster.support.migration;
18+
19+
import org.apache.dubbo.common.extension.SPI;
20+
import org.apache.dubbo.rpc.Invoker;
21+
22+
import java.util.List;
23+
24+
@SPI
25+
public interface MigrationClusterComparator {
26+
27+
<T> boolean shouldMigrate(List<Invoker<T>> interfaceInvokers, List<Invoker<T>> serviceInvokers);
28+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.rpc.cluster.support.migration;
18+
19+
import org.apache.dubbo.common.URL;
20+
import org.apache.dubbo.rpc.cluster.ClusterInvoker;
21+
22+
import java.util.concurrent.atomic.AtomicBoolean;
23+
24+
public interface MigrationClusterInvoker<T> extends ClusterInvoker<T> {
25+
26+
boolean isServiceInvoker();
27+
28+
MigrationRule getMigrationRule();
29+
30+
void setMigrationRule(MigrationRule rule);
31+
32+
void destroyServiceDiscoveryInvoker(ClusterInvoker<?> invoker);
33+
34+
void discardServiceDiscoveryInvokerAddress(ClusterInvoker<?> invoker);
35+
36+
void discardInterfaceInvokerAddress(ClusterInvoker<T> invoker);
37+
38+
void refreshServiceDiscoveryInvoker();
39+
40+
void refreshInterfaceInvoker();
41+
42+
void destroyInterfaceInvoker(ClusterInvoker<T> invoker);
43+
44+
boolean isMigrationMultiRegsitry();
45+
46+
void migrateToServiceDiscoveryInvoker(boolean forceMigrate);
47+
48+
void reRefer(URL newSubscribeUrl);
49+
50+
void fallbackToInterfaceInvoker();
51+
52+
AtomicBoolean invokersChanged();
53+
54+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.rpc.cluster.support.migration;
18+
19+
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
20+
import org.apache.dubbo.common.utils.StringUtils;
21+
import org.apache.dubbo.rpc.model.ApplicationModel;
22+
import org.yaml.snakeyaml.Yaml;
23+
import org.yaml.snakeyaml.constructor.Constructor;
24+
25+
import java.util.Optional;
26+
27+
public class MigrationRule {
28+
private static final String DUBBO_SERVICEDISCOVERY_MIGRATION_KEY = "dubbo.application.service-discovery.migration";
29+
public static final String DUBBO_SERVICEDISCOVERY_MIGRATION_GROUP = "MIGRATION";
30+
public static final String RULE_KEY = ApplicationModel.getName() + ".migration";
31+
32+
private static DynamicConfiguration configuration = null;
33+
34+
static {
35+
Optional<DynamicConfiguration> optional = ApplicationModel.getEnvironment().getDynamicConfiguration();
36+
if (optional.isPresent()) {
37+
configuration = optional.get();
38+
}
39+
}
40+
41+
private String key;
42+
private MigrationStep step = MigrationStep.FORCE_INTERFACE;
43+
44+
public String getKey() {
45+
return key;
46+
}
47+
48+
public void setKey(String key) {
49+
this.key = key;
50+
}
51+
52+
public MigrationStep getStep() {
53+
return step;
54+
}
55+
56+
public void setStep(MigrationStep step) {
57+
this.step = step;
58+
}
59+
60+
public static MigrationRule parse(String rawRule) {
61+
if (null == configuration) {
62+
return getMigrationRule(null);
63+
}
64+
65+
if (StringUtils.isBlank(rawRule) || "INIT".equals(rawRule)) {
66+
String step = (String)configuration.getInternalProperty(DUBBO_SERVICEDISCOVERY_MIGRATION_KEY);
67+
return getMigrationRule(step);
68+
69+
}
70+
71+
Constructor constructor = new Constructor(MigrationRule.class);
72+
Yaml yaml = new Yaml(constructor);
73+
return yaml.load(rawRule);
74+
}
75+
76+
public static MigrationRule queryRule() {
77+
if (null == configuration) {
78+
return getMigrationRule(null);
79+
}
80+
81+
String rawRule = configuration.getConfig(MigrationRule.RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION_GROUP);
82+
return parse(rawRule);
83+
}
84+
85+
private static MigrationRule getMigrationRule(String step) {
86+
MigrationRule rule = new MigrationRule();
87+
rule.setStep(Enum.valueOf(MigrationStep.class, StringUtils.isBlank(step) ? MigrationStep.APPLICATION_FIRST.name() : step));
88+
return rule;
89+
}
90+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.rpc.cluster.support.migration;
18+
19+
public enum MigrationStep {
20+
FORCE_INTERFACE,
21+
APPLICATION_FIRST,
22+
FORCE_APPLICATION
23+
}

0 commit comments

Comments
 (0)