Kea  2.3.5-git
isc::ha::HAService Class Reference

High availability service. More...

#include <ha_service.h>

+ Inheritance diagram for isc::ha::HAService:

Public Member Functions

 HAService (const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAConfigPtr &config, const HAServerType &server_type=HAServerType::DHCPv4)
 Constructor. More...
 
virtual ~HAService ()
 Destructor. More...
 
void adjustNetworkState ()
 Enables or disables network state depending on the served scopes. More...
 
size_t asyncSendLeaseUpdates (const dhcp::Pkt4Ptr &query, const dhcp::Lease4CollectionPtr &leases, const dhcp::Lease4CollectionPtr &deleted_leases, const hooks::ParkingLotHandlePtr &parking_lot)
 Schedules asynchronous IPv4 leases updates. More...
 
size_t asyncSendLeaseUpdates (const dhcp::Pkt6Ptr &query, const dhcp::Lease6CollectionPtr &leases, const dhcp::Lease6CollectionPtr &deleted_leases, const hooks::ParkingLotHandlePtr &parking_lot)
 Schedules asynchronous IPv6 lease updates. More...
 
void backupStateHandler ()
 Handler for the "backup" state. More...
 
void checkPermissionsClientAndListener ()
 Check client and(or) listener current thread permissions to perform thread pool state transition. More...
 
void communicationRecoveryHandler ()
 Handler for the "communication-recovery" state. More...
 
virtual void defineEvents ()
 Defines events used by the HA service. More...
 
virtual void defineStates ()
 Defines states of the HA service. More...
 
int getPartnerState () const
 Returns last known state of the partner. More...
 
HAServerType getServerType () const
 Returns HA server type used in object construction. More...
 
void inMaintenanceStateHandler ()
 Handler for the "in-maintenance" state. More...
 
bool inScope (dhcp::Pkt4Ptr &query4)
 Checks if the DHCPv4 query should be processed by this server. More...
 
bool inScope (dhcp::Pkt6Ptr &query6)
 Checks if the DHCPv6 query should be processed by this server. More...
 
void normalStateHandler ()
 Handler for the "hot-standby" and "load-balancing" states. More...
 
void partnerDownStateHandler ()
 Handler for "partner-down" state. More...
 
void partnerInMaintenanceStateHandler ()
 Handler for "partner-in-maintenance" state. More...
 
void passiveBackupStateHandler ()
 Handler for "passive-backup" state. More...
 
void pauseClientAndListener ()
 Pauses client and(or) listener thread pool operations. More...
 
data::ConstElementPtr processContinue ()
 Processes ha-continue command and returns a response. More...
 
data::ConstElementPtr processHAReset ()
 Processes ha-reset command and returns a response. More...
 
data::ConstElementPtr processHeartbeat ()
 Processes ha-heartbeat command and returns a response. More...
 
data::ConstElementPtr processMaintenanceCancel ()
 Processes ha-maintenance-cancel command and returns a response. More...
 
data::ConstElementPtr processMaintenanceNotify (const bool cancel)
 Processes ha-maintenance-notify command and returns a response. More...
 
data::ConstElementPtr processMaintenanceStart ()
 Processes ha-maintenance-start command and returns a response. More...
 
data::ConstElementPtr processScopes (const std::vector< std::string > &scopes)
 Processes ha-scopes command and returns a response. More...
 
data::ConstElementPtr processStatusGet () const
 Processes status-get command and returns a response. More...
 
data::ConstElementPtr processSyncCompleteNotify ()
 Process ha-sync-complete-notify command and returns a response. More...
 
data::ConstElementPtr processSynchronize (const std::string &server_name, const unsigned int max_period)
 Processes ha-sync command and returns a response. More...
 
void readyStateHandler ()
 Handler for "ready" state. More...
 
void resumeClientAndListener ()
 Resumes client and(or) listener thread pool operations. More...
 
void serveDefaultScopes ()
 Instructs the HA service to serve default scopes. More...
 
void startClientAndListener ()
 Start the client and(or) listener instances. More...
 
void stopClientAndListener ()
 Stop the client and(or) listener instances. More...
 
void syncingStateHandler ()
 Handler for "syncing" state. More...
 
void terminatedStateHandler ()
 Handler for "terminated" state. More...
 
bool unpause ()
 Unpauses the HA state machine with logging. More...
 
virtual void verifyEvents ()
 Verifies events used by the HA service. More...
 
void waitingStateHandler ()
 Handler for "waiting" state. More...
 
- Public Member Functions inherited from isc::util::StateModel
 StateModel ()
 Constructor. More...
 
virtual ~StateModel ()
 Destructor. More...
 
bool didModelFail () const
 Returns whether or not the model failed. More...
 
void endModel ()
 Conducts a normal transition to the end of the model. More...
 
std::string getContextStr () const
 Convenience method which returns a string rendition of the current state and next event. More...
 
unsigned int getCurrState () const
 Fetches the model's current state. More...
 
std::string getEventLabel (const int event) const
 Fetches the label associated with an event value. More...
 
unsigned int getLastEvent () const
 Fetches the model's last event. More...
 
unsigned int getNextEvent () const
 Fetches the model's next event. More...
 
std::string getPrevContextStr () const
 Convenience method which returns a string rendition of the previous state and last event. More...
 
unsigned int getPrevState () const
 Fetches the model's previous state. More...
 
std::string getStateLabel (const int state) const
 Fetches the label associated with an state value. More...
 
bool isModelDone () const
 Returns whether or not the model has finished execution. More...
 
bool isModelNew () const
 Returns whether or not the model is new. More...
 
bool isModelPaused () const
 Returns whether or not the model is paused. More...
 
bool isModelRunning () const
 Returns whether or not the model is running. More...
 
bool isModelWaiting () const
 Returns whether or not the model is waiting. More...
 
void nopStateHandler ()
 An empty state handler. More...
 
virtual void runModel (unsigned int event)
 Processes events through the state model. More...
 
void startModel (const int start_state)
 Begins execution of the model. More...
 
void unpauseModel ()
 Unpauses state model. More...
 

Static Public Attributes

static const int HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED = 1001
 Control result returned in response to ha-maintenance-notify. More...
 
static const int HA_HEARTBEAT_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 1
 Finished heartbeat command. More...
 
static const int HA_LEASE_UPDATES_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 2
 Finished lease updates commands. More...
 
static const int HA_MAINTENANCE_CANCEL_EVT = SM_DERIVED_EVENT_MIN + 7
 ha-maintenance-cancel command received. More...
 
static const int HA_MAINTENANCE_NOTIFY_EVT = SM_DERIVED_EVENT_MIN + 5
 ha-maintenance-notify command received. More...
 
static const int HA_MAINTENANCE_START_EVT = SM_DERIVED_EVENT_MIN + 6
 ha-maintenance-start command received. More...
 
static const int HA_SYNCED_PARTNER_UNAVAILABLE_EVT = SM_DERIVED_EVENT_MIN + 8
 The heartbeat command failed after receiving ha-sync-complete-notify command from the partner. More...
 
static const int HA_SYNCING_FAILED_EVT = SM_DERIVED_EVENT_MIN + 3
 Lease database synchronization failed. More...
 
static const int HA_SYNCING_SUCCEEDED_EVT = SM_DERIVED_EVENT_MIN + 4
 Lease database synchronization succeeded. More...
 
- Static Public Attributes inherited from isc::util::StateModel
static const int NEW_ST = 0
 State that a state model is in immediately after construction. More...
 
static const int END_ST = 1
 Final state, all the state model has reached its conclusion. More...
 
static const int SM_DERIVED_STATE_MIN = 11
 Value at which custom states in a derived class should begin. More...
 
static const int NOP_EVT = 0
 Signifies that no event has occurred. More...
 
static const int START_EVT = 1
 Event issued to start the model execution. More...
 
static const int END_EVT = 2
 Event issued to end the model execution. More...
 
static const int FAIL_EVT = 3
 Event issued to abort the model execution. More...
 
static const int SM_DERIVED_EVENT_MIN = 11
 Value at which custom events in a derived class should begin. More...
 

Protected Types

typedef std::function< void(const bool, const std::string &, const int)> PostRequestCallback
 Callback invoked when request was sent and a response received or an error occurred. More...
 
typedef std::function< void(const bool, const std::string &, const bool)> PostSyncCallback
 Callback invoked when lease database synchronization is complete. More...
 

Protected Member Functions

void asyncDisableDHCPService (http::HttpClient &http_client, const std::string &server_name, const unsigned int max_period, PostRequestCallback post_request_action)
 Schedules asynchronous "dhcp-disable" command to the specified server. More...
 
void asyncEnableDHCPService (http::HttpClient &http_client, const std::string &server_name, PostRequestCallback post_request_action)
 Schedules asynchronous "dhcp-enable" command to the specified server. More...
 
