BlobStore.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. namespace MediaWiki\Storage;
  23. use StatusValue;
  24. /**
  25. * Service for loading and storing data blobs.
  26. *
  27. * @note This was written to act as a drop-in replacement for the corresponding
  28. * static methods in Revision.
  29. *
  30. * @since 1.31
  31. */
  32. interface BlobStore {
  33. /**
  34. * Hint key for use with storeBlob, indicating the general role the block
  35. * takes in the application. For instance, it should be "page-content" if
  36. * the blob represents a Content object.
  37. */
  38. const DESIGNATION_HINT = 'designation';
  39. /**
  40. * Hint key for use with storeBlob, indicating the page the blob is associated with.
  41. * This may be used for sharding.
  42. */
  43. const PAGE_HINT = 'page_id';
  44. /**
  45. * Hint key for use with storeBlob, indicating the slot the blob is associated with.
  46. * May be relevant for reference counting.
  47. */
  48. const ROLE_HINT = 'role_name';
  49. /**
  50. * Hint key for use with storeBlob, indicating the revision the blob is associated with.
  51. * This may be used for differential storage and reference counting.
  52. */
  53. const REVISION_HINT = 'rev_id';
  54. /**
  55. * Hint key for use with storeBlob, indicating the parent revision of the revision
  56. * the blob is associated with. This may be used for differential storage.
  57. */
  58. const PARENT_HINT = 'rev_parent_id';
  59. /**
  60. * Hint key for use with storeBlob, providing the SHA1 hash of the blob as passed to the
  61. * method. This can be used to avoid re-calculating the hash if it is needed by the BlobStore.
  62. */
  63. const SHA1_HINT = 'cont_sha1';
  64. /**
  65. * Hint key for use with storeBlob, indicating the model of the content encoded in the
  66. * given blob. May be used to implement optimized storage for some well known models.
  67. */
  68. const MODEL_HINT = 'cont_model';
  69. /**
  70. * Hint key for use with storeBlob, indicating the serialization format used to create
  71. * the blob, as a MIME type. May be used for optimized storage in the underlying database.
  72. */
  73. const FORMAT_HINT = 'cont_format';
  74. /**
  75. * Retrieve a blob, given an address.
  76. *
  77. * MCR migration note: this replaces Revision::loadText
  78. *
  79. * @param string $blobAddress The blob address as returned by storeBlob(),
  80. * such as "tt:12345" or "ex:DB://s16/456/9876".
  81. * @param int $queryFlags See IDBAccessObject.
  82. *
  83. * @throws BlobAccessException
  84. * @return string binary blob data
  85. */
  86. public function getBlob( $blobAddress, $queryFlags = 0 );
  87. /**
  88. * A batched version of BlobStore::getBlob.
  89. *
  90. * @param string[] $blobAddresses An array of blob addresses.
  91. * @param int $queryFlags See IDBAccessObject.
  92. * @throws BlobAccessException
  93. * @return StatusValue A status with a map of blobAddress => binary blob data or null
  94. * if fetching the blob has failed. Fetch failures errors are the
  95. * warnings in the status object.
  96. * @since 1.34
  97. */
  98. public function getBlobBatch( $blobAddresses, $queryFlags = 0 );
  99. /**
  100. * Stores an arbitrary blob of data and returns an address that can be used with
  101. * getBlob() to retrieve the same blob of data,
  102. *
  103. * @param string $data raw binary data
  104. * @param array $hints An array of hints. Implementations may use the hints to optimize storage.
  105. * All hints are optional, supported hints depend on the implementation. Hint names by
  106. * convention correspond to the names of fields in the database. Callers are encouraged to
  107. * provide the well known hints as defined by the XXX_HINT constants.
  108. *
  109. * @throws BlobAccessException
  110. * @return string an address that can be used with getBlob() to retrieve the data.
  111. */
  112. public function storeBlob( $data, $hints = [] );
  113. /**
  114. * Check if the blob metadata or backing blob data store is read-only
  115. *
  116. * @return bool
  117. */
  118. public function isReadOnly();
  119. }