ShardManager.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Doctrine\DBAL\Sharding;
  3. /**
  4. * Sharding Manager gives access to APIs to implementing sharding on top of
  5. * Doctrine\DBAL\Connection instances.
  6. *
  7. * For simplicity and developer ease-of-use (and understanding) the sharding
  8. * API only covers single shard queries, no fan-out support. It is primarily
  9. * suited for multi-tenant applications.
  10. *
  11. * The assumption about sharding here
  12. * is that a distribution value can be found that gives access to all the
  13. * necessary data for all use-cases. Switching between shards should be done with
  14. * caution, especially if lazy loading is implemented. Any query is always
  15. * executed against the last shard that was selected. If a query is created for
  16. * a shard Y but then a shard X is selected when its actually executed you
  17. * will hit the wrong shard.
  18. *
  19. * @deprecated
  20. */
  21. interface ShardManager
  22. {
  23. /**
  24. * Selects global database with global data.
  25. *
  26. * This is the default database that is connected when no shard is
  27. * selected.
  28. *
  29. * @return void
  30. */
  31. public function selectGlobal();
  32. /**
  33. * Selects the shard against which the queries after this statement will be issued.
  34. *
  35. * @param string $distributionValue
  36. *
  37. * @return void
  38. *
  39. * @throws ShardingException If no value is passed as shard identifier.
  40. */
  41. public function selectShard($distributionValue);
  42. /**
  43. * Gets the distribution value currently used for sharding.
  44. *
  45. * @return string|null
  46. */
  47. public function getCurrentDistributionValue();
  48. /**
  49. * Gets information about the amount of shards and other details.
  50. *
  51. * Format is implementation specific, each shard is one element and has an
  52. * 'id' attribute at least.
  53. *
  54. * @return mixed[][]
  55. */
  56. public function getShards();
  57. /**
  58. * Queries all shards in undefined order and return the results appended to
  59. * each other. Restore the previous distribution value after execution.
  60. *
  61. * Using {@link Connection::fetchAll()} to retrieve rows internally.
  62. *
  63. * @param string $sql
  64. * @param mixed[] $params
  65. * @param int[]|string[] $types
  66. *
  67. * @return mixed[]
  68. */
  69. public function queryAll($sql, array $params, array $types);
  70. }