Skip to content

Commit

Permalink
fix: possible incorrect result set obtained by Gc synchronizer when s…
Browse files Browse the repository at this point in the history
…artup (#5325)

#### What type of PR is this?
/kind bug
/area core
/milestone 2.13.x

#### What this PR does / why we need it:
修复启动时 GcSynchronizer 没有精准过滤出所需数据导致内存占用会出现较高峰值的问题

#### Which issue(s) this PR fixes:
Fixes #5324

#### Does this PR introduce a user-facing change?
```release-note
修复启动时 GcSynchronizer 没有精准过滤出所需数据导致内存占用会出现较高峰值的问题
```
  • Loading branch information
guqing authored Feb 5, 2024
1 parent dcef5d4 commit 06a44d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package run.halo.app.extension.gc;

import static run.halo.app.extension.Comparators.compareCreationTimestamp;

import java.util.List;
import java.util.function.Predicate;
import org.springframework.data.domain.Sort;
import run.halo.app.extension.Extension;
import run.halo.app.extension.ExtensionClient;
Expand Down Expand Up @@ -64,8 +61,6 @@ public void start() {
if (event instanceof SchemeRegistered registeredEvent) {
var newScheme = registeredEvent.getNewScheme();
listDeleted(newScheme.type()).forEach(watcher::onDelete);
client.list(newScheme.type(), deleted(), compareCreationTimestamp(true))
.forEach(watcher::onDelete);
}
});
client.watch(watcher);
Expand All @@ -77,16 +72,8 @@ public void start() {
<E extends Extension> List<E> listDeleted(Class<E> type) {
var options = new ListOptions()
.setFieldSelector(
FieldSelector.of(QueryFactory.all("metadata.deletionTimestamp"))
FieldSelector.of(QueryFactory.isNotNull("metadata.deletionTimestamp"))
);
return client.listAll(type, options, Sort.by("metadata.creationTimestamp"))
.stream()
.sorted(compareCreationTimestamp(true))
.toList();
}

private <E extends Extension> Predicate<E> deleted() {
return extension -> extension.getMetadata().getDeletionTimestamp() != null;
return client.listAll(type, options, Sort.by(Sort.Order.asc("metadata.creationTimestamp")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import run.halo.app.extension.ListOptions;
import run.halo.app.extension.ListResult;
import run.halo.app.extension.PageRequest;
import run.halo.app.extension.index.query.All;
import run.halo.app.extension.index.query.QueryIndexViewImpl;
import run.halo.app.extension.router.selector.FieldSelector;
import run.halo.app.extension.router.selector.LabelSelector;
Expand Down Expand Up @@ -155,12 +154,13 @@ List<String> doRetrieve(Indexer indexer, ListOptions options, Sort sort) {
stopWatch.stop();

stopWatch.start("retrieve matched metadata names");
var hasLabelSelector = hasLabelSelector(options.getLabelSelector());
final List<String> matchedByLabels = hasLabelSelector
? retrieveForLabelMatchers(options.getLabelSelector().getMatchers(), fieldPathEntryMap,
allMetadataNames)
: allMetadataNames;
indexView.removeByIdNotIn(new TreeSet<>(matchedByLabels));
if (hasLabelSelector(options.getLabelSelector())) {
var matchedByLabels = retrieveForLabelMatchers(options.getLabelSelector().getMatchers(),
fieldPathEntryMap, allMetadataNames);
if (allMetadataNames.size() != matchedByLabels.size()) {
indexView.removeByIdNotIn(new TreeSet<>(matchedByLabels));
}
}
stopWatch.stop();

stopWatch.start("retrieve matched metadata names by fields");
Expand Down Expand Up @@ -188,8 +188,6 @@ boolean hasLabelSelector(LabelSelector labelSelector) {
}

boolean hasFieldSelector(FieldSelector fieldSelector) {
return fieldSelector != null
&& fieldSelector.query() != null
&& !(fieldSelector.query() instanceof All);
return fieldSelector != null;
}
}

0 comments on commit 06a44d0

Please sign in to comment.