Skip to content

Use fluent comparators in ShardSnapshotTaskRunner #89971

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.repositories.SnapshotShardContext;

import java.io.IOException;
import java.util.Comparator;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand All @@ -32,6 +33,9 @@ public class ShardSnapshotTaskRunner {
private final CheckedBiConsumer<SnapshotShardContext, FileInfo, IOException> fileSnapshotter;

abstract static class SnapshotTask implements Comparable<SnapshotTask>, Runnable {
private static final Comparator<SnapshotTask> COMPARATOR = Comparator.comparingInt(SnapshotTask::priority)
.thenComparingLong(t -> t.context.snapshotStartTime());

protected final SnapshotShardContext context;

SnapshotTask(SnapshotShardContext context) {
Expand All @@ -46,11 +50,7 @@ public SnapshotShardContext context() {

@Override
public final int compareTo(SnapshotTask other) {
int res = Integer.compare(priority(), other.priority());
if (res != 0) {
return res;
}
return Long.compare(context.snapshotStartTime(), other.context.snapshotStartTime());
return COMPARATOR.compare(this, other);
}
}

Expand Down