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

@@ -78,7 +78,7 @@ static void statsmaker(void *data, struct stasis_subscription *sub,
}
/*!
* \brief Router callback for \ref stasis_cache_update messages.
* \brief Router callback for \ref ast_channel_snapshot_update messages.
* \param data Data pointer given when added to router.
* \param sub This subscription.
* \param topic The topic the message was posted to. This is not necessarily the
@@ -92,34 +92,25 @@ static void updates(void *data, struct stasis_subscription *sub,
/* Since this came from a message router, we know the type of the
* message. We can cast the data without checking its type.
*/
struct stasis_cache_update *update = stasis_message_data(message);
struct ast_channel_snapshot_update *update = stasis_message_data(message);
/* We're only interested in channel snapshots, so check the type
* of the underlying message.
*/
if (ast_channel_snapshot_type() != update->type) {
return;
}
/* There are three types of cache updates.
* !old && new -> Initial cache entry
* old && new -> Updated cache entry
* old && !new -> Cache entry removed.
/* There are three types of channel snapshot updates.
* !old && new -> Initial channel creation
* old && new -> Updated channel snapshot
* old && dead -> Final channel snapshot
*/
if (!update->old_snapshot && update->new_snapshot) {
/* Initial cache entry; count a channel creation */
/* Initial channel snapshot; count a channel creation */
ast_statsd_log_string("channels.count", AST_STATSD_GAUGE, "+1", 1.0);
} else if (update->old_snapshot && !update->new_snapshot) {
/* Cache entry removed. Compute the age of the channel and post
} else if (update->old_snapshot && ast_test_flag(&update->new_snapshot->flags, AST_FLAG_DEAD)) {
/* Channel is gone. Compute the age of the channel and post
* that, as well as decrementing the channel count.
*/
struct ast_channel_snapshot *last;
int64_t age;
last = stasis_message_data(update->old_snapshot);
age = ast_tvdiff_ms(*stasis_message_timestamp(message),
last->creationtime);
update->new_snapshot->creationtime);
ast_statsd_log("channels.calltime", AST_STATSD_TIMER, age);
/* And decrement the channel count */
@@ -161,11 +152,11 @@ static int load_module(void)
{
/* You can create a message router to route messages by type */
router = stasis_message_router_create(
ast_channel_topic_all_cached());
ast_channel_topic_all());
if (!router) {
return AST_MODULE_LOAD_DECLINE;
}
stasis_message_router_add(router, stasis_cache_update_type(),
stasis_message_router_add(router, ast_channel_snapshot_type(),
updates, NULL);
stasis_message_router_set_default(router, default_route, NULL);