Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failover retry extension #14457

Open
wants to merge 1 commit into
base: 3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.rpc.RpcException;

public class DefaultRetryableFunction implements RetryableFunction {

@Override
public boolean retryable(RpcException e) {
return !e.isBiz();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import java.util.List;
import java.util.Set;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_RETRIES;
import static org.apache.dubbo.common.constants.CommonConstants.RETRIES_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RETRYABLE_FUNCTION_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CLUSTER_FAILED_MULTIPLE_RETRIES;

/**
Expand All @@ -50,8 +52,13 @@ public class FailoverClusterInvoker<T> extends AbstractClusterInvoker<T> {
private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(FailoverClusterInvoker.class);

private final RetryableFunction retryableFunction;

public FailoverClusterInvoker(Directory<T> directory) {
super(directory);
this.retryableFunction = getUrl().getOrDefaultApplicationModel()
.getExtensionLoader(RetryableFunction.class)
.getOrDefaultExtension(getUrl().getParameter(RETRYABLE_FUNCTION_KEY, DEFAULT_KEY));
}

@Override
Expand All @@ -77,7 +84,6 @@ public Result doInvoke(Invocation invocation, final List<Invoker<T>> invokers, L
Invoker<T> invoker = select(loadbalance, invocation, copyInvokers, invoked);
invoked.add(invoker);
RpcContext.getServiceContext().setInvokers((List) invoked);
boolean success = false;
try {
Result result = invokeWithContext(invoker, invocation);
if (le != null && logger.isWarnEnabled()) {
Expand All @@ -98,18 +104,16 @@ public Result doInvoke(Invocation invocation, final List<Invoker<T>> invokers, L
+ le.getMessage(),
le);
}
success = true;
return result;
} catch (RpcException e) {
if (e.isBiz()) { // biz exception.
throw e;
} catch (Throwable t) {
providers.add(invoker.getUrl().getAddress());
if (t instanceof RpcException) {
le = (RpcException) t;
} else {
le = new RpcException(t.getMessage(), t);
}
le = e;
} catch (Throwable e) {
le = new RpcException(e.getMessage(), e);
} finally {
if (!success) {
providers.add(invoker.getUrl().getAddress());
if (!retryableFunction.retryable(le)) {
throw le;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.rpc.RpcException;

@SPI
public interface RetryableFunction {

boolean retryable(RpcException e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default=org.apache.dubbo.rpc.cluster.support.DefaultRetryableFunction
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,6 @@ public interface CommonConstants {
String ZOOKEEPER_ENSEMBLE_TRACKER_KEY = "zookeeper.ensemble.tracker";

String DUBBO_VERSIONS_KEY = "META-INF/dubbo-versions";

String RETRYABLE_FUNCTION_KEY = "retryable-function";
}
4 changes: 4 additions & 0 deletions dubbo-distribution/dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,10 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.registry.integration.ServiceURLCustomizer</resource>
</transformer>

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.support.RetryableFunction</resource>
</transformer>
</transformers>
<filters>
<filter>
Expand Down
Loading