Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
ReplicationReporter.php
Go to the documentation of this file.
1<?php
20namespaceWikimedia\Rdbms\Replication;
21
22use Psr\Log\LoggerInterface;
23useWikimedia\ObjectCache\BagOStuff;
24useWikimedia\Rdbms\DBError;
25useWikimedia\Rdbms\DBPrimaryPos;
26useWikimedia\Rdbms\IDatabase;
27
33classReplicationReporter {
35protected$topologyRole;
37protected$logger;
39protected$srvCache;
41private $trxReplicaLagStatus =null;
42
49 $this->topologyRole =$topologyRole;
50 $this->logger =$logger;
51 $this->srvCache =$srvCache;
52 }
53
57publicfunctiongetTopologyRole() {
59 }
60
64publicfunctiongetLag(IDatabase $conn ) {
65if ( $this->topologyRole ===IDatabase::ROLE_STREAMING_MASTER ) {
66return 0;// this is the primary DB
67 } elseif ( $this->topologyRole ===IDatabase::ROLE_STATIC_CLONE ) {
68return 0;// static dataset
69 }
70
71return $this->doGetLag( $conn );
72 }
73
85protectedfunctiondoGetLag(IDatabase $conn ) {
86return 0;
87 }
88
98protectedfunctiongetApproximateLagStatus(IDatabase $conn ) {
99if ( $this->topologyRole ===IDatabase::ROLE_STREAMING_REPLICA ) {
100// Avoid exceptions as this is used internally in critical sections
101try {
102 $lag = $this->getLag( $conn );
103 }catch (DBError ) {
104 $lag =false;
105 }
106 }else {
107 $lag = 0;
108 }
109
110return ['lag' => $lag,'since' => microtime(true ) ];
111 }
112
119publicfunctionprimaryPosWait(IDatabase $conn,DBPrimaryPos $pos, $timeout ) {
120// Real waits are implemented in the subclass.
121return 0;
122 }
123
127publicfunctiongetReplicaPos(IDatabase $conn ) {
128// Stub
129returnfalse;
130 }
131
135publicfunctiongetPrimaryPos(IDatabase $conn ) {
136// Stub
137returnfalse;
138 }
139
144if ( $this->topologyRole ===IDatabase::ROLE_STREAMING_REPLICA ) {
145return ['Server is configured as a read-only replica database.','role' ];
146 } elseif ( $this->topologyRole ===IDatabase::ROLE_STATIC_CLONE ) {
147return ['Server is configured as a read-only static clone database.','role' ];
148 }
149
150returnnull;
151 }
152
154// With REPEATABLE-READ isolation, the first SELECT establishes the read snapshot,
155// so get the replication lag estimate before any transaction SELECT queries come in.
156// This way, the lag estimate reflects what will actually be read. Also, if heartbeat
157// tables are used, this avoids counting snapshot lag as part of replication lag.
158 $this->trxReplicaLagStatus =null;// clear cached value first
159 $this->trxReplicaLagStatus = $this->getApproximateLagStatus( $conn );
160 }
161
177finalprotectedfunctiongetRecordedTransactionLagStatus(IDatabase $conn ) {
178return $conn->trxLevel() ? $this->trxReplicaLagStatus :null;
179 }
180
184publicfunctiongetSessionLagStatus(IDatabase $conn ) {
185return $this->getRecordedTransactionLagStatus( $conn ) ?: $this->getApproximateLagStatus( $conn );
186 }
187
195protectedfunctiongetLogContext(IDatabase $conn, array $extras = [] ) {
196return array_merge(
197 [
198'db_server' => $conn->getServerName(),
199'db_name' => $conn->getDBname(),
200// TODO: Add db_user
201 ],
202 $extras
203 );
204 }
205}
Wikimedia\ObjectCache\BagOStuff
Abstract class for any ephemeral data store.
DefinitionBagOStuff.php:87
Wikimedia\Rdbms\DBError
Database error base class.
DefinitionDBError.php:36
Wikimedia\Rdbms\Replication\ReplicationReporter
DefinitionReplicationReporter.php:33
Wikimedia\Rdbms\Replication\ReplicationReporter\getSessionLagStatus
getSessionLagStatus(IDatabase $conn)
DefinitionReplicationReporter.php:184
Wikimedia\Rdbms\Replication\ReplicationReporter\$srvCache
BagOStuff $srvCache
DefinitionReplicationReporter.php:39
Wikimedia\Rdbms\Replication\ReplicationReporter\$logger
LoggerInterface $logger
DefinitionReplicationReporter.php:37
Wikimedia\Rdbms\Replication\ReplicationReporter\primaryPosWait
primaryPosWait(IDatabase $conn, DBPrimaryPos $pos, $timeout)
DefinitionReplicationReporter.php:119
Wikimedia\Rdbms\Replication\ReplicationReporter\getPrimaryPos
getPrimaryPos(IDatabase $conn)
DefinitionReplicationReporter.php:135
Wikimedia\Rdbms\Replication\ReplicationReporter\getTopologyBasedReadOnlyReason
getTopologyBasedReadOnlyReason()
DefinitionReplicationReporter.php:143
Wikimedia\Rdbms\Replication\ReplicationReporter\getLogContext
getLogContext(IDatabase $conn, array $extras=[])
Create a log context to pass to PSR-3 logger functions.
DefinitionReplicationReporter.php:195
Wikimedia\Rdbms\Replication\ReplicationReporter\__construct
__construct( $topologyRole, $logger, $srvCache)
DefinitionReplicationReporter.php:48
Wikimedia\Rdbms\Replication\ReplicationReporter\resetReplicationLagStatus
resetReplicationLagStatus(IDatabase $conn)
DefinitionReplicationReporter.php:153
Wikimedia\Rdbms\Replication\ReplicationReporter\doGetLag
doGetLag(IDatabase $conn)
Get the amount of replication lag for this database server.
DefinitionReplicationReporter.php:85
Wikimedia\Rdbms\Replication\ReplicationReporter\getReplicaPos
getReplicaPos(IDatabase $conn)
DefinitionReplicationReporter.php:127
Wikimedia\Rdbms\Replication\ReplicationReporter\getApproximateLagStatus
getApproximateLagStatus(IDatabase $conn)
Get a replica DB lag estimate for this server at the start of a transaction.
DefinitionReplicationReporter.php:98
Wikimedia\Rdbms\Replication\ReplicationReporter\$topologyRole
string $topologyRole
Replication topology role of the server; one of the class ROLE_* constants.
DefinitionReplicationReporter.php:35
Wikimedia\Rdbms\Replication\ReplicationReporter\getTopologyRole
getTopologyRole()
DefinitionReplicationReporter.php:57
Wikimedia\Rdbms\Replication\ReplicationReporter\getRecordedTransactionLagStatus
getRecordedTransactionLagStatus(IDatabase $conn)
Get the replica DB lag when the current transaction started.
DefinitionReplicationReporter.php:177
Wikimedia\Rdbms\Replication\ReplicationReporter\getLag
getLag(IDatabase $conn)
DefinitionReplicationReporter.php:64
Wikimedia\Rdbms\DBPrimaryPos
An object representing a primary or replica DB position in a replicated setup.
DefinitionDBPrimaryPos.php:14
Wikimedia\Rdbms\IDatabase
Interface to a relational database.
DefinitionIDatabase.php:45
Wikimedia\Rdbms\IDatabase\ROLE_STREAMING_MASTER
const ROLE_STREAMING_MASTER
Primary server than can stream writes to replica servers.
DefinitionIDatabase.php:108
Wikimedia\Rdbms\IDatabase\ROLE_STATIC_CLONE
const ROLE_STATIC_CLONE
Replica server within a static dataset.
DefinitionIDatabase.php:112
Wikimedia\Rdbms\IDatabase\ROLE_STREAMING_REPLICA
const ROLE_STREAMING_REPLICA
Replica server that receives writes from a primary server.
DefinitionIDatabase.php:110
Wikimedia\Rdbms\IDatabase\trxLevel
trxLevel()
Gets the current transaction level.
Wikimedia\Rdbms\IReadableDatabase\getDBname
getDBname()
Get the current database name; null if there isn't one.
Wikimedia\Rdbms\IReadableDatabase\getServerName
getServerName()
Get the readable name for the server.
Wikimedia\Rdbms\Replication
DefinitionMysqlReplicationReporter.php:20

[8]ページ先頭

©2009-2025 Movatter.jp