[svn-commits] dlee: branch dlee/stasis-cache-split r394157 - in /team/dlee/stasis-cache-spl...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Jul 11 16:01:02 CDT 2013
Author: dlee
Date: Thu Jul 11 16:01:00 2013
New Revision: 394157
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394157
Log:
Secondary caches were pretty much a bad idea.
Modified:
team/dlee/stasis-cache-split/include/asterisk/stasis.h
team/dlee/stasis-cache-split/main/stasis_cache.c
team/dlee/stasis-cache-split/main/stasis_channels.c
Modified: team/dlee/stasis-cache-split/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/include/asterisk/stasis.h?view=diff&rev=394157&r1=394156&r2=394157
==============================================================================
--- team/dlee/stasis-cache-split/include/asterisk/stasis.h (original)
+++ team/dlee/stasis-cache-split/include/asterisk/stasis.h Thu Jul 11 16:01:00 2013
@@ -647,24 +647,6 @@
struct stasis_topic *original_topic, struct stasis_cache *cache);
/*!
- * \brief Create a secondary cache off, indexed by a different field.
- *
- * The secondary cache should identify objects by a different field than the
- * primary cache. This is useful when snapshots may have multiple unique
- * identifiers (such as \ref ast_channel's uniqueid and name), and may be looked
- * up by either.
- *
- * The returned object is AO2 managed, so ao2_cleanup() when done with it.
- *
- * \param primary_cache Primary cache.
- * \param id_fn Identity function for the secondary cache.
- * \return Secondary cache
- * \return \c NULL on error
- */
-struct stasis_cache *stasis_cache_create_secondary(
- struct stasis_cache *primary_cache, snapshot_get_id id_fn);
-
-/*!
* \brief Unsubscribes a caching topic from its upstream topic.
*
* This function returns immediately, so be sure to cleanup when
Modified: team/dlee/stasis-cache-split/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/main/stasis_cache.c?view=diff&rev=394157&r1=394156&r2=394157
==============================================================================
--- team/dlee/stasis-cache-split/main/stasis_cache.c (original)
+++ team/dlee/stasis-cache-split/main/stasis_cache.c Thu Jul 11 16:01:00 2013
@@ -47,7 +47,6 @@
struct stasis_cache {
struct ao2_container *entries;
snapshot_get_id id_fn;
- struct stasis_cache *secondary_cache;
};
/*! \internal */
@@ -183,8 +182,6 @@
ao2_cleanup(cache->entries);
cache->entries = NULL;
- ao2_cleanup(cache->secondary_cache);
- cache->secondary_cache = NULL;
}
struct stasis_cache *stasis_cache_create(snapshot_get_id id_fn)
@@ -203,31 +200,6 @@
}
cache->id_fn = id_fn;
-
- ao2_ref(cache, +1);
- return cache;
-}
-
-struct stasis_cache *stasis_cache_create_secondary(
- struct stasis_cache *primary_cache, snapshot_get_id id_fn)
-{
- RAII_VAR(struct stasis_cache *, cache, NULL, ao2_cleanup);
-
- if (!primary_cache) {
- return NULL;
- }
-
- cache = stasis_cache_create(id_fn);
- if (!cache) {
- return NULL;
- }
-
- {
- SCOPED_AO2LOCK(lock, primary_cache);
- cache->secondary_cache = primary_cache->secondary_cache;
- ao2_ref(cache, +1);
- primary_cache->secondary_cache = cache;
- }
ao2_ref(cache, +1);
return cache;
@@ -397,22 +369,27 @@
return msg;
}
-static struct stasis_message *update_cache(
- struct stasis_cache *cache, struct stasis_caching_topic *caching_topic,
- struct stasis_subscription *sub, struct stasis_topic *topic,
- struct stasis_message *message)
-{
+static void caching_topic_exec(void *data, struct stasis_subscription *sub,
+ struct stasis_topic *topic, struct stasis_message *message)
+{
+ RAII_VAR(struct stasis_caching_topic *, caching_topic_needs_unref, NULL, ao2_cleanup);
+ struct stasis_caching_topic *caching_topic = data;
const char *id = NULL;
ast_assert(caching_topic->topic != NULL);
- ast_assert(cache->id_fn != NULL);
+ ast_assert(caching_topic->cache != NULL);
+ ast_assert(caching_topic->cache->id_fn != NULL);
+
+ if (stasis_subscription_final_message(sub, message)) {
+ caching_topic_needs_unref = caching_topic;
+ }
/* Handle cache clear event */
if (stasis_cache_clear_type() == stasis_message_type(message)) {
RAII_VAR(struct stasis_message *, old_snapshot, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, update, NULL, ao2_cleanup);
struct stasis_message *clear_msg = stasis_message_data(message);
- const char *clear_id = cache->id_fn(clear_msg);
+ const char *clear_id = caching_topic->cache->id_fn(clear_msg);
struct stasis_message_type *clear_type = stasis_message_type(clear_msg);
ast_assert(clear_type != NULL);
@@ -421,22 +398,21 @@
old_snapshot = cache_put(cache, clear_type, clear_id, NULL);
if (old_snapshot) {
update = update_create(topic, old_snapshot, NULL);
- ao2_ref(update, +1);
- return update;
+ stasis_publish(caching_topic->topic, update);
+ return;
}
ast_log(LOG_ERROR,
"Attempting to remove an item from the %s cache that isn't there: %s %s\n",
stasis_topic_name(caching_topic->topic), stasis_message_type_name(clear_type), clear_id);
- return NULL;
- }
- }
-
- id = cache->id_fn(message);
+ return;
+ }
+ }
+
+ id = caching_topic->cache->id_fn(message);
if (id == NULL) {
/* Object isn't cached; forward */
- ao2_ref(message, +1);
- return message;
+ stasis_forward_message(caching_topic->topic, topic, message);
} else {
/* Update the cache */
RAII_VAR(struct stasis_message *, old_snapshot, NULL, ao2_cleanup);
@@ -446,46 +422,10 @@
update = update_create(topic, old_snapshot, message);
if (update == NULL) {
- return NULL;
- }
-
- ao2_ref(update, +1);
- return update;
- }
-}
-
-static struct stasis_cache *cache_next(struct stasis_cache *cache)
-{
- if (!cache) {
- return NULL;
- } else {
- SCOPED_AO2LOCK(lock, cache);
- return cache->secondary_cache;
- }
-}
-
-static void caching_topic_exec(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic, struct stasis_message *message)
-{
- struct stasis_caching_topic *caching_topic = data;
- struct stasis_cache *cache = caching_topic->cache;
- struct stasis_message *new_message;
-
- new_message = update_cache(cache, caching_topic, sub, topic, message);
- if (new_message) {
- stasis_forward_message(caching_topic->topic, topic, new_message);
- ao2_cleanup(new_message);
- new_message = NULL;
- }
-
- /* Now update the secondary caches */
- cache = cache_next(cache);
-
- while (cache) {
- struct stasis_message *ignored =
- update_cache(cache, caching_topic, sub, topic, message);
- ao2_cleanup(ignored);
- cache = cache_next(cache);
+ return;
+ }
+
+ stasis_publish(caching_topic->topic, update);
}
if (stasis_subscription_final_message(sub, message)) {
Modified: team/dlee/stasis-cache-split/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-cache-split/main/stasis_channels.c?view=diff&rev=394157&r1=394156&r2=394157
==============================================================================
--- team/dlee/stasis-cache-split/main/stasis_channels.c (original)
+++ team/dlee/stasis-cache-split/main/stasis_channels.c Thu Jul 11 16:01:00 2013
@@ -61,6 +61,7 @@
static struct stasis_cache_all *channel_cache_all;
static struct stasis_cache *channel_cache_by_name;
+static struct stasis_caching_topic *channel_by_name_topic;
struct stasis_cache_all *ast_channel_cache_all(void)
{
@@ -854,6 +855,8 @@
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_start_type);
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_stop_type);
+ stasis_caching_unsubscribe_and_join(channel_by_name_topic);
+ channel_by_name_topic = NULL;
ao2_cleanup(channel_cache_by_name);
channel_cache_by_name = NULL;
ao2_cleanup(channel_cache_all);
@@ -873,8 +876,14 @@
}
channel_cache_by_name = stasis_cache_create_secondary(
- ast_channel_cache(), channel_snapshot_get_name);
+ channel_snapshot_get_name);
if (!channel_cache_by_name) {
+ return -1;
+ }
+
+ channel_by_name_topic = stasis_caching_topic_create(
+ "ast_channel_topic_by_name", channel_cache_by_name);
+ if (!channel_by_name_topic) {
return -1;
}
More information about the svn-commits
mailing list