[Rt-commit] rt branch, 4.4/external-storage, updated. rt-4.2.11-37-gf2a9727

Shawn Moore shawn at bestpractical.com
Fri May 22 14:43:04 EDT 2015


The branch, 4.4/external-storage has been updated
       via  f2a97277f0c5610462ed8cf03de68ccc0c217919 (commit)
       via  187de01fdbc0c5f7268dff98488c489d8916dbc9 (commit)
       via  cf750bf34979a3739aee12cd9a1c84359346fc83 (commit)
      from  4cfc6b50c49d7168f06df89b3cf3356c86a888a3 (commit)

Summary of changes:
 etc/RT_Config.pm.in                | 13 +++++++------
 lib/RT/Config.pm                   |  8 ++++++--
 lib/RT/ExternalStorage.pm          | 13 -------------
 lib/RT/Record.pm                   |  5 +++--
 lib/RT/System.pm                   |  7 +++++++
 sbin/rt-externalize-attachments.in | 15 ++++++++++++---
 6 files changed, 35 insertions(+), 26 deletions(-)

- Log -----------------------------------------------------------------
commit cf750bf34979a3739aee12cd9a1c84359346fc83
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 18:35:42 2015 +0000

    Hang $RT::ExternalStorage::BACKEND off RT->System

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 01ab952..0144e22 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -994,8 +994,12 @@ our %META;
 
             require RT::ExternalStorage;
 
