Package org.apache.hadoop.ha
Interface ActiveStandbyElector.ActiveStandbyElectorCallback
- Enclosing class:
- ActiveStandbyElector
public static interface ActiveStandbyElector.ActiveStandbyElectorCallback
Callback interface to interact with the ActiveStandbyElector object.
The application will be notified with a callback only on state changes (i.e. there will never be successive calls to becomeActive without an intermediate call to enterNeutralMode).
The callbacks will be running on Zookeeper client library threads. The application should return from these callbacks quickly so as not to impede Zookeeper client library performance and notifications. The app will typically remember the state change and return from the callback. It will then proceed with implementing actions around that state change. It is possible to be called back again while these actions are in flight and the app should handle this scenario.
The application will be notified with a callback only on state changes (i.e. there will never be successive calls to becomeActive without an intermediate call to enterNeutralMode).
The callbacks will be running on Zookeeper client library threads. The application should return from these callbacks quickly so as not to impede Zookeeper client library performance and notifications. The app will typically remember the state change and return from the callback. It will then proceed with implementing actions around that state change. It is possible to be called back again while these actions are in flight and the app should handle this scenario.
-
Method Summary
Modifier and TypeMethodDescriptionvoidThis method is called when the app becomes the active leader.voidThis method is called when the app becomes a standbyvoidIf the elector gets disconnected from Zookeeper and does not know about the lock state, then it will notify the service via the enterNeutralMode interface.voidfenceOldActive(byte[] oldActiveData) If an old active has failed, rather than exited gracefully, then the new active may need to take some fencing actions against it before proceeding with failover.voidnotifyFatalError(String errorMessage) If there is any fatal error (e.g. wrong ACL's, unexpected Zookeeper errors or Zookeeper persistent unavailability) then notifyFatalError is called to notify the app about it.
-
Method Details
-
becomeActive
This method is called when the app becomes the active leader. If the service fails to become active, it should throw ServiceFailedException. This will cause the elector to sleep for a short period, then re-join the election. Callback implementations are expected to manage their own timeouts (e.g. when making an RPC to a remote node).- Throws:
ServiceFailedException- Service Failed Exception.
-
becomeStandby
void becomeStandby()This method is called when the app becomes a standby -
enterNeutralMode
void enterNeutralMode()If the elector gets disconnected from Zookeeper and does not know about the lock state, then it will notify the service via the enterNeutralMode interface. The service may choose to ignore this or stop doing state changing operations. Upon reconnection, the elector verifies the leader status and calls back on the becomeActive and becomeStandby app interfaces.
Zookeeper disconnects can happen due to network issues or loss of Zookeeper quorum. Thus enterNeutralMode can be used to guard against split-brain issues. In such situations it might be prudent to call becomeStandby too. However, such state change operations might be expensive and enterNeutralMode can help guard against doing that for transient issues. -
notifyFatalError
If there is any fatal error (e.g. wrong ACL's, unexpected Zookeeper errors or Zookeeper persistent unavailability) then notifyFatalError is called to notify the app about it.- Parameters:
errorMessage- error message.
-
fenceOldActive
void fenceOldActive(byte[] oldActiveData) If an old active has failed, rather than exited gracefully, then the new active may need to take some fencing actions against it before proceeding with failover.- Parameters:
oldActiveData- the application data provided by the prior active
-