void asyncSendHAReset (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
 Sends ha-reset command to partner asynchronously. More...
 
void asyncSendHeartbeat ()
 Starts asynchronous heartbeat to a peer. More...
 
template<typename QueryPtrType >
void asyncSendLeaseUpdate (const QueryPtrType &query, const HAConfig::PeerConfigPtr &config, const data::ConstElementPtr &command, const hooks::ParkingLotHandlePtr &parking_lot)
 Asynchronously sends lease update to the peer. More...
 
void asyncSendLeaseUpdatesFromBacklog (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action)
 Sends lease updates from backlog to partner asynchronously. More...
 
void asyncSyncCompleteNotify (http::HttpClient &http_client, const std::string &server_name, PostRequestCallback post_request_action)
 Schedules asynchronous "ha-sync-complete-notify" command to the specified server. More...
 
void asyncSyncLeases ()
 Asynchronously reads leases from a peer and updates local lease database. More...
 
void asyncSyncLeases (http::HttpClient &http_client, const std::string &server_name, const unsigned int max_period, const dhcp::LeasePtr &last_lease, PostSyncCallback post_sync_action, const bool dhcp_disabled=false)
 Asynchronously reads leases from a peer and updates local lease database using a provided client instance. More...
 
void asyncSyncLeasesInternal (http::HttpClient &http_client, const std::string &server_name, const unsigned int max_period, const dhcp::LeasePtr &last_lease, PostSyncCallback post_sync_action, const bool dhcp_disabled)
 Implements fetching one page of leases during synchronization. More...
 
void clientCloseHandler (int tcp_native_fd)
 HttpClient close callback handler. More...
 
bool clientConnectHandler (const boost::system::error_code &ec, int tcp_native_fd)
 HttpClient connect callback handler. More...
 
bool clientHandshakeHandler (const boost::system::error_code &)
 HttpClient handshake callback handler. More...
 
void conditionalLogPausedState () const
 Logs if the server is paused in the current state. More...
 
int getNormalState () const
 Returns normal operation state for the current configuration. More...
 
template<typename QueryPtrType >
int getPendingRequest (const QueryPtrType &query)
 Get the number of scheduled requests for a given query. More...
 
bool isMaintenanceCanceled () const
 Convenience method checking if the current state is a result of canceling the maintenance. More...
 
bool isPartnerStateInvalid () const
 Indicates if the partner's state is invalid. More...
 
template<typename QueryPtrType >
bool leaseUpdateComplete (QueryPtrType &query, const hooks::ParkingLotHandlePtr &parking_lot)
 Handle last pending request for this query. More...
 
void localDisableDHCPService ()
 Disables local DHCP service. More...
 
void localEnableDHCPService ()
 Enables local DHCP service. More...
 
void logFailedLeaseUpdates (const dhcp::PktPtr &query, const data::ConstElementPtr &args) const
 Log failed lease updates. More...
 
size_t pendingRequestSize ()
 Get the number of entries in the pending request map. More...
 
void scheduleHeartbeat ()
 Schedules asynchronous heartbeat to a peer if it is not scheduled. More...
 
bool sendHAReset ()
 Sends ha-reset command to partner synchronously. More...
 
bool sendLeaseUpdatesFromBacklog ()
 Attempts to send all lease updates from the backlog synchronously. More...
 
bool shouldPartnerDown () const
 Indicates if the server should transition to the partner down state. More...
 
bool shouldQueueLeaseUpdates (const HAConfig::PeerConfigPtr &peer_config) const
 Checks if the lease updates should be queued. More...
 
bool shouldSendLeaseUpdates (const HAConfig::PeerConfigPtr &peer_config) const
 Checks if the lease updates should be sent as result of leases allocation or release. More...
 
bool shouldTerminate () const
 Indicates if the server should transition to the terminated state. More...
 
void socketReadyHandler (int tcp_native_fd)
 IfaceMgr external socket ready callback handler. More...
 
void startHeartbeat ()
 Unconditionally starts one heartbeat to a peer. More...
 
int synchronize (std::string &status_message, const std::string &server_name, const unsigned int max_period)
 Synchronizes lease database with a partner. More...
 
template<typename QueryPtrType >
void updatePendingRequest (QueryPtrType &query)
 Update pending request counter for this query. More...
 
void verboseTransition (const unsigned state)
 Transitions to a desired state and logs it. More...
 
data::ConstElementPtr verifyAsyncResponse (const http::HttpResponsePtr &response, int &rcode)
 Checks if the response is valid or contains an error. More...
 
- Protected Member Functions inherited from isc::util::StateModel
void abortModel (const std::string &explanation)
 Aborts model execution. More...
 
void defineEvent (unsigned int value, const std::string &label)
 Adds an event value and associated label to the set of events. More...
 
void defineState (unsigned int value, const std::string &label, StateHandler handler, const StatePausing &state_pausing=STATE_PAUSE_NEVER)
 Adds an state value and associated label to the set of states. More...
 
bool doOnEntry ()
 Checks if on entry flag is true. More...
 
bool doOnExit ()
 Checks if on exit flag is true. More...
 
const EventPtrgetEvent (unsigned int value)
 Fetches the event referred to by value. More...
 
const StatePtr getState (unsigned int value)
 Fetches the state referred to by value. More...
 
const StatePtr getStateInternal (unsigned int value)
 Fetches the state referred to by value. More...
 
void initDictionaries ()
 Initializes the event and state dictionaries. More...
 
virtual void onModelFailure (const std::string &explanation)
 Handler for fatal model execution errors. More...
 
void postNextEvent (unsigned int event)
 Sets the next event to the given event value. More...
 
void setState (unsigned int state)
 Sets the current state to the given state value. More...
 
void transition (unsigned int state, unsigned int event)
 Sets up the model to transition into given state with a given event. More...
 
virtual void verifyStates ()
 Validates the contents of the set of states. More...
 

Protected Attributes

http::HttpClientPtr client_
 HTTP client instance used to send HA commands and lease updates. More...
 
CommunicationStatePtr communication_state_
 Holds communication state with a peer. More...
 
HAConfigPtr config_
 Pointer to the HA hooks library configuration. More...
 
asiolink::IOServicePtr io_service_
 Pointer to the IO service object shared between this hooks library and the DHCP server. More...
 
LeaseUpdateBacklog lease_update_backlog_
 Backlog of DHCP lease updates. More...
 
config::CmdHttpListenerPtr listener_
 HTTP listener instance used to receive and respond to HA commands and lease updates. More...
 
dhcp::NetworkStatePtr network_state_
 Pointer to the state of the DHCP service (enabled/disabled). More...
 
QueryFilter query_filter_
 Selects queries to be processed/dropped. More...
 
HAServerType server_type_
 DHCP server type. More...
 
bool sync_complete_notified_
 An indicator that a partner sent ha-sync-complete-notify command. More...
 

Detailed Description

High availability service.

This class derives from the util::StateModel and implements a state machine for the high availability service in the Kea DHCP server instance.

Definition at line 43 of file ha_service.h.

Member Typedef Documentation

◆ PostRequestCallback

typedef std::function<void(const bool, const std::string&, const int)> isc::ha::HAService::PostRequestCallback
protected

Callback invoked when request was sent and a response received or an error occurred.

The first argument indicates if the operation passed (when true). The second argument holds error message. The third argument holds control status returned.

Definition at line 82 of file ha_service.h.

◆ PostSyncCallback

typedef std::function<void(const bool, const std::string&, const bool)> isc::ha::HAService::PostSyncCallback
protected

Callback invoked when lease database synchronization is complete.

The first argument indicates if the operation passed (when true). The second argument holds error message. The third argument indicates whether the synchronization resulted in disabling DHCP service on the partner server and has to be re-enabled.

Definition at line 91 of file ha_service.h.

Constructor & Destructor Documentation

◆ HAService()

isc::ha::HAService::HAService ( const asiolink::IOServicePtr io_service,
const dhcp::NetworkStatePtr network_state,
const HAConfigPtr config,
const HAServerType server_type = HAServerType::DHCPv4 
)

Constructor.

It clears the DHCP state using origin HA internal command and starts the state model in waiting state. Creates and starts the client and the listener (if one).

Parameters
io_servicePointer to the IO service used by the DHCP server.
configParsed HA hook library configuration.
network_stateObject holding state of the DHCP service (enabled/disabled).
server_typeServer type, i.e. DHCPv4 or DHCPv6 server.

Definition at line 74 of file ha_service.cc.

References client_, communication_state_, config_, isc::ha::DHCPv4, isc::ha::CommandCreator::ha_commands4_, isc::ha::CommandCreator::ha_commands6_, isc::ha::ha_logger, isc::ha::HA_SERVICE_STARTED, isc::ha::HA_WAITING_ST, isc::ha::HAConfig::HAModeToString(), io_service_, isc_throw, listener_, LOG_INFO, network_state_, isc::ha::HAConfig::PeerConfig::roleToString(), and isc::util::StateModel::startModel().

+ Here is the call graph for this function:

◆ ~HAService()

isc::ha::HAService::~HAService ( )
virtual

Destructor.

Stops the client and listener (if one). It clears the DHCP state using origin HA internal command.

Definition at line 143 of file ha_service.cc.

References network_state_, and stopClientAndListener().

+ Here is the call graph for this function:

Member Function Documentation

◆ adjustNetworkState()

◆ asyncDisableDHCPService()

void isc::ha::HAService::asyncDisableDHCPService ( http::HttpClient http_client,
const std::string &  server_name,
const unsigned int  max_period,
PostRequestCallback  post_request_action 
)
protected

Schedules asynchronous "dhcp-disable" command to the specified server.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to which the command should be sent.
max_periodmaximum number of seconds for which the DHCP service should be disabled.
post_request_actionpointer to the function to be executed when the request is completed.

Definition at line 1845 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::ha::CommandCreator::createDHCPDisable(), isc::ha::HA_DHCP_DISABLE_COMMUNICATIONS_FAILED, isc::ha::HA_DHCP_DISABLE_FAILED, isc::ha::ha_logger, LOG_ERROR, server_type_, isc::config::TIMEOUT_DEFAULT_HTTP_CLIENT_REQUEST, and verifyAsyncResponse().

Referenced by asyncSyncLeases(), and getPartnerState().

+ Here is the call graph for this function:

◆ asyncEnableDHCPService()

void isc::ha::HAService::asyncEnableDHCPService ( http::HttpClient http_client,
const std::string &  server_name,
PostRequestCallback  post_request_action 
)
protected

Schedules asynchronous "dhcp-enable" command to the specified server.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to which the command should be sent.
post_request_actionpointer to the function to be executed when the request is completed.

Definition at line 1925 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::ha::CommandCreator::createDHCPEnable(), isc::ha::HA_DHCP_ENABLE_COMMUNICATIONS_FAILED, isc::ha::HA_DHCP_ENABLE_FAILED, isc::ha::ha_logger, LOG_ERROR, server_type_, isc::config::TIMEOUT_DEFAULT_HTTP_CLIENT_REQUEST, and verifyAsyncResponse().

Referenced by getPartnerState(), and synchronize().

+ Here is the call graph for this function:

◆ asyncSendHAReset()

void isc::ha::HAService::asyncSendHAReset ( http::HttpClient http_client,
const HAConfig::PeerConfigPtr remote_config,
PostRequestCallback  post_request_action 
)
protected

Sends ha-reset command to partner asynchronously.

Parameters
http_clientreference to the HTTP client to be used for communication.
remote_configpointer to the remote server's configuration.
post_request_actioncallback to be invoked when the operation completes. It can be used for handling errors.

Definition at line 2504 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), isc::ha::CommandCreator::createHAReset(), isc::ha::ha_logger, isc::ha::HA_RESET_COMMUNICATIONS_FAILED, isc::ha::HA_RESET_FAILED, LOG_WARN, server_type_, and verifyAsyncResponse().

Referenced by getPartnerState(), and sendHAReset().

+ Here is the call graph for this function:

◆ asyncSendHeartbeat()

