ShardManager.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. use Doctrine\DBAL\Connection;
  21. /**
  22. * Sharding Manager gives access to APIs to implementing sharding on top of
  23. * Doctrine\DBAL\Connection instances.
  24. *
  25. * For simplicity and developer ease-of-use (and understanding) the sharding
  26. * API only covers single shard queries, no fan-out support. It is primarily
  27. * suited for multi-tenant applications.
  28. *
  29. * The assumption about sharding here
  30. * is that a distribution value can be found that gives access to all the
  31. * necessary data for all use-cases. Switching between shards should be done with
  32. * caution, especially if lazy loading is implemented. Any query is always
  33. * executed against the last shard that was selected. If a query is created for
  34. * a shard Y but then a shard X is selected when its actually excecuted you
  35. * will hit the wrong shard.
  36. *
  37. * @author Benjamin Eberlei <kontakt@beberlei.de>
  38. */
  39. interface ShardManager
  40. {
  41. /**
  42. * Select global database with global data.
  43. *
  44. * This is the default database that is connected when no shard is
  45. * selected.
  46. *
  47. * @return void
  48. */
  49. function selectGlobal();
  50. /**
  51. * SELECT queries after this statement will be issued against the selected
  52. * shard.
  53. *
  54. * @throws ShardingException If no value is passed as shard identifier.
  55. * @param mixed $distributionValue
  56. * @param array $options
  57. * @return void
  58. */
  59. function selectShard($distributionValue);
  60. /**
  61. * Get the distribution value currently used for sharding.
  62. *
  63. * @return string
  64. */
  65. function getCurrentDistributionValue();
  66. /**
  67. * Get information about the amount of shards and other details.
  68. *
  69. * Format is implementation specific, each shard is one element and has a
  70. * 'name' attribute at least.
  71. *
  72. * @return array
  73. */
  74. function getShards();
  75. /**
  76. * Query all shards in undefined order and return the results appended to
  77. * each other. Restore the previous distribution value after execution.
  78. *
  79. * Using {@link Connection::fetchAll} to retrieve rows internally.
  80. *
  81. * @param string $sql
  82. * @param array $params
  83. * @param array $types
  84. * @return array
  85. */
  86. function queryAll($sql, array $params, array $types);
  87. }