* @param array $urls The URLs of the text to get
* @return array Map from url to its data. Data is either string when found
* or false on failure.
+ * @throws MWException
*/
public static function batchFetchFromURLs( array $urls ) {
$batches = [];
if ( $store === false ) {
throw new MWException( "Invalid external storage protocol - $storeUrl" );
}
+
try {
- $url = $store->store( $path, $data ); // Try to save the object
+ if ( $store->isReadOnly( $path ) ) {
+ $msg = 'read only';
+ } else {
+ $url = $store->store( $path, $data );
+ if ( strlen( $url ) ) {
+ return $url; // a store accepted the write; done!
+ }
+ $msg = 'operation failed';
+ }
} catch ( Exception $error ) {
- $url = false;
- }
- if ( strlen( $url ) ) {
- return $url; // Done!
- } else {
- unset( $tryStores[$index] ); // Don't try this one again!
- $tryStores = array_values( $tryStores ); // Must have consecutive keys
- wfDebugLog( 'ExternalStorage',
- "Unable to store text to external storage $storeUrl" );
+ $msg = 'caught exception';
}
+
+ unset( $tryStores[$index] ); // Don't try this one again!
+ $tryStores = array_values( $tryStores ); // Must have consecutive keys
+ wfDebugLog( 'ExternalStorage',
+ "Unable to store text to external storage $storeUrl ($msg)" );
}
// All stores failed
if ( $error ) {
return "DB://$location/$id";
}
+ public function isReadOnly( $location ) {
+ return ( $this->getLoadBalancer( $location )->getReadOnlyReason() !== false );
+ }
+
/**
* Get a LoadBalancer for the specified cluster
*
* @ingroup ExternalStorage
*/
class ExternalStoreHttp extends ExternalStoreMedium {
- /**
- * @see ExternalStoreMedium::fetchFromURL()
- * @param string $url
- * @return string|bool
- * @throws MWException
- */
public function fetchFromURL( $url ) {
return Http::get( $url, [], __METHOD__ );
}
- /**
- * @see ExternalStoreMedium::store()
- * @param string $cluster
- * @param string $data
- * @return string|bool
- * @throws MWException
- */
- public function store( $cluster, $data ) {
+ public function store( $location, $data ) {
throw new MWException( "ExternalStoreHttp is read-only and does not support store()." );
}
+
+ public function isReadOnly( $location ) {
+ return true;
+ }
}
* @throws MWException
*/
abstract public function store( $location, $data );
+
+ /**
+ * Check if a given location is read-only
+ *
+ * @param string $location The location name
+ * @return bool Whether this location is read-only
+ * @since 1.31
+ */
+ public function isReadOnly( $location ) {
+ return false;
+ }
}
return $blobs;
}
- /**
- * @see ExternalStoreMedium::store()
- * @param string $backend
- * @param string $data
- * @return string|bool
- * @throws MWException
- */
public function store( $backend, $data ) {
$be = FileBackendGroup::singleton()->get( $backend );
if ( $be instanceof FileBackend ) {
return false;
}
+
+ public function isReadOnly( $backend ) {
+ $be = FileBackendGroup::singleton()->get( $backend );
+
+ return $be ? $be->isReadOnly() : false;
+ }
}