[Asterisk-code-review] res_sorcery_memory_cache: Disallow per-object expire with full backend. (asterisk[13])

Friendly Automation asteriskteam at digium.com
Thu Jun 18 17:56:19 CDT 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14511 )

Change subject: res_sorcery_memory_cache: Disallow per-object expire with full backend.
......................................................................

res_sorcery_memory_cache: Disallow per-object expire with full backend.

The AMI action and CLI command did not take into account the properties
of full backend caching. This resulted in an expired object remaining
removed until a full backend update occurred, instead of having the
object updated when needed.

This change makes it so that the AMI action and CLI command for object
expire will now fail instead of putting the cache into an undesired
state. If full backend caching is enabled then only operations
which act on the entire cache are available.

ASTERISK-28942

Change-Id: Id662d888f177ab566c8e802ad583083b742d21f4
---
A doc/CHANGES-staging/sorcery_memory_cache_full_expire_object.txt
M res/res_sorcery_memory_cache.c
2 files changed, 33 insertions(+), 4 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, approved
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, but someone else must approve
  Friendly Automation: Approved for Submit



diff --git a/doc/CHANGES-staging/sorcery_memory_cache_full_expire_object.txt b/doc/CHANGES-staging/sorcery_memory_cache_full_expire_object.txt
new file mode 100644
index 0000000..d568e38
--- /dev/null
+++ b/doc/CHANGES-staging/sorcery_memory_cache_full_expire_object.txt
@@ -0,0 +1,19 @@
+Subject: res_sorcery_memory_cache
+
+The SorceryMemoryCacheExpireObject AMI action and CLI
+command allow expiring of a specific object within the
+sorcery memory cache. This is done by removing the
+object from the cache with the expectation that the
+cache will then re-populate the object when it is next
+needed.
+
+For full backend caching this does not occur. The cache
+won't repopulate until an entire refresh is done resulting
+in the possibility that objects are missing until that
+time.
+
+The AMI action and CLI command will now not allow
+expiring of an object if the cache is configured as a
+full backend cache. Instead you must use either the
+SorceryMemoryCacheExpire or SorceryMemoryCachePopulate
+AMI actions or their associated CLI commands.
diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c
index 5029131..dad3146 100644
--- a/res/res_sorcery_memory_cache.c
+++ b/res/res_sorcery_memory_cache.c
@@ -54,7 +54,9 @@
 			</parameter>
 		</syntax>
 		<description>
-			<para>Expires (removes) an object from a sorcery memory cache.</para>
+			<para>Expires (removes) an object from a sorcery memory cache. If full backend caching is enabled
+			this action is not available and will fail. In this case the SorceryMemoryCachePopulate or
+			SorceryMemoryCacheExpire AMI actions must be used instead.</para>
 		</description>
 	</manager>
 	<manager name="SorceryMemoryCacheExpire" language="en_US">
@@ -1892,7 +1894,9 @@
 		remove_all_from_cache(cache);
 		ast_cli(a->fd, "All objects have been removed from cache '%s'\n", a->argv[4]);
 	} else {
-		if (!remove_from_cache(cache, a->argv[5], 1)) {
+		if (cache->full_backend_cache) {
+			ast_cli(a->fd, "Due to full backend caching per-object expiration is not available on cache '%s'\n", a->argv[4]);
+		} else if (!remove_from_cache(cache, a->argv[5], 1)) {
 			ast_cli(a->fd, "Successfully expired object '%s' from cache '%s'\n", a->argv[5], a->argv[4]);
 		} else {
 			ast_cli(a->fd, "Object '%s' was not expired from cache '%s' as it was not found\n", a->argv[5],
@@ -2084,12 +2088,18 @@
 	}
 
 	ao2_wrlock(cache->objects);
-	res = remove_from_cache(cache, object_name, 1);
+	if (cache->full_backend_cache) {
+		res = 1;
+	} else {
+		res = remove_from_cache(cache, object_name, 1);
+	}
 	ao2_unlock(cache->objects);
 
 	ao2_ref(cache, -1);
 
-	if (!res) {
+	if (res == 1) {
+		astman_send_error(s, m, "Due to full backend caching per-object expiration is not available, consider using SorceryMemoryCachePopulate or SorceryMemoryCacheExpire instead\n");
+	} else if (!res) {
 		astman_send_ack(s, m, "The provided object was expired from the cache\n");
 	} else {
 		astman_send_error(s, m, "The provided object could not be expired from the cache\n");

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14511
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Id662d888f177ab566c8e802ad583083b742d21f4
Gerrit-Change-Number: 14511
Gerrit-PatchSet: 5
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200618/f4b33b19/attachment-0001.html>


More information about the asterisk-code-review mailing list