From 9e3150b98ddf4ecfe09e281c73c634b89ba2514e Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Wed, 25 Jan 2017 15:26:53 -0600 Subject: Add reload options to CLI/AMI stale object commands. Marking an object as stale in a memory cache is supposed to prime the cache so that the next time the item is retrieved, the stale item is deleted from the cache and a background task is run to re-populate the cache with a fresh version of the object. The problem is, there are some object types out there for which there is no natural reason that they would be retrieved from the backend with any regularity. Outbound PJSIP registrations are a good example of this. At startup, they are read, and an object-specific state is created that refers to the initially-retrieved object for all time. Adding the "reload" option to the CLI/AMI commands gives the cache the opportunity to manually re-retrieve the object from the backend, both storing the new object in the cache and applying the new object's configuration to the module that uses that object. Change-Id: Ieb1fe7270ceed491f057ec5cbf0e097bde96c5c8 --- res/res_sorcery_memory_cache.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'res/res_sorcery_memory_cache.c') diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c index 7da72bca4..5f7ffb64e 100644 --- a/res/res_sorcery_memory_cache.c +++ b/res/res_sorcery_memory_cache.c @@ -83,6 +83,9 @@ The name of the object to mark as stale. + + If true, then immediately reload the object from the backend cache instead of waiting for the next retrieval + Marks an object as stale within a sorcery memory cache. @@ -1394,10 +1397,8 @@ static void sorcery_memory_cache_load(void *data, const struct ast_sorcery *sorc ast_debug(1, "Memory cache '%s' associated with sorcery instance '%p' of module '%s' with object type '%s'\n", cache->name, sorcery, ast_sorcery_get_module(sorcery), type); - if (cache->full_backend_cache) { - cache->sorcery = sorcery; - cache->object_type = ast_strdup(type); - } + cache->sorcery = sorcery; + cache->object_type = ast_strdup(type); } /*! @@ -1870,8 +1871,10 @@ static char *sorcery_memory_cache_stale(struct ast_cli_entry *e, int cmd, struct case CLI_INIT: e->command = "sorcery memory cache stale"; e->usage = - "Usage: sorcery memory cache stale [object name]\n" - " Mark a specific object or ALL objects as stale in a sorcery memory cache.\n"; + "Usage: sorcery memory cache stale [object name [reload]]\n" + " Mark a specific object or ALL objects as stale in a sorcery memory cache.\n" + " If \"reload\" is specified, then the object is marked stale and immediately\n" + " retrieved from backend storage to repopulate the cache\n"; return NULL; case CLI_GENERATE: if (a->pos == 4) { @@ -1883,7 +1886,7 @@ static char *sorcery_memory_cache_stale(struct ast_cli_entry *e, int cmd, struct } } - if (a->argc < 5 || a->argc > 6) { + if (a->argc < 5 || a->argc > 7) { return CLI_SHOWUSAGE; } @@ -1907,6 +1910,15 @@ static char *sorcery_memory_cache_stale(struct ast_cli_entry *e, int cmd, struct if (!mark_object_as_stale_in_cache(cache, a->argv[5])) { ast_cli(a->fd, "Successfully marked object '%s' in memory cache '%s' as stale\n", a->argv[5], a->argv[4]); + if (a->argc == 7 && ast_true(a->argv[6])) { + struct sorcery_memory_cached_object *cached; + + cached = ao2_find(cache->objects, a->argv[5], OBJ_SEARCH_KEY | OBJ_NOLOCK); + if (cached) { + memory_cache_stale_update_object(cache->sorcery, cache, cached); + ao2_ref(cached, -1); + } + } } else { ast_cli(a->fd, "Object '%s' in sorcery memory cache '%s' could not be marked as stale as it was not found\n", a->argv[5], a->argv[4]); @@ -2066,6 +2078,7 @@ static int sorcery_memory_cache_ami_stale_object(struct mansession *s, const str { const char *cache_name = astman_get_header(m, "Cache"); const char *object_name = astman_get_header(m, "Object"); + const char *reload = astman_get_header(m, "Reload"); struct sorcery_memory_cache *cache; int res; @@ -2084,7 +2097,19 @@ static int sorcery_memory_cache_ami_stale_object(struct mansession *s, const str } ao2_rdlock(cache->objects); + res = mark_object_as_stale_in_cache(cache, object_name); + + if (ast_true(reload)) { + struct sorcery_memory_cached_object *cached; + + cached = ao2_find(cache->objects, object_name, OBJ_SEARCH_KEY | OBJ_NOLOCK); + if (cached) { + memory_cache_stale_update_object(cache->sorcery, cache, cached); + ao2_ref(cached, -1); + } + } + ao2_unlock(cache->objects); ao2_ref(cache, -1); -- cgit v1.2.3