◆ asyncSendLeaseUpdate()

template<typename QueryPtrType >
void isc::ha::HAService::asyncSendLeaseUpdate ( const QueryPtrType &  query,
const HAConfig::PeerConfigPtr config,
const data::ConstElementPtr command,
const hooks::ParkingLotHandlePtr parking_lot 
)
protected

Asynchronously sends lease update to the peer.

Parameters
queryPointer to the DHCP client's query.
configPointer to the configuration of the server to which the command should be sent.
commandPointer to the command to be sent.
[out]parking_lotParking lot where the query is parked. This method uses this handle to unpark the packet when all asynchronous requests have been completed.
Template Parameters
QueryPtrTypeType of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr.
Exceptions
Unexpectedwhen an unexpected error occurs.

Definition at line 1344 of file ha_service.cc.

References isc::ha::HAConfig::PeerConfig::BACKUP, client_, clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::ha::HA_LEASE_UPDATE_COMMUNICATIONS_FAILED, isc::ha::HA_LEASE_UPDATE_CONFLICT, isc::ha::HA_LEASE_UPDATE_FAILED, HA_LEASE_UPDATES_COMPLETE_EVT, isc::ha::ha_logger, isc_throw, leaseUpdateComplete(), LOG_WARN, logFailedLeaseUpdates(), isc::util::StateModel::runModel(), isc::config::TIMEOUT_DEFAULT_HTTP_CLIENT_REQUEST, updatePendingRequest(), and verifyAsyncResponse().

Referenced by asyncSendLeaseUpdates(), and getPartnerState().

+ Here is the call graph for this function:

◆ asyncSendLeaseUpdates() [1/2]

size_t isc::ha::HAService::asyncSendLeaseUpdates ( const dhcp::Pkt4Ptr query,
const dhcp::Lease4CollectionPtr leases,
const dhcp::Lease4CollectionPtr deleted_leases,
const hooks::ParkingLotHandlePtr parking_lot 
)

Schedules asynchronous IPv4 leases updates.

This method schedules asynchronous lease updates as a result of the "leases4_committed" callout. The lease updates are transmitted over HTTP to the peers specified in the configuration (except self). If the server is in the partner-down state the lease updates are not sent to the partner but they are sent to all backup servers. In other states in which the server responds to DHCP queries, the lease updates are sent to all servers. The scheduled lease updates are performed after the callouts return. The server parks the processed DHCP packet and runs IO service shared between the server and the hook library.

If the lease update to the partner (primary, secondary or standby) fails, the parked packet is dropped. If the lease update to any of the backup server fails, an error message is logged but the DHCP packet is not dropped.

This method must be called only if there is at least one lease altered.

Parameters
queryPointer to the processed DHCP client message.
leasesPointer to a collection of the newly allocated or updated leases.
deleted_leasesPointer to a collection of the released leases.
[out]parking_lotPointer to the parking lot handle available for the "leases4_committed" hook point. This is where the DHCP client message is parked. This method calls unpark() on this object when the asynchronous updates are completed.
Returns
Number of peers to whom lease updates have been scheduled to be sent and from which we expect a response prior to unparking the packet and sending a response to the DHCP client.

Definition at line 1160 of file ha_service.cc.

References isc::ha::LeaseUpdateBacklog::ADD, asyncSendLeaseUpdate(), isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, config_, isc::ha::CommandCreator::createLease4Delete(), isc::ha::CommandCreator::createLease4Update(), isc::ha::LeaseUpdateBacklog::DELETE, lease_update_backlog_, isc::ha::LeaseUpdateBacklog::push(), shouldQueueLeaseUpdates(), and shouldSendLeaseUpdates().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ asyncSendLeaseUpdates() [2/2]

size_t isc::ha::HAService::asyncSendLeaseUpdates ( const dhcp::Pkt6Ptr query,
const dhcp::Lease6CollectionPtr leases,
const dhcp::Lease6CollectionPtr deleted_leases,
const hooks::ParkingLotHandlePtr parking_lot 
)

Schedules asynchronous IPv6 lease updates.

This method schedules asynchronous IPv6 lease updates as a result of the "leases6_committed" callout. It works analogously to the IPv4 version of this function.

Parameters
queryPointer to the processed DHCP client message.
leasesPointer to a collection of the newly allocated or updated leases.
deleted_leasesPointer to a collection of the released leases.
[out]parking_lotPointer to the parking lot handle available for the "leases6_committed" hook point. This is where the DHCP client message is parked. This method calls unpark() on this object when the asynchronous updates are completed.
Returns
Number of peers to whom lease updates have been scheduled to be sent and from which we expect a response prior to unparking the packet and sending a response to the DHCP client.

Definition at line 1229 of file ha_service.cc.

References isc::ha::LeaseUpdateBacklog::ADD, asyncSendLeaseUpdate(), isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, config_, isc::ha::CommandCreator::createLease6BulkApply(), isc::ha::LeaseUpdateBacklog::DELETE, lease_update_backlog_, isc::ha::LeaseUpdateBacklog::push(), shouldQueueLeaseUpdates(), and shouldSendLeaseUpdates().

+ Here is the call graph for this function:

◆ asyncSendLeaseUpdatesFromBacklog()

void isc::ha::HAService::asyncSendLeaseUpdatesFromBacklog ( http::HttpClient http_client,
const HAConfig::PeerConfigPtr remote_config,
PostRequestCallback  post_request_action 
)
protected

Sends lease updates from backlog to partner asynchronously.

This method checks if there are any outstanding DHCPv4 or DHCPv6 leases in the backlog and schedules asynchronous sends of these leases. In DHCPv6 case it sends a single lease6-bulk-apply command with all outstanding leases. In DHCPv4 case, it sends lease4-update or lease4-delete commands recursively (when one lease update completes successfully it schedules sending next lease update).

If there are no lease updates in the backlog it calls post_request_action callback.

This method is called from sendLeaseUpdatesFromBacklog.

Parameters
http_clientreference to the HTTP client to be used for communication.
remote_configpointer to the remote server's configuration.
post_request_actioncallback to be invoked when the operation completes. It can be used for handling errors.

Definition at line 2387 of file ha_service.cc.

References isc::ha::LeaseUpdateBacklog::ADD, isc::http::HttpClient::asyncSendRequest(), isc::config::CONTROL_RESULT_SUCCESS, isc::ha::CommandCreator::createLease4Delete(), isc::ha::CommandCreator::createLease4Update(), isc::ha::CommandCreator::createLease6BulkApply(), isc::ha::DHCPv4, isc::ha::HA_LEASES_BACKLOG_COMMUNICATIONS_FAILED, isc::ha::HA_LEASES_BACKLOG_FAILED, isc::ha::ha_logger, lease_update_backlog_, LOG_WARN, isc::ha::LeaseUpdateBacklog::pop(), server_type_, isc::ha::LeaseUpdateBacklog::size(), and verifyAsyncResponse().

Referenced by getPartnerState(), and sendLeaseUpdatesFromBacklog().

+ Here is the call graph for this function:

◆ asyncSyncCompleteNotify()

void isc::ha::HAService::asyncSyncCompleteNotify ( http::HttpClient http_client,
const std::string &  server_name,
PostRequestCallback  post_request_action 
)
protected

Schedules asynchronous "ha-sync-complete-notify" command to the specified server.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to which the command should be sent.
post_request_actionpointer to the function to be executed when the request is completed.

Definition at line 2856 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::ha::CommandCreator::createSyncCompleteNotify(), isc::ha::ha_logger, isc::ha::HA_SYNC_COMPLETE_NOTIFY_COMMUNICATIONS_FAILED, isc::ha::HA_SYNC_COMPLETE_NOTIFY_FAILED, LOG_ERROR, server_type_, isc::config::TIMEOUT_DEFAULT_HTTP_CLIENT_REQUEST, and verifyAsyncResponse().

Referenced by getPartnerState(), and synchronize().

+ Here is the call graph for this function:

◆ asyncSyncLeases() [1/2]

void isc::ha::HAService::asyncSyncLeases ( )
protected

Asynchronously reads leases from a peer and updates local lease database.

This method asynchronously sends lease4-get-page command to fetch leases from the HA peer database. When the response is received, the callback function iterates over the returned leases and inserts those that are not present in the local database and replaces any existing leases if the fetched lease instance is newer (based on cltt) than the instance in the local lease database.

If there is an error while inserting or updating any of the leases a warning message is logged and the process continues for the remaining leases.

This method variant uses default HTTP client for communication.

Definition at line 2012 of file ha_service.cc.

References client_, and config_.

Referenced by asyncSyncLeasesInternal(), getPartnerState(), and synchronize().

◆ asyncSyncLeases() [2/2]

void isc::ha::HAService::asyncSyncLeases ( http::HttpClient http_client,
const std::string &  server_name,
const unsigned int  max_period,
const dhcp::LeasePtr last_lease,
PostSyncCallback  post_sync_action,
const bool  dhcp_disabled = false 
)
protected

Asynchronously reads leases from a peer and updates local lease database using a provided client instance.

This method first sends dhcp-disable command to the server from which it will be fetching leases to disable its DHCP function while database synchronization is in progress. If the command is successful, it then sends lease4-get-page command to fetch a page of leases from the partner's database. Depending on the configured page size, it may be required to send multiple lease4-get-page or lease6-get-page commands to fetch all leases. If the lease database is large, the database synchronization may even take several minutes. Therefore, dhcp-disable command is sent prior to fetching each page, in order to reset the timeout for automatic re-enabling of the DHCP service on the remote server. Such timeout must only occur if there was no communication from the synchronizing server for longer period of time. If the synchronization is progressing the timeout must be deferred.

The asyncSyncLeases method calls itself (recurses) when the previous lease4-get-page or lease6-get-page command has completed successfully. If the last page of leases was fetched or if any error occurred, the synchronization is terminated and the post_sync_action callback is invoked.

The last parameter passed to the post_sync_action callback indicates whether this server has successfully disabled DHCP service on the partner server at least once. If that's the case, the DHCP service must be re-enabled by sending dhcp-enable command. This is done in the HAService::synchronize method.

