[BUG] why thre are two same selector when register a new client
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Bug
when i register a new client,there are two same selector data

and in database, there are two records

after debug, i find if using nacos as registration center, and deploy more than one admin instance(for example two). when i start a client and to register, both admin server receive nacos change event and start to register meta data as follow:
`org.apache.shenyu.admin.service.impl.SelectorServiceImpl#registerDefault(org.apache.shenyu.register.common.dto.MetaDataRegisterDTO, java.lang.String, java.lang.String)`
below code, both admin instance with not find selectorDO and will create two same selector data
```
String contextPath = ContextPathUtils.buildContextPath(dto.getContextPath(), dto.getAppName());
SelectorDO selectorDO = findByNameAndPluginName(contextPath, pluginName);
if (Objects.isNull(selectorDO)) {
SelectorDTO selectorDTO = SelectorUtil.buildSelectorDTO(contextPath, pluginMapper.selectByName(pluginName).getId());
selectorDTO.setHandle(selectorHandler);
return registerDefault(selectorDTO);
}
```
that cause lot of warn
`AbstractRetryTask [shenyu-shared_wheel_timer-2] Failed to execute task:/o:divide,retried:1 ,total retries:-1,cause:nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at org.apache.shenyu.admin.service.impl.SelectorServiceImpl#registerDefault and trace the Nacos registration event handling when multiple admin instances receive the same change. Reproduce with two admin instances and inspect the selector records created for one client registration. Done means duplicate selectors are prevented and the TooManyResultsException warnings no longer occur.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100