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

Track queued merges in ElasticsearchMergeScheduler and InternalEngine #121794

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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 @@ -59,6 +59,11 @@ public Set<OnGoingMerge> onGoingMerges() {
return mergeTracking.onGoingMerges();
}

@Override
public Set<OnGoingMerge> queuedMerges() {
return mergeTracking.queuedMerges();
}

/** We're currently only interested in messages with this prefix. */
private static final String MERGE_THREAD_MESSAGE_PREFIX = "merge thread";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface ElasticsearchMergeScheduler {

Set<OnGoingMerge> onGoingMerges();

Set<OnGoingMerge> queuedMerges();

MergeStats stats();

void refreshConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,14 @@ public MergeStats getMergeStats() {
return mergeScheduler.stats();
}

public boolean hasQueuedOrOnGoingMerges() {
return hasQueuedMerges() || mergeScheduler.onGoingMerges().isEmpty() == false;
}

public boolean hasQueuedMerges() {
return mergeScheduler.queuedMerges().isEmpty() == false;
}

protected LocalCheckpointTracker getLocalCheckpointTracker() {
return localCheckpointTracker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class MergeTracking {
private final Set<OnGoingMerge> onGoingMerges = ConcurrentCollections.newConcurrentSet();
private final Set<OnGoingMerge> readOnlyOnGoingMerges = Collections.unmodifiableSet(onGoingMerges);

private final Set<OnGoingMerge> queuedMerges = ConcurrentCollections.newConcurrentSet();
private final Set<OnGoingMerge> readOnlyQueuedMerges = Collections.unmodifiableSet(queuedMerges);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting idea! I guess we can piggy back on the fact that UnmodifiableCollection is just a shell and the changes to queuedMerges are guaranteed to be visible via the readOnlyQueuedMerges reference.


public MergeTracking(Logger logger, DoubleSupplier mbPerSecAutoThrottle) {
this.logger = logger;
this.mbPerSecAutoThrottle = mbPerSecAutoThrottle;
Expand All @@ -50,13 +53,26 @@ public Set<OnGoingMerge> onGoingMerges() {
return readOnlyOnGoingMerges;
}

public Set<OnGoingMerge> queuedMerges() {
return readOnlyQueuedMerges;
}

public void markMergeQueued(OnGoingMerge merge) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do see MergeTracking being used in stateless but also in stateful (InternalEngine). So I wonder why we do not call this function also for the stateful merges? An oversight? Or is it because merges cannot be queued in stateful and they just immediately execute?

If we do not mark queued merges in core ES, at least we should document it in the javadoc of markMergeQueued, hasQueuedOrOnGoingMerges() and hasQueuedMerges(), so at least people are not misled to use the functions in stateful without understanding that queued merges are not there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it because merges cannot be queued in stateful and they just immediately execute?

In stateful merges get executed immediately in their own new thread (

@Override
protected MergeThread getMergeThread(MergeSource mergeSource, MergePolicy.OneMerge merge) throws IOException {
MergeThread thread = super.getMergeThread(mergeSource, merge);
thread.setName(
EsExecutors.threadName(indexSettings, "[" + shardId.getIndexName() + "][" + shardId.id() + "]: " + thread.getName())
);
return thread;
}
).

If we do not mark queued merges in core ES, at least we should document it in the javadoc of markMergeQueued, hasQueuedOrOnGoingMerges() and hasQueuedMerges(), so at least people are not misled to use the functions in stateful without understanding that queued merges are not there.

Sure, I'll add a javadoc and mention that it's implementation dependant 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK thanks for explaining! Yea javadoc to maybe explain what you just said would be nice so that people know in stateful there are no queued merges.

queuedMerges.add(merge);
}

public void unmarkMergeQueued(OnGoingMerge merge) {
queuedMerges.remove(merge);
}

public void mergeStarted(OnGoingMerge onGoingMerge) {
MergePolicy.OneMerge merge = onGoingMerge.getMerge();
int totalNumDocs = merge.totalNumDocs();
long totalSizeInBytes = merge.totalBytesSize();
currentMerges.inc();
currentMergesNumDocs.inc(totalNumDocs);
currentMergesSizeInBytes.inc(totalSizeInBytes);
unmarkMergeQueued(onGoingMerge);
onGoingMerges.add(onGoingMerge);

if (logger.isTraceEnabled()) {
Expand Down