Aias00 opened a new issue, #6525:
URL: https://github.com/apache/shenyu/issues/6525

   ### 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!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to