If there is an error while inserting or updating any of the leases a warning message is logged and the process continues for the remaining leases.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service
last_leasePointer to the last lease returned on the previous page of leases. This lease is used to set the value of the "from" parameter in the lease4-get-page and lease6-get-page commands. If this command is sent to fetch the first page, the last_lease parameter should be set to null.
post_sync_actionpointer to the function to be executed when lease database synchronization is complete. If this is null, no post synchronization action is invoked.
dhcp_disabledBoolean flag indicating if the remote DHCP server is disabled. This flag propagates down to the post_sync_action to indicate whether the DHCP service has to be enabled after the leases synchronization.

Definition at line 2028 of file ha_service.cc.

References asyncDisableDHCPService(), and asyncSyncLeasesInternal().

+ Here is the call graph for this function:

◆ asyncSyncLeasesInternal()

void isc::ha::HAService::asyncSyncLeasesInternal ( http::HttpClient http_client,
const std::string &  server_name,
const unsigned int  max_period,
const dhcp::LeasePtr last_lease,
PostSyncCallback  post_sync_action,
const bool  dhcp_disabled 
)
protected

Implements fetching one page of leases during synchronization.

This method implements the actual lease fetching from the partner and synchronization of the database. It excludes sending dhcp-disable command. This command is sent by HAService::asyncSyncLeases.

When the page of leases is successfully synchronized, this method will call HAService::asyncSyncLeases to schedule synchronization of the next page of leases.

Parameters
http_clientreference to the client to be used to communicate with the other server.
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service
last_leasePointer to the last lease returned on the previous page of leases. This lease is used to set the value of the "from" parameter in the lease4-get-page and lease6-get-page commands. If this command is sent to fetch the first page, the last_lease parameter should be set to null.
post_sync_actionpointer to the function to be executed when lease database synchronization is complete. If this is null, no post synchronization action is invoked.
dhcp_disabledBoolean flag indicating if the remote DHCP server is disabled. This flag propagates down to the post_sync_action to indicate whether the DHCP service has to be enabled after the leases synchronization.

Definition at line 2059 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), asyncSyncLeases(), clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::ha::CommandCreator::createLease4GetPage(), isc::ha::CommandCreator::createLease6GetPage(), isc::log::DBGLVL_TRACE_BASIC, isc::ha::DHCPv4, isc::ha::HA_LEASE_SYNC_FAILED, isc::ha::HA_LEASE_SYNC_STALE_LEASE4_SKIP, isc::ha::HA_LEASE_SYNC_STALE_LEASE6_SKIP, isc::ha::HA_LEASES_SYNC_COMMUNICATIONS_FAILED, isc::ha::HA_LEASES_SYNC_FAILED, isc::ha::HA_LEASES_SYNC_LEASE_PAGE_RECEIVED, isc::ha::ha_logger, isc_throw, LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_WARN, server_type_, and verifyAsyncResponse().

Referenced by asyncSyncLeases(), and getPartnerState().

+ Here is the call graph for this function:

◆ backupStateHandler()

void isc::ha::HAService::backupStateHandler ( )

Handler for the "backup" state.

This is the normal operation state for a backup server. Only the backup server can be transitioned to this state. The DHCP service is disabled in this state and the server merely receives lease updates from the active servers. The backup server may be manually instructed to enable DHCP service and serve selected scopes, e.g. when both primary and secondary (or standby) servers are down.

This handler disables DHCP service on the first pass. It is no-op during all subsequent passes.

Definition at line 232 of file ha_service.cc.

References adjustNetworkState(), conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, and isc::ha::QueryFilter::serveNoScopes().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ checkPermissionsClientAndListener()

void isc::ha::HAService::checkPermissionsClientAndListener ( )

Check client and(or) listener current thread permissions to perform thread pool state transition.

Exceptions
MultiThreadingInvalidOperationif the state transition is done on any of the worker threads.

Definition at line 3149 of file ha_service.cc.

References client_, isc::ha::ha_logger, isc::ha::HA_PAUSE_CLIENT_LISTENER_FAILED, isc::ha::HA_PAUSE_CLIENT_LISTENER_ILLEGAL, listener_, LOG_ERROR, and isc::Exception::what().

Referenced by getPartnerState(), and startClientAndListener().

+ Here is the call graph for this function:

◆ clientCloseHandler()

void isc::ha::HAService::clientCloseHandler ( int  tcp_native_fd)
protected

HttpClient close callback handler.

Passed into HttpClient calls to allow unregistration of client's TCP socket with an external monitor (such as IfaceMgr's main-thread select()).

Parameters
tcp_native_fdsocket descriptor to register

Definition at line 3111 of file ha_service.cc.

Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncCompleteNotify(), asyncSyncLeasesInternal(), clientHandshakeHandler(), processMaintenanceCancel(), and processMaintenanceStart().

◆ clientConnectHandler()

bool isc::ha::HAService::clientConnectHandler ( const boost::system::error_code &  ec,
int  tcp_native_fd 
)
protected

HttpClient connect callback handler.

Passed into HttpClient calls to allow registration of client's TCP socket with an external monitor (such as IfaceMgr's main-thread select()).

Parameters
ecError status of the ASIO connect
tcp_native_fdsocket descriptor to register
Returns
always true. Registration cannot fail, and if ec indicates a real error we want Connection logic to process it.

Definition at line 3071 of file ha_service.cc.

References client_, and socketReadyHandler().

Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncCompleteNotify(), asyncSyncLeasesInternal(), getPartnerState(), processMaintenanceCancel(), and processMaintenanceStart().

+ Here is the call graph for this function:

◆ clientHandshakeHandler()

bool isc::ha::HAService::clientHandshakeHandler ( const boost::system::error_code &  )
inlineprotected

HttpClient handshake callback handler.

Currently is never called and does nothing.

Returns
always true.

Definition at line 1125 of file ha_service.h.

References clientCloseHandler(), and socketReadyHandler().

Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncCompleteNotify(), asyncSyncLeasesInternal(), processMaintenanceCancel(), and processMaintenanceStart().

+ Here is the call graph for this function:

◆ communicationRecoveryHandler()

void isc::ha::HAService::communicationRecoveryHandler ( )

Handler for the "communication-recovery" state.

This is a handler invoked for the active servers running in the load-balancing mode. A primary or secondary server may transition into this state when it detects that the communication with its partner is failing.

If the communication is resumed before the server transitions to the partner-down state, the server will transition back to the load-balancing state.

In the communication-recovery state the server remains responsive to the DHCP clients but does not send lease updates to the partner. Instead, it collects the lease updates and tries to send them in bulk when it returns to the load-balancing state.

Transitioning into this state is only enabled when delayed-updates-limit is non-zero.

A server running in the hot-standby mode is never allowed to enter this state. In this mode, even a short communication failure may cause the primary server to transition to the partner-down state. Consequently, two servers would be responding to DHCP queries, possibly allocating the same addresses to two different clients. This doesn't occur in load-balancing mode because the address pools are required to be split.

Definition at line 247 of file ha_service.cc.

References adjustNetworkState(), isc::ha::LeaseUpdateBacklog::clear(), communication_state_, conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::util::StateModel::doOnExit(), getNormalState(), isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_READY_ST, isc::ha::HA_SYNCING_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::ha::HA_WAITING_ST, isMaintenanceCanceled(), isc::util::StateModel::isModelPaused(), isPartnerStateInvalid(), lease_update_backlog_, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), sendHAReset(), sendLeaseUpdatesFromBacklog(), isc::ha::QueryFilter::serveDefaultScopes(), shouldPartnerDown(), shouldTerminate(), verboseTransition(), and isc::ha::LeaseUpdateBacklog::wasOverflown().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ conditionalLogPausedState()

void isc::ha::HAService::conditionalLogPausedState ( ) const
protected

◆ defineEvents()

void isc::ha::HAService::defineEvents ( )
virtual

◆ defineStates()

◆ getNormalState()

int isc::ha::HAService::getNormalState ( ) const
protected

Returns normal operation state for the current configuration.

Returns
"load-balancing" for active servers in load balancing mode, "hot-standby" for active servers in hot-standby mode, "backup" for backup servers and "passive-backup" for primary server in the "passive-backup" mode.

Definition at line 978 of file ha_service.cc.

References isc::ha::HAConfig::PeerConfig::BACKUP, config_, isc::ha::HA_BACKUP_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::HA_PASSIVE_BACKUP_ST, isc::ha::HAConfig::HOT_STANDBY, and isc::ha::HAConfig::LOAD_BALANCING.

Referenced by communicationRecoveryHandler(), getPartnerState(), partnerDownStateHandler(), and readyStateHandler().

◆ getPartnerState()

◆ getPendingRequest()

template<typename QueryPtrType >
template int isc::ha::HAService::getPendingRequest ( const QueryPtrType &  query)
protected

Get the number of scheduled requests for a given query.

Note
Currently for testing purposes only.

If there is an entry in the pending request map for the given query the entry is returned else zero is returned.

Parameters
queryPointer to the DHCP client's query.
Returns
Number of scheduled requests for the query or zero.

Definition at line 3129 of file ha_service.cc.

Referenced by stopClientAndListener().

◆ getServerType()

◆ inMaintenanceStateHandler()

void isc::ha::HAService::inMaintenanceStateHandler ( )

Handler for the "in-maintenance" state.

This is a handler invoked when one of the servers detected that its partner is in the "partner-in-maintenance" state. The server in this state is awaiting the shutdown by the administrator. The administrator shuts down the server to perform some planned maintenance. Meanwhile, the partner in the "partner-in-maintenance" state responds to all DHCP queries. The server in the "in-maintenance" state responds to no DHCP queries.

Definition at line 439 of file ha_service.cc.

References adjustNetworkState(), conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::ha::ha_logger, isc::ha::HA_MAINTENANCE_SHUTDOWN_SAFE, LOG_INFO, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), and isc::ha::QueryFilter::serveNoScopes().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ inScope() [1/2]

bool isc::ha::HAService::inScope ( dhcp::Pkt4Ptr query4)

Checks if the DHCPv4 query should be processed by this server.

It also associates the DHCPv4 query with required classes appropriate to the server that should process the packet and increments counters of unanswered DHCP queries when in communications interrupted state.

Parameters
[out]query4pointer to the DHCPv4 query received. A client class will be appended to this query instance, appropriate for the server to process this query, e.g. "HA_server1" if the "server1" should process the query etc.
Returns
true if DHCPv4 query should be processed by this server instance, false otherwise.

Definition at line 1020 of file ha_service.cc.

Referenced by getPartnerState().

◆ inScope() [2/2]

bool isc::ha::HAService::inScope ( dhcp::Pkt6Ptr query6)

Checks if the DHCPv6 query should be processed by this server.

It also associates the DHCPv6 query with required classes appropriate to the server that should process the packet and increments counters of unanswered DHCP queries when in communications interrupted state.

Parameters
[out]query6pointer to the DHCPv6 query received. A client class will be appended to this query instance, appropriate for the server to process this query, e.g. "HA_server1" if the "server1" should process the query etc.
Returns
true if DHCPv6 query should be processed by this server instance, false otherwise.

Definition at line 1025 of file ha_service.cc.

References communication_state_, isc::ha::QueryFilter::inScope(), and query_filter_.

+ Here is the call graph for this function:

◆ isMaintenanceCanceled()

bool isc::ha::HAService::isMaintenanceCanceled ( ) const
protected

Convenience method checking if the current state is a result of canceling the maintenance.

Returns
true if the maintenance was canceled, false otherwise.

Definition at line 1125 of file ha_service.cc.

References isc::util::StateModel::getLastEvent(), and HA_MAINTENANCE_CANCEL_EVT.

Referenced by communicationRecoveryHandler(), getPartnerState(), normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

+ Here is the call graph for this function:

◆ isPartnerStateInvalid()

bool isc::ha::HAService::isPartnerStateInvalid ( ) const
protected

Indicates if the partner's state is invalid.

Partner's state is invalid from the local server's perspective when the remote server can't transition to this state if the configuration is consistent with the local server's configuration.

The following cases are currently checked:

  • partner in communication-recovery state but this server not in the load balancing mode,
  • partner in the hot-standby state but this server not in the hot standby mode,
  • partner in the load-balancing state but this server not in the load balancing mode.
Returns
true if the partner's state is invalid, false otherwise.

Definition at line 1130 of file ha_service.cc.

References communication_state_, config_, isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_INVALID_PARTNER_STATE_COMMUNICATION_RECOVERY, isc::ha::HA_INVALID_PARTNER_STATE_HOT_STANDBY, isc::ha::HA_INVALID_PARTNER_STATE_LOAD_BALANCING, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::ha_logger, isc::ha::HAConfig::HOT_STANDBY, isc::ha::HAConfig::LOAD_BALANCING, and LOG_WARN.

Referenced by communicationRecoveryHandler(), getPartnerState(), normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

◆ leaseUpdateComplete()

template<typename QueryPtrType >
bool isc::ha::HAService::leaseUpdateComplete ( QueryPtrType &  query,
const hooks::ParkingLotHandlePtr parking_lot 
)
protected

Handle last pending request for this query.

Search if there are pending requests for this query:

  • if there are decrement the count
  • if there were at least two return false
  • if there was none or one unpark the query
  • if there was one remove the query from the map
  • return true
Template Parameters
QueryPtrTypeType of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr.
Parameters
queryPointer to the DHCP client's query.
[out]parking_lotParking lot where the query is parked. This method uses this handle to unpark the packet when all asynchronous requests have been completed.
Returns
When all lease updates are complete returns true, false otherwise.

Definition at line 1290 of file ha_service.cc.

Referenced by asyncSendLeaseUpdate().

◆ localDisableDHCPService()

void isc::ha::HAService::localDisableDHCPService ( )
protected

Disables local DHCP service.

Definition at line 2002 of file ha_service.cc.

References network_state_.

Referenced by getPartnerState().

◆ localEnableDHCPService()

void isc::ha::HAService::localEnableDHCPService ( )
protected

Enables local DHCP service.

Definition at line 2007 of file ha_service.cc.

References network_state_.

Referenced by getPartnerState(), and processSyncCompleteNotify().

◆ logFailedLeaseUpdates()

void isc::ha::HAService::logFailedLeaseUpdates ( const dhcp::PktPtr query,
const data::ConstElementPtr args 
) const
protected

Log failed lease updates.

Logs failed lease updates included in the "failed-deleted-leases" and/or "failed-leases" carried in the response to the lease6-bulk-apply command.

Parameters
queryPointer to the DHCP client's query.
argsArguments of the response. It may be null, in which case the function simply returns.

Definition at line 1542 of file ha_service.cc.

References isc::ha::HA_LEASE_UPDATE_CREATE_UPDATE_FAILED_ON_PEER, isc::ha::HA_LEASE_UPDATE_DELETE_FAILED_ON_PEER, isc::ha::ha_logger, and LOG_INFO.

Referenced by asyncSendLeaseUpdate(), and getPartnerState().

◆ normalStateHandler()

void isc::ha::HAService::normalStateHandler ( )

Handler for the "hot-standby" and "load-balancing" states.

This is a handler invoked for the servers running in the hot-standby or load-balancing mode, both for the primary and the standby (or secondary) server.

In the hot-standby mode, the primary server responds to all DHCP queries from the clients. The standby server receives lease updates from the primary, but it doesn't respond to any DHCP queries. Both servers exchange heartbeats to monitor each other states. If any of the servers detects a failure of its partner, it transitions to the "partner-down" state.

In the load-balancing mode, both servers respond to the DHCP queries and exchange the heartbeats and lease updates. If any of the servers detects a failure of its partner, it transitions to the "partner-down" state.

If any of the servers in the "hot-standby" or "load-balancing" state detects that its partner is in the "partner-down" state, the server transitions to the "waiting" state. Such situation may occur if the Control Agent of this server crashes but the DHCP daemon continues to run. The partner will transition to the "partner-down" state if the failure detection algorithm (based on "secs" field or "elapsed time" option monitoring) and this server is considered to be offline based solely on the fact that it doesn't respond to heartbeats.

Definition at line 364 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), isc::util::StateModel::doOnExit(), isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::ha::HA_WAITING_ST, isMaintenanceCanceled(), isc::util::StateModel::isModelPaused(), isPartnerStateInvalid(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveDefaultScopes(), shouldPartnerDown(), shouldTerminate(), and verboseTransition().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ partnerDownStateHandler()

void isc::ha::HAService::partnerDownStateHandler ( )

Handler for "partner-down" state.

This is a handler invoked for the server which detected a failure of its partner. The partner was not responding to heartbeats and did not respond to a number of DHCP queries directed to it. In some configurations, the server may transition to this state when the server is not responding to the heartbeats, without checking whether it responds to DHCP queries ("max-unacked-clients" parameter is set to 0).

In the "partner-down" state the server responds to all DHCP queries, i.e. the queries it would normally respond to and to the queries to which its partner would respond.

The backup server would never transition to this state.

The server will transition from the "partner-down" state to the "load-balancing" or "hot-standby" state if its partner is in the "ready" state. In this state, the partner indicates that it has synchronized its database and is ready to enable its DHCP service.

If this server finds that the partner is in an unexpected state, i.e. "load-balancing", "hot-standby" or "partner-down", it transitions to the "waiting" state to try to resolve the conflict with the partner.

Definition at line 464 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), isc::util::StateModel::getLastEvent(), getNormalState(), isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::ha_logger, HA_MAINTENANCE_START_EVT, isc::ha::HA_MAINTENANCE_STARTED_IN_PARTNER_DOWN, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_READY_ST, HA_SYNCED_PARTNER_UNAVAILABLE_EVT, isc::ha::HA_TERMINATED_ST, isc::ha::HA_WAITING_ST, isMaintenanceCanceled(), isc::util::StateModel::isModelPaused(), isPartnerStateInvalid(), LOG_INFO, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveDefaultScopes(), isc::ha::QueryFilter::serveFailoverScopes(), shouldTerminate(), and verboseTransition().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ partnerInMaintenanceStateHandler()

void isc::ha::HAService::partnerInMaintenanceStateHandler ( )

Handler for "partner-in-maintenance" state.

This is a handler invoked for the server which was administratively transitioned to the "partner-in-maintenance" state. This is the case when the partner needs to be shutdown for some planned maintenance.

The server receiving ha-maintenance-start command transitions to this state. It sends the ha-maintenance-notify command to the partner to cause the partner to stop responding to the DHCP queries. Next, this server starts responding to all DHCP queries. This allows the server administrator to safely shutdown the partner as it is no longer responsible for any portion of the DHCP traffic.

The server in the "partner-in-maintenance" state remains in this state until the first unsuccessful lease update, ha-heartbeat or any other command send to the partner due to the issues with communication. In that case the server assumes that the partner has been shutdown and transitions to the "partner-down" state in which it still responds to all DHCP queries but doesn't attempt to send lease updates to the offline partner.

Definition at line 555 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::ha::ha_logger, isc::ha::HA_MAINTENANCE_STARTED, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::util::StateModel::isModelPaused(), LOG_INFO, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveFailoverScopes(), shouldTerminate(), and verboseTransition().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ passiveBackupStateHandler()

void isc::ha::HAService::passiveBackupStateHandler ( )

Handler for "passive-backup" state.

This handler is invoked for the server entering the "passive-backup" state. The primary server enters this state in the "passive-backup" mode of operation in which there is one server responding to the DHCP queries and zero, one or more backup servers which receive lease updates from this server.

Definition at line 594 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, and isc::ha::QueryFilter::serveDefaultScopes().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ pauseClientAndListener()

void isc::ha::HAService::pauseClientAndListener ( )

Pauses client and(or) listener thread pool operations.

Suspends the client and listener thread pool event processing. Has no effect in single-threaded mode or if thread pools are not currently running. Serves as the MultiThreading critical section entry callback.

Definition at line 3193 of file ha_service.cc.

References client_, isc::ha::ha_logger, isc::ha::HA_PAUSE_CLIENT_LISTENER_FAILED, listener_, and LOG_ERROR.

Referenced by getPartnerState(), and startClientAndListener().

◆ pendingRequestSize()

size_t isc::ha::HAService::pendingRequestSize ( )
protected

Get the number of entries in the pending request map.

Note
Currently for testing purposes only.
Returns
Number of entries in the pending request map.

Definition at line 3118 of file ha_service.cc.

◆ processContinue()

ConstElementPtr isc::ha::HAService::processContinue ( )

Processes ha-continue command and returns a response.

Returns
Pointer to the response to the ha-continue command.

Definition at line 2586 of file ha_service.cc.

References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), and unpause().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processHAReset()

ConstElementPtr isc::ha::HAService::processHAReset ( )

Processes ha-reset command and returns a response.

This method processes ha-reset command which instructs the server to transition to the waiting state. A partner may send this command when the communication is re-established between the servers in the communication-recovery state and full lease database synchronization is required. This command may also be sent by an operator if the server's state is invalid and the reset operation may help correct the situation.

