[BUG] ZooKeeper registry checks and watches raw service keys instead of instance paths
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/shenyu/issues) and found no similar issues.
### Apache ShenYu Component
shenyu-registry
### What happened
The ZooKeeper registry implementation uses different key formats for the same logical discovery service key.
`selectInstances(selectKey)` converts a service key into the instance parent path before reading children:
```java
final String watchKey = StringUtils.isNotBlank(watchPath)
? InstancePathConstants.buildRealNode(watchPath, selectKey)
: InstancePathConstants.buildInstanceParentPath(selectKey);
```
But `serviceExists(key)` and `watchInstances(key, listener)` use the raw key directly:
```java
public boolean serviceExists(final String key) {
return Objects.nonNull(client.get(key));
}
public void watchInstances(final String key, final ChangedEventListener listener) {
CuratorCache treeCache = client.addCache(key, ...);
}
```
The admin discovery path passes the listener node or default service name to these methods:
```java
String key = buildProxySelectorKey(discoveryHandlerDTO.getListenerNode());
if (!shenyuInstanceRegisterRepository.serviceExists(key)) {
throw new ShenyuAdminException(...);
}
shenyuInstanceRegisterRepository.watchInstances(key, ...);
```
For ordinary service keys, the actual ZooKeeper instance data is stored under `/shenyu/register/instance/{serviceName}` via `InstancePathConstants.buildInstanceParentPath(serviceName)`. Therefore `serviceExists("{serviceName}")` can check the wrong node, and `watchInstances("{serviceName}")` can watch the wrong path.
This can prevent ProxySelector discovery startup or attach a watcher that never receives instance changes.
### What you expected to happen
ZooKeeper `serviceExists()` and `watchInstances()` should normalize keys the same way as `selectInstances()`, using the configured `watchPath` when present or `InstancePathConstants.buildInstanceParentPath(key)` otherwise.
### How to reproduce
1. Configure ZooKeeper discovery.
2. Register an instance for a service name, for example `demo-service`, under ShenYu's normal instance path.
3. Create/start a ProxySelector whose listener node is `demo-service`.
4. `DefaultDiscoveryProcessor` calls `serviceExists("demo-service")` and `watchInstances("demo-service")`, but the ZooKeeper implementation checks/watches the raw key rather than `/shenyu/register/instance/demo-service`.
### Debug logs
_No response_
### Environment
Current master branch.
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in the shenyu-registry ZooKeeper implementation with selectInstances, serviceExists, watchInstances, and InstancePathConstants, then trace the calls from DefaultDiscoveryProcessor. Reproduce the demo-service scenario with ProxySelector discovery and compare the paths used for existence checks, watches, and instance storage. Done means both methods use the same normalized path behavior as selectInstances and discovery receives instance changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100