ExternalStorage::insertWithFallback is reported to return false on
failure, but it doesn't. It has a single exit point, and return value is
checked with strlen(), so actually it can only return the URL or throw.
Thus, update any related doc and remove a redundant check from code
calling insertToDefault.
Change-Id: Ic95c3aed19118b987aef105f8077d55558f39127
if ( $this->useExternalStore ) {
// Store and get the URL
$data = ExternalStore::insertToDefault( $data );
if ( $this->useExternalStore ) {
// Store and get the URL
$data = ExternalStore::insertToDefault( $data );
- if ( !$data ) {
- throw new BlobAccessException( "Failed to store text to external storage" );
- }
if ( $flags ) {
$flags .= ',';
}
if ( $flags ) {
$flags .= ',';
}
*
* @param string $data
* @param array $params Map of ExternalStoreMedium::__construct context parameters
*
* @param string $data
* @param array $params Map of ExternalStoreMedium::__construct context parameters
- * @return string|bool The URL of the stored data item, or false on error
+ * @return string The URL of the stored data item
* @throws MWException
*/
public static function insertToDefault( $data, array $params = [] ) {
* @throws MWException
*/
public static function insertToDefault( $data, array $params = [] ) {
* @param array $tryStores Refer to $wgDefaultExternalStore
* @param string $data
* @param array $params Map of ExternalStoreMedium::__construct context parameters
* @param array $tryStores Refer to $wgDefaultExternalStore
* @param string $data
* @param array $params Map of ExternalStoreMedium::__construct context parameters
- * @return string|bool The URL of the stored data item, or false on error
+ * @return string The URL of the stored data item
* @throws MWException
*/
public static function insertWithFallback( array $tryStores, $data, array $params = [] ) {
* @throws MWException
*/
public static function insertWithFallback( array $tryStores, $data, array $params = [] ) {
/**
* @param string $data
* @param string $wiki
/**
* @param string $data
* @param string $wiki
- * @return string|bool The URL of the stored data item, or false on error
+ * @return string The URL of the stored data item
* @throws MWException
*/
public static function insertToForeignDefault( $data, $wiki ) {
* @throws MWException
*/
public static function insertToForeignDefault( $data, $wiki ) {
+ /**
+ * @inheritDoc
+ */
public function store( $location, $data ) {
$dbw = $this->getMaster( $location );
$dbw->insert( $this->getTable( $dbw ),
public function store( $location, $data ) {
$dbw = $this->getMaster( $location );
$dbw->insert( $this->getTable( $dbw ),
return "DB://$location/$id";
}
return "DB://$location/$id";
}
+ /**
+ * @inheritDoc
+ */
public function isReadOnly( $location ) {
$lb = $this->getLoadBalancer( $location );
$domainId = $this->getDomainId( $lb->getServerInfo( $lb->getWriterIndex() ) );
public function isReadOnly( $location ) {
$lb = $this->getLoadBalancer( $location );
$domainId = $this->getDomainId( $lb->getServerInfo( $lb->getWriterIndex() ) );
+ /**
+ * @inheritDoc
+ */
public function store( $backend, $data ) {
$be = FileBackendGroup::singleton()->get( $backend );
public function store( $backend, $data ) {
$be = FileBackendGroup::singleton()->get( $backend );
- if ( $be instanceof FileBackend ) {
- // Get three random base 36 characters to act as shard directories
- $rand = Wikimedia\base_convert( mt_rand( 0, 46655 ), 10, 36, 3 );
- // Make sure ID is roughly lexicographically increasing for performance
- $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT );
- // Segregate items by wiki ID for the sake of bookkeeping
- // @FIXME: this does not include the domain for b/c but it ideally should
- $wiki = $this->params['wiki'] ?? wfWikiID();
+ // Get three random base 36 characters to act as shard directories
+ $rand = Wikimedia\base_convert( mt_rand( 0, 46655 ), 10, 36, 3 );
+ // Make sure ID is roughly lexicographically increasing for performance
+ $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT );
+ // Segregate items by wiki ID for the sake of bookkeeping
+ // @FIXME: this does not include the domain for b/c but it ideally should
+ $wiki = $this->params['wiki'] ?? wfWikiID();
- $url = $be->getContainerStoragePath( 'data' ) . '/' . rawurlencode( $wiki );
- $url .= ( $be instanceof FSFileBackend )
- ? "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}" // keep directories small
- : "/{$rand[0]}/{$rand[1]}/{$id}"; // container sharding is only 2-levels
+ $url = $be->getContainerStoragePath( 'data' ) . '/' . rawurlencode( $wiki );
+ $url .= ( $be instanceof FSFileBackend )
+ ? "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}" // keep directories small
+ : "/{$rand[0]}/{$rand[1]}/{$id}"; // container sharding is only 2-levels
- $be->prepare( [ 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ] );
- if ( $be->create( [ 'dst' => $url, 'content' => $data ] )->isOK() ) {
- return $url;
- }
- }
+ $be->prepare( [ 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ] );
+ $status = $be->create( [ 'dst' => $url, 'content' => $data ] );
+ if ( $status->isOK() ) {
+ return $url;
+ } else {
+ throw new MWException( __METHOD__ . ": operation failed: $status" );
+ }
}
public function isReadOnly( $backend ) {
}
public function isReadOnly( $backend ) {
if ( $wgDefaultExternalStore ) {
$data = ExternalStore::insertToDefault( $data );
if ( $wgDefaultExternalStore ) {
$data = ExternalStore::insertToDefault( $data );
- if ( !$data ) {
- throw new MWException( "Unable to store text to external storage" );
- }
if ( $flags ) {
$flags .= ',';
}
if ( $flags ) {
$flags .= ',';
}