The ha-reset takes no arguments.

Returns
Pointer to a response to the ha-reset command.

Definition at line 1666 of file ha_service.cc.

References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::util::StateModel::getCurrState(), isc::ha::HA_WAITING_ST, isc::util::StateModel::NOP_EVT, isc::util::StateModel::runModel(), and verboseTransition().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processHeartbeat()

ConstElementPtr isc::ha::HAService::processHeartbeat ( )

Processes ha-heartbeat command and returns a response.

This method processes a ha-heartbeat command sent by a peer. This command is sent periodically to the server to detect its state. The servers use the heartbeat mechanism to detect peers' failures and to synchronize their operations when they start up after the failure or a restart.

The ha-heartbeat command takes no arguments. The response contains a server state, served scopes and timestamp in the following format:

{
"arguments": {
"date-time": "Thu, 01 Feb 2018 21:18:26 GMT",
"scopes": [ "server1" ],
"state": "waiting"
},
"result": 0,
"text": "HA peer status returned."
}
Returns
Pointer to the response to the heartbeat.

Definition at line 1643 of file ha_service.cc.

References communication_state_, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::util::StateModel::getCurrState(), isc::ha::QueryFilter::getServedScopes(), isc::util::StateModel::getState(), query_filter_, and isc::http::HttpDateTime::rfc1123Format().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processMaintenanceCancel()

ConstElementPtr isc::ha::HAService::processMaintenanceCancel ( )

Processes ha-maintenance-cancel command and returns a response.

The server receiving this command will try to revert the partner's state from the in-maintenance to the previous state, and also it will try to revert its own state from the partner-in-maintenance to the previous state. It effectively means canceling the request for maintenance signaled with the ha-maintenance-start command.

In some cases canceling the maintenance is no longer possible, e.g. if the server has already got into the partner-down state. Generally, canceling the maintenance is only possible if this server is in the partner-in-maintenance state and the partner is in the in-maintenance state.

Returns
Pointer to the response to the ha-maintenance-cancel.

Definition at line 2760 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::ha::CommandCreator::createMaintenanceNotify(), isc::util::StateModel::getCurrState(), isc::util::StateModel::getPrevState(), isc::ha::ha_logger, HA_MAINTENANCE_CANCEL_EVT, isc::ha::HA_MAINTENANCE_NOTIFY_CANCEL_COMMUNICATIONS_FAILED, isc::ha::HA_MAINTENANCE_NOTIFY_CANCEL_FAILED, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, LOG_ERROR, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), isc::util::StateModel::runModel(), server_type_, isc::config::TIMEOUT_DEFAULT_HTTP_CLIENT_REQUEST, verboseTransition(), and verifyAsyncResponse().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processMaintenanceNotify()

ConstElementPtr isc::ha::HAService::processMaintenanceNotify ( const bool  cancel)

Processes ha-maintenance-notify command and returns a response.

This command attempts to transition the server to the in-maintenance state if the cancel flag is set to false. Such transition is not allowed if the server is currently in one of the following states:

  • backup: because maintenance is not supported for backup servers,
  • partner-in-maintenance: because only one server is in maintenance while the partner must be in partner-in-maintenance state,
  • terminated: because the only way to resume HA service is by shutting down the server, fixing the clock skew and restarting.

If the cancel flag is set to true, the server will be transitioned from the in-maintenance state to the previous state it was in before entering the in-maintenance state.

Parameters
cancelboolean value indicating if the maintenance is being canceled with this operation. If it is set to false the maintenance is being started.
Returns
Pointer to the response to the ha-maintenance-notify.

Definition at line 2594 of file ha_service.cc.

References isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::util::StateModel::getCurrState(), isc::util::StateModel::getPrevState(), isc::ha::HA_BACKUP_ST, HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED, isc::ha::HA_IN_MAINTENANCE_ST, HA_MAINTENANCE_CANCEL_EVT, HA_MAINTENANCE_NOTIFY_EVT, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_TERMINATED_ST, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), isc::util::StateModel::runModel(), isc::ha::stateToString(), and verboseTransition().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processMaintenanceStart()

ConstElementPtr isc::ha::HAService::processMaintenanceStart ( )

Processes ha-maintenance-start command and returns a response.

The server receiving this command will try to send the ha-maintenance-notify command to the partner to instruct the partner to transition to the in-maintenance state. In this state the partner will not respond to any DHCP queries. Next, this server will transition to the partner-in-maintenance state and therefore will start responding to all DHCP queries. If the partner responds to the ha-maintenance-notify with an error, this server won't transition to the partner-in-maintenance state and signal an error to the caller. If the partner is unavailable, this server will directly transition to the partner-down state.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Returns
Pointer to the response to the ha-maintenance-start.

Definition at line 2630 of file ha_service.cc.

References isc::http::HttpClient::asyncSendRequest(), clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::ha::CommandCreator::createMaintenanceNotify(), isc::util::StateModel::getCurrState(), isc::ha::HA_BACKUP_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::ha_logger, isc::ha::HA_MAINTENANCE_NOTIFY_COMMUNICATIONS_FAILED, isc::ha::HA_MAINTENANCE_NOTIFY_FAILED, HA_MAINTENANCE_START_EVT, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_TERMINATED_ST, LOG_ERROR, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), isc::util::StateModel::runModel(), server_type_, isc::ha::stateToString(), isc::config::TIMEOUT_DEFAULT_HTTP_CLIENT_REQUEST, verboseTransition(), and verifyAsyncResponse().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processScopes()

ConstElementPtr isc::ha::HAService::processScopes ( const std::vector< std::string > &  scopes)

Processes ha-scopes command and returns a response.

Parameters
scopesvector of scope names to be enabled.
Returns
Pointer to the response to the ha-scopes command.

Definition at line 2573 of file ha_service.cc.

References adjustNetworkState(), isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), query_filter_, and isc::ha::QueryFilter::serveScopes().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processStatusGet()

ConstElementPtr isc::ha::HAService::processStatusGet ( ) const

Processes status-get command and returns a response.

HAImpl::commandProcessed calls this to add information about the HA servers status into the status-get response.

Definition at line 1594 of file ha_service.cc.

References isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, config_, isc::util::StateModel::getCurrState(), isc::ha::QueryFilter::getServedScopes(), isc::ha::HAConfig::PASSIVE_BACKUP, query_filter_, isc::ha::HAConfig::PeerConfig::roleToString(), and isc::ha::stateToString().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processSyncCompleteNotify()

ConstElementPtr isc::ha::HAService::processSyncCompleteNotify ( )

Process ha-sync-complete-notify command and returns a response.

A server finishing a lease database synchronization may notify its partner about it with this command. This function implements reception and processing of the command.

It enables DHCP service unless the server is in the partner-down state. In this state, the server will first have to check connectivity with the partner and transition to a state in which it will send lease updates.

Returns
Pointer to the response to the ha-sync-complete-notify command.

Definition at line 2937 of file ha_service.cc.

References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::util::StateModel::getCurrState(), isc::ha::HA_PARTNER_DOWN_ST, localEnableDHCPService(), and sync_complete_notified_.

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ processSynchronize()

ConstElementPtr isc::ha::HAService::processSynchronize ( const std::string &  server_name,
const unsigned int  max_period 
)

Processes ha-sync command and returns a response.

This method processes ha-sync command. It instructs the server to disable the DHCP service on the HA peer, fetch all leases from the peer and update the local lease database. Leases synchronization is usually performed automatically by the server which starts up for the first time or after a failure. However, the ha-sync command can also be triggered manually by the server administrator to force synchronization of the lease database in cases when manual recovery is required. One of the possible cases is when the lease database has to be recovered from the backup server, e.g. when both primary and secondary (or standby) servers have crashed.

Parameters
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service of the peer. This value is used in dhcp-disable command issued to the peer before the lease4-get-page command.
Returns
Pointer to the response to the ha-sync command.

Definition at line 2255 of file ha_service.cc.

References isc::config::createAnswer(), and synchronize().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ readyStateHandler()

void isc::ha::HAService::readyStateHandler ( )

Handler for "ready" state.

This a handler invoked for the server which finished synchronizing its lease database with the partner and is indicating readiness to start normal operation, i.e. load balancing or hot standby. The partner in the "partner-down" state will transition to the "load-balancing" or "hot-standby" state. The "ready" server will also transition to one of these states following the transition of the partner.

If both servers appear to be in the "ready" state, the primary server transitions to the "load-balancing" or "hot-standby" state first.

The server in the "ready" state is not responding to the DHCP queries.

Definition at line 612 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), getNormalState(), isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_READY_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::ha::HA_WAITING_ST, isMaintenanceCanceled(), isc::util::StateModel::isModelPaused(), isPartnerStateInvalid(), isc::ha::HAConfig::LOAD_BALANCING, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), isc::ha::HAConfig::PeerConfig::PRIMARY, query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveNoScopes(), shouldPartnerDown(), shouldTerminate(), and verboseTransition().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ resumeClientAndListener()

void isc::ha::HAService::resumeClientAndListener ( )

Resumes client and(or) listener thread pool operations.

Resumes the client and listener thread pool event processing. Has no effect in single-threaded mode or if thread pools are not currently paused. Serves as the MultiThreading critical section exit callback.

Definition at line 3211 of file ha_service.cc.

References client_, isc::ha::ha_logger, isc::ha::HA_RESUME_CLIENT_LISTENER_FAILED, listener_, and LOG_ERROR.

Referenced by getPartnerState(), and startClientAndListener().

◆ scheduleHeartbeat()

void isc::ha::HAService::scheduleHeartbeat ( )
protected

Schedules asynchronous heartbeat to a peer if it is not scheduled.

The heartbeat will be sent according to the value of the heartbeat-delay setting in the HA configuration. This is one shot heartbeat. The callback will reschedule it.

Definition at line 1829 of file ha_service.cc.

References communication_state_, and startHeartbeat().

Referenced by communicationRecoveryHandler(), getPartnerState(), inMaintenanceStateHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

+ Here is the call graph for this function:

◆ sendHAReset()

bool isc::ha::HAService::sendHAReset ( )
protected

Sends ha-reset command to partner synchronously.

This method attempts to send ha-reset command to the active partner synchronously. It may be invoked when the communication with the partner is re-established after temporary failure. It causes the partner to transition the partner to the waiting state. This effectively means that the partner will synchronize its lease database with this server.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Returns
true if the command was sent successfully, false otherwise.

