[BUG] ProcessorSlotChain may get wrong one
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
When I was reading the source code of Sentinel, I found that the ProcessorSlotChain obtained varies for different resources. I found that ResourceWrapper overrides the equals and hashcode to get unique chain here.
```java
// ResourceWrapper
@Override
public int hashCode() {
return getName().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ResourceWrapper) {
ResourceWrapper rw = (ResourceWrapper)obj;
return rw.getName().equals(getName());
}
return false;
}
// CtSph
ProcessorSlot lookProcessChain(ResourceWrapper resourceWrapper) {
ProcessorSlotChain chain = chainMap.get(resourceWrapper);
if (chain == null) {
synchronized (LOCK) {
chain = chainMap.get(resourceWrapper);
if (chain == null) {
// Entry size limit.
if (chainMap.size() >= Constants.MAX_SLOT_CHAIN_SIZE) {
return null;
}
chain = SlotChainProvider.newSlotChain();
Map newMap = new HashMap(
chainMap.size() + 1);
newMap.putAll(chainMap);
newMap.put(resourceWrapper, chain);
chainMap = newMap;
}
}
}
return chain;
}
```
As you see, there will use the same chain if resources have the same name, even if they are different resource type. But as user, we may use the same name for different resource by accident. Is there any wrong happen with sentinel because of this case?
The define in `ClusterNode` considers the name and type. Why not consider as the same at `ResourceWrapper`?
```java
public class ClusterNode extends StatisticNode {
private final String name;
private final int resourceType;
}
```
I'm not sure if my idea is right. If anything wrong, please correct me.
### Describe what happened
### Describe what you expected to happen
Maybe we need to consider resource type for resourceWrapper when geting chain.
```java
// ResourceWrapper
@Override
public int hashCode() {
return (getName() + getResourceType()).hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ResourceWrapper) {
ResourceWrapper rw = (ResourceWrapper)obj;
return rw.getName().equals(getName()) && rw.getResourceType() == getResourceType();
}
return false;
}
```
### How to reproduce it (as minimally and precisely as possible)
1.
2.
3.
### Tell us your environment
### Anything else we need to know?
Contributor guide
Assessment
This issue has not been assessed yet.