@@ -459,7 +459,8 @@ protected static final class IndexThrottle {
459459 private final Lock pauseIndexingLock = new ReentrantLock ();
460460 private final Condition pauseCondition = pauseIndexingLock .newCondition ();
461461 private final ReleasableLock pauseLockReference = new ReleasableLock (pauseIndexingLock );
462- private volatile AtomicBoolean pauseIndexing = new AtomicBoolean ();
462+ // private volatile AtomicBoolean pauseIndexing = new AtomicBoolean();
463+ private volatile AtomicBoolean pauseThrottling = new AtomicBoolean ();
463464 private final boolean pauseWhenThrottled ;
464465 private volatile ReleasableLock lock = NOOP_LOCK ;
465466
@@ -471,7 +472,9 @@ public Releasable acquireThrottle() {
471472 if (lock == pauseLockReference ) {
472473 pauseLockReference .acquire ();
473474 try {
474- while (pauseIndexing .getAcquire ()) {
475+ // while (pauseIndexing.getAcquire()) {
476+ // If throttling is activate and not temporarily paused
477+ while ((lock == pauseLockReference ) && (pauseThrottling .getAcquire () == false )) {
475478 logger .trace ("Waiting on pause indexing lock" );
476479 pauseCondition .await ();
477480 }
@@ -490,10 +493,11 @@ public Releasable acquireThrottle() {
490493 /** Activate throttling, which switches the lock to be a real lock */
491494 public void activate () {
492495 assert lock == NOOP_LOCK : "throttling activated while already active" ;
496+
493497 startOfThrottleNS = System .nanoTime ();
494498 if (pauseWhenThrottled ) {
495- pauseIndexing .setRelease (true );
496499 lock = pauseLockReference ;
500+ logger .trace ("Activated index throttling pause" );
497501 } else {
498502 lock = lockReference ;
499503 }
@@ -503,19 +507,15 @@ public void activate() {
503507 public void deactivate () {
504508 assert lock != NOOP_LOCK : "throttling deactivated but not active" ;
505509
506- if (lock == pauseLockReference ) {
507- logger .trace ("Deactivate index throttling pause" );
508-
510+ lock = NOOP_LOCK ;
511+ if (pauseWhenThrottled ) {
509512 // Signal the threads that are waiting on pauseCondition
510- pauseLockReference .acquire ();
511- try {
512- pauseIndexing .setRelease (false );
513+ try (Releasable releasableLock = pauseLockReference .acquire ()) {
514+ // pauseIndexing.setRelease(false);
513515 pauseCondition .signalAll ();
514- } finally {
515- pauseLockReference .close ();
516516 }
517+ logger .trace ("Deactivated index throttling pause" );
517518 }
518- lock = NOOP_LOCK ;
519519
520520 assert startOfThrottleNS > 0 : "Bad state of startOfThrottleNS" ;
521521 long throttleTimeNS = System .nanoTime () - startOfThrottleNS ;
@@ -542,6 +542,28 @@ boolean isThrottled() {
542542 return lock != NOOP_LOCK ;
543543 }
544544
545+ // Pause throttling to allow another task such as relocation to acquire all indexing permits
546+ public void pauseThrottle () {
547+ if (pauseWhenThrottled ) {
548+ try (Releasable releasableLock = pauseLockReference .acquire ()) {
549+ // pauseIndexing.setRelease(false);
550+ pauseThrottling .setRelease (true );
551+ pauseCondition .signalAll ();
552+ }
553+ }
554+ }
555+
556+ // Reverse what was done in pauseThrottle()
557+ public void unpauseThrottle () {
558+ if (pauseWhenThrottled ) {
559+ try (Releasable releasableLock = pauseLockReference .acquire ()) {
560+ // pauseIndexing.setRelease(true);
561+ pauseThrottling .setRelease (false );
562+ pauseCondition .signalAll ();
563+ }
564+ }
565+ }
566+
545567 boolean throttleLockIsHeldByCurrentThread () { // to be used in assertions and tests only
546568 if (isThrottled ()) {
547569 return lock .isHeldByCurrentThread ();
0 commit comments