Skip to content

Commit

Permalink
Merge pull request #3017, fixes #2981, refresh invocation's attachmen…
Browse files Browse the repository at this point in the history
…ts in each invoke.

Fixes #2981.
  • Loading branch information
carryxyh authored and chickenlj committed Jan 24, 2019
1 parent 4fbdc4f commit 6a87dc5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ public void destroy() {
* @param invokers invoker candidates
* @param selected exclude selected invokers or not
* @return the invoker which will final to do invoke.
* @throws RpcException
* @throws RpcException exception
*/
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {

if (CollectionUtils.isEmpty(invokers)) {
return null;
}
String methodName = invocation == null ? StringUtils.EMPTY : invocation.getMethodName();

boolean sticky = invokers.get(0).getUrl()
.getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);
.getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);

//ignore overloaded method
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
Expand All @@ -142,7 +142,7 @@ protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation,
}

private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {

if (CollectionUtils.isEmpty(invokers)) {
return null;
Expand Down Expand Up @@ -180,19 +180,20 @@ private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation,
* Reselect, use invokers not in `selected` first, if all invokers are in `selected`,
* just pick an available one using loadbalance policy.
*
* @param loadbalance
* @param invocation
* @param invokers
* @param selected
* @return
* @throws RpcException
* @param loadbalance load balance policy
* @param invocation invocation
* @param invokers invoker candidates
* @param selected exclude selected invokers or not
* @param availablecheck check invoker available if true
* @return the reselect result to do invoke
* @throws RpcException exception
*/
private Invoker<T> reselect(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected, boolean availablecheck) throws RpcException {
List<Invoker<T>> invokers, List<Invoker<T>> selected, boolean availablecheck) throws RpcException {

//Allocating one in advance, this list is certain to be used.
List<Invoker<T>> reselectInvokers = new ArrayList<>(
invokers.size() > 1 ? (invokers.size() - 1) : invokers.size());
invokers.size() > 1 ? (invokers.size() - 1) : invokers.size());

// First, try picking a invoker not in `selected`.
for (Invoker<T> invoker : invokers) {
Expand Down Expand Up @@ -242,7 +243,6 @@ public Result invoke(final Invocation invocation) throws RpcException {
}

protected void checkWhetherDestroyed() {

if (destroyed.get()) {
throw new RpcException("Rpc cluster invoker for " + getInterface() + " on consumer " + NetUtils.getLocalHost()
+ " use dubbo version " + Version.getVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public class ContextFilter implements Filter {
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
Map<String, String> attachments = invocation.getAttachments();
if (attachments != null) {
attachments = new HashMap<String, String>(attachments);
attachments = new HashMap<>(attachments);
attachments.remove(Constants.PATH_KEY);
attachments.remove(Constants.INTERFACE_KEY);
attachments.remove(Constants.GROUP_KEY);
attachments.remove(Constants.VERSION_KEY);
attachments.remove(Constants.DUBBO_VERSION_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public Result invoke(Invocation inv) throws RpcException {
}
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);


try {
return doInvoke(invocation);
} catch (InvocationTargetException e) { // biz exception
Expand Down

0 comments on commit 6a87dc5

Please sign in to comment.