Change all table calls to use default retry behavior. (#312)

* Change all table calls to use default retry behavior and change default retry behavior.

* Add warning for table retries.
This commit is contained in:
Robert Nishihara
2017-02-24 12:41:32 -08:00
committed by Stephanie Wang
parent aa174e6311
commit 232601f90d
8 changed files with 48 additions and 104 deletions
+13 -15
View File
@@ -3,16 +3,10 @@
#include <inttypes.h>
#include "redis.h"
void default_table_failure_callback(object_id id,
void *user_context,
void *user_data) {
CHECKM(0, "default_table_failure_callback was called.");
}
static const retry_info default_retry = {
.num_retries = 0,
.timeout = 1000,
.fail_callback = default_table_failure_callback};
/* The default behavior is to retry every ten seconds forever. */
static const retry_info default_retry = {.num_retries = -1,
.timeout = 10000,
.fail_callback = NULL};
table_callback_data *init_table_callback(db_handle *db_handle,
unique_id id,
@@ -84,9 +78,10 @@ int64_t table_timeout_handler(event_loop *loop,
CHECK(user_context != NULL);
table_callback_data *callback_data = (table_callback_data *) user_context;
CHECK(callback_data->retry.num_retries >= 0)
LOG_DEBUG("retrying operation, retry_count = %d",
callback_data->retry.num_retries);
CHECK(callback_data->retry.num_retries >= 0 ||
callback_data->retry.num_retries == -1);
LOG_WARN("retrying operation, retry_count = %d",
callback_data->retry.num_retries);
if (callback_data->retry.num_retries == 0) {
/* We didn't get a response from the database after exhausting all retries;
@@ -101,8 +96,11 @@ int64_t table_timeout_handler(event_loop *loop,
return EVENT_LOOP_TIMER_DONE;
}
/* Decrement retry count and try again. */
callback_data->retry.num_retries--;
/* Decrement retry count and try again. We use -1 to indicate infinite
* retries. */
if (callback_data->retry.num_retries != -1) {
callback_data->retry.num_retries--;
}
callback_data->retry_callback(callback_data);
return callback_data->retry.timeout;
}
+6 -2
View File
@@ -29,10 +29,14 @@ typedef void (*table_fail_callback)(unique_id id,
typedef void (*table_retry_callback)(table_callback_data *callback_data);
/**
* Data structure consolidating the retry related varaibles.
* Data structure consolidating the retry related variables. If a NULL
* retry_info struct is used, the default behavior will be to retry infinitely
* many times.
*/
typedef struct {
/** Number of retries left. */
/** Number of retries. This field will be decremented every time a retry
* occurs (unless the value is -1). If this value is -1, then there will be
* infinitely many retries. */
int num_retries;
/** Timeout, in milliseconds. */
uint64_t timeout;