#include <stdlib.h>
#include <string.h>
#include <jnx/aux_types.h>
#include <jnx/trace.h>
#include <jnx/junos_trace.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "hellopics-mgmt_logging.h"
#include "hellopics-mgmt_conn.h"
#include "hellopics-mgmt_ha.h"
#include <jnx/junos_sync.h>
Go to the source code of this file.
Defines | |
#define | HELLOPICS_HA_REPLICATION_PORT 39089 |
port # to use for messaging | |
#define | HELLOPICS_HA_REPLICATION_KA 30 |
keepalive message interval | |
Functions | |
void | update_hellopics_statistics (hellopics_stats_t *data) |
static void | replication_data_hton (hellopics_stats_t *data) |
static void | replication_data_ntoh (hellopics_stats_t *data) |
static void | ack_notify (junos_sync_tlv_t *data UNUSED, size_t len UNUSED) |
static void | decode (void *data, size_t len) |
static void * | get_next (void *current __unused, junos_sync_getnext_data_t *gndata __unused) |
static void | conn_status_change (junos_sync_conn_status_t conn_status) |
static void | init_sync_done (size_t num_of_entries_synced) |
static void | bind_done (in_port_t port) |
static void | log_msg (const char *format,...) |
static void | db_clear (void) |
status_t | init_replication (in_addr_t master_address) |
void | update_replication_entry (hellopics_stats_t *data) |
void | stop_replication (void) |
void | set_mastership (boolean state, in_addr_t master_addr) |
Variables | |
static junos_sync_state_t | rep_state |
replication state | |
static junos_sync_callbacks_t | rep_callbacks |
replication callbacks | |
static junos_sync_context_t * | rep_ctx |
replication API context | |
volatile boolean | is_master |
hellopics_stats_t | hellopics_stats |
global message stats | |
evContext | present_ctx |
These functions will manage the packet statistics replication for a master/slave management component.
Definition in file hellopics-mgmt_ha.c.
static void ack_notify | ( | junos_sync_tlv_t *data | UNUSED, | |
size_t len | UNUSED | |||
) | [static] |
Callback when an acknolewedgement is received
[in] | data | The TLV data ack'd |
[in] | len | The TLV data's length |
Definition at line 96 of file hellopics-mgmt_ha.c.
References LOG.
Referenced by init_replication().
static void bind_done | ( | in_port_t | port | ) | [static] |
Callback to notify application that the master finished binding
[in] | port | Free port on which it bound itself |
Definition at line 176 of file hellopics-mgmt_ha.c.
References HELLOPICS_HA_REPLICATION_PORT, and LOG.
Referenced by init_replication().
static void conn_status_change | ( | junos_sync_conn_status_t | conn_status | ) | [static] |
Callback to notify that the connection's status has changed
[in] | conn_status | Number of entries / messages passed in initial replication |
Definition at line 148 of file hellopics-mgmt_ha.c.
References LOG.
Referenced by init_replication().
static void db_clear | ( | void | ) | [static] |
Callback to clean up the backup database
Definition at line 209 of file hellopics-mgmt_ha.c.
References LOG.
Referenced by init_replication().
static void decode | ( | void * | data, | |
size_t | len | |||
) | [static] |
Callback when a data record is received and need to be decoded and added to the backup database
[in] | data | data to be decoded |
[out] | len | length of data |
Definition at line 113 of file hellopics-mgmt_ha.c.
References LOG, rep_state, replication_data_ntoh(), and update_hellopics_statistics().
Referenced by init_replication().
static void* get_next | ( | void *current | __unused, | |
junos_sync_getnext_data_t *gndata | __unused | |||
) | [static] |
Iterator callback to get the next data in application's database. Called during the initial (re-)sync.
[in] | current | Null for first item, otherwise the item before the next one returned This could be the last item returned (works iterator-style). |
[out] | gndata | The struct containing the TLV. We popluate data with an allocated copy of the replication data to send |
Definition at line 135 of file hellopics-mgmt_ha.c.
Referenced by init_replication().
status_t init_replication | ( | in_addr_t | master_address | ) |
Init the data structures that will store configuration info
[in] | master_address | Address of master, or 0 if this is the master |
Definition at line 228 of file hellopics-mgmt_ha.c.
References ack_notify(), bind_done(), conn_status_change(), db_clear(), decode(), get_next(), HELLOPICS_HA_REPLICATION_KA, HELLOPICS_HA_REPLICATION_PORT, init_sync_done(), LOG, log_msg(), present_ctx, rep_callbacks, rep_ctx, and rep_state.
Referenced by set_mastership().
static void init_sync_done | ( | size_t | num_of_entries_synced | ) | [static] |
Callback to notify that the initial synchronization is done
[in] | num_of_entries_synced | Number of entries / messages passed in initial replication |
Definition at line 162 of file hellopics-mgmt_ha.c.
References LOG.
Referenced by init_replication().
static void log_msg | ( | const char * | format, | |
... | ||||
) | [static] |
Callback to log a message
[in] | format | message to log |
Definition at line 196 of file hellopics-mgmt_ha.c.
Referenced by init_replication().
static void replication_data_hton | ( | hellopics_stats_t * | data | ) | [static] |
Perform necessary host to network byte-order swaps
[in,out] | data | replication data |
Definition at line 60 of file hellopics-mgmt_ha.c.
References hellopics_stats_s::msgs_badorder, hellopics_stats_s::msgs_missed, hellopics_stats_s::msgs_received, and hellopics_stats_s::msgs_sent.
Referenced by update_replication_entry().
static void replication_data_ntoh | ( | hellopics_stats_t * | data | ) | [static] |
Perform necessary network to host byte-order swaps
[in,out] | data | replication data |
Definition at line 76 of file hellopics-mgmt_ha.c.
References hellopics_stats_s::msgs_badorder, hellopics_stats_s::msgs_missed, hellopics_stats_s::msgs_received, and hellopics_stats_s::msgs_sent.
Referenced by decode().
void set_mastership | ( | boolean | state, | |
in_addr_t | master_addr | |||
) |
Configure mastership of this data component
[in] | state | Mastership state (T=Master, F=Slave) |
[in] | master_addr | Master address (only present if state=F/slave) |
Definition at line 353 of file hellopics-mgmt_ha.c.
References init_replication(), and is_master.
Referenced by init_config().
void stop_replication | ( | void | ) |
Stop and shutdown all the replication subsystem
Definition at line 319 of file hellopics-mgmt_ha.c.
References rep_ctx.
void update_hellopics_statistics | ( | hellopics_stats_t * | data | ) |
Function called in backup daemon to update the state received from the master
[in] | data | Data received from the master |
Definition at line 331 of file hellopics-mgmt_ha.c.
References hellopics_stats, LOG, hellopics_stats_s::msgs_badorder, hellopics_stats_s::msgs_missed, hellopics_stats_s::msgs_received, and hellopics_stats_s::msgs_sent.
Referenced by decode().
void update_replication_entry | ( | hellopics_stats_t * | data | ) |
Pass replication data to add or update to the slave
[in] | data | The data to replicate to the slave |
Definition at line 287 of file hellopics-mgmt_ha.c.
References LOG, rep_ctx, and replication_data_hton().
Referenced by receive_message(), and sendHelloMessage().