stasis: Use an implementation specific channel snapshot cache.

Channels no longer use the Stasis cache for channel snapshots. Instead
they are stored in a hash table in stasis_channels which reduces the
number of Stasis messages created and allows better storage.

As a result the following APIs are no longer available since the stasis
cache is no longer used:
ast_channel_topic_cached()
ast_channel_topic_all_cached()

The ast_channel_cache_all() and ast_channel_cache_by_name() functions
now return an ao2_container of ast_channel_snapshots rather than
a container of stasis_messages therefore you can't (and don't need
to) call stasis_cache functions on it.

The ast_channel_topic_all() function now returns a normal topic not
a cached one so you can't use stasis cache functions on it either.

The ast_channel_snapshot_type() stasis message now has the
ast_channel_snapshot_update structure as it's data. It contains the
last snapshot and the new one.

ast_channel_snapshot_get_latest() still returns the latest snapshot.

The latest snapshot is now stored on the channel itself to eliminate
cache hits when Stasis messages that have the snapshot as a payload
are created.

ASTERISK-28102

Change-Id: I9334febff60a82d7c39703e49059fa3a68825786
This commit is contained in:
Joshua Colp
2018-10-10 11:28:18 -03:00
parent 0a60bc1a68
commit d0ccbb3377
28 changed files with 456 additions and 551 deletions

View File

@@ -888,14 +888,6 @@ static void cel_channel_state_change(
{
int is_hungup, was_hungup;
if (!new_snapshot) {
cel_report_event(old_snapshot, AST_CEL_CHANNEL_END, NULL, NULL, NULL);
if (ast_cel_track_event(AST_CEL_LINKEDID_END)) {
check_retire_linkedid(old_snapshot);
}
return;
}
if (!old_snapshot) {
cel_report_event(new_snapshot, AST_CEL_CHANNEL_START, NULL, NULL, NULL);
return;
@@ -915,6 +907,11 @@ static void cel_channel_state_change(
cel_report_event(new_snapshot, AST_CEL_HANGUP, NULL, extra, NULL);
ast_json_unref(extra);
ao2_cleanup(dialstatus);
cel_report_event(new_snapshot, AST_CEL_CHANNEL_END, NULL, NULL, NULL);
if (ast_cel_track_event(AST_CEL_LINKEDID_END)) {
check_retire_linkedid(new_snapshot);
}
return;
}
@@ -928,7 +925,7 @@ static void cel_channel_linkedid_change(
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot)
{
if (!old_snapshot || !new_snapshot) {
if (!old_snapshot) {
return;
}
@@ -946,8 +943,7 @@ static void cel_channel_app_change(
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot)
{
if (new_snapshot && old_snapshot
&& !strcmp(old_snapshot->appl, new_snapshot->appl)) {
if (old_snapshot && !strcmp(old_snapshot->appl, new_snapshot->appl)) {
return;
}
@@ -957,7 +953,7 @@ static void cel_channel_app_change(
}
/* new snapshot has an application, start it */
if (new_snapshot && !ast_strlen_zero(new_snapshot->appl)) {
if (!ast_strlen_zero(new_snapshot->appl)) {
cel_report_event(new_snapshot, AST_CEL_APP_START, NULL, NULL, NULL);
}
}
@@ -984,22 +980,15 @@ static int cel_filter_channel_snapshot(struct ast_channel_snapshot *snapshot)
static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
struct stasis_message *message)
{
struct stasis_cache_update *update = stasis_message_data(message);
if (ast_channel_snapshot_type() == update->type) {
struct ast_channel_snapshot *old_snapshot;
struct ast_channel_snapshot *new_snapshot;
size_t i;
struct ast_channel_snapshot_update *update = stasis_message_data(message);
size_t i;
old_snapshot = stasis_message_data(update->old_snapshot);
new_snapshot = stasis_message_data(update->new_snapshot);
if (cel_filter_channel_snapshot(update->old_snapshot) || cel_filter_channel_snapshot(update->new_snapshot)) {
return;
}
if (cel_filter_channel_snapshot(old_snapshot) || cel_filter_channel_snapshot(new_snapshot)) {
return;
}
for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
cel_channel_monitors[i](old_snapshot, new_snapshot);
}
for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
cel_channel_monitors[i](update->old_snapshot, update->new_snapshot);
}
}
@@ -1453,7 +1442,7 @@ static int create_subscriptions(void)
}
cel_channel_forwarder = stasis_forward_all(
ast_channel_topic_all_cached(),
ast_channel_topic_all(),
cel_aggregation_topic);
if (!cel_channel_forwarder) {
return -1;
@@ -1498,7 +1487,7 @@ static int create_routes(void)
6 * AST_TASKPROCESSOR_HIGH_WATER_LEVEL);
ret |= stasis_message_router_add(cel_state_router,
stasis_cache_update_type(),
ast_channel_snapshot_type(),
cel_snapshot_update_cb,
NULL);