mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 10:20:04 +00:00
use max count not max delay time for backoff
This commit is contained in:
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- Added log for time difference of parodus connect time and boot time
|
||||
- added NULL check for device mac id in upstream retrieve message handling
|
||||
- backoff retry to include find_servers in loop (connection.c)
|
||||
- backoff max is max count not max delay
|
||||
|
||||
## [1.0.1] - 2018-07-18
|
||||
### Added
|
||||
|
||||
@@ -106,7 +106,8 @@ typedef struct {
|
||||
|
||||
//--- Used in connection.c for backoff delay timer
|
||||
typedef struct {
|
||||
int max_delay;
|
||||
int count;
|
||||
int max_count;
|
||||
int delay;
|
||||
} backoff_timer_t;
|
||||
|
||||
|
||||
@@ -192,19 +192,20 @@ int check_timer_expired (expire_timer_t *timer, long timeout_ms)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
void init_backoff_timer (backoff_timer_t *timer, int max_delay)
|
||||
void init_backoff_timer (backoff_timer_t *timer, int max_count)
|
||||
{
|
||||
timer->max_delay = max_delay;
|
||||
timer->count = 1;
|
||||
timer->max_count = max_count;
|
||||
timer->delay = 1;
|
||||
}
|
||||
|
||||
int update_backoff_delay (backoff_timer_t *timer)
|
||||
{
|
||||
if (timer->delay < timer->max_delay)
|
||||
if (timer->count < timer->max_count) {
|
||||
timer->count += 1;
|
||||
timer->delay = timer->delay + timer->delay + 1;
|
||||
// 3,7,15,31 ..
|
||||
if (timer->delay > timer->max_delay)
|
||||
timer->delay = timer->max_delay;
|
||||
}
|
||||
return timer->delay;
|
||||
}
|
||||
|
||||
@@ -531,7 +532,7 @@ int keep_trying_to_connect (create_connection_ctx_t *ctx,
|
||||
int createNopollConnection(noPollCtx *ctx)
|
||||
{
|
||||
create_connection_ctx_t conn_ctx;
|
||||
int max_retry_sleep;
|
||||
int max_retry_count;
|
||||
int query_dns_status;
|
||||
struct timespec connect_time,*connectTimePtr;
|
||||
connectTimePtr = &connect_time;
|
||||
@@ -545,15 +546,15 @@ int createNopollConnection(noPollCtx *ctx)
|
||||
ParodusInfo("Received reboot_reason as:%s\n", get_parodus_cfg()->hw_last_reboot_reason);
|
||||
ParodusInfo("Received reconnect_reason as:%s\n", reconnect_reason);
|
||||
|
||||
max_retry_sleep = (int) get_parodus_cfg()->webpa_backoff_max;
|
||||
ParodusPrint("max_retry_sleep is %d\n", max_retry_sleep );
|
||||
max_retry_count = (int) get_parodus_cfg()->webpa_backoff_max;
|
||||
ParodusPrint("max_retry_count is %d\n", max_retry_count );
|
||||
|
||||
conn_ctx.nopoll_ctx = ctx;
|
||||
init_expire_timer (&conn_ctx.connect_timer);
|
||||
init_header_info (&conn_ctx.header_info);
|
||||
set_extra_headers (&conn_ctx, false);
|
||||
set_server_list_null (&conn_ctx.server_list);
|
||||
init_backoff_timer (&backoff_timer, max_retry_sleep);
|
||||
init_backoff_timer (&backoff_timer, max_retry_count);
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ extern server_t *get_current_server (server_list_t *server_list);
|
||||
extern int parse_server_url (const char *full_url, server_t *server);
|
||||
extern void init_expire_timer (expire_timer_t *timer);
|
||||
extern int check_timer_expired (expire_timer_t *timer, long timeout_ms);
|
||||
extern void init_backoff_timer (backoff_timer_t *timer, int max_delay);
|
||||
extern void init_backoff_timer (backoff_timer_t *timer, int max_count);
|
||||
extern int update_backoff_delay (backoff_timer_t *timer);
|
||||
extern int init_header_info (header_info_t *header_info);
|
||||
extern void free_header_info (header_info_t *header_info);
|
||||
@@ -301,12 +301,12 @@ void test_expire_timer()
|
||||
void test_backoff_delay_timer()
|
||||
{
|
||||
backoff_timer_t btimer;
|
||||
init_backoff_timer (&btimer, 30);
|
||||
init_backoff_timer (&btimer, 5);
|
||||
assert_int_equal (3, update_backoff_delay (&btimer));
|
||||
assert_int_equal (7, update_backoff_delay (&btimer));
|
||||
assert_int_equal (15, update_backoff_delay (&btimer));
|
||||
assert_int_equal (30, update_backoff_delay (&btimer));
|
||||
assert_int_equal (30, update_backoff_delay (&btimer));
|
||||
assert_int_equal (31, update_backoff_delay (&btimer));
|
||||
assert_int_equal (31, update_backoff_delay (&btimer));
|
||||
}
|
||||
|
||||
|
||||
@@ -823,7 +823,7 @@ void test_keep_trying ()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
init_backoff_timer (&backoff_timer, 30);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, true);
|
||||
|
||||
@@ -847,7 +847,7 @@ void test_keep_trying ()
|
||||
expect_function_call (nopoll_conn_is_ok);
|
||||
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
init_backoff_timer (&backoff_timer, 30);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, true);
|
||||
|
||||
@@ -869,7 +869,7 @@ void test_keep_trying ()
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
init_backoff_timer (&backoff_timer, 30);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, false);
|
||||
|
||||
@@ -878,7 +878,7 @@ void test_keep_trying ()
|
||||
expect_function_call (nopoll_conn_tls_new);
|
||||
will_return (checkHostIp, 0);
|
||||
expect_function_call (checkHostIp);
|
||||
init_backoff_timer (&backoff_timer, 30);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, false);
|
||||
|
||||
@@ -893,7 +893,7 @@ void test_keep_trying ()
|
||||
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
|
||||
will_return (nopoll_conn_ref_count, 0);
|
||||
expect_function_call (nopoll_conn_ref_count);
|
||||
init_backoff_timer (&backoff_timer, 30);
|
||||
init_backoff_timer (&backoff_timer, 5);
|
||||
rtn = keep_trying_to_connect (&ctx, &backoff_timer);
|
||||
assert_int_equal (rtn, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user