Class LearnerSyncThrottler

java.lang.Object
org.apache.zookeeper.server.quorum.LearnerSyncThrottler

public class LearnerSyncThrottler extends Object
Utility class to limit the number of concurrent syncs from a leader to observers and followers or from a follower to observers. LearnerHandler objects should call beginSync(boolean) before sending a sync and endSync() after finishing, successfully or not.
  • Constructor Details

    • LearnerSyncThrottler

      public LearnerSyncThrottler(int maxConcurrentSyncs, LearnerSyncThrottler.SyncType syncType) throws IllegalArgumentException
      Constructs a new instance limiting the concurrent number of syncs to maxConcurrentSyncs.
      Parameters:
      maxConcurrentSyncs - maximum concurrent number of syncs
      syncType - either a snapshot sync or a txn-based diff sync
      Throws:
      IllegalArgumentException - when maxConcurrentSyncs is less than 1
  • Method Details

    • beginSync

      protected void beginSync(boolean essential) throws SyncThrottleException, InterruptedException
      Indicates that a new sync is about to be sent.
      Parameters:
      essential - if true, do not throw an exception even if throttling limit is reached
      Throws:
      SyncThrottleException - if throttling limit has been exceeded and essential == false, even after waiting for the timeout period, if any
      InterruptedException - if thread is interrupted while trying to start a sync; cannot happen if timeout is zero
    • endSync

      public void endSync()
      Indicates that a sync has been completed.
    • setMaxConcurrentSyncs

      public void setMaxConcurrentSyncs(int maxConcurrentSyncs)
    • getSyncInProgress

      public int getSyncInProgress()