Skip to content

Commit

Permalink
usrloc: Add urecord reference counting mechanism
Browse files Browse the repository at this point in the history
This mechanism is required by the mid-registrar, which needs to
"reserve" contact IDs while the main registrar decides upon them.
This means that a blank urecord structure must be kept alive during
this process.

By reference counting the blank urecord structures, we prevent them
from being cleared by the timer before the outgoing registrations
get a chance to receive a reply.

(cherry picked from commit ad274fa)
  • Loading branch information
liviuchircu committed Jan 17, 2018
1 parent b2554c3 commit 3a079a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions modules/usrloc/udomain.c
Expand Up @@ -1156,7 +1156,7 @@ int mem_timer_udomain(udomain_t* _d)
flush=1;

/* Remove the entire record if it is empty */
if (ptr->contacts == NULL)
if (ptr->no_clear_ref <= 0 && ptr->contacts == NULL)
{
if (exists_ulcb_type(UL_AOR_EXPIRE))
run_ul_callbacks(UL_AOR_EXPIRE, ptr);
Expand Down Expand Up @@ -1349,9 +1349,6 @@ int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r,
}
}

if (!is_replicated && ul_replicate_cluster)
replicate_urecord_delete(_r);

c = _r->contacts;
while(c) {
t = c;
Expand All @@ -1361,6 +1358,13 @@ int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r,
return -1;
}
}

if (_r->no_clear_ref > 0)
return 0;

if (!is_replicated && ul_replicate_cluster)
replicate_urecord_delete(_r);

release_urecord(_r, is_replicated);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/usrloc/urecord.c
Expand Up @@ -481,7 +481,7 @@ void release_urecord(urecord_t* _r, char is_replicated)
LM_ERR("failed to sync with db\n");
/* now simply free everything */
free_urecord(_r);
} else if (_r->contacts == 0) {
} else if (_r->no_clear_ref <= 0 && _r->contacts == 0) {
if (exists_ulcb_type(UL_AOR_DELETE))
run_ul_callbacks(UL_AOR_DELETE, _r);

Expand Down
3 changes: 2 additions & 1 deletion modules/usrloc/urecord.h
Expand Up @@ -53,12 +53,13 @@ typedef struct urecord {
str aor; /*!< Address of record */
unsigned int aorhash; /*!< Hash over address of record */
unsigned int label; /*!< Labels over AVL tree */
unsigned short next_clabel; /*!< Labels to be assigned to contacts */
unsigned short next_clabel; /*!< Labels to be assigned to contacts */
ucontact_t* contacts; /*!< One or more contact fields */

struct hslot* slot; /*!< Collision slot in the hash table
* array we belong to */

int no_clear_ref; /*!< Keep the record while positive */
void **attached_data; /*!< data attached by API subscribers >*/
} urecord_t;

Expand Down

0 comments on commit 3a079a7

Please sign in to comment.