Skip to content

Commit ec91a19

Browse files
committed
commit
1 parent 2601960 commit ec91a19

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

server/src/main/java/org/elasticsearch/index/engine/Engine.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ protected static final class IndexThrottle {
461461
private final Lock pauseIndexingLock = new ReentrantLock();
462462
private final Condition pauseCondition = pauseIndexingLock.newCondition();
463463
private final ReleasableLock pauseLockReference = new ReleasableLock(pauseIndexingLock);
464-
private volatile AtomicBoolean pauseThrottling = new AtomicBoolean();
464+
private volatile AtomicBoolean suspendThrottling = new AtomicBoolean();
465465
private final boolean pauseWhenThrottled;
466466
private volatile ReleasableLock lock = NOOP_LOCK;
467467

@@ -472,10 +472,10 @@ public IndexThrottle(boolean pause) {
472472
public Releasable acquireThrottle() {
473473
var lockCopy = this.lock;
474474
if (lockCopy == pauseLockReference) {
475-
//try (pauseLockReference.acquire();)
476-
try (var ignored = pauseLockReference.acquire()) {
475+
// try (pauseLockReference.acquire();)
476+
try (var ignored = pauseLockReference.acquire()) {
477477
// If throttling is activated and not temporarily paused
478-
while ((lock == pauseLockReference) && (pauseThrottling.getAcquire() == false)) {
478+
while ((lock == pauseLockReference) && (suspendThrottling.getAcquire() == false)) {
479479
logger.trace("Waiting on pause indexing lock");
480480
pauseCondition.await();
481481
}
@@ -541,7 +541,7 @@ long getThrottleTimeInMillis() {
541541
public void suspendThrottle() {
542542
if (pauseWhenThrottled) {
543543
try (Releasable releasableLock = pauseLockReference.acquire()) {
544-
pauseThrottling.setRelease(true);
544+
suspendThrottling.setRelease(true);
545545
pauseCondition.signalAll();
546546
}
547547
}
@@ -551,7 +551,7 @@ public void suspendThrottle() {
551551
public void resumeThrottle() {
552552
if (pauseWhenThrottled) {
553553
try (Releasable releasableLock = pauseLockReference.acquire()) {
554-
pauseThrottling.setRelease(false);
554+
suspendThrottling.setRelease(false);
555555
pauseCondition.signalAll();
556556
}
557557
}
@@ -2345,12 +2345,12 @@ public interface Warmer {
23452345
* another task trying to get indexing permits might want to pause throttling
23462346
* by letting one thread pass at a time so that it does not get starved.
23472347
*/
2348-
public abstract void pauseThrottling();
2348+
public abstract void suspendThrottling();
23492349

23502350
/**
2351-
* Reverses a previous {@link #pauseThrottling} call.
2351+
* Reverses a previous {@link #resumeThrottling} call.
23522352
*/
2353-
public abstract void unPauseThrottling();
2353+
public abstract void resumeThrottling();
23542354

23552355
public abstract boolean isIndexingPaused();
23562356

server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,32 +2823,36 @@ public void accept(ElasticsearchDirectoryReader reader, ElasticsearchDirectoryRe
28232823

28242824
@Override
28252825
public void activateThrottling() {
2826-
int count = throttleRequestCount.incrementAndGet();
2827-
assert count >= 1 : "invalid post-increment throttleRequestCount=" + count;
2828-
if (count == 1) {
2829-
throttle.activate();
2830-
logger.info("Activated throttling");
2826+
synchronized (throttleRequestCount) {
2827+
int count = throttleRequestCount.incrementAndGet();
2828+
assert count >= 1 : "invalid post-increment throttleRequestCount=" + count;
2829+
if (count == 1) {
2830+
throttle.activate();
2831+
logger.info("Activated throttling");
2832+
}
28312833
}
28322834
}
28332835

28342836
@Override
28352837
public void deactivateThrottling() {
2836-
int count = throttleRequestCount.decrementAndGet();
2837-
assert count >= 0 : "invalid post-decrement throttleRequestCount=" + count;
2838-
if (count == 0) {
2839-
throttle.deactivate();
2840-
logger.info("Deactivated throttling");
2838+
synchronized (throttleRequestCount) {
2839+
int count = throttleRequestCount.decrementAndGet();
2840+
assert count >= 0 : "invalid post-decrement throttleRequestCount=" + count;
2841+
if (count == 0) {
2842+
throttle.deactivate();
2843+
logger.info("Deactivated throttling");
2844+
}
28412845
}
28422846
}
28432847

28442848
@Override
2845-
public void pauseThrottling() {
2846-
throttle.pauseThrottle();
2849+
public void suspendThrottling() {
2850+
throttle.suspendThrottle();
28472851
}
28482852

28492853
@Override
2850-
public void unPauseThrottling() {
2851-
throttle.unpauseThrottle();
2854+
public void resumeThrottling() {
2855+
throttle.resumeThrottle();
28522856
}
28532857

28542858
@Override

server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ public void activateThrottling() {}
508508
public void deactivateThrottling() {}
509509

510510
@Override
511-
public void pauseThrottling() {}
511+
public void suspendThrottling() {}
512512

513513
@Override
514-
public void unPauseThrottling() {}
514+
public void resumeThrottling() {}
515515

516516
@Override
517517
public boolean isIndexingPaused() {

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,7 @@ public void deactivateThrottling() {
27582758
}
27592759
}
27602760

2761-
public boolean pauseThrottling() {
2761+
public boolean suspendThrottling() {
27622762
Engine engine = getEngineOrNull();
27632763
final boolean indexingPaused;
27642764
if (engine == null) {
@@ -2767,15 +2767,15 @@ public boolean pauseThrottling() {
27672767
indexingPaused = engine.isIndexingPaused();
27682768
}
27692769
if (indexingPaused) {
2770-
engine.pauseThrottling();
2770+
engine.suspendThrottling();
27712771
return (true);
27722772
}
27732773
return (false);
27742774
}
27752775

2776-
public void unpauseThrottling() {
2776+
public void resumeThrottling() {
27772777
try {
2778-
getEngine().unPauseThrottling();
2778+
getEngine().resumeThrottling();
27792779
} catch (AlreadyClosedException ex) {
27802780
// ignore
27812781
}

server/src/main/java/org/elasticsearch/index/shard/IndexShardOperationPermits.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ public void blockOperations(
8888
@Nullable IndexShard indexShard
8989
) {
9090
delayOperations();
91-
// If indexing is paused on the shard, unpause it so that any currently waiting task can
91+
// If indexing is paused on the shard, suspend it so that any currently paused task can
9292
// go ahead and release the indexing permit it holds.
93-
boolean throttlingPaused = indexShard.pauseThrottling();
93+
boolean throttlingPaused = indexShard.suspendThrottling();
9494
waitUntilBlocked(ActionListener.assertOnce(onAcquired), timeout, timeUnit, executor);
9595
if (throttlingPaused) {
96-
indexShard.unpauseThrottling();
96+
indexShard.resumeThrottling();
9797
}
9898
}
9999

0 commit comments

Comments
 (0)