Kea 2.7.5
|
High availability service. More...
#include <ha_service.h>
Public Member Functions | |
HAService (const unsigned int id, const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAConfigPtr &config, const HAServerType &server_type=HAServerType::DHCPv4) | |
Constructor. | |
virtual | ~HAService () |
Destructor. | |
void | adjustNetworkState () |
Enables or disables network state depending on the served scopes. | |
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. | |
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. | |
size_t | asyncSendSingleLeaseUpdate (const dhcp::Pkt4Ptr &query, const dhcp::Lease4Ptr &lease, const hooks::ParkingLotHandlePtr &parking_lot) |
Schedules an asynchronous IPv4 lease update. | |
void | checkPermissionsClientAndListener () |
Check client and(or) listener current thread permissions to perform thread pool state transition. | |
HAServerType | getServerType () const |
Returns HA server type used in object construction. | |
bool | inScope (dhcp::Pkt4Ptr &query4) |
Checks if the DHCPv4 query should be processed by this server. | |
bool | inScope (dhcp::Pkt6Ptr &query6) |
Checks if the DHCPv6 query should be processed by this server. | |
void | pauseClientAndListener () |
Pauses client and(or) listener thread pool operations. | |
data::ConstElementPtr | processContinue () |
Processes ha-continue command and returns a response. | |
data::ConstElementPtr | processHAReset () |
Processes ha-reset command and returns a response. | |
data::ConstElementPtr | processHeartbeat () |
Processes ha-heartbeat command and returns a response. | |
data::ConstElementPtr | processMaintenanceCancel () |
Processes ha-maintenance-cancel command and returns a response. | |
data::ConstElementPtr | processMaintenanceNotify (const bool cancel) |
Processes ha-maintenance-notify command and returns a response. | |
data::ConstElementPtr | processMaintenanceStart () |
Processes ha-maintenance-start command and returns a response. | |
data::ConstElementPtr | processScopes (const std::vector< std::string > &scopes) |
Processes ha-scopes command and returns a response. | |
data::ConstElementPtr | processStatusGet () const |
Processes status-get command and returns a response. | |
data::ConstElementPtr | processSyncCompleteNotify (const unsigned int origin_id) |
Process ha-sync-complete-notify command and returns a response. | |
data::ConstElementPtr | processSynchronize (const std::string &server_name, const unsigned int max_period) |
Processes ha-sync command and returns a response. | |
void | resumeClientAndListener () |
Resumes client and(or) listener thread pool operations. | |
void | serveDefaultScopes () |
Instructs the HA service to serve default scopes. | |
void | serveFailoverScopes () |
Instructs the HA service to serve failover scopes. | |
void | startClientAndListener () |
Start the client and(or) listener instances. | |
void | stopClientAndListener () |
Stop the client and(or) listener instances. | |
bool | unpause () |
Unpauses the HA state machine with logging. | |
Public Member Functions inherited from isc::util::StateModel | |
StateModel () | |
Constructor. | |
virtual | ~StateModel () |
Destructor. | |
bool | didModelFail () const |
Returns whether or not the model failed. | |
void | endModel () |
Conducts a normal transition to the end of the model. | |
std::string | getContextStr () const |
Convenience method which returns a string rendition of the current state and next event. | |
unsigned int | getCurrState () const |
Fetches the model's current state. | |
std::string | getEventLabel (const int event) const |
Fetches the label associated with an event value. | |
unsigned int | getLastEvent () const |
Fetches the model's last event. | |
unsigned int | getNextEvent () const |
Fetches the model's next event. | |
std::string | getPrevContextStr () const |
Convenience method which returns a string rendition of the previous state and last event. | |
unsigned int | getPrevState () const |
Fetches the model's previous state. | |
std::string | getStateLabel (const int state) const |
Fetches the label associated with an state value. | |
bool | isModelDone () const |
Returns whether or not the model has finished execution. | |
bool | isModelNew () const |
Returns whether or not the model is new. | |
bool | isModelPaused () const |
Returns whether or not the model is paused. | |
bool | isModelRunning () const |
Returns whether or not the model is running. | |
bool | isModelWaiting () const |
Returns whether or not the model is waiting. | |
void | nopStateHandler () |
An empty state handler. | |
virtual void | runModel (unsigned int event) |
Processes events through the state model. | |
void | startModel (const int start_state) |
Begins execution of the model. | |
void | unpauseModel () |
Unpauses state model. | |
Static Public Attributes | |
static const int | HA_CONTROL_RESULT_MAINTENANCE_NOT_ALLOWED = 1001 |
Control result returned in response to ha-maintenance-notify. | |
static const int | HA_HEARTBEAT_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 1 |
Finished heartbeat command. | |
static const int | HA_LEASE_UPDATES_COMPLETE_EVT = SM_DERIVED_EVENT_MIN + 2 |
Finished lease updates commands. | |
static const int | HA_MAINTENANCE_CANCEL_EVT = SM_DERIVED_EVENT_MIN + 7 |
ha-maintenance-cancel command received. | |
static const int | HA_MAINTENANCE_NOTIFY_EVT = SM_DERIVED_EVENT_MIN + 5 |
ha-maintenance-notify command received. | |
static const int | HA_MAINTENANCE_START_EVT = SM_DERIVED_EVENT_MIN + 6 |
ha-maintenance-start command received. | |
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. | |
static const int | HA_SYNCING_FAILED_EVT = SM_DERIVED_EVENT_MIN + 3 |
Lease database synchronization failed. | |
static const int | HA_SYNCING_SUCCEEDED_EVT = SM_DERIVED_EVENT_MIN + 4 |
Lease database synchronization succeeded. | |
static const int | HA_WAITING_TO_TERMINATED_ST_DELAY_MINUTES = 10 |
A delay in minutes to transition from the waiting to terminated state when the partner remains in terminated state. | |
Static Public Attributes inherited from isc::util::StateModel | |
static const int | END_EVT = 2 |
Event issued to end the model execution. | |
static const int | END_ST = 1 |
Final state, all the state model has reached its conclusion. | |
static const int | FAIL_EVT = 3 |
Event issued to abort the model execution. | |
static const int | NEW_ST = 0 |
State that a state model is in immediately after construction. | |
static const int | NOP_EVT = 0 |
Signifies that no event has occurred. | |
static const int | SM_DERIVED_EVENT_MIN = 11 |
Value at which custom events in a derived class should begin. | |
static const int | SM_DERIVED_STATE_MIN = 11 |
Value at which custom states in a derived class should begin. | |
static const int | START_EVT = 1 |
Event issued to start the model execution. | |
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. | |
typedef std::function< void(const bool, const std::string &, const bool) | PostSyncCallback) |
Callback invoked when lease database synchronization is complete. | |
Protected Member Functions | |
void | asyncDisableDHCPService (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, const unsigned int max_period, PostRequestCallback post_request_action) |
Schedules asynchronous "dhcp-disable" command to the specified server. | |
void | asyncEnableDHCPService (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action) |
Schedules asynchronous "dhcp-enable" command to the specified server. | |
void | asyncSendHAReset (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action) |
Sends ha-reset command to partner asynchronously. | |
void | asyncSendHeartbeat () |
Starts asynchronous heartbeat to a peer. | |
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. | |
void | asyncSendLeaseUpdatesFromBacklog (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action) |
Sends lease updates from backlog to partner asynchronously. | |
void | asyncSyncCompleteNotify (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, PostRequestCallback post_request_action) |
Schedules asynchronous "ha-sync-complete-notify" command to the specified server. | |
void | asyncSyncLeases () |
Asynchronously reads leases from a peer and updates local lease database. | |
void | asyncSyncLeases (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, 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. | |
void | asyncSyncLeasesInternal (http::HttpClient &http_client, const HAConfig::PeerConfigPtr &remote_config, 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. | |
void | clientCloseHandler (int tcp_native_fd) |
HttpClient close callback handler. | |
bool | clientConnectHandler (const boost::system::error_code &ec, int tcp_native_fd) |
HttpClient connect callback handler. | |
bool | clientHandshakeHandler (const boost::system::error_code &) |
HttpClient handshake callback handler. | |
void | conditionalLogPausedState () const |
Logs if the server is paused in the current state. | |
int | getNormalState () const |
Returns normal operation state for the current configuration. | |
template<typename QueryPtrType > | |
int | getPendingRequest (const QueryPtrType &query) |
Get the number of scheduled requests for a given query. | |
bool | isMaintenanceCanceled () const |
Convenience method checking if the current state is a result of canceling the maintenance. | |
bool | isPartnerStateInvalid () const |
Indicates if the partner's state is invalid. | |
template<typename QueryPtrType > | |
bool | leaseUpdateComplete (QueryPtrType &query, const hooks::ParkingLotHandlePtr &parking_lot) |
Handle last pending request for this query. | |
void | localDisableDHCPService () |
Disables local DHCP service. | |
void | localEnableDHCPService () |
Enables local DHCP service. | |
void | logFailedLeaseUpdates (const dhcp::PktPtr &query, const data::ConstElementPtr &args) const |
Log failed lease updates. | |
size_t | pendingRequestSize () |
Get the number of entries in the pending request map. | |
void | scheduleHeartbeat () |
Schedules asynchronous heartbeat to a peer if it is not scheduled. | |
bool | sendHAReset () |
Sends ha-reset command to partner synchronously. | |
bool | sendLeaseUpdatesFromBacklog () |
Attempts to send all lease updates from the backlog synchronously. | |
bool | shouldPartnerDown () const |
Indicates if the server should transition to the partner down state. | |
bool | shouldQueueLeaseUpdates (const HAConfig::PeerConfigPtr &peer_config) const |
Checks if the lease updates should be queued. | |
bool | shouldSendLeaseUpdates (const HAConfig::PeerConfigPtr &peer_config) const |
Checks if the lease updates should be sent as result of leases allocation or release. | |
bool | shouldTerminate () const |
Indicates if the server should transition to the terminated state. | |
void | socketReadyHandler (int tcp_native_fd) |
IfaceMgr external socket ready callback handler. | |
void | startHeartbeat () |
Unconditionally starts one heartbeat to a peer. | |
int | synchronize (std::string &status_message, const HAConfig::PeerConfigPtr &remote_config, const unsigned int max_period) |
Synchronizes lease database with a partner. | |
template<typename QueryPtrType > | |
void | updatePendingRequest (QueryPtrType &query) |
Update pending request counter for this query. | |
void | verboseTransition (const unsigned state) |
Transitions to a desired state and logs it. | |
data::ConstElementPtr | verifyAsyncResponse (const http::HttpResponsePtr &response, int &rcode) |
Checks if the response is valid or contains an error. | |
Protected Member Functions inherited from isc::util::StateModel | |
void | abortModel (const std::string &explanation) |
Aborts model execution. | |
void | defineEvent (unsigned int value, const std::string &label) |
Adds an event value and associated label to the set of events. | |
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. | |
bool | doOnEntry () |
Checks if on entry flag is true. | |
bool | doOnExit () |
Checks if on exit flag is true. | |
const EventPtr & | getEvent (unsigned int value) |
Fetches the event referred to by value. | |
const StatePtr | getState (unsigned int value) |
Fetches the state referred to by value. | |
const StatePtr | getStateInternal (unsigned int value) |
Fetches the state referred to by value. | |
void | initDictionaries () |
Initializes the event and state dictionaries. | |
virtual void | onModelFailure (const std::string &explanation) |
Handler for fatal model execution errors. | |
void | postNextEvent (unsigned int event) |
Sets the next event to the given event value. | |
void | setState (unsigned int state) |
Sets the current state to the given state value. | |
void | transition (unsigned int state, unsigned int event) |
Sets up the model to transition into given state with a given event. | |
virtual void | verifyStates () |
Validates the contents of the set of states. | |
Protected Attributes | |
http::HttpClientPtr | client_ |
HTTP client instance used to send HA commands and lease updates. | |
CommunicationStatePtr | communication_state_ |
Holds communication state with a peer. | |
HAConfigPtr | config_ |
Pointer to the HA hooks library configuration. | |
unsigned int | id_ |
Unique service id. | |
asiolink::IOServicePtr | io_service_ |
Pointer to the IO service object shared between this hooks library and the DHCP server. | |
LeaseSyncFilter | lease_sync_filter_ |
Lease synchronization filter used in hub-and-spoke model. | |
LeaseUpdateBacklog | lease_update_backlog_ |
Backlog of DHCP lease updates. | |
config::CmdHttpListenerPtr | listener_ |
HTTP listener instance used to receive and respond to HA commands and lease updates. | |
dhcp::NetworkStatePtr | network_state_ |
Pointer to the state of the DHCP service (enabled/disabled). | |
QueryFilter | query_filter_ |
Selects queries to be processed/dropped. | |
HAServerType | server_type_ |
DHCP server type. | |
bool | sync_complete_notified_ |
An indicator that a partner sent ha-sync-complete-notify command. | |
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 52 of file ha_service.h.
|
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 95 of file ha_service.h.
|
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 104 of file ha_service.h.
isc::ha::HAService::HAService | ( | const unsigned int | id, |
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).
id | Unique HAService id. |
io_service | Pointer to the IO service used by the DHCP server. |
config | Parsed HA hook library configuration. |
network_state | Object holding state of the DHCP service (enabled/disabled). |
server_type | Server type, i.e. DHCPv4 or DHCPv6 server. |
Definition at line 76 of file ha_service.cc.
References client_, isc::config::CmdResponseCreator::command_accept_list_, 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::asiolink::IOAddress::IPV4_ZERO_ADDRESS(), isc_throw, listener_, LOG_INFO, network_state_, isc::ha::HAConfig::PeerConfig::roleToString(), and isc::util::StateModel::startModel().
|
virtual |
Destructor.
Stops the client and listener (if one). It clears the DHCP state using origin HA internal command.
Definition at line 147 of file ha_service.cc.
References network_state_, and stopClientAndListener().
void isc::ha::HAService::adjustNetworkState | ( | ) |
Enables or disables network state depending on the served scopes.
This method is called in each HA state to enable/disable DHCP service as appropriate for that state.
Definition at line 1089 of file ha_service.cc.
References config_, isc::util::StateModel::getCurrState(), isc::util::StateModel::getStateLabel(), isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, isc::ha::HA_LOCAL_DHCP_DISABLE, isc::ha::HA_LOCAL_DHCP_ENABLE, 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_TERMINATED_ST, LOG_INFO, and network_state_.
|
protected |
Schedules asynchronous "dhcp-disable" command to the specified server.
http_client | reference to the client to be used to communicate with the other server. |
remote_config | config of the partner to which the command should be sent. |
max_period | maximum number of seconds for which the DHCP service should be disabled. |
post_request_action | pointer to the function to be executed when the request is completed. |
Definition at line 1936 of file ha_service.cc.
References isc::ha::HA_DHCP_DISABLE_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.
|
protected |
Schedules asynchronous "dhcp-enable" command to the specified server.
http_client | reference to the client to be used to communicate with the other server. |
remote_config | config of the partner to which the command should be sent. |
post_request_action | pointer to the function to be executed when the request is completed. |
Definition at line 2017 of file ha_service.cc.
References isc::ha::HA_DHCP_ENABLE_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.
|
protected |
Sends ha-reset command to partner asynchronously.
http_client | reference to the HTTP client to be used for communication. |
remote_config | pointer to the remote server's configuration. |
post_request_action | callback to be invoked when the operation completes. It can be used for handling errors. |
Definition at line 2649 of file ha_service.cc.
References isc::ha::ha_logger, isc::ha::HA_RESET_FAILED, isc::http::HttpVersion::HTTP_11(), and LOG_WARN.
|
protected |
Starts asynchronous heartbeat to a peer.
Definition at line 1763 of file ha_service.cc.
References isc::ha::HA_HEARTBEAT_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_WARN.
|
protected |
Asynchronously sends lease update to the peer.
query | Pointer to the DHCP client's query. | |
config | Pointer to the configuration of the server to which the command should be sent. | |
command | Pointer to the command to be sent. | |
[out] | parking_lot | Parking lot where the query is parked. This method uses this handle to unpark the packet when all asynchronous requests have been completed. |
QueryPtrType | Type of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr. |
Unexpected | when an unexpected error occurs. |
Definition at line 1418 of file ha_service.cc.
References isc::ha::HAConfig::PeerConfig::BACKUP, client_, 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::http::HttpVersion::HTTP_11(), leaseUpdateComplete(), LOG_WARN, logFailedLeaseUpdates(), isc::util::StateModel::runModel(), and verifyAsyncResponse().
Referenced by asyncSendLeaseUpdates(), and asyncSendLeaseUpdates().
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.
query | Pointer to the processed DHCP client message. |
leases | Pointer to a collection of the newly allocated or updated leases. |
deleted_leases | Pointer to a collection of the released leases. |
parking_lot | Pointer 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. |
Definition at line 1202 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 asyncSendSingleLeaseUpdate().
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.
query | Pointer to the processed DHCP client message. | |
leases | Pointer to a collection of the newly allocated or updated leases. | |
deleted_leases | Pointer to a collection of the released leases. | |
[out] | parking_lot | Pointer 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. |
Definition at line 1295 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().
|
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
.
http_client | reference to the HTTP client to be used for communication. |
remote_config | pointer to the remote server's configuration. |
post_request_action | callback to be invoked when the operation completes. It can be used for handling errors. |
Definition at line 2523 of file ha_service.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::ha::HA_LEASES_BACKLOG_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_WARN.
size_t isc::ha::HAService::asyncSendSingleLeaseUpdate | ( | const dhcp::Pkt4Ptr & | query, |
const dhcp::Lease4Ptr & | lease, | ||
const hooks::ParkingLotHandlePtr & | parking_lot ) |
Schedules an asynchronous IPv4 lease update.
This method is a convenience wrapper around asyncSendLeaseUpdates() for propagating updates for a single lease. It is currently only used by the "lease4_server_decline" callout.
query | Pointer to the processed DHCP client message. |
lease | Pointer to the updated lease |
parking_lot | Pointer to the parking lot handle available for the hook point if one. This is where the DHCP client message is parked if it is parked. This method calls unpark() on this object when the asynchronous updates are completed. |
Definition at line 1284 of file ha_service.cc.
References asyncSendLeaseUpdates().
|
protected |
Schedules asynchronous "ha-sync-complete-notify" command to the specified server.
http_client | reference to the client to be used to communicate with the other server. |
remote_config | config of the partner to which the command should be sent. |
post_request_action | pointer to the function to be executed when the request is completed. |
Definition at line 3022 of file ha_service.cc.
References isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, isc::ha::ha_logger, isc::ha::HA_SYNC_COMPLETE_NOTIFY_FAILED, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.
|
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 2105 of file ha_service.cc.
|
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.
http_client | reference to the client to be used to communicate with the other server. |
remote_config | config of the partner to fetch leases from. |
max_period | maximum number of seconds to disable DHCP service |
last_lease | Pointer 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_action | pointer to the function to be executed when lease database synchronization is complete. If this is null, no post synchronization action is invoked. |
dhcp_disabled | Boolean 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 2122 of file ha_service.cc.
|
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.
http_client | reference to the client to be used to communicate with the other server. |
remote_config | config of the partner to fetch leases from. |
max_period | maximum number of seconds to disable DHCP service |
last_lease | Pointer 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_action | pointer to the function to be executed when lease database synchronization is complete. If this is null, no post synchronization action is invoked. |
dhcp_disabled | Boolean 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 2153 of file ha_service.cc.
References isc::ha::HA_LEASES_SYNC_FAILED, isc::ha::ha_logger, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.
void isc::ha::HAService::checkPermissionsClientAndListener | ( | ) |
Check client and(or) listener current thread permissions to perform thread pool state transition.
MultiThreadingInvalidOperation | if the state transition is done on any of the worker threads. |
Definition at line 3327 of file ha_service.cc.
References isc::ha::ha_logger, isc::ha::HA_PAUSE_CLIENT_LISTENER_FAILED, isc::ha::HA_PAUSE_CLIENT_LISTENER_ILLEGAL, and LOG_ERROR.
|
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()).
tcp_native_fd | socket descriptor to register |
Definition at line 3289 of file ha_service.cc.
References isc::dhcp::IfaceMgr::instance().
|
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()).
ec | Error status of the ASIO connect |
tcp_native_fd | socket descriptor to register |
Definition at line 3249 of file ha_service.cc.
References isc::dhcp::IfaceMgr::instance().
|
inlineprotected |
HttpClient handshake callback handler.
Currently is never called and does nothing.
Definition at line 1196 of file ha_service.h.
|
protected |
Logs if the server is paused in the current state.
This method is internally called by the state handlers upon entry to a new state.
Definition at line 1037 of file ha_service.cc.
References config_, isc::util::StateModel::getCurrState(), isc::ha::ha_logger, isc::ha::HA_STATE_MACHINE_PAUSED, isc::util::StateModel::isModelPaused(), LOG_INFO, and isc::ha::stateToString().
|
protected |
Returns normal operation state for the current configuration.
Definition at line 1010 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.
|
protected |
Get the number of scheduled requests for a given query.
If there is an entry in the pending request map for the given query the entry is returned else zero is returned.
query | Pointer to the DHCP client's query. |
Definition at line 3307 of file ha_service.cc.
References isc::util::MultiThreadingMgr::instance().
|
inline |
Returns HA server type used in object construction.
Definition at line 133 of file ha_service.h.
References server_type_.
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.
[out] | query4 | pointer 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. |
Definition at line 1059 of file ha_service.cc.
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.
[out] | query6 | pointer 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. |
Definition at line 1064 of file ha_service.cc.
|
protected |
Convenience method checking if the current state is a result of canceling the maintenance.
Definition at line 1164 of file ha_service.cc.
References isc::util::StateModel::getLastEvent(), and HA_MAINTENANCE_CANCEL_EVT.
|
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:
Definition at line 1169 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.
|
protected |
Handle last pending request for this query.
Search if there are pending requests for this query:
QueryPtrType | Type of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr. |
query | Pointer to the DHCP client's query. | |
[out] | parking_lot | Parking lot where the query is parked. This method uses this handle to unpark the packet when all asynchronous requests have been completed. |
Definition at line 1362 of file ha_service.cc.
References isc::util::MultiThreadingMgr::instance().
Referenced by asyncSendLeaseUpdate().
|
protected |
Disables local DHCP service.
Definition at line 2095 of file ha_service.cc.
|
protected |
Enables local DHCP service.
Definition at line 2100 of file ha_service.cc.
|
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.
query | Pointer to the DHCP client's query. |
args | Arguments of the response. It may be null, in which case the function simply returns. |
Definition at line 1621 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, isc::data::Element::list, LOG_INFO, isc::data::Element::map, and isc::data::Element::string.
Referenced by asyncSendLeaseUpdate().
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 3373 of file ha_service.cc.
References isc::ha::ha_logger, isc::ha::HA_PAUSE_CLIENT_LISTENER_FAILED, and LOG_ERROR.
|
protected |
Get the number of entries in the pending request map.
Definition at line 3296 of file ha_service.cc.
References isc::util::MultiThreadingMgr::instance().
ConstElementPtr isc::ha::HAService::processContinue | ( | ) |
Processes ha-continue command and returns a response.
Definition at line 2738 of file ha_service.cc.
References isc::config::CONTROL_RESULT_SUCCESS, and isc::config::createAnswer().
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.
Definition at line 1753 of file ha_service.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), and isc::ha::HA_WAITING_ST.
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:
Definition at line 1730 of file ha_service.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::data::Element::create(), isc::config::createAnswer(), isc::data::Element::createList(), isc::data::Element::createMap(), and isc::http::HttpDateTime::rfc1123Format().
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.
Definition at line 2919 of file ha_service.cc.
References isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), isc::ha::ha_logger, isc::ha::HA_MAINTENANCE_NOTIFY_CANCEL_FAILED, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::http::HttpVersion::HTTP_11(), and LOG_ERROR.
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:
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.
cancel | boolean value indicating if the maintenance is being canceled with this operation. If it is set to false the maintenance is being started. |
Definition at line 2746 of file ha_service.cc.
References isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), isc::ha::HA_BACKUP_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_TERMINATED_ST, and isc::ha::stateToString().
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().
Definition at line 2782 of file ha_service.cc.
References isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), isc::ha::HA_BACKUP_ST, isc::ha::HA_IN_MAINTENANCE_ST, isc::ha::ha_logger, isc::ha::HA_MAINTENANCE_NOTIFY_FAILED, isc::ha::HA_PARTNER_IN_MAINTENANCE_ST, isc::ha::HA_TERMINATED_ST, isc::http::HttpVersion::HTTP_11(), LOG_ERROR, and isc::ha::stateToString().
ConstElementPtr isc::ha::HAService::processScopes | ( | const std::vector< std::string > & | scopes | ) |
Processes ha-scopes command and returns a response.
scopes | vector of scope names to be enabled. |
Definition at line 2725 of file ha_service.cc.
References isc::config::CONTROL_RESULT_ERROR, isc::config::CONTROL_RESULT_SUCCESS, and isc::config::createAnswer().
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 1673 of file ha_service.cc.
References isc::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), isc::util::ptimeToText(), and isc::ha::stateToString().
ConstElementPtr isc::ha::HAService::processSyncCompleteNotify | ( | const unsigned int | origin_id | ) |
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.
origin_id | a numeric value of the origin created from the HAService identifier to enable the DHCP service. |
Definition at line 3105 of file ha_service.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), and isc::ha::HA_PARTNER_DOWN_ST.
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.
server_name | name of the server to fetch leases from. |
max_period | maximum 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. |
Definition at line 2369 of file ha_service.cc.
References isc::config::CONTROL_RESULT_ERROR, and isc::config::createAnswer().
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 3391 of file ha_service.cc.
References isc::ha::ha_logger, isc::ha::HA_RESUME_CLIENT_LISTENER_FAILED, and LOG_ERROR.
|
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 1920 of file ha_service.cc.
|
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().
Definition at line 2702 of file ha_service.cc.
|
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().
Definition at line 2601 of file ha_service.cc.
References isc::ha::HA_LEASES_BACKLOG_NOTHING_TO_SEND, isc::ha::HA_LEASES_BACKLOG_START, isc::ha::HA_LEASES_BACKLOG_SUCCESS, isc::ha::ha_logger, LOG_INFO, and isc::util::Stopwatch::stop().
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 1049 of file ha_service.cc.
References query_filter_, and isc::ha::QueryFilter::serveDefaultScopes().
void isc::ha::HAService::serveFailoverScopes | ( | ) |
Instructs the HA service to serve failover 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 1054 of file ha_service.cc.
References query_filter_, and isc::ha::QueryFilter::serveFailoverScopes().
|
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.
Definition at line 1121 of file ha_service.cc.
References communication_state_, config_, isc::ha::HAConfig::LOAD_BALANCING, network_state_, and isc::ha::HAConfig::PeerConfig::STANDBY.
|
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.
peer_config | pointer to the configuration of the peer to which the updates are to be sent. |
Definition at line 1608 of file ha_service.cc.
References isc::ha::HA_COMMUNICATION_RECOVERY_ST.
Referenced by asyncSendLeaseUpdates(), and asyncSendLeaseUpdates().
|
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.
peer_config | pointer to the configuration of the peer to which the updates are to be sent. |
Definition at line 1576 of file ha_service.cc.
References isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_ST, and isc::ha::HA_PARTNER_IN_MAINTENANCE_ST.
Referenced by asyncSendLeaseUpdates(), asyncSendLeaseUpdates(), and verboseTransition().
|
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.
Definition at line 1148 of file ha_service.cc.
References communication_state_.
|
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.
tcp_native_fd | socket descriptor of the ready socket |
Definition at line 3280 of file ha_service.cc.
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 3356 of file ha_service.cc.
References isc::util::MultiThreadingMgr::instance().
|
protected |
Unconditionally starts one heartbeat to a peer.
Definition at line 1927 of file ha_service.cc.
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 3410 of file ha_service.cc.
References isc::util::MultiThreadingMgr::instance().
Referenced by ~HAService().
|
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().
[out] | status_message | status message in textual form. |
remote_config | config of the server to fetch leases from. | |
max_period | maximum 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. |
Definition at line 2388 of file ha_service.cc.
References 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, LOG_ERROR, LOG_INFO, and isc::util::Stopwatch::stop().
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.
Definition at line 1026 of file ha_service.cc.
References config_, isc::ha::ha_logger, isc::ha::HA_STATE_MACHINE_CONTINUED, isc::util::StateModel::isModelPaused(), LOG_INFO, and isc::util::StateModel::unpauseModel().
|
protected |
Update pending request counter for this query.
QueryPtrType | Type of the pointer to the DHCP client's message, i.e. Pkt4Ptr or Pkt6Ptr. |
query | Pointer to the DHCP client's query. |
Definition at line 1397 of file ha_service.cc.
References isc::util::MultiThreadingMgr::instance().
|
protected |
Transitions to a desired state and logs it.
state | the new value to assign to the current state. |
Definition at line 939 of file ha_service.cc.
References isc::ha::HAConfig::PeerConfig::BACKUP, communication_state_, config_, isc::util::StateModel::getCurrState(), isc::util::StateModel::getNextEvent(), isc::util::StateModel::getStateLabel(), isc::ha::HA_CONFIG_LEASE_SYNCING_DISABLED_REMINDER, isc::ha::HA_CONFIG_LEASE_UPDATES_DISABLED_REMINDER, isc::ha::HA_LEASE_UPDATES_DISABLED, isc::ha::HA_LEASE_UPDATES_ENABLED, isc::ha::ha_logger, isc::ha::HA_READY_ST, isc::ha::HA_STATE_TRANSITION, isc::ha::HA_STATE_TRANSITION_PASSIVE_BACKUP, isc::ha::HA_WAITING_ST, LOG_INFO, isc::ha::HAConfig::PASSIVE_BACKUP, shouldSendLeaseUpdates(), and isc::util::StateModel::transition().
|
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.
response | pointer to the received response. | |
[out] | rcode | result found in the response. |
CtrlChannelError | if response is invalid or contains an error. |
CommandUnsupportedError | if sent command is unsupported. |
ConflictError | if 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 3126 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::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), isc::data::Element::integer, isc_throw, isc::data::Element::list, isc::data::Element::map, isc::config::parseAnswer(), and isc::data::Element::string.
Referenced by asyncSendLeaseUpdate().
|
protected |
HTTP client instance used to send HA commands and lease updates.
Definition at line 1244 of file ha_service.h.
Referenced by HAService(), and asyncSendLeaseUpdate().
|
protected |
Holds communication state with a peer.
Definition at line 1251 of file ha_service.h.
Referenced by HAService(), asyncSendLeaseUpdate(), asyncSendLeaseUpdates(), asyncSendLeaseUpdates(), isPartnerStateInvalid(), shouldPartnerDown(), shouldTerminate(), and verboseTransition().
|
protected |
Pointer to the HA hooks library configuration.
Definition at line 1238 of file ha_service.h.
Referenced by HAService(), adjustNetworkState(), asyncSendLeaseUpdate(), asyncSendLeaseUpdates(), asyncSendLeaseUpdates(), conditionalLogPausedState(), getNormalState(), isPartnerStateInvalid(), shouldPartnerDown(), unpause(), and verboseTransition().
|
static |
Control result returned in response to ha-maintenance-notify.
Definition at line 81 of file ha_service.h.
|
static |
Finished heartbeat command.
Definition at line 56 of file ha_service.h.
|
static |
Finished lease updates commands.
Definition at line 59 of file ha_service.h.
Referenced by asyncSendLeaseUpdate().
|
static |
ha-maintenance-cancel command received.
Definition at line 74 of file ha_service.h.
Referenced by isMaintenanceCanceled().
|
static |
ha-maintenance-notify command received.
Definition at line 68 of file ha_service.h.
|
static |
ha-maintenance-start command received.
Definition at line 71 of file ha_service.h.
|
static |
The heartbeat command failed after receiving ha-sync-complete-notify command from the partner.
Definition at line 78 of file ha_service.h.
|
static |
Lease database synchronization failed.
Definition at line 62 of file ha_service.h.
|
static |
Lease database synchronization succeeded.
Definition at line 65 of file ha_service.h.
|
static |
A delay in minutes to transition from the waiting to terminated state when the partner remains in terminated state.
Definition at line 85 of file ha_service.h.
|
protected |
Unique service id.
Definition at line 1228 of file ha_service.h.
|
protected |
Pointer to the IO service object shared between this hooks library and the DHCP server.
Definition at line 1232 of file ha_service.h.
Referenced by HAService().
|
protected |
Lease synchronization filter used in hub-and-spoke model.
Definition at line 1257 of file ha_service.h.
|
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 1371 of file ha_service.h.
Referenced by asyncSendLeaseUpdates(), and asyncSendLeaseUpdates().
|
protected |
HTTP listener instance used to receive and respond to HA commands and lease updates.
Definition at line 1248 of file ha_service.h.
Referenced by HAService().
|
protected |
Pointer to the state of the DHCP service (enabled/disabled).
Definition at line 1235 of file ha_service.h.
Referenced by HAService(), ~HAService(), adjustNetworkState(), and shouldPartnerDown().
|
protected |
Selects queries to be processed/dropped.
Definition at line 1254 of file ha_service.h.
Referenced by serveDefaultScopes(), and serveFailoverScopes().
|
protected |
|
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 1380 of file ha_service.h.