-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Modify the mechanism to pause indexing #128405
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
Changes from 7 commits
60ed208
e1728df
6d4202e
00dfd32
aa4d58a
ff014b8
a2c8eb2
50129f3
0fabe84
93723b6
72b3b75
8d2c216
a88680b
ab6644e
4755af4
941c181
f3d91a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 128405 | ||
| summary: Modify the mechanism to pause indexing | ||
| area: Distributed | ||
| type: bug | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -455,32 +455,71 @@ protected static final class IndexThrottle { | |||||
| private final CounterMetric throttleTimeMillisMetric = new CounterMetric(); | ||||||
| private volatile long startOfThrottleNS; | ||||||
| private static final ReleasableLock NOOP_LOCK = new ReleasableLock(new NoOpLock()); | ||||||
| private final PauseLock throttlingLock; | ||||||
| private final ReleasableLock lockReference; | ||||||
| private final ReleasableLock lockReference = new ReleasableLock(new ReentrantLock()); | ||||||
| private final Lock pauseIndexingLock = new ReentrantLock(); | ||||||
| private final Condition pauseCondition = pauseIndexingLock.newCondition(); | ||||||
| private final ReleasableLock pauseLockReference = new ReleasableLock(pauseIndexingLock); | ||||||
| private volatile AtomicBoolean pauseIndexing = new AtomicBoolean(); | ||||||
| private final boolean pauseWhenThrottled; | ||||||
| private volatile ReleasableLock lock = NOOP_LOCK; | ||||||
|
|
||||||
| public IndexThrottle(boolean pause) { | ||||||
| throttlingLock = new PauseLock(pause ? 0 : 1); | ||||||
| lockReference = new ReleasableLock(throttlingLock); | ||||||
| pauseWhenThrottled = pause; | ||||||
| } | ||||||
|
|
||||||
| public Releasable acquireThrottle() { | ||||||
| return lock.acquire(); | ||||||
| if (lock == pauseLockReference) { | ||||||
| pauseLockReference.acquire(); | ||||||
| try { | ||||||
| while (pauseIndexing.getAcquire()) { | ||||||
|
||||||
| while (pauseIndexing.getAcquire()) { | |
| while (lock == pauseLockReference) { |
and thus we can avoid the extra boolean?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might as well release the lock immediately and return a noop releasable?
That would allow us to use try-with-resource when acquiring the pauseLockReference too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still like to see this carried through.
As we wake up after pause throttling, with the current mechanism, we'll only wake up one of the paused threads at a time until each of their indexing requests complete. Notice that await only allows one thread at a time to come out of await until the lock is released, since returning from await reacquires the lock.
This means that if the situation is cured, but the first few indexing requests take "a long time", we are still essentially throttling to fewer threads for a while.
I'll LGTM it for now, since it is not that harmful, but would prefer to see this sorted in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had also thought about this problem that even after throttling gets deactivated, we still only let one indexing job pass at a time. But I reasoned that we were already doing that before I moved to the pause indexing option.
But I think I understand now your solution.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the pauseIndexing boolean as suggested above, we need to set the lock = noop no later than here.
I think we could simply this to:
lock = NOOP_LOCK;
pauseLockReference.acquire();
try {
// System.out.println("Deactivate pause");
pauseIndexing.setRelease(false);
Comment
To avoid the `pauseIndexing` boolean as suggested above, we need to set the `lock = noop` no later than here.
I think we could simply this to:
lock = NOOP_LOCK;
try (pauseLockReference.acquire()) {
pauseCondition.signalAll();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We read
locktwice when doing regular throttling, once for the condition here and once below. Since it is volatile, it would be good to only read it once, i.e., copy it to a local variable:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But don't we need to read the latest value of lock inside the try block ?