Duansg opened a new pull request, #3977:
URL: https://github.com/apache/hertzbeat/pull/3977
## What's changed?
### First 30 Minutes (Both Caches Present):
> 1st call to evaluate("metric > 50"):
- tokenStreamCache.get() → cache miss → create tokens#1 (position=0)
- expressionCache.get() → cache miss → execute parser.expr() → consume
tokens#1 to EOF
- tokens#1.LA(1) == EOF ✓ check passed
> 2nd call to evaluate("metric > 50"):
- tokenStreamCache.get() → cache hit → returns tokens#1 (still at EOF)
- expressionCache.get() → Cache hit → Returns the cached ParseTree
- tokens#1.LA(1) == EOF ✓ Passed
### 30 minutes later (tokenStreamCache expires):
> 1st call to evaluate("metric > 50"):
- tokenStreamCache.get() → cache miss → create tokens#2 (position=0)
- expressionCache.get() → cache hit → returns old ParseTree (does not
execute parser.expr())
- tokens#2.LA(1) != EOF ✗ Check failed! Because tokens#2 was not consumed
### Key issue
`expressionCache.get(expr, e -> parser.expr())`
- When a cache hit occurs: lambda is not executed, and parser.expr() is not
called.
- When cache miss occurs: Execute lambda, call parser.expr() to consume
tokens
### Modification details
1. New tokens are created each time. Creation involves only saving
references and initializing internal state, with an O(1) time complexity.
2. EOF validation occurs only during the initial parsing; cache hits skip
the check since validation has already been performed.
3. Validation test cases passed
## Checklist
- [x] I have read the [Contributing
Guide](https://hertzbeat.apache.org/docs/community/code_style_and_quality_guide)
- [ ] I have written the necessary doc or comment.
- [x] I have added the necessary unit tests and all cases have passed.
## Add or update API
- [ ] I have added the necessary [e2e
tests](https://github.com/apache/hertzbeat/tree/master/e2e) and all cases have
passed.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]