shenyu
shenyu copied to clipboard
[Question] What is the intention of changing selection sort rule in v2.5.0
Question
https://github.com/apache/shenyu/pull/3579
This change includes an implicit sort rule which may cause wrong url match for upgrading from v2.4.3. On the other hand, users may confuse with the sort rule because the url matching order may not be the same with they configed.
After this change, all and
selections have higher priority than all or
selections.
If I config another selection with just one condition, I think there is no difference between and
and or
. But, not !!
Can you provide a more detailed case?Thanks a lot.
I think the codes under is u commented about, Yes? With selector and rule, we match the best one to execute your logic, so we can change selector and rule to do that. Is that right?
# @see org.apache.shenyu.plugin.base.AbstractShenyuPlugin;
private SelectorData manyMatchSelector(final List<SelectorData> filterCollectors) {
//What needs to be dealt with here is the and condition. If the number of and conditions is the same and is matched at the same time,
// it will be sorted by the sort field.
Map<Integer, List<Pair<Integer, SelectorData>>> collect =
filterCollectors.stream().map(selector -> {
boolean match = MatchModeEnum.match(selector.getMatchMode(), MatchModeEnum.AND);
int sort = 0;
if (match) {
sort = selector.getConditionList().size();
}
return Pair.of(sort, selector);
}).collect(Collectors.groupingBy(Pair::getLeft));
Integer max = Collections.max(collect.keySet());
List<Pair<Integer, SelectorData>> pairs = collect.get(max);
return pairs.stream().map(Pair::getRight).min(Comparator.comparing(SelectorData::getSort)).orElse(null);
}
Can you provide a more detailed case?Thanks a lot.
For example, I config 2 selectors :
The first one:
MatchType
: or
conditions
: 1. url match /a/**
2. url match /b/**
continued
: false
order
: 1
The second one:
MatchType
: and
conditions
: url match /**
continued
: false
order
: 1000
Now I have a request http://host:port/a/action
.
In version 2.4.3
, the first selector is selected because the first selector's order is smaller.
In version 2.5.0
, the second selector is selected because and
matchType have higher priority.
So,when I upgrade shenyu to 2.5.0
, I have to change the MatchType
of the second selector to or
.
However, as a user of shenyu, I may think and
and or
matchTypes are same for a selector if there is just one condition in the selector.
@yu199195 same question. Why use selector.getConditionList().size()
as sort field?