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 callbeginSync(boolean)
before sending a sync andendSync()
after finishing, successfully or not.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LearnerSyncThrottler.SyncType
-
Constructor Summary
Constructors Constructor Description LearnerSyncThrottler(int maxConcurrentSyncs, LearnerSyncThrottler.SyncType syncType)
Constructs a new instance limiting the concurrent number of syncs tomaxConcurrentSyncs
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
beginSync(boolean essential)
Indicates that a new sync is about to be sent.void
endSync()
Indicates that a sync has been completed.int
getSyncInProgress()
void
setMaxConcurrentSyncs(int maxConcurrentSyncs)
-
-
-
Constructor Detail
-
LearnerSyncThrottler
public LearnerSyncThrottler(int maxConcurrentSyncs, LearnerSyncThrottler.SyncType syncType) throws IllegalArgumentException
Constructs a new instance limiting the concurrent number of syncs tomaxConcurrentSyncs
.- Parameters:
maxConcurrentSyncs
- maximum concurrent number of syncssyncType
- either a snapshot sync or a txn-based diff sync- Throws:
IllegalArgumentException
- whenmaxConcurrentSyncs
is less than 1
-
-
Method Detail
-
beginSync
protected void beginSync(boolean essential) throws SyncThrottleException, InterruptedException
Indicates that a new sync is about to be sent.- Parameters:
essential
- iftrue
, do not throw an exception even if throttling limit is reached- Throws:
SyncThrottleException
- if throttling limit has been exceeded andessential == false
, even after waiting for the timeout period, if anyInterruptedException
- 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()
-
-