- private function masterRunningReadOnly( $domain, IDatabase $conn = null ) {
- $cache = $this->wanCache;
- $masterServer = $this->getServerName( $this->getWriterIndex() );
+ private function isMasterConnectionReadOnly( IDatabase $conn, $flags = 0 ) {
+ // Note that table prefixes are not related to server-side read-only mode
+ $key = $this->srvCache->makeGlobalKey(
+ 'rdbms-server-readonly',
+ $conn->getServer(),
+ $conn->getDBname(),
+ $conn->dbSchema()
+ );
+
+ if ( ( $flags & self::CONN_REFRESH_READ_ONLY ) == self::CONN_REFRESH_READ_ONLY ) {
+ try {
+ $readOnly = (int)$conn->serverIsReadOnly();
+ } catch ( DBError $e ) {
+ $readOnly = 0;
+ }
+ $this->srvCache->set( $key, $readOnly, BagOStuff::TTL_PROC_SHORT );
+ } else {
+ $readOnly = $this->srvCache->getWithSetCallback(
+ $key,
+ BagOStuff::TTL_PROC_SHORT,
+ function () use ( $conn ) {
+ try {
+ return (int)$conn->serverIsReadOnly();
+ } catch ( DBError $e ) {
+ return 0;
+ }
+ }
+ );
+ }