[Jifty-commit] jifty branch, cas-memcached, updated. 44359d5a34b95bcd2acf238f6d3eff815c235f03

Jifty commits jifty-commit at lists.jifty.org
Tue Jan 26 22:41:58 EST 2010


The branch, cas-memcached has been updated
       via  44359d5a34b95bcd2acf238f6d3eff815c235f03 (commit)
      from  409707d0b5faa01b126cb26aad4edea883a7c975 (commit)

Summary of changes:
 lib/Jifty/CAS.pm                 |    2 +-
 lib/Jifty/CAS/Store/Memcached.pm |   32 +++++++++++++++++++++++++++++---
 lib/Jifty/Config.pm              |    1 +
 3 files changed, 31 insertions(+), 4 deletions(-)

- Log -----------------------------------------------------------------
commit 44359d5a34b95bcd2acf238f6d3eff815c235f03
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Jan 26 22:40:53 2010 -0500

    Support falling back when memcached fails
    
    Fallback to default store, but with an error message.  This may be
    desireable to keep services functioning, but probably should be turned
    off in most cases after successful testing.

diff --git a/lib/Jifty/CAS.pm b/lib/Jifty/CAS.pm
index 63eaaeb..3f7e54f 100644
--- a/lib/Jifty/CAS.pm
+++ b/lib/Jifty/CAS.pm
@@ -45,7 +45,7 @@ however.
 
 Publishes the given C<CONTENT> at the address C<DOMAIN> and C<NAME>.
 C<METADATA> is an arbitrary hash; see L<Jifty::CAS::Blob> for more.
-Returns the key.
+Returns the key on success, or undef on failure.
 
 =head2 key DOMAIN NAME
 
diff --git a/lib/Jifty/CAS/Store/Memcached.pm b/lib/Jifty/CAS/Store/Memcached.pm
index 9603a0e..de429e2 100644
--- a/lib/Jifty/CAS/Store/Memcached.pm
+++ b/lib/Jifty/CAS/Store/Memcached.pm
@@ -64,7 +64,16 @@ sub _store {
             $err .= "  Perhaps you need to increase memcached's max item size?";
         }
         Jifty->log->error($err);
-        return;
+
+        if ( $class->memcached_fallback ) {
+            Jifty->log->error("Falling back to default, in-process memory store.  "
+                             ."This is suboptimal and you should investigate the cause.");
+            return $class->SUPER::_store($domain, $name, $blob);
+        }
+        else {
+            # fail with undef
+            return;
+        }
     }
 
     $success = $class->memcached->set("$domain:keys:$name", $key, 60*60*24*14);
@@ -86,7 +95,10 @@ C<NAME>, or undef if none such exists.
 
 sub key {
     my ($class, $domain, $name) = @_;
-    return $class->memcached->get("$domain:keys:$name");
+    my $key = $class->memcached->get("$domain:keys:$name");
+    return $key if defined $key;
+    return $class->SUPER::key($domain, $name) if $class->memcached_fallback;
+    return;
 }
 
 =head2 retrieve DOMAIN KEY
@@ -98,7 +110,10 @@ C<KEY>, or undef if none such exists.
 
 sub retrieve {
     my ($class, $domain, $key) = @_;
-    return $class->memcached->get("$domain:db:$key");
+    my $blob = $class->memcached->get("$domain:db:$key");
+    return $blob if defined $blob;
+    return $class->SUPER::retrieve($domain, $key) if $class->memcached_fallback;
+    return;
 }
 
 =head2 memcached_config
@@ -132,4 +147,15 @@ sub memcached_config {
         || Jifty->config->defaults->{'framework'}{'CAS'}{'Memcached'}
 }
 
+=head2 memcached_fallback
+
+Returns a boolean (from the config file) indicating whether or not memcached
+should fallback to the per-process, in-memory store.
+
+=cut
+
+sub memcached_fallback {
+    Jifty->config->framework('CAS')->{'MemcachedFallback'} ? 1 : 0
+}
+
 1;
diff --git a/lib/Jifty/Config.pm b/lib/Jifty/Config.pm
index fbbf046..41a7ed3 100644
--- a/lib/Jifty/Config.pm
+++ b/lib/Jifty/Config.pm
@@ -622,6 +622,7 @@ sub defaults {
                     namespace   => $self->framework('ApplicationName').":",
                     compress_threshold => 10240,
                 },
+                MemcachedFallback => 1,
             },
         }
     };

-----------------------------------------------------------------------


More information about the Jifty-commit mailing list