Definition at line 2554 of file ha_service.cc.

References asyncSendHAReset(), config_, isc::asiolink::IOService::run(), and isc::asiolink::IOService::stop().

Referenced by communicationRecoveryHandler(), and getPartnerState().

+ Here is the call graph for this function:

◆ sendLeaseUpdatesFromBacklog()

bool isc::ha::HAService::sendLeaseUpdatesFromBacklog ( )
protected

Attempts to send all lease updates from the backlog synchronously.

This method is called upon exiting communication-recovery state and before entering the load-balancing state. It ensures that all outstanding lease updates are sent to the partner before the server can continue normal operation in the load-balancing state. In order to prevent collisions between new allocations and outstanding updates this method is synchronous.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Returns
boolean value indicating that the lease updates were delivered successfully (when true) or unsuccessfully (when false).

Definition at line 2463 of file ha_service.cc.

References asyncSendLeaseUpdatesFromBacklog(), config_, isc::ha::HA_LEASES_BACKLOG_NOTHING_TO_SEND, isc::ha::HA_LEASES_BACKLOG_START, isc::ha::HA_LEASES_BACKLOG_SUCCESS, isc::ha::ha_logger, lease_update_backlog_, LOG_INFO, isc::asiolink::IOService::run(), isc::ha::LeaseUpdateBacklog::size(), and isc::asiolink::IOService::stop().

Referenced by communicationRecoveryHandler(), and getPartnerState().

+ Here is the call graph for this function:

◆ serveDefaultScopes()

void isc::ha::HAService::serveDefaultScopes ( )

Instructs the HA service to serve default scopes.

This method is mostly useful for unit testing. The scopes need to be enabled to test inScope methods invoked via HAImpl class.

Definition at line 1015 of file ha_service.cc.

References query_filter_, and isc::ha::QueryFilter::serveDefaultScopes().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ shouldPartnerDown()

bool isc::ha::HAService::shouldPartnerDown ( ) const
protected

Indicates if the server should transition to the partner down state.

It indicates that the server should transition to the partner down state when the communications is interrupted (over the control channel) and the partner is not answering DHCP queries in the load balancing case and in the hot standby case, when this server is a secondary.

In the hot standby case, when the server is primary, the communications interrupted is enough to transition to the partner down state.

Returns
true if the server should transition to the partner down state, false otherwise.

Definition at line 1082 of file ha_service.cc.

References communication_state_, config_, isc::ha::HAConfig::LOAD_BALANCING, network_state_, and isc::ha::HAConfig::PeerConfig::STANDBY.

Referenced by communicationRecoveryHandler(), getPartnerState(), normalStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

◆ shouldQueueLeaseUpdates()

bool isc::ha::HAService::shouldQueueLeaseUpdates ( const HAConfig::PeerConfigPtr peer_config) const
protected

Checks if the lease updates should be queued.

If lease updates should be sent to the partner but the server is in the communication-recovery state (temporarily unavailable) the lease updates should be queued and later sent when the communication is re-established. This function checks if the server is in the state in which lease updates should be queued.

Parameters
peer_configpointer to the configuration of the peer to which the updates are to be sent.
Returns
true if the server should queue lease updates, false otherwise.

Definition at line 1529 of file ha_service.cc.

References isc::ha::HAConfig::PeerConfig::BACKUP, config_, isc::util::StateModel::getCurrState(), and isc::ha::HA_COMMUNICATION_RECOVERY_ST.

Referenced by asyncSendLeaseUpdates(), and getPartnerState().

+ Here is the call graph for this function:

◆ shouldSendLeaseUpdates()

bool isc::ha::HAService::shouldSendLeaseUpdates ( const HAConfig::PeerConfigPtr peer_config) const
protected

Checks if the lease updates should be sent as result of leases allocation or release.

This method checks if the lease updates should be sent by the server while this server is in the given state. Note that the backup server will never send lease updates.

Parameters
peer_configpointer to the configuration of the peer to which the updates are to be sent.
Returns
true if the server should send lease updates, false otherwise.

Definition at line 1497 of file ha_service.cc.

References isc::ha::HAConfig::PeerConfig::BACKUP, config_, isc::util::StateModel::getCurrState(), isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, and isc::ha::HA_PARTNER_IN_MAINTENANCE_ST.

Referenced by asyncSendLeaseUpdates(), getPartnerState(), and verboseTransition().

+ Here is the call graph for this function:

◆ shouldTerminate()

bool isc::ha::HAService::shouldTerminate ( ) const
protected

Indicates if the server should transition to the terminated state.

There are two reasons for the server to transition to the terminated state. First, when the clock skew being too high. Second, when the server monitors rejected lease updates and the maximum configured rejected updates have been exceeded.

If the clock skew is is higher than 30 seconds but lower than 60 seconds this method only logs a warning. In case, the clock skew exceeds 60 seconds, this method logs a warning and returns true.

If the clock skew is acceptable the function can cause the transition to the terminated state when the number of recorded rejected lease updates exceeded the configured threshold.

Returns
true if the server should transition to the terminated state, false otherwise.

Definition at line 1109 of file ha_service.cc.

References communication_state_.

