Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / Storage / BlobStore.php
1 <?php
2 /**
3 * Service for loading and storing data blobs.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Storage;
24
25 use StatusValue;
26
27 /**
28 * Service for loading and storing data blobs.
29 *
30 * @note This was written to act as a drop-in replacement for the corresponding
31 * static methods in Revision.
32 *
33 * @since 1.31
34 */
35 interface BlobStore {
36
37 /**
38 * Hint key for use with storeBlob, indicating the general role the block
39 * takes in the application. For instance, it should be "page-content" if
40 * the blob represents a Content object.
41 */
42 const DESIGNATION_HINT = 'designation';
43
44 /**
45 * Hint key for use with storeBlob, indicating the page the blob is associated with.
46 * This may be used for sharding.
47 */
48 const PAGE_HINT = 'page_id';
49
50 /**
51 * Hint key for use with storeBlob, indicating the slot the blob is associated with.
52 * May be relevant for reference counting.
53 */
54 const ROLE_HINT = 'role_name';
55
56 /**
57 * Hint key for use with storeBlob, indicating the revision the blob is associated with.
58 * This may be used for differential storage and reference counting.
59 */
60 const REVISION_HINT = 'rev_id';
61
62 /**
63 * Hint key for use with storeBlob, indicating the parent revision of the revision
64 * the blob is associated with. This may be used for differential storage.
65 */
66 const PARENT_HINT = 'rev_parent_id';
67
68 /**
69 * Hint key for use with storeBlob, providing the SHA1 hash of the blob as passed to the
70 * method. This can be used to avoid re-calculating the hash if it is needed by the BlobStore.
71 */
72 const SHA1_HINT = 'cont_sha1';
73
74 /**
75 * Hint key for use with storeBlob, indicating the model of the content encoded in the
76 * given blob. May be used to implement optimized storage for some well known models.
77 */
78 const MODEL_HINT = 'cont_model';
79
80 /**
81 * Hint key for use with storeBlob, indicating the serialization format used to create
82 * the blob, as a MIME type. May be used for optimized storage in the underlying database.
83 */
84 const FORMAT_HINT = 'cont_format';
85
86 /**
87 * Retrieve a blob, given an address.
88 *
89 * MCR migration note: this replaces Revision::loadText
90 *
91 * @param string $blobAddress The blob address as returned by storeBlob(),
92 * such as "tt:12345" or "ex:DB://s16/456/9876".
93 * @param int $queryFlags See IDBAccessObject.
94 *
95 * @throws BlobAccessException
96 * @return string binary blob data
97 */
98 public function getBlob( $blobAddress, $queryFlags = 0 );
99
100 /**
101 * A batched version of BlobStore::getBlob.
102 *
103 * @param string[] $blobAddresses An array of blob addresses.
104 * @param int $queryFlags See IDBAccessObject.
105 * @throws BlobAccessException
106 * @return StatusValue A status with a map of blobAddress => binary blob data or null
107 * if fetching the blob has failed. Fetch failures errors are the
108 * warnings in the status object.
109 * @since 1.34
110 */
111 public function getBlobBatch( $blobAddresses, $queryFlags = 0 );
112
113 /**
114 * Stores an arbitrary blob of data and returns an address that can be used with
115 * getBlob() to retrieve the same blob of data,
116 *
117 * @param string $data raw binary data
118 * @param array $hints An array of hints. Implementations may use the hints to optimize storage.
119 * All hints are optional, supported hints depend on the implementation. Hint names by
120 * convention correspond to the names of fields in the database. Callers are encouraged to
121 * provide the well known hints as defined by the XXX_HINT constants.
122 *
123 * @throws BlobAccessException
124 * @return string an address that can be used with getBlob() to retrieve the data.
125 */
126 public function storeBlob( $data, $hints = [] );
127
128 /**
129 * Check if the blob metadata or backing blob data store is read-only
130 *
131 * @return bool
132 */
133 public function isReadOnly();
134 }