Index: trunk/phase3/includes/upload/UploadStash.php |
— | — | @@ -22,10 +22,6 @@ |
23 | 23 | // Format of the key for files -- has to be suitable as a filename itself (e.g. ab12cd34ef.jpg) |
24 | 24 | const KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/'; |
25 | 25 | |
26 | | - // When a given stashed file can't be loaded, wait for the slaves to catch up. If they're more than MAX_LAG |
27 | | - // behind, throw an exception instead. (at what point is broken better than slow?) |
28 | | - const MAX_LAG = 30; |
29 | | - |
30 | 26 | /** |
31 | 27 | * repository that this uses to store temp files |
32 | 28 | * public because we sometimes need to get a LocalFile within the same repo. |
— | — | @@ -98,23 +94,9 @@ |
99 | 95 | $dbr = $this->repo->getSlaveDb(); |
100 | 96 | |
101 | 97 | if ( !isset( $this->fileMetadata[$key] ) ) { |
102 | | - // try this first. if it fails to find the row, check for lag, wait, try again. if its still missing, throw an exception. |
103 | | - // this more complex solution keeps things moving for page loads with many requests |
104 | | - // (ie. validating image ownership) when replag is high |
105 | 98 | if ( !$this->fetchFileMetadata( $key ) ) { |
106 | | - $lag = $dbr->getLag(); |
107 | | - if ( $lag > 0 && $lag <= self::MAX_LAG ) { |
108 | | - // if there's not too much replication lag, just wait for the slave to catch up to our last insert. |
109 | | - sleep( ceil( $lag ) ); |
110 | | - } elseif ( $lag > self::MAX_LAG ) { |
111 | | - // that's a lot of lag to introduce into the middle of the UI. |
112 | | - throw new UploadStashMaxLagExceededException( |
113 | | - 'Couldn\'t load stashed file metadata, and replication lag is above threshold: (MAX_LAG=' . self::MAX_LAG . ')' |
114 | | - ); |
115 | | - } |
116 | | - |
117 | | - // now that the waiting has happened, try again |
118 | | - $this->fetchFileMetadata( $key ); |
| 99 | + // If nothing was received, it's likely due to replication lag. Check the master to see if the record is there. |
| 100 | + $this->fetchFileMetadata( $key, true ); |
119 | 101 | } |
120 | 102 | |
121 | 103 | if ( !isset( $this->fileMetadata[$key] ) ) { |
— | — | @@ -470,9 +452,16 @@ |
471 | 453 | * @param $key String: key |
472 | 454 | * @return boolean |
473 | 455 | */ |
474 | | - protected function fetchFileMetadata( $key ) { |
| 456 | + protected function fetchFileMetadata( $key, $readFromMaster = false ) { |
475 | 457 | // populate $fileMetadata[$key] |
476 | | - $dbr = $this->repo->getSlaveDb(); |
| 458 | + $dbr = null; |
| 459 | + if( $readFromMaster ) { |
| 460 | + // sometimes reading from the master is necessary, if there's replication lag. |
| 461 | + $dbr = $this->repo->getMasterDb(); |
| 462 | + } else { |
| 463 | + $dbr = $this->repo->getSlaveDb(); |
| 464 | + } |
| 465 | + |
477 | 466 | $row = $dbr->selectRow( |
478 | 467 | 'uploadstash', |
479 | 468 | '*', |
— | — | @@ -685,5 +674,4 @@ |
686 | 675 | class UploadStashZeroLengthFileException extends MWException {}; |
687 | 676 | class UploadStashNotLoggedInException extends MWException {}; |
688 | 677 | class UploadStashWrongOwnerException extends MWException {}; |
689 | | -class UploadStashMaxLagExceededException extends MWException {}; |
690 | 678 | class UploadStashNoSuchKeyException extends MWException {}; |