Make use of strong consistency with Ceph RGW
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 18 Mar 2014 06:47:53 +0000 (23:47 -0700)
committerBryanDavis <bdavis@wikimedia.org>
Wed, 19 Mar 2014 17:27:48 +0000 (17:27 +0000)
Change-Id: Ic3b764363e91c3279d3dc017ddce630dae26bec5

includes/filebackend/FileBackendStore.php
includes/filebackend/SwiftFileBackend.php

index 16300af..2d8214e 100644 (file)
@@ -648,7 +648,8 @@ abstract class FileBackendStore extends FileBackend {
                $stat = $this->doGetFileStat( $params );
                wfProfileOut( __METHOD__ . '-miss-' . $this->name );
                if ( is_array( $stat ) ) { // file exists
-                       $stat['latest'] = $latest;
+                       // Strongly consistent backends can automatically set "latest"
+                       $stat['latest'] = isset( $stat['latest'] ) ? $stat['latest'] : $latest;
                        $this->cheapCache->set( $path, 'stat', $stat );
                        $this->setFileCache( $path, $stat ); // update persistent cache
                        if ( isset( $stat['sha1'] ) ) { // some backends store SHA-1 as metadata
@@ -1295,7 +1296,8 @@ abstract class FileBackendStore extends FileBackend {
                                continue; // this shouldn't happen
                        }
                        if ( is_array( $stat ) ) { // file exists
-                               $stat['latest'] = $latest;
+                               // Strongly consistent backends can automatically set "latest"
+                               $stat['latest'] = isset( $stat['latest'] ) ? $stat['latest'] : $latest;
                                $this->cheapCache->set( $path, 'stat', $stat );
                                $this->setFileCache( $path, $stat ); // update persistent cache
                                if ( isset( $stat['sha1'] ) ) { // some backends store SHA-1 as metadata
index 706da96..7050226 100644 (file)
@@ -72,6 +72,9 @@ class SwiftFileBackend extends FileBackendStore {
        /** @var int UNIX timestamp */
        protected $authErrorTimestamp = null;
 
+       /** @var bool Whether the server is an Ceph RGW */
+       protected $isRGW = false;
+
        /**
         * @see FileBackendStore::__construct()
         * Additional $config params include:
@@ -1518,6 +1521,9 @@ class SwiftFileBackend extends FileBackendStore {
                                        'md5'   => ctype_xdigit( $rhdrs['etag'] ) ? $rhdrs['etag'] : null,
                                        'xattr' => array( 'metadata' => $metadata, 'headers' => $headers )
                                );
+                               if ( $this->isRGW ) {
+                                       $stat['latest'] = true; // strong consistency
+                               }
                        } elseif ( $rcode === 404 ) {
                                $stat = false;
                        } else {
@@ -1582,6 +1588,10 @@ class SwiftFileBackend extends FileBackendStore {
                                        return null;
                                }
                        }
+                       // Ceph RGW does not use <account> in URLs (OpenStack Swift uses "/v1/<account>")
+                       if ( substr( $this->authCreds['storage_url'], -3 ) === '/v1' ) {
+                               $this->isRGW = true; // take advantage of strong consistency
+                       }
                }
 
                return $this->authCreds;