Fix the cache unclear bug. (#4739)

* Fix the cache unclear bug.

* Update LimitedSizeBufferedData.java

Co-authored-by: kezhenxu94 <kezhenxu94@apache.org>
This commit is contained in:
吴晟 Wu Sheng 2020-05-04 10:46:11 +08:00 committed by GitHub
parent c33f583806
commit a2eddd699e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -74,8 +74,12 @@ public class LimitedSizeBufferedData<STORAGE_DATA extends ComparableStorageData
@Override
public List<STORAGE_DATA> read() {
List<STORAGE_DATA> collection = new ArrayList<>();
data.values().forEach(e -> e.forEach(collection::add));
return collection;
try {
List<STORAGE_DATA> collection = new ArrayList<>();
data.values().forEach(collection::addAll);
return collection;
} finally {
data.clear();
}
}
}

View File

@ -57,6 +57,10 @@ public class MergableBufferedData<METRICS extends Metrics> implements BufferedDa
@Override
public List<METRICS> read() {
return buffer.values().stream().collect(Collectors.toList());
try {
return buffer.values().stream().collect(Collectors.toList());
} finally {
buffer.clear();
}
}
}