ShardManager.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\DBAL\Sharding;
  20. /**
  21. * Sharding Manager gives access to APIs to implementing sharding on top of
  22. * Doctrine\DBAL\Connection instances.
  23. *
  24. * For simplicity and developer ease-of-use (and understanding) the sharding
  25. * API only covers single shard queries, no fan-out support. It is primarily
  26. * suited for multi-tenant applications.
  27. *
  28. * The assumption about sharding here
  29. * is that a distribution value can be found that gives access to all the
  30. * necessary data for all use-cases. Switching between shards should be done with
  31. * caution, especially if lazy loading is implemented. Any query is always
  32. * executed against the last shard that was selected. If a query is created for
  33. * a shard Y but then a shard X is selected when its actually executed you
  34. * will hit the wrong shard.
  35. *
  36. * @author Benjamin Eberlei <kontakt@beberlei.de>
  37. */
  38. interface ShardManager
  39. {
  40. /**
  41. * Selects global database with global data.
  42. *
  43. * This is the default database that is connected when no shard is
  44. * selected.
  45. *
  46. * @return void
  47. */
  48. function selectGlobal();
  49. /**
  50. * Selects the shard against which the queries after this statement will be issued.
  51. *
  52. * @param string $distributionValue
  53. *
  54. * @return void
  55. *
  56. * @throws \Doctrine\DBAL\Sharding\ShardingException If no value is passed as shard identifier.
  57. */
  58. function selectShard($distributionValue);
  59. /**
  60. * Gets the distribution value currently used for sharding.
  61. *
  62. * @return string
  63. */
  64. function getCurrentDistributionValue();
  65. /**
  66. * Gets information about the amount of shards and other details.
  67. *
  68. * Format is implementation specific, each shard is one element and has an
  69. * 'id' attribute at least.
  70. *
  71. * @return array
  72. */
  73. function getShards();
  74. /**
  75. * Queries all shards in undefined order and return the results appended to
  76. * each other. Restore the previous distribution value after execution.
  77. *
  78. * Using {@link \Doctrine\DBAL\Connection::fetchAll} to retrieve rows internally.
  79. *
  80. * @param string $sql
  81. * @param array $params
  82. * @param array $types
  83. *
  84. * @return array
  85. */
  86. function queryAll($sql, array $params, array $types);
  87. }