Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/97349
Change subject: filebackend: cleaned up the FileBackend constructor
......................................................................
filebackend: cleaned up the FileBackend constructor
* Moved some of the graph construction work to FileBackendGroup.
This helps the code in not depending on the rest of MW so much.
* Updated tests and FileBackendMultiwrite, which are the only things
directly constructing FileBackend objects.
Change-Id: I188a053c70ce088ce34613d5db40e6708e3ea9b7
---
M includes/filebackend/FileBackend.php
M includes/filebackend/FileBackendGroup.php
M includes/filebackend/FileBackendMultiWrite.php
M tests/phpunit/includes/filebackend/FileBackendTest.php
4 files changed, 19 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/49/97349/1
diff --git a/includes/filebackend/FileBackend.php
b/includes/filebackend/FileBackend.php
index d042dc4..7f01a70 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/filebackend/FileBackend.php
@@ -91,13 +91,14 @@
* This name should not be changed after use (e.g.
with journaling).
* Note that the name is *not* used in actual
container names.
* - wikiId : Prefix to container names that is unique to this
backend.
- * If not provided, this defaults to the current wiki
ID.
* It should only consist of alphanumberic, '-', and
'_' characters.
* This ID is what avoids collisions if multiple
logical backends
* use the same storage system, so this should be set
carefully.
- * - lockManager : Registered name of a file lock manager to use.
+ * - lockManager : LockManager object to use for any file locking.
+ * If not provided, then no file locking will be
enforced.
* - fileJournal : File journal configuration; see
FileJournal::factory().
* Journals simply log changes to files stored in the
backend.
+ * If not provided, then change journaling will be
disabled.
* - readOnly : Write operations are disallowed if this is a
non-empty string.
* It should be an explanation for the backend being
read-only.
* - parallelize : When to do file operations in parallel (when
possible).
@@ -110,16 +111,12 @@
if ( !preg_match( '!^[a-zA-Z0-9-_]{1,255}$!', $this->name ) ) {
throw new MWException( "Backend name `{$this->name}` is
invalid." );
}
- $this->wikiId = isset( $config['wikiId'] )
- ? $config['wikiId']
- : wfWikiID(); // e.g. "my_wiki-en_"
- $this->lockManager = ( $config['lockManager'] instanceof
LockManager )
+ $this->wikiId = $config['wikiId']; // e.g. "my_wiki-en_"
+ $this->lockManager = isset( $config['lockManager'] )
? $config['lockManager']
- : LockManagerGroup::singleton( $this->wikiId )->get(
$config['lockManager'] );
+ : new NullLockManager( array() );
$this->fileJournal = isset( $config['fileJournal'] )
- ? ( ( $config['fileJournal'] instanceof FileJournal )
- ? $config['fileJournal']
- : FileJournal::factory( $config['fileJournal'],
$this->name ) )
+ ? $config['fileJournal']
: FileJournal::factory( array( 'class' =>
'NullFileJournal' ), $this->name );
$this->readOnly = isset( $config['readOnly'] )
? (string)$config['readOnly']
diff --git a/includes/filebackend/FileBackendGroup.php
b/includes/filebackend/FileBackendGroup.php
index 491424b..e451e3c 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -152,6 +152,14 @@
if ( !isset( $this->backends[$name]['instance'] ) ) {
$class = $this->backends[$name]['class'];
$config = $this->backends[$name]['config'];
+ $config['wikiId'] = isset( $config['wikiId'] )
+ ? $config['wikiId']
+ : wfWikiID(); // e.g. "my_wiki-en_"
+ $config['lockManager'] =
+ LockManagerGroup::singleton( $config['wikiId']
)->get( $config['lockManager'] );
+ $config['fileJournal'] = isset( $config['fileJournal'] )
+ ? FileJournal::factory( $config['fileJournal'],
$name )
+ : FileJournal::factory( array( 'class' =>
'NullFileJournal' ), $name );
$this->backends[$name]['instance'] = new $class(
$config );
}
diff --git a/includes/filebackend/FileBackendMultiWrite.php
b/includes/filebackend/FileBackendMultiWrite.php
index b3c46c6..cb7a58e 100644
--- a/includes/filebackend/FileBackendMultiWrite.php
+++ b/includes/filebackend/FileBackendMultiWrite.php
@@ -125,8 +125,8 @@
// Alter certain sub-backend settings for sanity
unset( $config['readOnly'] ); // use proxy backend
setting
unset( $config['fileJournal'] ); // use proxy backend
journal
+ unset( $config['lockManager'] ); // lock under proxy
backend
$config['wikiId'] = $this->wikiId; // use the proxy
backend wiki ID
- $config['lockManager'] = 'nullLockManager'; // lock
under proxy backend
if ( !empty( $config['isMultiMaster'] ) ) {
if ( $this->masterIndex >= 0 ) {
throw new MWException( 'More than one
master backend defined.' );
diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php
b/tests/phpunit/includes/filebackend/FileBackendTest.php
index fcfa724..6043738 100644
--- a/tests/phpunit/includes/filebackend/FileBackendTest.php
+++ b/tests/phpunit/includes/filebackend/FileBackendTest.php
@@ -37,6 +37,7 @@
$useConfig['shardViaHashLevels'] = array( //
test sharding
'unittest-cont1' => array( 'levels' =>
1, 'base' => 16, 'repeat' => 1 )
);
+ $useConfig['lockManager'] =
LockManagerGroup::singleton()->get( $useConfig['lockManager'] );
$class = $useConfig['class'];
self::$backendToUse = new $class( $useConfig );
$this->singleBackend = self::$backendToUse;
@@ -44,7 +45,7 @@
} else {
$this->singleBackend = new FSFileBackend( array(
'name' => 'localtesting',
- 'lockManager' => 'fsLockManager',
+ 'lockManager' =>
LockManagerGroup::singleton()->get( 'fsLockManager' ),
#'parallelize' => 'implicit',
'wikiId' => wfWikiID() . $uniqueId,
'containerPaths' => array(
@@ -54,14 +55,13 @@
}
$this->multiBackend = new FileBackendMultiWrite( array(
'name' => 'localtesting',
- 'lockManager' => 'fsLockManager',
+ 'lockManager' => LockManagerGroup::singleton()->get(
'fsLockManager' ),
'parallelize' => 'implicit',
'wikiId' => wfWikiId() . $uniqueId,
'backends' => array(
array(
'name' => 'localmultitesting1',
'class' => 'FSFileBackend',
- 'lockManager' => 'nullLockManager',
'containerPaths' => array(
'unittest-cont1' =>
"{$tmpPrefix}-localtestingmulti1-cont1",
'unittest-cont2' =>
"{$tmpPrefix}-localtestingmulti1-cont2" ),
@@ -70,7 +70,6 @@
array(
'name' => 'localmultitesting2',
'class' => 'FSFileBackend',
- 'lockManager' => 'nullLockManager',
'containerPaths' => array(
'unittest-cont1' =>
"{$tmpPrefix}-localtestingmulti2-cont1",
'unittest-cont2' =>
"{$tmpPrefix}-localtestingmulti2-cont2" ),
--
To view, visit https://gerrit.wikimedia.org/r/97349
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I188a053c70ce088ce34613d5db40e6708e3ea9b7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits