MediaWiki  1.23.2
ChronologyProtector.php
Go to the documentation of this file.
1 <?php
30  protected $startupPositions = array();
31 
33  protected $shutdownPositions = array();
34 
36  protected $initialized = false;
37 
49  public function initLB( LoadBalancer $lb ) {
50  if ( $lb->getServerCount() <= 1 ) {
51  return; // non-replicated setup
52  }
53  if ( !$this->initialized ) {
54  $this->initialized = true;
55  if ( isset( $_SESSION[__CLASS__] ) && is_array( $_SESSION[__CLASS__] ) ) {
56  $this->startupPositions = $_SESSION[__CLASS__];
57  }
58  }
59  $masterName = $lb->getServerName( 0 );
60  if ( !empty( $this->startupPositions[$masterName] ) ) {
61  $info = $lb->parentInfo();
62  $pos = $this->startupPositions[$masterName];
63  wfDebug( __METHOD__ . ": LB " . $info['id'] . " waiting for master pos $pos\n" );
64  $lb->waitFor( $pos );
65  }
66  }
67 
75  public function shutdownLB( LoadBalancer $lb ) {
76  if ( session_id() == '' || $lb->getServerCount() <= 1 ) {
77  return; // don't start a session; don't bother with non-replicated setups
78  }
79  $masterName = $lb->getServerName( 0 );
80  if ( isset( $this->shutdownPositions[$masterName] ) ) {
81  return; // already done
82  }
83  // Only save the position if writes have been done on the connection
84  $db = $lb->getAnyOpenConnection( 0 );
85  $info = $lb->parentInfo();
86  if ( !$db || !$db->doneWrites() ) {
87  wfDebug( __METHOD__ . ": LB {$info['id']}, no writes done\n" );
88 
89  return;
90  }
91  $pos = $db->getMasterPos();
92  wfDebug( __METHOD__ . ": LB {$info['id']} has master pos $pos\n" );
93  $this->shutdownPositions[$masterName] = $pos;
94  }
95 
102  public function shutdown() {
103  if ( session_id() != '' && count( $this->shutdownPositions ) ) {
104  wfDebug( __METHOD__ . ": saving master pos for " .
105  count( $this->shutdownPositions ) . " master(s)\n" );
106  $_SESSION[__CLASS__] = $this->shutdownPositions;
107  }
108  }
109 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ChronologyProtector\$startupPositions
array $startupPositions
(DB master name => position) *
Definition: ChronologyProtector.php:29
ChronologyProtector
Class for ensuring a consistent ordering of events as seen by the user, despite replication.
Definition: ChronologyProtector.php:28
$lb
if( $wgAPIRequestLog) $lb
Definition: api.php:126
ChronologyProtector\initLB
initLB(LoadBalancer $lb)
Initialise a LoadBalancer to give it appropriate chronology protection.
Definition: ChronologyProtector.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
LoadBalancer
Database load balancing object.
Definition: LoadBalancer.php:30
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
ChronologyProtector\$shutdownPositions
array $shutdownPositions
(DB master name => position) *
Definition: ChronologyProtector.php:31
ChronologyProtector\shutdownLB
shutdownLB(LoadBalancer $lb)
Notify the ChronologyProtector that the LoadBalancer is about to shut down.
Definition: ChronologyProtector.php:72
ChronologyProtector\$initialized
bool $initialized
Whether the session data was loaded *.
Definition: ChronologyProtector.php:33
ChronologyProtector\shutdown
shutdown()
Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now.
Definition: ChronologyProtector.php:99