-
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 12 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,33 +455,64 @@ 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 pauseThrottling = 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 { | ||
| // If throttling is activate and not temporarily paused | ||
| while ((lock == pauseLockReference) && (pauseThrottling.getAcquire() == false)) { | ||
| logger.trace("Waiting on pause indexing lock"); | ||
| pauseCondition.await(); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| logger.trace("Acquired pause indexing lock"); | ||
| } | ||
| return pauseLockReference; | ||
|
||
| } else { | ||
| return lock.acquire(); | ||
| } | ||
| } | ||
|
|
||
| /** Activate throttling, which switches the lock to be a real lock */ | ||
| public void activate() { | ||
| assert lock == NOOP_LOCK : "throttling activated while already active"; | ||
|
|
||
| startOfThrottleNS = System.nanoTime(); | ||
| throttlingLock.throttle(); | ||
| lock = lockReference; | ||
| if (pauseWhenThrottled) { | ||
| lock = pauseLockReference; | ||
| logger.trace("Activated index throttling pause"); | ||
| } else { | ||
| lock = lockReference; | ||
| } | ||
| } | ||
|
|
||
| /** Deactivate throttling, which switches the lock to be an always-acquirable NoOpLock */ | ||
| public void deactivate() { | ||
| assert lock != NOOP_LOCK : "throttling deactivated but not active"; | ||
|
|
||
| throttlingLock.unthrottle(); | ||
| lock = NOOP_LOCK; | ||
| if (pauseWhenThrottled) { | ||
| // Signal the threads that are waiting on pauseCondition | ||
| try (Releasable releasableLock = pauseLockReference.acquire()) { | ||
| pauseCondition.signalAll(); | ||
| } | ||
| logger.trace("Deactivated index throttling pause"); | ||
| } | ||
|
|
||
| assert startOfThrottleNS > 0 : "Bad state of startOfThrottleNS"; | ||
| long throttleTimeNS = System.nanoTime() - startOfThrottleNS; | ||
|
|
@@ -508,6 +539,26 @@ boolean isThrottled() { | |
| return lock != NOOP_LOCK; | ||
| } | ||
|
|
||
| // Pause throttling to allow another task such as relocation to acquire all indexing permits | ||
| public void pauseThrottle() { | ||
| if (pauseWhenThrottled) { | ||
| try (Releasable releasableLock = pauseLockReference.acquire()) { | ||
| pauseThrottling.setRelease(true); | ||
| pauseCondition.signalAll(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Reverse what was done in pauseThrottle() | ||
| public void unpauseThrottle() { | ||
| if (pauseWhenThrottled) { | ||
| try (Releasable releasableLock = pauseLockReference.acquire()) { | ||
| pauseThrottling.setRelease(false); | ||
| pauseCondition.signalAll(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| boolean throttleLockIsHeldByCurrentThread() { // to be used in assertions and tests only | ||
| if (isThrottled()) { | ||
| return lock.isHeldByCurrentThread(); | ||
|
|
||
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.
Can we name this and the method differently, like
suspendThrottling?pauseThrottlingsounds like a variable indicating that the "pause throttling" mechanism is enabled when instead it is that it is disabled ;-)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.
Yes.