jenkins-bot has submitted this change and it was merged.
Change subject: Add a ReplicatedBagOStuff class
......................................................................
Add a ReplicatedBagOStuff class
Bug: T88634
Change-Id: I1f7cccd6ac376055ff2b84641ff38a85571c65b0
---
M autoload.php
A includes/objectcache/ReplicatedBagOStuff.php
2 files changed, 127 insertions(+), 0 deletions(-)
Approvals:
Tim Starling: Looks good to me, approved
jenkins-bot: Verified
diff --git a/autoload.php b/autoload.php
index a5560f2..705f5bd 100644
--- a/autoload.php
+++ b/autoload.php
@@ -964,6 +964,7 @@
'RenderAction' => __DIR__ . '/includes/actions/RenderAction.php',
'ReplacementArray' => __DIR__ . '/includes/libs/ReplacementArray.php',
'Replacer' => __DIR__ . '/includes/libs/replacers/Replacer.php',
+ 'ReplicatedBagOStuff' => __DIR__ .
'/includes/objectcache/ReplicatedBagOStuff.php',
'RepoGroup' => __DIR__ . '/includes/filerepo/RepoGroup.php',
'RequestContext' => __DIR__ . '/includes/context/RequestContext.php',
'ResetUserTokens' => __DIR__ . '/maintenance/resetUserTokens.php',
diff --git a/includes/objectcache/ReplicatedBagOStuff.php
b/includes/objectcache/ReplicatedBagOStuff.php
new file mode 100644
index 0000000..8097308
--- /dev/null
+++ b/includes/objectcache/ReplicatedBagOStuff.php
@@ -0,0 +1,126 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Cache
+ * @author Aaron Schulz
+ */
+
+/**
+ * A cache class that directs writes to one set of servers and reads to
+ * another. This assumes that the servers used for reads are setup to slave
+ * those that writes go to. This can easily be used with redis for example.
+ *
+ * In the WAN scenario (e.g. multi-datacenter case), this is useful when
+ * writes are rare or usually takes place on the primary datacenter.
+ *
+ * @ingroup Cache
+ * @since 1.25
+ */
+class ReplicatedBagOStuff extends BagOStuff {
+ /** @var BagOStuff */
+ protected $mCache;
+ /** @var BagOStuff */
+ protected $sCache;
+
+ /**
+ * Constructor. Parameters are:
+ * - masterCache : Cache parameter structures, in the style required
by $wgObjectCaches.
+ * See the documentation of $wgObjectCaches for more
detail.
+ * - slaveCache : Cache parameter structures, in the style required
by $wgObjectCaches.
+ * See the documentation of $wgObjectCaches for more
detail.
+ *
+ * @param array $params
+ * @throws MWException
+ */
+ public function __construct( $params ) {
+ parent::__construct( $params );
+
+ if ( !isset( $params['masterCache'] ) ) {
+ throw new MWException( __METHOD__ . ': the
"masterCache" parameter is required' );
+ } elseif ( !isset( $params['slaveCache'] ) ) {
+ throw new MWException( __METHOD__ . ': the "slaveCache"
parameter is required' );
+ }
+
+ $this->mCache = ( $params['masterCache'] instanceof BagOStuff )
+ ? $params['masterCache']
+ : ObjectCache::newFromParams( $params['masterCache'] );
+ $this->sCache = ( $params['slaveCache'] instanceof BagOStuff )
+ ? $params['slaveCache']
+ : ObjectCache::newFromParams( $params['slaveCache'] );
+ }
+
+ public function setDebug( $debug ) {
+ $this->mCache->setDebug( $debug );
+ $this->sCache->setDebug( $debug );
+ }
+
+ public function get( $key, &$casToken = null ) {
+ return $this->sCache->get( $key, $casToken );
+ }
+
+ public function getMulti( $keys ) {
+ return $this->sCache->getMulti( $keys );
+ }
+
+ public function set( $key, $value, $exptime = 0 ) {
+ return $this->mCache->set( $key, $value, $exptime );
+ }
+
+ public function delete( $key ) {
+ return $this->mCache->delete( $key );
+ }
+
+ public function add( $key, $value, $exptime = 0 ) {
+ return $this->mCache->add( $key, $value, $exptime );
+ }
+
+ public function incr( $key, $value = 1 ) {
+ return $this->mCache->incr( $key, $value );
+ }
+
+ public function decr( $key ) {
+ return $this->mCache->decr( $key );
+ }
+
+ public function lock( $key, $timeout = 6, $expiry = 6 ) {
+ return $this->mCache->lock( $key, $timeout, $expiry );
+ }
+
+ public function unlock( $key ) {
+ return $this->mCache->unlock( $key );
+ }
+
+ public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) {
+ return $this->mCache->merge( $key, $callback, $exptime,
$attempts );
+ }
+
+ public function getLastError() {
+ return ( $this->mCache->getLastError() != self::ERR_NONE )
+ ? $this->mCache->getLastError()
+ : $this->sCache->getLastError();
+ }
+
+ public function clearLastError() {
+ $this->mCache->clearLastError();
+ $this->sCache->clearLastError();
+ }
+
+ protected function cas( $casToken, $key, $value, $exptime = 0 ) {
+ $this->mCache->cas( $casToken, $key, $value, $exptime );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/188732
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1f7cccd6ac376055ff2b84641ff38a85571c65b0
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits