Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-2.12] fix: possible incorrect result set obtained by Gc synchronizer when sartup #5331

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}