Sean-Walker0 opened a new pull request, #7515:
URL: https://github.com/apache/shenyu/pull/7515

   Fixes #7469
   
   ## Modifications
   
   `DiscoveryServiceImpl#importData` remapped each `discovery_rel` row's 
`selectorId` / `proxySelectorId` through the import-context mappings and 
**inserted the row even when the mapping was missing** — the remapping silently 
nulled the reference and `insertSelective` happily persisted it (null columns 
are omitted), leaving relations in the imported namespace that point at 
nothing. The same happened for rels of discoveries that carry no handler 
(`discoveryHandlerId` null).
   
   Both references are now resolved first, and the rel is **skipped with a warn 
log** when the exported id was set but its target was not imported into this 
namespace, or when there is no handler to attach it to:
   
   ```java
   boolean selectorReferenceLost = 
Objects.nonNull(discoveryRelDO.getSelectorId()) && 
Objects.isNull(remappedSelectorId);
   boolean proxySelectorReferenceLost = 
Objects.nonNull(discoveryRelDO.getProxySelectorId()) && 
Objects.isNull(remappedProxySelectorId);
   if (Objects.isNull(discoveryHandlerId) || selectorReferenceLost || 
proxySelectorReferenceLost) {
       LOG.warn("skip discovery rel of discovery [{}]: referenced 
selector/proxy selector was not imported", discoveryName);
   } else { ... insertSelective ... }
   ```
   
   Relations whose exported references were already null keep that shape (the 
exported data itself had none).
   
   ## Verifying this change
   
   - [x] `testImportSkipsRelWhenSelectorMappingMissing` / 
`testImportSkipsRelWhenProxySelectorMappingMissing` — red on the pre-fix code 
(`insertSelective` was invoked with the nulled reference), green after.
   - [x] `testImportRemapsRelReferencesWhenMappingsExist` — guards the 
successful remap path with an `ArgumentCaptor` asserting the inserted row 
carries the remapped id (green before and after).
   - [x] `./mvnw -pl shenyu-admin -am test -B -Dtest=DiscoveryServiceImplTest` 
— 9/9 green (6 pre-existing cases unchanged), module checkstyle clean.
   
   ## Notes
   
   - Behavior change: rels whose targets were not part of the import are 
skipped (with a warn) instead of being inserted with dangling references; 
nothing that previously imported correctly changes.
   - Orthogonality: no open PR modifies `DiscoveryServiceImpl` (verified 
against the file lists of all 97 open PRs).
   
   Make sure that:
   
   - [x] You have read the [contribution 
guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [x] You submit test cases (unit or integration tests) that back your 
changes.
   - [x] Your local test passed `./mvnw clean install 
-Dmaven.javadoc.skip=true` (module-scoped: `shenyu-admin` targeted test class + 
checkstyle green; full-module suite left to CI as with the other admin PRs).


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