Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/212584

Change subject: Made ReplicatedBagOStuff wrapping the SQL class the default 
stash
......................................................................

Made ReplicatedBagOStuff wrapping the SQL class the default stash

* To make this work, a slaveOnly flag was added to SqlBagOStuff
  and it no longer prunes expired items on get(), it just treats
  them as missing. The use of collectGarbage() for the writeFactory
  cache and the use of replace() on updates already makes this
  a non-issue.

Bug: T88493
Change-Id: I9d1f31305e08430de29a3cd521cdb10a82dffd10
---
M includes/DefaultSettings.php
M includes/objectcache/SqlBagOStuff.php
2 files changed, 30 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/84/212584/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 2ea8b29..052555c 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -2151,6 +2151,19 @@
        CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
        CACHE_MEMCACHED => array( 'factory' => 'ObjectCache::newMemcached', 
'loggroup' => 'memcached' ),
 
+       'db-replicated' => array(
+               'class'       => 'ReplicatedBagOStuff',
+               'readFactory' => array(
+                       'class' => 'SqlBagOStuff',
+                       'args'  => array( array( 'slaveOnly' => true ) )
+               ),
+               'writeFactory' => array(
+                       'class' => 'SqlBagOStuff',
+                       'args'  => array( array( 'slaveOnly' => false ) )
+               ),
+               'loggroup'  => 'SQLBagOStuff'
+       ),
+
        'apc' => array( 'class' => 'APCBagOStuff' ),
        'xcache' => array( 'class' => 'XCacheBagOStuff' ),
        'wincache' => array( 'class' => 'WinCacheBagOStuff' ),
@@ -2213,6 +2226,7 @@
  * lightweight data like hit counters and user activity. Sites with multiple
  * data-centers should have this use a store that replicates all writes. The
  * store should have enough consistency for CAS operations to be usable.
+ * Reads outside of those needed for merge() may be eventually consistent.
  *
  * The options are:
  *   - db:      Store cache objects in the DB
@@ -2221,7 +2235,7 @@
  *
  * @since 1.26
  */
-$wgMainStash = 'db';
+$wgMainStash = 'db-replicated';
 
 /**
  * The expiry time for the parser cache, in seconds.
diff --git a/includes/objectcache/SqlBagOStuff.php 
b/includes/objectcache/SqlBagOStuff.php
index 82eeb84..05115c9 100644
--- a/includes/objectcache/SqlBagOStuff.php
+++ b/includes/objectcache/SqlBagOStuff.php
@@ -30,6 +30,7 @@
        /** @var LoadBalancer */
        protected $lb;
 
+       /** @var array */
        protected $serverInfos;
 
        /** @var array */
@@ -52,6 +53,9 @@
 
        /** @var string */
        protected $tableName = 'objectcache';
+
+       /** @var bool */
+       protected $slaveOnly = false;
 
        /** @var array UNIX timestamps */
        protected $connFailureTimes = array();
@@ -84,6 +88,10 @@
         *                  required to hold the largest shard index. Data will 
be
         *                  distributed across all tables by key hash. This is 
for
         *                  MySQL bugs 61735 and 61736.
+        *   - slaveOnly:   Whether to only use slave DBs and avoid triggering
+        *                  garbage collection logic of expired items. This only
+        *                  makes sense if the primary DB is used and only if 
get()
+        *                  calls will be used. This is used by 
ReplicatedBagOStuff.
         *
         * @param array $params
         */
@@ -112,6 +120,7 @@
                if ( isset( $params['shards'] ) ) {
                        $this->shards = intval( $params['shards'] );
                }
+               $this->slaveOnly = !empty( $params['slaveOnly'] );
        }
 
        /**
@@ -155,12 +164,13 @@
                                 * However, SQLite has an opposite behavior. 
And PostgreSQL needs to know
                                 * if we are in transaction or no
                                 */
-                               if ( wfGetDB( DB_MASTER )->getType() == 'mysql' 
) {
+                               $index = $this->slaveOnly ? DB_SLAVE : 
DB_MASTER;
+                               if ( wfGetDB( $index )->getType() == 'mysql' ) {
                                        $this->lb = 
wfGetLBFactory()->newMainLB();
-                                       $db = $this->lb->getConnection( 
DB_MASTER );
+                                       $db = $this->lb->getConnection( $index 
);
                                        $db->clearFlag( DBO_TRX ); // 
auto-commit mode
                                } else {
-                                       $db = wfGetDB( DB_MASTER );
+                                       $db = wfGetDB( $index );
                                }
                        }
                        if ( $wgDebugDBTransactions ) {
@@ -274,12 +284,7 @@
                                try {
                                        $db = $this->getDB( $row->serverIndex );
                                        if ( $this->isExpired( $db, 
$row->exptime ) ) { // MISS
-                                               $this->debug( "get: key has 
expired, deleting" );
-                                               # Put the expiry time in the 
WHERE condition to avoid deleting a
-                                               # newly-inserted value
-                                               $db->delete( $row->tableName,
-                                                       array( 'keyname' => 
$key, 'exptime' => $row->exptime ),
-                                                       __METHOD__ );
+                                               $this->debug( "get: key has 
expired" );
                                        } else { // HIT
                                                $values[$key] = 
$this->unserialize( $db->decodeBlob( $row->value ) );
                                        }
@@ -546,7 +551,7 @@
        }
 
        protected function garbageCollect() {
-               if ( !$this->purgePeriod ) {
+               if ( !$this->purgePeriod || $this->slaveOnly ) {
                        // Disabled
                        return;
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/212584
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d1f31305e08430de29a3cd521cdb10a82dffd10
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to