Skip to content

Commit

Permalink
clusterer: properly set status/report all queued sync requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Jul 13, 2022
1 parent 816ef38 commit e8d1407
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions modules/clusterer/sync.c
Expand Up @@ -89,6 +89,24 @@ static int get_sync_source(cluster_info_t *cluster, str *capability,
return 0;
}

int queue_sync_request(cluster_info_t *cluster, struct local_cap *lcap)
{
lock_get(cluster->lock);
lcap->flags |= CAP_SYNC_PENDING;

if (cluster->current_node->flags & NODE_IS_SEED)
gettimeofday(&lcap->sync_req_time, NULL);

lock_release(cluster->lock);

sr_set_status(cl_srg, STR2CI(lcap->reg.sr_id), CAP_SR_SYNC_PENDING,
STR2CI(CAP_SR_STATUS_STR(CAP_SR_SYNC_PENDING)), 0);
if (sr_add_report_fmt(cl_srg, STR2CI(lcap->reg.sr_id), 0, "Sync requested"))
return -1;

return 0;
}

int cl_request_sync(str *capability, int cluster_id)
{
cluster_info_t *cluster;
Expand Down Expand Up @@ -147,30 +165,14 @@ int cl_request_sync(str *capability, int cluster_id)
if (source_id == 0) { /* we didn't find any node ready to sync from */
LM_DBG("donor node not found\n");
/* send requst later */
lock_get(cluster->lock);
lcap->flags |= CAP_SYNC_PENDING;

if (cluster->current_node->flags & NODE_IS_SEED)
gettimeofday(&lcap->sync_req_time, NULL);

lock_release(cluster->lock);

sr_set_status(cl_srg, STR2CI(lcap->reg.sr_id), CAP_SR_SYNC_PENDING,
STR2CI(CAP_SR_STATUS_STR(CAP_SR_SYNC_PENDING)), 0);
if (sr_add_report_fmt(cl_srg, STR2CI(lcap->reg.sr_id), 0,
"Sync requested"))
return -1;
queue_sync_request(cluster, lcap);
} else {
LM_DBG("found donor node: %d\n", source_id);
rc = send_sync_req(capability, cluster_id, source_id);
if (rc == CLUSTERER_DEST_DOWN || rc == CLUSTERER_CURR_DISABLED) {
/* node was up and ready but in the meantime got disabled or down */
lock_get(cluster->lock);
lcap->flags |= CAP_SYNC_PENDING;

if (cluster->current_node->flags & NODE_IS_SEED)
gettimeofday(&lcap->sync_req_time, NULL);
lock_release(cluster->lock);
/* node was up and ready but in the meantime got disabled or down,
* retry requst later */
queue_sync_request(cluster, lcap);
} else if (rc == CLUSTERER_SEND_ERR) {
return -1;
} else {
Expand Down

0 comments on commit e8d1407

Please sign in to comment.