Referenced by communicationRecoveryHandler(), getPartnerState(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().

◆ socketReadyHandler()

void isc::ha::HAService::socketReadyHandler ( int  tcp_native_fd)
protected

IfaceMgr external socket ready callback handler.

IfaceMgr invokes this call back when a registered socket has been flagged as ready to read. It is installed by the invocation to register the socket with IfaceMgr made in clientConnectHandler.

The handler calls http::HttpClient::closeIfOutOfBand() to catch and close any sockets that have gone ready outside of transactions.

We do this in case the other peer closed the socket (e.g. idle timeout), as this will cause the socket to appear ready to read to the IfaceMgr::select(). If this happens while no transactions are in progress, we won't have anything to deal with the socket event. This causes IfaceMgr::select() to endlessly interrupt on the socket.

Parameters
tcp_native_fdsocket descriptor of the ready socket

Definition at line 3102 of file ha_service.cc.

References client_.

Referenced by clientConnectHandler(), and clientHandshakeHandler().

◆ startClientAndListener()

void isc::ha::HAService::startClientAndListener ( )

Start the client and(or) listener instances.

When HA+MT is enabled it starts the client's thread pool and the dedicated listener thread pool, if the listener exists. It registers pauseClientAndListener() and resumeClientAndListener() as the MultiThreading critical section entry and exit callbacks, respectively.

Definition at line 3176 of file ha_service.cc.

References checkPermissionsClientAndListener(), client_, listener_, pauseClientAndListener(), and resumeClientAndListener().

Referenced by getPartnerState().

+ Here is the call graph for this function:

◆ startHeartbeat()

void isc::ha::HAService::startHeartbeat ( )
protected

Unconditionally starts one heartbeat to a peer.

Definition at line 1836 of file ha_service.cc.

References asyncSendHeartbeat(), communication_state_, and config_.

Referenced by asyncSendHeartbeat(), getPartnerState(), and scheduleHeartbeat().

+ Here is the call graph for this function:

◆ stopClientAndListener()

void isc::ha::HAService::stopClientAndListener ( )

Stop the client and(or) listener instances.

It unregisters the MultiThreading critical section callbacks, closes all connections and stops the thread pools for the client and listener, if they exist.

Definition at line 3229 of file ha_service.cc.

References client_, getPendingRequest(), and listener_.

Referenced by getPartnerState(), and ~HAService().

+ Here is the call graph for this function:

◆ synchronize()

int isc::ha::HAService::synchronize ( std::string &  status_message,
const std::string &  server_name,
const unsigned int  max_period 
)
protected

Synchronizes lease database with a partner.

It instructs the server to disable the DHCP service on the HA peer, fetch all leases from the peer and update the local lease database. It sends ha-sync-complete-notify command to the partner when the synchronization completes successfully. If the partner does not support this command, it sends dhcp-enable command to enable the DHCP service on the partner.

This method creates its own instances of the HttpClient and IOService and invokes IOService::run().

Parameters
[out]status_messagestatus message in textual form.
server_namename of the server to fetch leases from.
max_periodmaximum number of seconds to disable DHCP service of the peer. This value is used in dhcp-disable command issued to the peer before the lease4-get-page command.
Returns
Synchronization result according to the status codes returned in responses to control commands.

Definition at line 2263 of file ha_service.cc.

References asyncEnableDHCPService(), asyncSyncCompleteNotify(), asyncSyncLeases(), isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::ha::ha_logger, isc::ha::HA_SYNC_FAILED, isc::ha::HA_SYNC_START, isc::ha::HA_SYNC_SUCCESSFUL, HA_SYNCING_FAILED_EVT, HA_SYNCING_SUCCEEDED_EVT, LOG_ERROR, LOG_INFO, isc::util::Stopwatch::logFormatLastDuration(), isc::util::StateModel::postNextEvent(), isc::asiolink::IOService::run(), isc::util::Stopwatch::stop(), and isc::asiolink::IOService::stop().

Referenced by getPartnerState(), processSynchronize(), and syncingStateHandler().

+ Here is the call graph for this function:

◆ syncingStateHandler()

void isc::ha::HAService::syncingStateHandler ( )

Handler for "syncing" state.

This is a handler invoked for the server in the "syncing" state. The server in this state is trying to retrieve leases from the partner's database and update its local database. Every primary, secondary and standby server must transition via this state to retrieve up to date lease information from the active partner. If the partner is offline the server will eventually transition to the "partner-down" state without synchronizing the lease database.

The lease database synchronization is performed synchronously, i.e. the handler doesn't return until the synchronization completes or a communication failure occurs.

The server in the "syncing" state is not responding to the DHCP queries.

Definition at line 692 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::config::CONTROL_RESULT_SUCCESS, isc::util::StateModel::doOnEntry(), isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_READY_ST, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::ha::HA_WAITING_ST, isMaintenanceCanceled(), isc::util::StateModel::isModelPaused(), isPartnerStateInvalid(), isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveNoScopes(), shouldPartnerDown(), shouldTerminate(), synchronize(), and verboseTransition().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ terminatedStateHandler()

void isc::ha::HAService::terminatedStateHandler ( )

Handler for "terminated" state.

This is a handler invoked for the server in the "terminated" state. This indicates that the HA service is disabled, typically as a result of an unrecoverable error such as detecting that clocks skew between the active HA servers being too large. This situation requires manual intervention of an administrator. When the problem is corrected, the HA service needs to be restarted.

Note
Currently, restarting the HA service requires restarting the DHCP server. In the future, we will provide a command to restart the HA service.

The server in the "terminated" state will respond to DHCP clients as if it was in a hot-standby or load-balancing state. However, it will neither send nor receive lease updates. It also won't send heartbeats to the partner.

Definition at line 782 of file ha_service.cc.

References adjustNetworkState(), communication_state_, conditionalLogPausedState(), isc::util::StateModel::doOnEntry(), isc::ha::ha_logger, isc::ha::HA_TERMINATED, LOG_ERROR, isc::util::StateModel::NOP_EVT, isc::util::StateModel::postNextEvent(), query_filter_, and isc::ha::QueryFilter::serveDefaultScopes().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

◆ unpause()

bool isc::ha::HAService::unpause ( )

Unpauses the HA state machine with logging.

It un-pauses the state machine if it is paused and logs an informational message. It doesn't log the message if the state machine is not paused.

Returns
true if the state machine was unpaused, false if the state machine was not paused when this method was invoked.

Definition at line 994 of file ha_service.cc.

References isc::ha::ha_logger, isc::ha::HA_STATE_MACHINE_CONTINUED, isc::util::StateModel::isModelPaused(), LOG_INFO, and isc::util::StateModel::unpauseModel().

Referenced by getPartnerState(), and processContinue().

+ Here is the call graph for this function:

◆ updatePendingRequest()

template<typename QueryPtrType >
void isc::ha::HAService::updatePendingRequest ( QueryPtrType &  query)
protected

Update pending request counter for this query.

Template Parameters
QueryPtrTypeType of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr.
Parameters
queryPointer to the DHCP client's query.

Definition at line 1323 of file ha_service.cc.

Referenced by asyncSendLeaseUpdate().

◆ verboseTransition()

◆ verifyAsyncResponse()

ConstElementPtr isc::ha::HAService::verifyAsyncResponse ( const http::HttpResponsePtr response,
int &  rcode 
)
protected

Checks if the response is valid or contains an error.

The response must be non-null, must contain a JSON body and must contain a success status code.

Parameters
responsepointer to the received response.
[out]rcoderesult found in the response.
Returns
Pointer to the response arguments.
Exceptions
CtrlChannelErrorif response is invalid or contains an error.
CommandUnsupportedErrorif sent command is unsupported.
ConflictErrorif the response comprises the conflict status code or it contains an empty status code in response to the lease6-bulk-apply and there are leases with the conflict status codes listed in the response.

Definition at line 2948 of file ha_service.cc.

References isc::config::CONTROL_RESULT, isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::config::CONTROL_RESULT_CONFLICT, isc::config::CONTROL_RESULT_EMPTY, isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::CONTROL_TEXT, isc_throw, and isc::config::parseAnswer().

Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHAReset(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSendLeaseUpdatesFromBacklog(), asyncSyncCompleteNotify(), asyncSyncLeasesInternal(), getPartnerState(), processMaintenanceCancel(), and processMaintenanceStart().

+ Here is the call graph for this function:

◆ verifyEvents()

void isc::ha::HAService::verifyEvents ( )
virtual

◆ waitingStateHandler()

void isc::ha::HAService::waitingStateHandler ( )

Handler for "waiting" state.

This is a handler invoked for the server in the "waiting" state. This is the first state of every server after its startup. The server initiates a heartbeat to learn the state of its partner. If the partner is operating (e.g. is in the "partner-down" state), the server will transition to the "syncing" state to fetch lease information from the partner. If leases synchronization is administratively disabled with 'sync-leases' parameter, the server will transition directly to the "ready" state. If both servers are in the "waiting" state the primary transitions to the "syncing" or "ready" state first. If the partner is in the "syncing" state, this server will remain in the "waiting" state until the partner completes synchronization.

If the server starts, but the partner appears to be offline, the server transitions to the "partner-down" state.

A backup server transitions from the "waiting" to the "backup" state directly.

The server in the "waiting" state is not responding to the DHCP queries.

Definition at line 804 of file ha_service.cc.

References adjustNetworkState(), isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), isc::ha::HA_BACKUP_ST, isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::ha_logger, isc::ha::HA_PARTNER_DOWN_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_PASSIVE_BACKUP_ST, isc::ha::HA_READY_ST, isc::ha::HA_SYNCING_ST, isc::ha::HA_TERMINATED_RESTART_PARTNER, isc::ha::HA_TERMINATED_ST, isc::ha::HA_UNAVAILABLE_ST, isc::ha::HA_WAITING_ST, isMaintenanceCanceled(), isc::util::StateModel::isModelPaused(), isPartnerStateInvalid(), LOG_INFO, isc::util::StateModel::NOP_EVT, isc::ha::HAConfig::PASSIVE_BACKUP, isc::util::StateModel::postNextEvent(), isc::ha::HAConfig::PeerConfig::PRIMARY, query_filter_, scheduleHeartbeat(), isc::ha::QueryFilter::serveNoScopes(), shouldPartnerDown(), shouldTerminate(), and verboseTransition().

Referenced by defineStates(), and getServerType().

+ Here is the call graph for this function:

Member Data Documentation

◆ client_

◆ communication_state_

◆ config_

◆ HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED

const int isc::ha::HAService::HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED = 1001
static

Control result returned in response to ha-maintenance-notify.

Definition at line 72 of file ha_service.h.

Referenced by processMaintenanceNotify().

◆ HA_HEARTBEAT_COMPLETE_EVT

const int isc::ha::HAService::HA_HEARTBEAT_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 1
static

Finished heartbeat command.

Definition at line 47 of file ha_service.h.

Referenced by asyncSendHeartbeat(), defineEvents(), and verifyEvents().

◆ HA_LEASE_UPDATES_COMPLETE_EVT

const int isc::ha::HAService::HA_LEASE_UPDATES_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 2
static

Finished lease updates commands.

Definition at line 50 of file ha_service.h.

Referenced by asyncSendLeaseUpdate(), defineEvents(), and verifyEvents().

◆ HA_MAINTENANCE_CANCEL_EVT

const int isc::ha::HAService::HA_MAINTENANCE_CANCEL_EVT = SM_DERIVED_EVENT_MIN + 7
static

ha-maintenance-cancel command received.

Definition at line 65 of file ha_service.h.

Referenced by defineEvents(), isMaintenanceCanceled(), processMaintenanceCancel(), processMaintenanceNotify(), and verifyEvents().

◆ HA_MAINTENANCE_NOTIFY_EVT

const int isc::ha::HAService::HA_MAINTENANCE_NOTIFY_EVT = SM_DERIVED_EVENT_MIN + 5
static

ha-maintenance-notify command received.

Definition at line 59 of file ha_service.h.

Referenced by defineEvents(), processMaintenanceNotify(), and verifyEvents().

◆ HA_MAINTENANCE_START_EVT

const int isc::ha::HAService::HA_MAINTENANCE_START_EVT = SM_DERIVED_EVENT_MIN + 6
static

ha-maintenance-start command received.

Definition at line 62 of file ha_service.h.

Referenced by defineEvents(), partnerDownStateHandler(), processMaintenanceStart(), and verifyEvents().

◆ HA_SYNCED_PARTNER_UNAVAILABLE_EVT

const int isc::ha::HAService::HA_SYNCED_PARTNER_UNAVAILABLE_EVT = SM_DERIVED_EVENT_MIN + 8
static

The heartbeat command failed after receiving ha-sync-complete-notify command from the partner.

Definition at line 69 of file ha_service.h.

Referenced by asyncSendHeartbeat(), defineEvents(), partnerDownStateHandler(), and verifyEvents().

◆ HA_SYNCING_FAILED_EVT

const int isc::ha::HAService::HA_SYNCING_FAILED_EVT = SM_DERIVED_EVENT_MIN + 3
static

Lease database synchronization failed.

Definition at line 53 of file ha_service.h.

Referenced by defineEvents(), synchronize(), and verifyEvents().

◆ HA_SYNCING_SUCCEEDED_EVT

const int isc::ha::HAService::HA_SYNCING_SUCCEEDED_EVT = SM_DERIVED_EVENT_MIN + 4
static

Lease database synchronization succeeded.

Definition at line 56 of file ha_service.h.

Referenced by defineEvents(), synchronize(), and verifyEvents().

◆ io_service_

asiolink::IOServicePtr isc::ha::HAService::io_service_
protected

Pointer to the IO service object shared between this hooks library and the DHCP server.

Definition at line 1158 of file ha_service.h.

Referenced by HAService().

◆ lease_update_backlog_

LeaseUpdateBacklog isc::ha::HAService::lease_update_backlog_
protected

Backlog of DHCP lease updates.

Unsent lease updates are stored in this queue when the server is in the communication-recovery state and is temporarily unable to send lease updates to the partner.

Definition at line 1294 of file ha_service.h.

Referenced by asyncSendLeaseUpdates(), asyncSendLeaseUpdatesFromBacklog(), communicationRecoveryHandler(), and sendLeaseUpdatesFromBacklog().

◆ listener_

config::CmdHttpListenerPtr isc::ha::HAService::listener_
protected

HTTP listener instance used to receive and respond to HA commands and lease updates.

Definition at line 1174 of file ha_service.h.

Referenced by checkPermissionsClientAndListener(), HAService(), pauseClientAndListener(), resumeClientAndListener(), startClientAndListener(), and stopClientAndListener().

◆ network_state_

dhcp::NetworkStatePtr isc::ha::HAService::network_state_
protected

Pointer to the state of the DHCP service (enabled/disabled).

Definition at line 1161 of file ha_service.h.

Referenced by adjustNetworkState(), HAService(), localDisableDHCPService(), localEnableDHCPService(), shouldPartnerDown(), and ~HAService().

◆ query_filter_

◆ server_type_

◆ sync_complete_notified_

bool isc::ha::HAService::sync_complete_notified_
protected

An indicator that a partner sent ha-sync-complete-notify command.

This indicator is set when the partner finished synchronization. It blocks enabling DHCP service in the partner-down state. The server will first send heartbeat to the partner to ensure that the communication is re-established. If the communication remains broken, the server clears this flag and enables DHCP service to continue the service.

Definition at line 1303 of file ha_service.h.

Referenced by asyncSendHeartbeat(), and processSyncCompleteNotify().


The documentation for this class was generated from the following files: