konlue opened a new pull request, #7844:
URL: https://github.com/apache/shenyu/pull/7844
Fixes #7830.
## Summary
`SensitiveWordPlugin#dictionary` relied on `subscribeOn(boundedElastic())`,
which only moves the subscription point: the redis driver still emits on its
own io threads, so the cpu-bound Aho-Corasick construction ran there. The
`onErrorResume` fallback built the rule-words automaton inline on the error
thread as well.
## Modifications
- Hop with `publishOn(Schedulers.boundedElastic())` between `collectList()`
and the automaton construction.
- Defer the fallback rule-words build with `Mono.fromCallable` +
`subscribeOn`, so it never runs on the error-emitting thread.
- Extract the two construction paths as package-private seams
(`redisAutomaton`, `ruleWordsAutomaton`) to make the threading directly
testable.
## Verifying this change
- [x] `testTheDictionaryIsBuiltOffTheRedisIoThreads`: the redis source is
pinned to a named `simulated-redis-io` scheduler; the construction thread must
be a bounded elastic worker. Fails on the current code (build lands on the io
thread), passes with the fix.
- [x] `testTheRuleWordsAutomatonBuildIsDeferred`: assembling the fallback
automaton must not invoke the build (thread-local static interception captures
nothing at assembly time); the deferred build still completes on subscription.
- [x] Red-green: reverting only the fix internals (keeping the extracted
seams) fails both tests; restoring them passes. Full `SensitiveWordPluginTest`
18/18, no regressions.
- [x] Targeted tests pass:
```bash
./mvnw -B -ntp -pl
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-sensitive-word test
-Dtest=SensitiveWordPluginTest
```
18/18 green.
- [x] Checkstyle passes:
```bash
./mvnw -B -ntp -pl
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-sensitive-word checkstyle:check
```
clean.
## Notes
Cache semantics (`CachedDictionary` write, staleness, fail-open/fail-closed
priorities) are unchanged; only where the construction runs. The extraction
also sets up the follow-up performance fix for redundant rule-word parsing
(#7829), which touches the same method.
--
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]