Persistent rules are lost due to improper use of memory id generator
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
When I use external datasource to persist rules,Once SentinelDashboard restart,new rules will overwrite old rules when inserted, causing the old rules to be lost.
### Describe what happened (or what feature you want)
The rule ID generator currently in use is an AtomicLong,when dashboard restart,the AtomicLong will clean,However, the in-memory rule cache is loaded from the external datasource, and the rule ids start at 0. Insert a new rule at this point will override the old rule.
The code directory is:sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/
### Describe what you expected to happen
Solving this problem requires a continuously increasing ID generator,For convenience, I used a timestamp instead,but the display order of rules in the Dashboard is inconsistent with the insert order
### How to reproduce it (as minimally and precisely as possible)
1. Configure an external data source to hold rule data
2. Insert a few rules
3. Restart sentinelDashboard and insert a few more rules
### environment
jdk 1.8
Contributor guide
Research direction
Start in sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/ and inspect how rule IDs are generated, cached, and loaded from an external datasource. Reproduce the sequence of inserting rules, restarting SentinelDashboard, and inserting more rules; done means existing rules are not overwritten and newly inserted rules retain a consistent order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100