MediaWiki  1.28.1
MySqlLockManager.php
Go to the documentation of this file.
1 <?php
16  protected $lockTypeMap = [
17  self::LOCK_SH => self::LOCK_SH,
18  self::LOCK_UW => self::LOCK_SH,
19  self::LOCK_EX => self::LOCK_EX
20  ];
21 
22  public function __construct( array $config ) {
23  parent::__construct( $config );
24 
25  $this->session = substr( $this->session, 0, 31 ); // fit to field
26  }
27 
28  protected function initConnection( $lockDb, IDatabase $db ) {
29  # Let this transaction see lock rows from other transactions
30  $db->query( "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;" );
31  # Do everything in a transaction as it all gets rolled back eventually
32  $db->startAtomic( __CLASS__ );
33  }
34 
45  protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
47 
48  $db = $this->getConnection( $lockSrv ); // checked in isServerUp()
49 
50  $keys = []; // list of hash keys for the paths
51  $data = []; // list of rows to insert
52  $checkEXKeys = []; // list of hash keys that this has no EX lock on
53  # Build up values for INSERT clause
54  foreach ( $paths as $path ) {
55  $key = $this->sha1Base36Absolute( $path );
56  $keys[] = $key;
57  $data[] = [ 'fls_key' => $key, 'fls_session' => $this->session ];
58  if ( !isset( $this->locksHeld[$path][self::LOCK_EX] ) ) {
59  $checkEXKeys[] = $key; // this has no EX lock on $key itself
60  }
61  }
62 
63  # Block new writers (both EX and SH locks leave entries here)...
64  $db->insert( 'filelocks_shared', $data, __METHOD__, [ 'IGNORE' ] );
65  # Actually do the locking queries...
66  if ( $type == self::LOCK_SH ) { // reader locks
67  # Bail if there are any existing writers...
68  if ( count( $checkEXKeys ) ) {
69  $blocked = $db->selectField(
70  'filelocks_exclusive',
71  '1',
72  [ 'fle_key' => $checkEXKeys ],
73  __METHOD__
74  );
75  } else {
76  $blocked = false;
77  }
78  # Other prospective writers that haven't yet updated filelocks_exclusive
79  # will recheck filelocks_shared after doing so and bail due to this entry.
80  } else { // writer locks
81  $encSession = $db->addQuotes( $this->session );
82  # Bail if there are any existing writers...
83  # This may detect readers, but the safe check for them is below.
84  # Note: if two writers come at the same time, both bail :)
85  $blocked = $db->selectField(
86  'filelocks_shared',
87  '1',
88  [ 'fls_key' => $keys, "fls_session != $encSession" ],
89  __METHOD__
90  );
91  if ( !$blocked ) {
92  # Build up values for INSERT clause
93  $data = [];
94  foreach ( $keys as $key ) {
95  $data[] = [ 'fle_key' => $key ];
96  }
97  # Block new readers/writers...
98  $db->insert( 'filelocks_exclusive', $data, __METHOD__ );
99  # Bail if there are any existing readers...
100  $blocked = $db->selectField(
101  'filelocks_shared',
102  '1',
103  [ 'fls_key' => $keys, "fls_session != $encSession" ],
104  __METHOD__
105  );
106  }
107  }
108 
109  if ( $blocked ) {
110  foreach ( $paths as $path ) {
111  $status->fatal( 'lockmanager-fail-acquirelock', $path );
112  }
113  }
114 
115  return $status;
116  }
117 
122  protected function releaseAllLocks() {
124 
125  foreach ( $this->conns as $lockDb => $db ) {
126  if ( $db->trxLevel() ) { // in transaction
127  try {
128  $db->rollback( __METHOD__ ); // finish transaction and kill any rows
129  } catch ( DBError $e ) {
130  $status->fatal( 'lockmanager-fail-db-release', $lockDb );
131  }
132  }
133  }
134 
135  return $status;
136  }
137 }
initConnection($lockDb, IDatabase $db)
sha1Base36Absolute($path)
Get the base 36 SHA-1 of a string, padded to 31 digits.
Database error base class.
Definition: DBError.php:26
the array() calling protocol came about after MediaWiki 1.4rc1.
doGetLocksOnServer($lockSrv, array $paths, $type)
Get a connection to a lock DB and acquire locks on $paths.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:2102
query($sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Version of LockManager based on using named/row DB locks.
string $session
Random 32-char hex number.
Definition: LockManager.php:65
array $lockTypeMap
Mapping of lock types to the type actually used.
static newGood($value=null)
Factory function for good results.
Definition: StatusValue.php:76
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
startAtomic($fname=__METHOD__)
Begin an atomic section of statements.
MySQL version of DBLockManager that supports shared locks.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getConnection($lockDb)
Get (or reuse) a connection to a lock DB.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1046
__construct(array $config)
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2491
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:34