alibaba / alibaba/Sentinel

[Dashboard bug] When the method of saveAll (List rules) is called , InMemoryRuleRepositoryAdapter will clear all historical rules, but you don't save the new rules.

Open
#1,837 1 comment 0 reactions 0 assignees View on GitHub
area/dashboard
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## Issue Description

Type: *bug report*

### Describe what happened (or what feature you want)
When calling the saveAll InMemoryRuleRepositoryAdapter () method, can clear rules of the original data, however, did not save the new data.

**InMemoryRuleRepositoryAdapter.java**
```
@Override
public List saveAll(List rules) {
// TODO: check here.
allRules.clear();
machineRules.clear();
appRules.clear();

if (rules == null) {
return null;
}
List savedRules = new ArrayList<>(rules.size());
for (T rule : rules) {
savedRules.add(save(rule));
}
return savedRules;
}
```

### Describe what you expected to happen

Sentinel dashboard rules are persisted to Apollo.

Saving a new rule after dashboard restarts will result in loss of historical data.

### How to reproduce it (as minimally and precisely as possible)

1. First,the application has some saved rules.
2. Restart the sentinel dashboard.
3. Add a rule of this application,it can be any type of rules.
4. You will find that a piece of data is missing from the history rule after you saved a new rule item.

### Tell us your environment

Sentinel 1.8.0.
Integration with Apollo dynamic data source.
Extends the ability to persist Dashboard rules to Apollo.

### Anything else we need to know?
Save the new rules after clear them.

**InMemoryRuleRepositoryAdapter.java**
```
@Override
public List saveAll(List rules) {
// TODO: check here.
allRules.clear();
machineRules.clear();
appRules.clear();

if (rules == null) {
return null;
}
List savedRules = new ArrayList<>(rules.size());
for (T rule : rules) {
//add. save new rules
T processedEntity = preProcess(rule);
if (processedEntity != null) {
allRules.put(processedEntity.getId(), processedEntity);
machineRules.computeIfAbsent(MachineInfo.of(processedEntity.getApp(), processedEntity.getIp(),
processedEntity.getPort()), e -> new ConcurrentHashMap<>(32))
.put(processedEntity.getId(), processedEntity);
appRules.computeIfAbsent(processedEntity.getApp(), v -> new ConcurrentHashMap<>(32))
.put(processedEntity.getId(), processedEntity);
}
savedRules.add(save(rule));
}
return savedRules;
}

```

Contributor guide

Open the contributing guide

Research direction

Start with InMemoryRuleRepositoryAdapter.java and inspect the saveAll(List rules) entry point, including its clearing and saving behavior. Reproduce the restart-and-save sequence described in the issue; done means historical rules remain available while the new rules are saved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.