Kea
1.9.9-git
|
High availability service. More...
#include <ha_service.h>
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 | 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 | 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_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 &)> | 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 | 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 as a result of high clock skew. 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 EventPtr & | getEvent (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... | |
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.
|
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.
Definition at line 77 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 86 of file ha_service.h.
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).
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 53 of file ha_service.cc.
References client_, communication_state_, config_, isc::ha::DHCPv4, 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().
|
virtual |
Destructor.
Stops the client and listener (if one). It clears the DHCP state using origin HA internal command.
Definition at line 108 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 995 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_.
Referenced by backupStateHandler(), communicationRecoveryHandler(), inMaintenanceStateHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), passiveBackupStateHandler(), processScopes(), readyStateHandler(), syncingStateHandler(), terminatedStateHandler(), and waitingStateHandler().
|
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. |
server_name | name of the server 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 1717 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().
|
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. |
server_name | name of the server 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 1796 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 synchronize().
|
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 2329 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 sendHAReset().
|
protected |
Starts asynchronous heartbeat to a peer.
Definition at line 1579 of file ha_service.cc.
References client_, clientCloseHandler(), clientConnectHandler(), clientHandshakeHandler(), communication_state_, config_, isc::ha::CommandCreator::createHeartbeat(), isc::ha::HA_COMMUNICATION_INTERRUPTED, isc::ha::HA_HEARTBEAT_COMMUNICATIONS_FAILED, HA_HEARTBEAT_COMPLETE_EVT, isc::ha::HA_HEARTBEAT_FAILED, isc::ha::ha_logger, isc_throw, LOG_WARN, isc::util::StateModel::runModel(), server_type_, startHeartbeat(), isc::config::TIMEOUT_DEFAULT_HTTP_CLIENT_REQUEST, and verifyAsyncResponse().
Referenced by startHeartbeat().
|
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 1270 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_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().
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. | |
[out] | 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 1102 of file ha_service.cc.
References isc::ha::LeaseUpdateBacklog::ADD, asyncSendLeaseUpdate(), isc::ha::HAConfig::PeerConfig::BACKUP, config_, isc::ha::CommandCreator::createLease4Delete(), isc::ha::CommandCreator::createLease4Update(), isc::ha::LeaseUpdateBacklog::DELETE, lease_update_backlog_, isc::ha::LeaseUpdateBacklog::push(), shouldQueueLeaseUpdates(), and shouldSendLeaseUpdates().
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 1163 of file ha_service.cc.
References isc::ha::LeaseUpdateBacklog::ADD, asyncSendLeaseUpdate(), isc::ha::HAConfig::PeerConfig::BACKUP, 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 2212 of file ha_service.cc.
References isc::ha::LeaseUpdateBacklog::ADD, isc::http::HttpClient::asyncSendRequest(), 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 sendLeaseUpdatesFromBacklog().
|
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 1882 of file ha_service.cc.
References client_, and config_.
Referenced by asyncSyncLeasesInternal(), and synchronize().
|
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. |
server_name | name of the server 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 1898 of file ha_service.cc.
References asyncDisableDHCPService(), and asyncSyncLeasesInternal().
|
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. |
server_name | name of the server 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 1929 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().
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 195 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().
|
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 2779 of file ha_service.cc.
Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncLeasesInternal(), processMaintenanceCancel(), and processMaintenanceStart().
|
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 2739 of file ha_service.cc.
References client_, and socketReadyHandler().
Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncLeasesInternal(), processMaintenanceCancel(), and processMaintenanceStart().
|
inlineprotected |
HttpClient handshake callback handler.
Currently is never called and does nothing.
Definition at line 1067 of file ha_service.h.
Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncLeasesInternal(), processMaintenanceCancel(), and processMaintenanceStart().
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 210 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().
|
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 949 of file ha_service.cc.
References isc::util::StateModel::getCurrState(), isc::ha::ha_logger, isc::ha::HA_STATE_MACHINE_PAUSED, isc::util::StateModel::isModelPaused(), LOG_INFO, and isc::ha::stateToString().
Referenced by backupStateHandler(), communicationRecoveryHandler(), inMaintenanceStateHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), passiveBackupStateHandler(), readyStateHandler(), syncingStateHandler(), terminatedStateHandler(), and waitingStateHandler().
|
virtual |
Defines events used by the HA service.
Reimplemented from isc::util::StateModel.
Definition at line 116 of file ha_service.cc.
References isc::util::StateModel::defineEvent(), HA_HEARTBEAT_COMPLETE_EVT, HA_LEASE_UPDATES_COMPLETE_EVT, HA_MAINTENANCE_CANCEL_EVT, HA_MAINTENANCE_NOTIFY_EVT, HA_MAINTENANCE_START_EVT, HA_SYNCING_FAILED_EVT, and HA_SYNCING_SUCCEEDED_EVT.
|
virtual |
Defines states of the HA service.
Reimplemented from isc::util::StateModel.
Definition at line 142 of file ha_service.cc.
References backupStateHandler(), communicationRecoveryHandler(), config_, isc::util::StateModel::defineState(), 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_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_ST, isc::ha::HA_WAITING_ST, inMaintenanceStateHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), passiveBackupStateHandler(), readyStateHandler(), isc::ha::stateToString(), syncingStateHandler(), terminatedStateHandler(), and waitingStateHandler().
|
protected |
Returns normal operation state for the current configuration.
Definition at line 923 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(), and readyStateHandler().
|
inline |
Returns last known state of the partner.
CommunicationState::getPartnerState.
Definition at line 348 of file ha_service.h.
References communication_state_.
|
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 2797 of file ha_service.cc.
|
inline |
Returns HA server type used in object construction.
Definition at line 113 of file ha_service.h.
References server_type_.
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 402 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().
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 965 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 970 of file ha_service.cc.
|
protected |
Convenience method checking if the current state is a result of canceling the maintenance.
Definition at line 1067 of file ha_service.cc.
References isc::util::StateModel::getLastEvent(), and HA_MAINTENANCE_CANCEL_EVT.
Referenced by communicationRecoveryHandler(), normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().
|
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 1072 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(), normalStateHandler(), partnerDownStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().
|
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 1216 of file ha_service.cc.
Referenced by asyncSendLeaseUpdate().
|
protected |
Disables local DHCP service.
Definition at line 1872 of file ha_service.cc.
References network_state_.
|
protected |
Enables local DHCP service.
Definition at line 1877 of file ha_service.cc.
References network_state_.
|
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 1448 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().
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 327 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().
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 427 of file ha_service.cc.
References adjustNetworkState(), communication_state_, conditionalLogPausedState(), config_, isc::util::StateModel::doOnEntry(), isc::util::StateModel::getLastEvent(), isc::ha::HA_COMMUNICATION_RECOVERY_ST, isc::ha::HA_HOT_STANDBY_ST, isc::ha::HA_LOAD_BALANCING_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, isc::ha::HA_TERMINATED_ST, isc::ha::HA_WAITING_ST, isMaintenanceCanceled(), isc::util::StateModel::isModelPaused(), isPartnerStateInvalid(), isc::ha::HAConfig::LOAD_BALANCING, 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().
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 504 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().
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 543 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().
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 2833 of file ha_service.cc.
References client_, isc::ha::ha_logger, isc::ha::HA_PAUSE_CLIENT_LISTENER_FAILED, listener_, and LOG_ERROR.
Referenced by startClientAndListener().
|
protected |
Get the number of entries in the pending request map.
Definition at line 2786 of file ha_service.cc.
ConstElementPtr isc::ha::HAService::processContinue | ( | ) |
Processes ha-continue command and returns a response.
Definition at line 2411 of file ha_service.cc.
References isc::config::CONTROL_RESULT_SUCCESS, isc::config::createAnswer(), and unpause().
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 1569 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().
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 1549 of file ha_service.cc.
References 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().
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 2585 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().
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 2419 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().
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 2455 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().
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 2398 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().
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 1500 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().
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 2125 of file ha_service.cc.
References isc::config::createAnswer(), and synchronize().
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 561 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().
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 2851 of file ha_service.cc.
References client_, isc::ha::ha_logger, isc::ha::HA_RESUME_CLIENT_LISTENER_FAILED, listener_, and LOG_ERROR.
Referenced by startClientAndListener().
|
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 1701 of file ha_service.cc.
References communication_state_, and startHeartbeat().
Referenced by communicationRecoveryHandler(), inMaintenanceStateHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().
|
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 2379 of file ha_service.cc.
References asyncSendHAReset(), config_, isc::asiolink::IOService::run(), and isc::asiolink::IOService::stop().
Referenced by communicationRecoveryHandler().
|
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 2288 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().
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 960 of file ha_service.cc.
References query_filter_, and isc::ha::QueryFilter::serveDefaultScopes().
|
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 1027 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(), normalStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().
|
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 1435 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().
|
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 1403 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(), and verboseTransition().
|
protected |
Indicates if the server should transition to the terminated state as a result of high clock skew.
It indicates that the server should transition to the terminated state because of the clock skew being too high. 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.
Definition at line 1054 of file ha_service.cc.
References communication_state_.
Referenced by communicationRecoveryHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().
|
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 2770 of file ha_service.cc.
References client_.
Referenced by clientConnectHandler().
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 2817 of file ha_service.cc.
References client_, listener_, pauseClientAndListener(), and resumeClientAndListener().
|
protected |
Unconditionally starts one heartbeat to a peer.
Definition at line 1708 of file ha_service.cc.
References asyncSendHeartbeat(), communication_state_, and config_.
Referenced by asyncSendHeartbeat(), and scheduleHeartbeat().
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 2869 of file ha_service.cc.
References client_, and listener_.
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.
This method creates its own instances of the HttpClient and IOService and invokes IOService::run().
[out] | status_message | status message in textual form. |
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 2133 of file ha_service.cc.
References asyncEnableDHCPService(), asyncSyncLeases(), 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 processSynchronize(), and 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 640 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().
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.
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 729 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().
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 939 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 processContinue().
|
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 1249 of file ha_service.cc.
Referenced by asyncSendLeaseUpdate().
|
protected |
Transitions to a desired state and logs it.
state | the new value to assign to the current state. |
Definition at line 858 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().
Referenced by communicationRecoveryHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), processHAReset(), processMaintenanceCancel(), processMaintenanceNotify(), processMaintenanceStart(), readyStateHandler(), syncingStateHandler(), and waitingStateHandler().
|
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. |
Definition at line 2681 of file ha_service.cc.
References isc::config::CONTROL_RESULT, 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(), asyncSyncLeasesInternal(), processMaintenanceCancel(), and processMaintenanceStart().
|
virtual |
Verifies events used by the HA service.
Reimplemented from isc::util::StateModel.
Definition at line 129 of file ha_service.cc.
References isc::util::StateModel::getEvent(), HA_HEARTBEAT_COMPLETE_EVT, HA_LEASE_UPDATES_COMPLETE_EVT, HA_MAINTENANCE_CANCEL_EVT, HA_MAINTENANCE_NOTIFY_EVT, HA_MAINTENANCE_START_EVT, HA_SYNCING_FAILED_EVT, and HA_SYNCING_SUCCEEDED_EVT.
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 750 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().
|
protected |
HTTP client instance used to send HA commands and lease updates.
Definition at line 1112 of file ha_service.h.
Referenced by asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncLeases(), clientConnectHandler(), HAService(), pauseClientAndListener(), resumeClientAndListener(), socketReadyHandler(), startClientAndListener(), and stopClientAndListener().
|
protected |
Holds communication state with a peer.
Definition at line 1119 of file ha_service.h.
Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSyncLeasesInternal(), communicationRecoveryHandler(), getPartnerState(), HAService(), isPartnerStateInvalid(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), passiveBackupStateHandler(), processMaintenanceCancel(), processMaintenanceStart(), processStatusGet(), readyStateHandler(), scheduleHeartbeat(), shouldPartnerDown(), shouldTerminate(), startHeartbeat(), syncingStateHandler(), terminatedStateHandler(), verboseTransition(), and waitingStateHandler().
|
protected |
Pointer to the HA hooks library configuration.
Definition at line 1106 of file ha_service.h.
Referenced by adjustNetworkState(), asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHeartbeat(), asyncSendLeaseUpdate(), asyncSendLeaseUpdates(), asyncSyncLeases(), asyncSyncLeasesInternal(), defineStates(), getNormalState(), HAService(), isPartnerStateInvalid(), normalStateHandler(), partnerDownStateHandler(), processMaintenanceCancel(), processMaintenanceStart(), processStatusGet(), readyStateHandler(), sendHAReset(), sendLeaseUpdatesFromBacklog(), shouldPartnerDown(), shouldQueueLeaseUpdates(), shouldSendLeaseUpdates(), startHeartbeat(), syncingStateHandler(), verboseTransition(), and waitingStateHandler().
|
static |
Control result returned in response to ha-maintenance-notify.
Definition at line 68 of file ha_service.h.
Referenced by processMaintenanceNotify().
|
static |
Finished heartbeat command.
Definition at line 47 of file ha_service.h.
Referenced by asyncSendHeartbeat(), defineEvents(), and verifyEvents().
|
static |
Finished lease updates commands.
Definition at line 50 of file ha_service.h.
Referenced by asyncSendLeaseUpdate(), defineEvents(), and verifyEvents().
|
static |
ha-maintenance-cancel command received.
Definition at line 65 of file ha_service.h.
Referenced by defineEvents(), isMaintenanceCanceled(), processMaintenanceCancel(), processMaintenanceNotify(), and verifyEvents().
|
static |
ha-maintenance-notify command received.
Definition at line 59 of file ha_service.h.
Referenced by defineEvents(), processMaintenanceNotify(), and verifyEvents().
|
static |
ha-maintenance-start command received.
Definition at line 62 of file ha_service.h.
Referenced by defineEvents(), partnerDownStateHandler(), processMaintenanceStart(), and verifyEvents().
|
static |
Lease database synchronization failed.
Definition at line 53 of file ha_service.h.
Referenced by defineEvents(), synchronize(), and verifyEvents().
|
static |
Lease database synchronization succeeded.
Definition at line 56 of file ha_service.h.
Referenced by defineEvents(), synchronize(), and verifyEvents().
|
protected |
Pointer to the IO service object shared between this hooks library and the DHCP server.
Definition at line 1100 of file ha_service.h.
Referenced by HAService().
|
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 1236 of file ha_service.h.
Referenced by asyncSendLeaseUpdates(), asyncSendLeaseUpdatesFromBacklog(), communicationRecoveryHandler(), and sendLeaseUpdatesFromBacklog().
|
protected |
HTTP listener instance used to receive and respond to HA commands and lease updates.
Definition at line 1116 of file ha_service.h.
Referenced by HAService(), pauseClientAndListener(), resumeClientAndListener(), startClientAndListener(), and stopClientAndListener().
|
protected |
Pointer to the state of the DHCP service (enabled/disabled).
Definition at line 1103 of file ha_service.h.
Referenced by adjustNetworkState(), HAService(), localDisableDHCPService(), localEnableDHCPService(), shouldPartnerDown(), and ~HAService().
|
protected |
Selects queries to be processed/dropped.
Definition at line 1122 of file ha_service.h.
Referenced by backupStateHandler(), communicationRecoveryHandler(), inMaintenanceStateHandler(), normalStateHandler(), partnerDownStateHandler(), partnerInMaintenanceStateHandler(), passiveBackupStateHandler(), processHeartbeat(), processScopes(), processStatusGet(), readyStateHandler(), serveDefaultScopes(), syncingStateHandler(), terminatedStateHandler(), and waitingStateHandler().
|
protected |
DHCP server type.
Definition at line 1109 of file ha_service.h.
Referenced by asyncDisableDHCPService(), asyncEnableDHCPService(), asyncSendHAReset(), asyncSendHeartbeat(), asyncSendLeaseUpdatesFromBacklog(), asyncSyncLeasesInternal(), getServerType(), processMaintenanceCancel(), and processMaintenanceStart().