[Asterisk-code-review] Add reload options to CLI/AMI stale object commands. (asterisk[certified/13.13])

Joshua Colp asteriskteam at digium.com
Thu Feb 2 18:08:35 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/4819 )

Change subject: Add reload options to CLI/AMI stale object commands.
......................................................................


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
---
M res/res_sorcery_memory_cache.c
1 file changed, 32 insertions(+), 7 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c
index 7da72bc..5f7ffb6 100644
--- a/res/res_sorcery_memory_cache.c
+++ b/res/res_sorcery_memory_cache.c
@@ -83,6 +83,9 @@
 			<parameter name="Object" required="true">
 				<para>The name of the object to mark as stale.</para>
 			</parameter>
+			<parameter name="Reload" required="false">
+				<para>If true, then immediately reload the object from the backend cache instead of waiting for the next retrieval</para>
+			</parameter>
 		</syntax>
 		<description>
 			<para>Marks an object as stale within a sorcery memory cache.</para>
@@ -1394,10 +1397,8 @@
 	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 @@
 	case CLI_INIT:
 		e->command = "sorcery memory cache stale";
 		e->usage =
-		    "Usage: sorcery memory cache stale <cache name> [object name]\n"
-		    "       Mark a specific object or ALL objects as stale in a sorcery memory cache.\n";
+		    "Usage: sorcery memory cache stale <cache name> [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 @@
 		}
 	}
 
-	if (a->argc < 5 || a->argc > 6) {
+	if (a->argc < 5 || a->argc > 7) {
 		return CLI_SHOWUSAGE;
 	}
 
@@ -1907,6 +1910,15 @@
 		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 @@
 {
 	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 @@
 	}
 
 	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);

-- 
To view, visit https://gerrit.asterisk.org/4819
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieb1fe7270ceed491f057ec5cbf0e097bde96c5c8
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.13
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list