-            $hash{Write} = $RT::ExternalStorage::WRITE;
-            $RT::ExternalStorage::BACKEND = RT::ExternalStorage::Backend->new( %hash );
+            my $backend = RT::ExternalStorage::Backend->new(
+                %hash,
+                Write => $RT::ExternalStorage::WRITE,
+            );
+
+            RT->System->ExternalStorage($backend);
         },
     },
     ChartColors => {
diff --git a/lib/RT/ExternalStorage.pm b/lib/RT/ExternalStorage.pm
index abf7ada..b6740de 100644
--- a/lib/RT/ExternalStorage.pm
+++ b/lib/RT/ExternalStorage.pm
@@ -131,7 +131,6 @@ storage.
 
 =cut
 
-our $BACKEND;
 our $WRITE;
 
 sub Store {
@@ -139,11 +138,10 @@ sub Store {
     my $content = shift;
 
     my $key = Digest::SHA::sha256_hex( $content );
-    my ($ok, $msg) = $BACKEND->Store( $key => $content );
+    my ($ok, $msg) = RT->System->ExternalStorage->Store( $key => $content );
     return ($ok, $msg) unless defined $ok;
 
     return ($key);
 }
 
-
 1;
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 365b9e5..88800ef 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -889,12 +889,13 @@ sub _DecodeLOB {
     my $Content         = shift;
 
     if ($ContentEncoding eq 'external') {
-        unless ($RT::ExternalStorage::BACKEND) {
+        my $Storage = RT->System->ExternalStorage;
+        unless ($Storage) {
             RT->Logger->error( "Failed to load $Content; external storage not configured" );
             return ("");
         };
 
-        my ($ok, $msg) = $RT::ExternalStorage::BACKEND->Get( $Content );
+        my ($ok, $msg) = $Storage->Get( $Content );
         unless (defined $ok) {
             RT->Logger->error( "Failed to load $Content from external storage: $msg" );
             return ("");
diff --git a/lib/RT/System.pm b/lib/RT/System.pm
index b487cf2..32c2866 100644
--- a/lib/RT/System.pm
+++ b/lib/RT/System.pm
@@ -327,6 +327,13 @@ sub ParsedUpgradeHistory {
     return ($version_status, @lines);
 }
 
+sub ExternalStorage {
+    my $self = shift;
+    if (@_) {
+        $self->{ExternalStorage} = shift;
+    }
+    return $self->{ExternalStorage};
+}
 
 RT::Base->_ImportOverlays();
 
diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments.in
index b5e87cf..45f2d61 100755
--- a/sbin/rt-externalize-attachments.in
+++ b/sbin/rt-externalize-attachments.in
@@ -74,8 +74,7 @@ use Fcntl ':flock';
 exit unless flock main::DATA, LOCK_EX | LOCK_NB;
 
 die "\%ExternalStorage is not configured\n"
-    unless RT->Config->Get("ExternalStorage")
-        && $RT::ExternalStorage::BACKEND;
+    unless RT->System->ExternalStorage;
 
 # pull out the previous high-water mark for each object type
 my $last = RT->System->FirstAttribute("ExternalStorage");

commit 187de01fdbc0c5f7268dff98488c489d8916dbc9
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 18:37:35 2015 +0000

    Move Store routine from RT::ExternalStorage to script
    
        This eliminates all API from RT::ExternalStorage
        itself; instead, developers should be talking to
        RT->System->ExternalStorage. Furthermore, there are all sorts of
        consistency (like updating ContentEncoding to external) and safety
        checks (like $WRITE=1 performing a -w check) that the script does
        that RT::ExternalStorage->Store doesn't.

diff --git a/lib/RT/ExternalStorage.pm b/lib/RT/ExternalStorage.pm
index b6740de..0045467 100644
--- a/lib/RT/ExternalStorage.pm
+++ b/lib/RT/ExternalStorage.pm
@@ -133,15 +133,4 @@ storage.
 
 our $WRITE;
 
-sub Store {
-    my $class = shift;
-    my $content = shift;
-
-    my $key = Digest::SHA::sha256_hex( $content );
-    my ($ok, $msg) = RT->System->ExternalStorage->Store( $key => $content );
-    return ($ok, $msg) unless defined $ok;
-
-    return ($key);
-}
-
 1;
diff --git a/sbin/rt-externalize-attachments.in b/sbin/rt-externalize-attachments.in
index 45f2d61..3b9c17f 100755
--- a/sbin/rt-externalize-attachments.in
+++ b/sbin/rt-externalize-attachments.in
@@ -144,7 +144,7 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
             );
 
             # Attempt to write that out
-            my ($key, $msg) = RT::ExternalStorage->Store( $content );
+            my ($key, $msg) = Store( $content );
             unless ($key) {
                 RT->Logger->error("Failed to store $class $id: $msg");
                 exit 1;
@@ -176,5 +176,15 @@ for my $class (qw/RT::Attachments RT::ObjectCustomFieldValues/) {
 # update high-water mark for each object type
 RT->System->SetAttribute( Name => "ExternalStorage", Content => $last );
 
+sub Store {
+    my $content = shift;
+
+    my $key = Digest::SHA::sha256_hex( $content );
+    my ($ok, $msg) = RT->System->ExternalStorage->Store( $key => $content );
+    return ($ok, $msg) unless defined $ok;
+
+    return ($key);
+}
+
 # don't remove; for locking (see call to flock above)
 __DATA__

commit f2a97277f0c5610462ed8cf03de68ccc0c217919
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 18:42:41 2015 +0000

    Explain what a Binary CF is
    
        Users know this as a file upload, Binary is the internal name

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 30de2d7..9935bf5 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2559,12 +2559,13 @@ Set(%ExternalStorage, ());
 
 =item C<$ExternalStorageCutoffSize>
 
-Certain object types, like values for Binary custom fields, are always
-put into external storage. However, for other object types, like images
-and text, there is a line in the sand where you want small objects in the
-database but large objects in external storage. By default, objects larger
-than 10 MiB (10*1024*1024 bytes) will be put into external storage.
-C<$ExternalStorageCutoffSize> adjusts that line in the sand.
+Certain object types, like values for Binary (aka file upload) custom
+fields, are always put into external storage. However, for other object
+types, like images and text, there is a line in the sand where you want
+small objects in the database but large objects in external storage. By
+default, objects larger than 10 MiB (10*1024*1024 bytes) will be put
+into external storage. C<$ExternalStorageCutoffSize> adjusts that line
+in the sand.
 
 Note that changing this setting does not affect existing attachments, only
 the new ones that C<sbin/rt-externalize-attachments> hasn't seen yet.

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


More information about the rt-commit mailing list